xref: /titanic_52/usr/src/uts/intel/ia32/ml/desctbls_asm.s (revision a29e56d91db891741f1af9f6bbd3e3c3cac5f19b)
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 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/asm_linkage.h>
27#include <sys/asm_misc.h>
28#include <sys/regset.h>
29#include <sys/panic.h>
30#include <sys/ontrap.h>
31#include <sys/privregs.h>
32#include <sys/segments.h>
33#include <sys/trap.h>
34
35#if defined(__lint)
36#include <sys/types.h>
37#include <sys/systm.h>
38#include <sys/thread.h>
39#include <sys/archsystm.h>
40#include <sys/byteorder.h>
41#include <sys/dtrace.h>
42#include <sys/x86_archext.h>
43#else   /* __lint */
44#include "assym.h"
45#endif  /* __lint */
46
47#if defined(__lint)
48
49/*ARGSUSED*/
50void
51rd_idtr(desctbr_t *idtr)
52{}
53
54/*ARGSUSED*/
55void
56wr_idtr(desctbr_t *idtr)
57{}
58
59#else	/* __lint */
60
61#if defined(__amd64)
62
63	ENTRY_NP(rd_idtr)
64	sidt	(%rdi)
65	ret
66	SET_SIZE(rd_idtr)
67
68	ENTRY_NP(wr_idtr)
69	lidt	(%rdi)
70	ret
71	SET_SIZE(wr_idtr)
72
73#elif defined(__i386)
74
75	ENTRY_NP(rd_idtr)
76	pushl	%ebp
77	movl	%esp, %ebp
78	movl	8(%ebp), %edx
79	sidt	(%edx)
80	leave
81	ret
82	SET_SIZE(rd_idtr)
83
84	ENTRY_NP(wr_idtr)
85	pushl	%ebp
86	movl	%esp, %ebp
87	movl	8(%ebp), %edx
88	lidt	(%edx)
89	leave
90	ret
91	SET_SIZE(wr_idtr)
92
93#endif	/* __i386 */
94#endif	/* __lint */
95
96#if defined(__lint)
97
98/*ARGSUSED*/
99void
100rd_gdtr(desctbr_t *gdtr)
101{}
102
103/*ARGSUSED*/
104void
105wr_gdtr(desctbr_t *gdtr)
106{}
107
108#else	/* __lint */
109
110#if defined(__amd64)
111
112	ENTRY_NP(rd_gdtr)
113	pushq	%rbp
114	movq	%rsp, %rbp
115	sgdt	(%rdi)
116	leave
117	ret
118	SET_SIZE(rd_gdtr)
119
120	ENTRY_NP(wr_gdtr)
121	pushq	%rbp
122	movq	%rsp, %rbp
123	lgdt	(%rdi)
124	jmp	1f
125	nop
1261:
127	leave
128	ret
129	SET_SIZE(wr_gdtr)
130
131#elif defined(__i386)
132
133	ENTRY_NP(rd_gdtr)
134	pushl	%ebp
135	movl	%esp, %ebp
136	movl	8(%ebp), %edx
137	sgdt	(%edx)
138	leave
139	ret
140	SET_SIZE(rd_gdtr)
141
142	ENTRY_NP(wr_gdtr)
143	pushl	%ebp
144	movl	%esp, %ebp
145	movl	8(%ebp), %edx
146	lgdt	(%edx)
147	jmp	1f
148	nop
1491:
150	leave
151	ret
152	SET_SIZE(wr_gdtr)
153
154#endif	/* __i386 */
155#endif	/* __lint */
156
157#if defined(__amd64)
158#if defined(__lint)
159
160/*ARGSUSED*/
161void
162load_segment_registers(selector_t cs, selector_t fs, selector_t gs,
163    selector_t ss)
164{}
165
166selector_t
167get_cs_register()
168{ return (0); }
169
170#else	/* __lint */
171
172	/*
173	 * loads zero selector for ds and es.
174	 */
175	ENTRY_NP(load_segment_registers)
176	pushq	%rbp
177	movq	%rsp, %rbp
178	pushq	%rdi
179	pushq	$.newcs
180	lretq
181.newcs:
182	/*
183	 * zero %ds and %es - they're ignored anyway
184	 */
185	xorl	%eax, %eax
186	movw	%ax, %ds
187	movw	%ax, %es
188	movl	%esi, %eax
189	movw	%ax, %fs
190	movl	%edx, %eax
191	movw	%ax, %gs
192	movl	%ecx, %eax
193	movw	%ax, %ss
194	leave
195	ret
196	SET_SIZE(load_segment_registers)
197
198	ENTRY_NP(get_cs_register)
199	movq	%cs, %rax
200	ret
201	SET_SIZE(get_cs_register)
202
203#endif	/* __lint */
204#elif defined(__i386)
205
206#if defined(__lint)
207
208/*ARGSUSED*/
209void
210load_segment_registers(
211    selector_t cs, selector_t ds, selector_t es,
212    selector_t fs, selector_t gs, selector_t ss)
213{}
214
215selector_t
216get_cs_register()
217{ return ((selector_t) 0); }
218
219#else	/* __lint */
220
221	ENTRY_NP(load_segment_registers)
222	pushl	%ebp
223	movl	%esp, %ebp
224
225	pushl	0x8(%ebp)
226	pushl	$.newcs
227	lret
228.newcs:
229	movw	0xc(%ebp), %ax
230	movw	%ax, %ds
231	movw	0x10(%ebp), %ax
232	movw	%ax, %es
233	movw	0x14(%ebp), %ax
234	movw	%ax, %fs
235	movw	0x18(%ebp), %ax
236	movw	%ax, %gs
237	movw	0x1c(%ebp), %ax
238	movw	%ax, %ss
239	leave
240	ret
241	SET_SIZE(load_segment_registers)
242
243	ENTRY_NP(get_cs_register)
244	movl	$0, %eax
245	movw	%cs, %ax
246	ret
247	SET_SIZE(get_cs_register)
248
249#endif	/* __lint */
250#endif	/* __i386 */
251
252#if defined(__lint)
253
254/*ARGSUSED*/
255void
256wr_ldtr(selector_t ldtsel)
257{}
258
259selector_t
260rd_ldtr(void)
261{ return (0); }
262
263#else	/* __lint */
264
265#if defined(__amd64)
266
267	ENTRY_NP(wr_ldtr)
268	movq	%rdi, %rax
269	lldt	%ax
270	ret
271	SET_SIZE(wr_ldtr)
272
273	ENTRY_NP(rd_ldtr)
274	xorl	%eax, %eax
275	sldt	%ax
276	ret
277	SET_SIZE(rd_ldtr)
278
279#elif defined(__i386)
280
281	ENTRY_NP(wr_ldtr)
282	movw	4(%esp), %ax
283	lldt	%ax
284	ret
285	SET_SIZE(wr_ldtr)
286
287	ENTRY_NP(rd_ldtr)
288	xorl	%eax, %eax
289	sldt	%ax
290	ret
291	SET_SIZE(rd_ldtr)
292
293#endif	/* __i386 */
294#endif	/* __lint */
295
296#if defined(__lint)
297
298/*ARGSUSED*/
299void
300wr_tsr(selector_t tsssel)
301{}
302
303#else	/* __lint */
304
305#if defined(__amd64)
306
307	ENTRY_NP(wr_tsr)
308	movq	%rdi, %rax
309	ltr	%ax
310	ret
311	SET_SIZE(wr_tsr)
312
313#elif defined(__i386)
314
315	ENTRY_NP(wr_tsr)
316	movw	4(%esp), %ax
317	ltr	%ax
318	ret
319	SET_SIZE(wr_tsr)
320
321#endif	/* __i386 */
322#endif	/* __lint */
323