xref: /titanic_44/usr/src/uts/i86pc/sys/machprivregs.h (revision 5151fb1220e0ceafdc172203863c73da4285c170)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MACHPRIVREGS_H
28 #define	_SYS_MACHPRIVREGS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Platform dependent instruction sequences for manipulating
34  * privileged state
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define	ASSERT_UPCALL_MASK_IS_SET		/* empty */
42 
43 /*
44  * CLI and STI
45  */
46 
47 #define	CLI(r)			\
48 	cli
49 
50 #define	STI			\
51 	sti
52 
53 /*
54  * Used to re-enable interrupts in the body of exception handlers
55  */
56 
57 #if defined(__amd64)
58 
59 #define	ENABLE_INTR_FLAGS		\
60 	pushq	$F_ON;			\
61 	popfq
62 
63 #elif defined(__i386)
64 
65 #define	ENABLE_INTR_FLAGS		\
66 	pushl	$F_ON;			\
67 	popfl
68 
69 #endif	/* __i386 */
70 
71 /*
72  * IRET and SWAPGS
73  */
74 #if defined(__amd64)
75 
76 #define	IRET	iretq
77 #define	SWAPGS	swapgs
78 
79 #elif defined(__i386)
80 
81 #define	IRET	iret
82 
83 #endif	/* __i386 */
84 
85 #define	CLEAN_CS	/* empty */
86 
87 /*
88  * Macros for saving the original segment registers and restoring them
89  * for fast traps.
90  */
91 #if defined(__amd64)
92 
93 /*
94  * Smaller versions of INTR_PUSH and INTR_POP for fast traps.
95  * The following registers have been pushed onto the stack by
96  * hardware at this point:
97  *
98  *	greg_t  r_rip;
99  *	greg_t  r_cs;
100  *	greg_t  r_rfl;
101  *	greg_t  r_rsp;
102  *	greg_t  r_ss;
103  *
104  * This handler is executed both by 32-bit and 64-bit applications.
105  * 64-bit applications allow us to treat the set (%rdi, %rsi, %rdx,
106  * %rcx, %r8, %r9, %r10, %r11, %rax) as volatile across function calls.
107  * However, 32-bit applications only expect (%eax, %edx, %ecx) to be volatile
108  * across a function call -- in particular, %esi and %edi MUST be saved!
109  *
110  * We could do this differently by making a FAST_INTR_PUSH32 for 32-bit
111  * programs, and FAST_INTR_PUSH for 64-bit programs, but it doesn't seem
112  * particularly worth it.
113  */
114 #define	FAST_INTR_PUSH			\
115 	INTGATE_INIT_KERNEL_FLAGS;	\
116 	subq	$REGOFF_RIP, %rsp;	\
117 	movq	%rsi, REGOFF_RSI(%rsp);	\
118 	movq	%rdi, REGOFF_RDI(%rsp);	\
119 	swapgs
120 
121 #define	FAST_INTR_POP			\
122 	swapgs;				\
123 	movq	REGOFF_RSI(%rsp), %rsi;	\
124 	movq	REGOFF_RDI(%rsp), %rdi;	\
125 	addq	$REGOFF_RIP, %rsp
126 
127 #define	FAST_INTR_RETURN	iretq
128 
129 #elif defined(__i386)
130 
131 #define	FAST_INTR_PUSH          \
132 	cld;                    \
133 	__SEGREGS_PUSH          \
134 	__SEGREGS_LOAD_KERNEL
135 
136 #define	FAST_INTR_POP		\
137 	__SEGREGS_POP
138 
139 #define	FAST_INTR_RETURN	iret
140 
141 #endif	/* __i386 */
142 
143 /*
144  * Handling the CR0.TS bit for floating point handling.
145  *
146  * When the TS bit is *set*, attempts to touch the floating
147  * point hardware will result in a #nm trap.
148  */
149 #if defined(__amd64)
150 
151 #define	STTS(rtmp)		\
152 	movq	%cr0, rtmp;	\
153 	orq	$CR0_TS, rtmp;	\
154 	movq	rtmp, %cr0
155 
156 #elif defined(__i386)
157 
158 #define	STTS(rtmp)		\
159 	movl	%cr0, rtmp;	\
160 	orl	$CR0_TS, rtmp;	\
161 	movl	rtmp, %cr0
162 
163 #endif	/* __i386 */
164 
165 #define	CLTS			\
166 	clts
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif	/* _SYS_MACHPRIVREGS_H */
173