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