xref: /titanic_44/usr/src/uts/intel/sys/segments.h (revision 749f21d359d8fbd020c974a1a5227316221bfc9c)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef	_SYS_SEGMENTS_H
7 #define	_SYS_SEGMENTS_H
8 
9 #pragma ident	"%Z%%M%	%I%	%E% SMI"
10 
11 #ifdef	__cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16  * Copyright (c) 1989, 1990 William F. Jolitz
17  * Copyright (c) 1990 The Regents of the University of California.
18  * All rights reserved.
19  *
20  * This code is derived from software contributed to Berkeley by
21  * William Jolitz.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *	This product includes software developed by the University of
34  *	California, Berkeley and its contributors.
35  * 4. Neither the name of the University nor the names of its contributors
36  *    may be used to endorse or promote products derived from this software
37  *    without specific prior written permission.
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  *
51  *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
52  * $FreeBSD: src/sys/i386/include/segments.h,v 1.34 2003/09/10 01:07:04
53  * jhb Exp $
54  *
55  * 386 Segmentation Data Structures and definitions
56  *	William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
57  */
58 
59 #include <sys/tss.h>
60 
61 /*
62  * Selector register format
63  * CS, DS, ES, FS, GS, SS
64  *
65  *  15                  3  2  1 0
66  * +---------------------+---+----+
67  * |          SI         |TI |RPL |
68  * +---------------------+---+----+
69  *
70  * SI  = selector index
71  * TI  = table indicator (0 = GDT, 1 = LDT)
72  * RPL = requestor privilege level
73  */
74 #if !defined(_ASM) || defined(__GNUC_AS__)
75 #define	IDXTOSEL(s)	((s) << 3)		/* index to selector */
76 #define	SEL_GDT(s, r)	(IDXTOSEL(s) | r)	/* global sel */
77 #else
78 #define	IDXTOSEL(s)	[s << 3]
79 #define	SEL_GDT(s, r)	[IDXTOSEL(s) | r]
80 #endif
81 
82 #define	SELTOIDX(s)	((s) >> 3)	/* selector to index */
83 #define	SEL_KPL		0		/* kernel priority level */
84 #define	SEL_UPL		3		/* user priority level */
85 #define	SEL_TI_LDT	4		/* local descriptor table */
86 #define	SEL_LDT(s)	(IDXTOSEL(s) | SEL_TI_LDT | SEL_UPL)	/* local sel */
87 #define	CPL_MASK	3		/* RPL mask for selector */
88 #define	SELISLDT(s)	(((s) & SEL_TI_LDT) == SEL_TI_LDT)
89 #define	SELISUPL(s)	(((s) & CPL_MASK) == SEL_UPL)
90 
91 #ifndef	_ASM
92 
93 typedef	uint16_t	selector_t;	/* selector reigster */
94 
95 /*
96  * Hardware descriptor table register format for GDT and IDT.
97  */
98 #if defined(__amd64)
99 
100 #pragma pack(2)
101 typedef struct {
102 	uint16_t dtr_limit;	/* table limit */
103 	uint64_t dtr_base;	/* table base address  */
104 } desctbr_t;
105 #pragma	pack()
106 
107 #elif defined(__i386)
108 
109 #pragma pack(2)
110 typedef struct {
111 	uint16_t dtr_limit;	/* table limit */
112 	uint32_t dtr_base;	/* table base address  */
113 } desctbr_t;
114 #pragma	pack()
115 
116 #endif	/* __i386 */
117 
118 /*
119  * Functions for loading and storing descriptor table
120  * registers.
121  */
122 extern void rd_idtr(desctbr_t *);
123 extern void wr_idtr(desctbr_t *);
124 extern void rd_gdtr(desctbr_t *);
125 extern void wr_gdtr(desctbr_t *);
126 extern void wr_ldtr(selector_t);
127 extern selector_t rd_ldtr(void);
128 extern void wr_tsr(selector_t);
129 
130 #if defined(__amd64)
131 extern void clr_ldt_sregs(void);
132 #endif
133 
134 #if !defined(__amd64)
135 
136 /*
137  * User segment descriptors (code and data).
138  * Legacy mode 64-bits wide.
139  */
140 typedef struct user_desc {
141 	uint32_t usd_lolimit:16;	/* segment limit 15:0 */
142 	uint32_t usd_lobase:16;		/* segment base 15:0 */
143 	uint32_t usd_midbase:8;		/* segment base 23:16 */
144 	uint32_t usd_type:5;		/* segment type, includes S bit */
145 	uint32_t usd_dpl:2;		/* segment descriptor priority level */
146 	uint32_t usd_p:1;		/* segment descriptor present */
147 	uint32_t usd_hilimit:4;		/* segment limit 19:16 */
148 	uint32_t usd_avl:1;		/* available to sw, but not used */
149 	uint32_t usd_reserved:1;	/* unused, ignored */
150 	uint32_t usd_def32:1;		/* default 32 vs 16 bit operand */
151 	uint32_t usd_gran:1;		/* limit units (bytes vs pages) */
152 	uint32_t usd_hibase:8;		/* segment base 31:24 */
153 } user_desc_t;
154 
155 #define	USEGD_GETBASE(usd)		((usd)->usd_lobase |		\
156 					(usd)->usd_midbase << 16 |	\
157 					(usd)->usd_hibase << (16 + 8))
158 
159 #define	USEGD_SETBASE(usd, b)		((usd)->usd_lobase = (b),	\
160 					(usd)->usd_midbase = (b) >> 16, \
161 					(usd)->usd_hibase = (b) >> (16 + 8))
162 
163 #define	USEGD_GETLIMIT(usd)		((usd)->usd_lolimit |		\
164 					(usd)->usd_hilimit << 16)
165 
166 #define	USEGD_SETLIMIT(usd, lim)	((usd)->usd_lolimit = lim,	\
167 					(usd)->usd_hilimit = lim >> 16)
168 
169 #define	USD_TYPESHIFT			5	/* size of usd_type field */
170 
171 #else	/* __amd64 */
172 
173 /*
174  * User segment descriptors.
175  * Long mode 64-bits wide.
176  *
177  * In 32-bit compatibility mode (%cs:usd_long=0) all fields are interpreted
178  * as in legacy mode for both code and data.
179  *
180  * In 64-bit mode (%cs:usd_long=1) code segments only have the conforming
181  * bit in usd_type, usd_dpl, usd_p, usd_long and usd_def32=0. usd_def32
182  * must be zero in 64-bit mode. Setting it to 1 is reserved for future use.
183  * All other fields are loaded but ignored by hardware.
184  *
185  * 64-bit data segments only have usd_p. All other fields are loaded but
186  * ignored by hardware when in 64-bit mode.
187  */
188 typedef struct user_desc {
189 	uint64_t usd_lolimit:16;	/* segment limit 15:0 */
190 	uint64_t usd_lobase:16;		/* segment base 15:0 */
191 	uint64_t usd_midbase:8;		/* segment base 23:16 */
192 	uint64_t usd_type:5;		/* segment type, includes S bit */
193 	uint64_t usd_dpl:2;		/* segment descriptor priority level */
194 	uint64_t usd_p:1;		/* segment descriptor present */
195 	uint64_t usd_hilimit:4;		/* segment limit 19:16 */
196 	uint64_t usd_avl:1;		/* available to sw, but not used */
197 	uint64_t usd_long:1;		/* long mode (%cs only) */
198 	uint64_t usd_def32:1;		/* default 32 vs 16 bit operand */
199 	uint64_t usd_gran:1;		/* limit units (bytes vs page) */
200 	uint64_t usd_hibase:8;		/* segment base 31:24 */
201 } user_desc_t;
202 
203 #define	USEGD_GETBASE(usd)		((usd)->usd_lobase |		\
204 					(usd)->usd_midbase << 16 |	\
205 					(usd)->usd_hibase << (16 + 8))
206 
207 #define	USEGD_SETBASE(usd, b)		((usd)->usd_lobase = (b),	\
208 					(usd)->usd_midbase = (b) >> 16, \
209 					(usd)->usd_hibase = (b) >> (16 + 8))
210 
211 #define	USEGD_GETLIMIT(usd)		((usd)->usd_lolimit |		\
212 					(usd)->usd_hilimit << 16)
213 
214 #define	USEGD_SETLIMIT(usd, lim)	((usd)->usd_lolimit = lim,	\
215 					(usd)->usd_hilimit = lim >> 16)
216 
217 #define	USD_TYPESHIFT			5	/* size of usd_type field */
218 
219 #endif /* __amd64 */
220 
221 #if !defined(__amd64)
222 
223 /*
224  * System segment descriptors for LDT and TSS segments.
225  * Legacy mode 64-bits wide.
226  */
227 typedef struct system_desc {
228 	uint32_t ssd_lolimit:16;	/* segment limit 15:0 */
229 	uint32_t ssd_lobase:16;		/* segment base 15:0 */
230 	uint32_t ssd_midbase:8;		/* segment base 23:16 */
231 	uint32_t ssd_type:4;		/* segment type */
232 	uint32_t ssd_zero:1;		/* must be zero */
233 	uint32_t ssd_dpl:2;		/* segment descriptor priority level */
234 	uint32_t ssd_p:1;		/* segment descriptor present */
235 	uint32_t ssd_hilimit:4;		/* segment limit 19:16 */
236 	uint32_t ssd_avl:1;		/* available to sw, but not used */
237 	uint32_t ssd_reserved:2;	/* unused, ignored */
238 	uint32_t ssd_gran:1;		/* limit unit (bytes vs pages) */
239 	uint32_t ssd_hibase:8;		/* segment base 31:24 */
240 } system_desc_t;
241 
242 #else	/* __amd64 */
243 
244 /*
245  * System segment descriptors for LDT and TSS segments.
246  * Long mode 128-bits wide.
247  *
248  * 32-bit LDT and TSS descriptor types are redefined to 64-bit equivalents.
249  * All other legacy types are reserved and illegal.
250  */
251 typedef struct system_desc {
252 	uint64_t ssd_lolimit:16;	/* segment limit 15:0 */
253 	uint64_t ssd_lobase:16;		/* segment base 15:0 */
254 	uint64_t ssd_midbase:8;		/* segment base 23:16 */
255 	uint64_t ssd_type:4;		/* segment type */
256 	uint64_t ssd_zero1:1;		/* must be zero */
257 	uint64_t ssd_dpl:2;		/* segment descriptor priority level */
258 	uint64_t ssd_p:1;		/* segment descriptor present */
259 	uint64_t ssd_hilimit:4;		/* segment limit 19:16 */
260 	uint64_t ssd_avl:1;		/* available to sw, but not used */
261 	uint64_t ssd_resv1:2;		/* unused, ignored */
262 	uint64_t ssd_gran:1;		/* limit unit (bytes vs pages) */
263 	uint64_t ssd_hibase:8;		/* segment base 31:24 */
264 	uint64_t ssd_hi64base:32;	/* segment base 63:32 */
265 	uint64_t ssd_resv2:8;		/* unused, ignored */
266 	uint64_t ssd_zero2:5;		/* must be zero */
267 	uint64_t ssd_resv3:19;		/* unused, ignored */
268 } system_desc_t;
269 
270 #endif	/* __amd64 */
271 
272 #define	SYSSEGD_SETLIMIT(ssd, lim)	((ssd)->ssd_lolimit = lim,	\
273 					(ssd)->ssd_hilimit = lim >> 16)
274 #if !defined(__amd64)
275 
276 /*
277  * System gate segment descriptors for interrupt, trap, call and task gates.
278  * Legacy mode 64-bits wide.
279  */
280 typedef struct gate_desc {
281 	uint32_t sgd_looffset:16;	/* segment code offset 15:0 */
282 	uint32_t sgd_selector:16;	/* target code or task selector */
283 	uint32_t sgd_stkcpy:5;		/* number of stack wds to cpy */
284 	uint32_t sgd_resv:3;		/* unused, ignored */
285 	uint32_t sgd_type:5;		/* segment type, includes S bit */
286 	uint32_t sgd_dpl:2;		/* segment descriptor priority level */
287 	uint32_t sgd_p:1;		/* segment descriptor present */
288 	uint32_t sgd_hioffset:16;	/* code seg off 31:16 */
289 } gate_desc_t;
290 
291 #define	GATESEG_GETOFFSET(sgd)		((sgd)->sgd_looffset |		\
292 					(sgd)->sgd_hioffset << 16)
293 
294 #else	/* __amd64 */
295 
296 /*
297  * System segment descriptors for interrupt, trap and call gates.
298  * Long mode 128-bits wide.
299  *
300  * 32-bit interrupt, trap and call gate types are redefined to 64-bit
301  * equivalents. Task gates along with all other legacy types are reserved
302  * and illegal.
303  */
304 typedef struct gate_desc {
305 	uint64_t sgd_looffset:16;	/* segment code offset 15:0 */
306 	uint64_t sgd_selector:16;	/* target code or task selector */
307 	uint64_t sgd_ist:3;		/* IST table index */
308 	uint64_t sgd_resv1:5;		/* unused, ignored */
309 	uint64_t sgd_type:5;		/* segment type, includes S bit */
310 	uint64_t sgd_dpl:2;		/* segment descriptor priority level */
311 	uint64_t sgd_p:1;		/* segment descriptor present */
312 	uint64_t sgd_hioffset:16;	/* segment code offset 31:16 */
313 	uint64_t sgd_hi64offset:32;	/* segment code offset 63:32 */
314 	uint64_t sgd_resv2:8;		/* unused, ignored */
315 	uint64_t sgd_zero:5;		/* call gate only: must be zero */
316 	uint64_t sgd_resv3:19;		/* unused, ignored */
317 } gate_desc_t;
318 
319 #define	GATESEG_GETOFFSET(sgd)		((sgd)->sgd_looffset |		\
320 					(sgd)->sgd_hioffset << 16 |	\
321 					(sgd)->sgd_hi64offset << 32)
322 
323 #endif	/* __amd64 */
324 
325 /*
326  * functions for initializing and updating segment descriptors.
327  */
328 #if defined(__amd64)
329 
330 extern void set_usegd(user_desc_t *, uint_t, void *, size_t, uint_t, uint_t,
331     uint_t, uint_t);
332 extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t, uint_t,
333     uint_t, uint_t);
334 
335 #elif defined(__i386)
336 
337 extern void set_usegd(user_desc_t *, void *, size_t, uint_t, uint_t,
338     uint_t, uint_t);
339 extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t,
340     uint_t, uint_t, uint_t);
341 
342 #endif	/* __i386 */
343 
344 void set_syssegd(system_desc_t *, void *, size_t, uint_t, uint_t);
345 
346 #endif	/* _ASM */
347 
348 /*
349  * Common segment parameter defintions for granularity, default
350  * operand size and operaton mode.
351  */
352 #define	SDP_BYTES	0	/* segment limit scaled to bytes */
353 #define	SDP_PAGES	1	/* segment limit scaled to pages */
354 #define	SDP_OP32	1	/* code and data default operand = 32 bits */
355 #define	SDP_LONG	1	/* long mode code segment (64 bits) */
356 #define	SDP_SHORT	0	/* compat/legacy code segment (32 bits) */
357 /*
358  * System segments and gate types.
359  *
360  * In long mode i386 32-bit ldt, tss, call, interrupt and trap gate
361  * types are redefined into 64-bit equivalents.
362  */
363 #define	SDT_SYSNULL	 0	/* system null */
364 #define	SDT_SYS286TSS	 1	/* system 286 TSS available */
365 #define	SDT_SYSLDT	 2	/* system local descriptor table */
366 #define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
367 #define	SDT_SYS286CGT	 4	/* system 286 call gate */
368 #define	SDT_SYSTASKGT	 5	/* system task gate */
369 #define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
370 #define	SDT_SYS286TGT	 7	/* system 286 trap gate */
371 #define	SDT_SYSNULL2	 8	/* system null again */
372 #define	SDT_SYSTSS	 9	/* system TSS available */
373 #define	SDT_SYSNULL3	10	/* system null again */
374 #define	SDT_SYSTSSBSY	11	/* system TSS busy */
375 #define	SDT_SYSCGT	12	/* system call gate */
376 #define	SDT_SYSNULL4	13	/* system null again */
377 #define	SDT_SYSIGT	14	/* system interrupt gate */
378 #define	SDT_SYSTGT	15	/* system trap gate */
379 
380 /*
381  * Memory segment types.
382  *
383  * While in long mode expand-down, writable and accessed type field
384  * attributes are ignored. Only the conforming bit is loaded by hardware
385  * for long mode code segment descriptors.
386  */
387 #define	SDT_MEMRO	16	/* read only */
388 #define	SDT_MEMROA	17	/* read only accessed */
389 #define	SDT_MEMRW	18	/* read write */
390 #define	SDT_MEMRWA	19	/* read write accessed */
391 #define	SDT_MEMROD	20	/* read only expand dwn limit */
392 #define	SDT_MEMRODA	21	/* read only expand dwn limit accessed */
393 #define	SDT_MEMRWD	22	/* read write expand dwn limit */
394 #define	SDT_MEMRWDA	23	/* read write expand dwn limit accessed */
395 #define	SDT_MEME	24	/* execute only */
396 #define	SDT_MEMEA	25	/* execute only accessed */
397 #define	SDT_MEMER	26	/* execute read */
398 #define	SDT_MEMERA	27	/* execute read accessed */
399 #define	SDT_MEMEC	28	/* execute only conforming */
400 #define	SDT_MEMEAC	29	/* execute only accessed conforming */
401 #define	SDT_MEMERC	30	/* execute read conforming */
402 #define	SDT_MEMERAC	31	/* execute read accessed conforming */
403 
404 /*
405  * Entries in the Interrupt Descriptor Table (IDT)
406  */
407 #define	IDT_DE		0	/* #DE: Divide Error */
408 #define	IDT_DB		1	/* #DB: Debug */
409 #define	IDT_NMI		2	/* Nonmaskable External Interrupt */
410 #define	IDT_BP		3	/* #BP: Breakpoint */
411 #define	IDT_OF		4	/* #OF: Overflow */
412 #define	IDT_BR		5	/* #BR: Bound Range Exceeded */
413 #define	IDT_UD		6	/* #UD: Undefined/Invalid Opcode */
414 #define	IDT_NM		7	/* #NM: No Math Coprocessor */
415 #define	IDT_DF		8	/* #DF: Double Fault */
416 #define	IDT_FPUGP	9	/* Coprocessor Segment Overrun */
417 #define	IDT_TS		10	/* #TS: Invalid TSS */
418 #define	IDT_NP		11	/* #NP: Segment Not Present */
419 #define	IDT_SS		12	/* #SS: Stack Segment Fault */
420 #define	IDT_GP		13	/* #GP: General Protection Fault */
421 #define	IDT_PF		14	/* #PF: Page Fault */
422 #define	IDT_MF		16	/* #MF: FPU Floating-Point Error */
423 #define	IDT_AC		17	/* #AC: Alignment Check */
424 #define	IDT_MC		18	/* #MC: Machine Check */
425 #define	IDT_XF		19	/* #XF: SIMD Floating-Point Exception */
426 #define	NIDT		256	/* size in entries of IDT */
427 
428 /*
429  * Entries in the Global Descriptor Table (GDT)
430  *
431  * We make sure to space the system descriptors (LDT's, TSS')
432  * such that they are double gdt slot aligned. This is because
433  * in long mode system segment decriptors expand to 128 bits.
434  *
435  * GDT_LWPFS and GDT_LWPGS must be the same for both 32 and 64-bit
436  * kernels. See setup_context in libc.
437  */
438 #if defined(__amd64)
439 
440 #define	GDT_NULL	0	/* null */
441 #define	GDT_B32DATA	1	/* copied from boot */
442 #define	GDT_B32CODE	2	/* copied from boot */
443 #define	GDT_B64DATA	3	/* copied from boot */
444 #define	GDT_B64CODE	4	/* copied from boot */
445 #define	GDT_KCODE	5	/* kernel code seg %cs */
446 #define	GDT_KDATA	6	/* kernel data seg %ds */
447 #define	GDT_U32CODE	7	/* 32-bit process on 64-bit kernel %cs */
448 #define	GDT_UDATA	8	/* user data seg %ds (32 and 64 bit) */
449 #define	GDT_UCODE	9	/* native user code  seg %cs */
450 #define	GDT_LDT		10	/* LDT for current process */
451 #define	GDT_KTSS	12	/* kernel tss */
452 #define	GDT_FS		GDT_NULL /* kernel %fs segment selector */
453 #define	GDT_GS		GDT_NULL /* kernel %gs segment selector */
454 #define	GDT_LWPFS	55	/* lwp private %fs segment selector */
455 #define	GDT_LWPGS	56	/* lwp private %gs segment selector */
456 #define	NGDT		58	/* number of entries in GDT */
457 
458 /*
459  * This selector is only used in the temporary GDT used to bring additional
460  * CPUs from 16-bit real mode into long mode in real_mode_start().
461  */
462 #define	TEMPGDT_KCODE64	1	/* 64-bit code selector */
463 
464 #elif defined(__i386)
465 
466 #define	GDT_NULL	0	/* null */
467 #define	GDT_BOOTFLAT	1	/* copied from boot */
468 #define	GDT_BOOTCODE	2	/* copied from boot */
469 #define	GDT_BOOTCODE16	3	/* copied from boot */
470 #define	GDT_BOOTDATA	4	/* copied from boot */
471 #define	GDT_LDT		40	/* LDT for current process */
472 #define	GDT_KTSS	42	/* kernel tss */
473 #define	GDT_KCODE	43	/* kernel code seg %cs */
474 #define	GDT_KDATA	44	/* kernel data seg %ds */
475 #define	GDT_UCODE	45	/* native user code  seg %cs */
476 #define	GDT_UDATA	46	/* user data seg %ds (32 and 64 bit) */
477 #define	GDT_DBFLT	47	/* double fault #DF selector */
478 #define	GDT_FS		53	/* kernel %fs segment selector */
479 #define	GDT_GS		54	/* kernel %gs segment selector */
480 #define	GDT_LWPFS	55	/* lwp private %fs segment selector */
481 #define	GDT_LWPGS	56	/* lwp private %gs segment selector */
482 #define	NGDT		90	/* number of entries in GDT */
483 
484 #endif	/* __i386 */
485 
486 /*
487  * Convenient selector definitions.
488  */
489 #define	KCS_SEL		SEL_GDT(GDT_KCODE, SEL_KPL)
490 #define	KDS_SEL		SEL_GDT(GDT_KDATA, SEL_KPL)
491 #define	UCS_SEL		SEL_GDT(GDT_UCODE, SEL_UPL)
492 #if defined(__amd64)
493 #define	TEMP_CS64_SEL	SEL_GDT(TEMPGDT_KCODE64, SEL_KPL)
494 #define	U32CS_SEL	SEL_GDT(GDT_U32CODE, SEL_UPL)
495 #endif	/* __amd64 */
496 #define	UDS_SEL		SEL_GDT(GDT_UDATA, SEL_UPL)
497 #define	ULDT_SEL	SEL_GDT(GDT_LDT, SEL_KPL)
498 #define	KTSS_SEL	SEL_GDT(GDT_KTSS, SEL_KPL)
499 #define	DFTSS_SEL	SEL_GDT(GDT_DBFLT, SEL_KPL)
500 #define	KFS_SEL		SEL_GDT(GDT_NULL, SEL_KPL)
501 #define	KGS_SEL		SEL_GDT(GDT_GS, SEL_KPL)
502 #define	LWPFS_SEL	SEL_GDT(GDT_LWPFS, SEL_UPL)
503 #define	LWPGS_SEL	SEL_GDT(GDT_LWPGS, SEL_UPL)
504 #if defined(__amd64)
505 #define	B64CODE_SEL	SEL_GDT(GDT_B64CODE, SEL_KPL)
506 #else
507 #define	BOOTCODE_SEL	SEL_GDT(GDT_BOOTCODE, SEL_KPL)
508 #define	BOOTFLAT_SEL	SEL_GDT(GDT_BOOTFLAT, SEL_KPL)
509 #endif
510 
511 /*
512  * Entries in default Local Descriptor Table (LDT) for every process.
513  */
514 #define	LDT_SYSCALL	0	/* call gate for libc.a (obsolete) */
515 #define	LDT_SIGCALL	1	/* EOL me, call gate for static sigreturn */
516 #define	LDT_RESVD1	2	/* old user %cs */
517 #define	LDT_RESVD2	3	/* old user %ds */
518 #define	LDT_ALTSYSCALL	4	/* alternate call gate for system calls */
519 #define	LDT_ALTSIGCALL	5	/* EOL me, alternate call gate for sigreturn */
520 #define	LDT_UDBASE	6	/* user descriptor base index */
521 #define	MINNLDT		64	/* Current min solaris ldt size */
522 #define	MAXNLDT		8192	/* max solaris ldt size */
523 
524 #ifndef	_ASM
525 
526 #pragma	align	16(idt0)
527 extern	gate_desc_t	idt0[NIDT];
528 extern	desctbr_t	idt0_default_reg;
529 #pragma	align	16(gdt0)
530 extern	user_desc_t	gdt0[NGDT];
531 
532 extern user_desc_t	zero_udesc;
533 extern system_desc_t	zero_sdesc;
534 
535 #if defined(__amd64)
536 extern user_desc_t	zero_u32desc;
537 #endif
538 
539 #pragma	align	16(ktss0)
540 extern struct tss ktss0;
541 
542 #if defined(__i386)
543 extern struct tss dftss0;
544 #endif	/* __i386 */
545 
546 extern void div0trap(), dbgtrap(), nmiint(), brktrap(), ovflotrap();
547 extern void boundstrap(), invoptrap(), ndptrap(), syserrtrap();
548 extern void invaltrap(), invtsstrap(), segnptrap(), stktrap();
549 extern void gptrap(), pftrap(), ndperr();
550 extern void overrun(), resvtrap();
551 extern void _start(), cmnint();
552 extern void achktrap(), mcetrap();
553 extern void xmtrap();
554 extern void fasttrap();
555 extern void dtrace_fasttrap(), dtrace_ret();
556 
557 #if !defined(__amd64)
558 extern void pentium_pftrap();
559 #endif
560 
561 #endif /* _ASM */
562 
563 #ifdef	__cplusplus
564 }
565 #endif
566 
567 #endif /* _SYS_SEGMENTS_H */
568