xref: /titanic_50/usr/src/uts/intel/sys/segments.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
1 /*
2  * Copyright 2007 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 privilege 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 extern void kmdb_enter(void);
130 
131 #if defined(__amd64)
132 extern void clr_ldt_sregs(void);
133 
134 /*
135  * inlines for update_segregs
136  */
137 extern void __set_ds(selector_t);
138 extern void __set_es(selector_t);
139 extern void __set_fs(selector_t);
140 extern void __set_gs(selector_t);
141 extern void __swapgs(void);
142 #endif	/* __amd64 */
143 
144 #if defined(__amd64)
145 extern void load_segment_registers(selector_t, selector_t, selector_t,
146     selector_t);	/* (alphabetical) */
147 #elif defined(__i386)
148 extern void load_segment_registers(selector_t, selector_t, selector_t,
149     selector_t, selector_t, selector_t);	/* (alphabetical) */
150 #endif	/* __i386 */
151 
152 #if !defined(__amd64)
153 
154 /*
155  * User segment descriptors (code and data).
156  * Legacy mode 64-bits wide.
157  */
158 typedef struct user_desc {
159 	uint32_t usd_lolimit:16;	/* segment limit 15:0 */
160 	uint32_t usd_lobase:16;		/* segment base 15:0 */
161 	uint32_t usd_midbase:8;		/* segment base 23:16 */
162 	uint32_t usd_type:5;		/* segment type, includes S bit */
163 	uint32_t usd_dpl:2;		/* segment descriptor priority level */
164 	uint32_t usd_p:1;		/* segment descriptor present */
165 	uint32_t usd_hilimit:4;		/* segment limit 19:16 */
166 	uint32_t usd_avl:1;		/* available to sw, but not used */
167 	uint32_t usd_reserved:1;	/* unused, ignored */
168 	uint32_t usd_def32:1;		/* default 32 vs 16 bit operand */
169 	uint32_t usd_gran:1;		/* limit units (bytes vs pages) */
170 	uint32_t usd_hibase:8;		/* segment base 31:24 */
171 } user_desc_t;
172 
173 #define	USEGD_GETBASE(usd)		((usd)->usd_lobase |		\
174 					(usd)->usd_midbase << 16 |	\
175 					(usd)->usd_hibase << (16 + 8))
176 
177 #define	USEGD_SETBASE(usd, b)		((usd)->usd_lobase = (b),	\
178 					(usd)->usd_midbase = (b) >> 16, \
179 					(usd)->usd_hibase = (b) >> (16 + 8))
180 
181 #define	USEGD_GETLIMIT(usd)		((usd)->usd_lolimit |		\
182 					(usd)->usd_hilimit << 16)
183 
184 #define	USEGD_SETLIMIT(usd, lim)	((usd)->usd_lolimit = lim,	\
185 					(usd)->usd_hilimit = lim >> 16)
186 
187 #define	USD_TYPESHIFT			5	/* size of usd_type field */
188 
189 #else	/* __amd64 */
190 
191 /*
192  * User segment descriptors.
193  * Long mode 64-bits wide.
194  *
195  * In 32-bit compatibility mode (%cs:usd_long=0) all fields are interpreted
196  * as in legacy mode for both code and data.
197  *
198  * In 64-bit mode (%cs:usd_long=1) code segments only have the conforming
199  * bit in usd_type, usd_dpl, usd_p, usd_long and usd_def32=0. usd_def32
200  * must be zero in 64-bit mode. Setting it to 1 is reserved for future use.
201  * All other fields are loaded but ignored by hardware.
202  *
203  * 64-bit data segments only have usd_p. All other fields are loaded but
204  * ignored by hardware when in 64-bit mode.
205  */
206 typedef struct user_desc {
207 	uint64_t usd_lolimit:16;	/* segment limit 15:0 */
208 	uint64_t usd_lobase:16;		/* segment base 15:0 */
209 	uint64_t usd_midbase:8;		/* segment base 23:16 */
210 	uint64_t usd_type:5;		/* segment type, includes S bit */
211 	uint64_t usd_dpl:2;		/* segment descriptor priority level */
212 	uint64_t usd_p:1;		/* segment descriptor present */
213 	uint64_t usd_hilimit:4;		/* segment limit 19:16 */
214 	uint64_t usd_avl:1;		/* available to sw, but not used */
215 	uint64_t usd_long:1;		/* long mode (%cs only) */
216 	uint64_t usd_def32:1;		/* default 32 vs 16 bit operand */
217 	uint64_t usd_gran:1;		/* limit units (bytes vs page) */
218 	uint64_t usd_hibase:8;		/* segment base 31:24 */
219 } user_desc_t;
220 
221 #define	USEGD_GETBASE(usd)		((usd)->usd_lobase |		\
222 					(usd)->usd_midbase << 16 |	\
223 					(usd)->usd_hibase << (16 + 8))
224 
225 #define	USEGD_SETBASE(usd, b)		((usd)->usd_lobase = (b),	\
226 					(usd)->usd_midbase = (b) >> 16, \
227 					(usd)->usd_hibase = (b) >> (16 + 8))
228 
229 #define	USEGD_GETLIMIT(usd)		((usd)->usd_lolimit |		\
230 					(usd)->usd_hilimit << 16)
231 
232 #define	USEGD_SETLIMIT(usd, lim)	((usd)->usd_lolimit = lim,	\
233 					(usd)->usd_hilimit = lim >> 16)
234 
235 #define	USD_TYPESHIFT			5	/* size of usd_type field */
236 
237 #endif /* __amd64 */
238 
239 #if !defined(__amd64)
240 
241 /*
242  * System segment descriptors for LDT and TSS segments.
243  * Legacy mode 64-bits wide.
244  */
245 typedef struct system_desc {
246 	uint32_t ssd_lolimit:16;	/* segment limit 15:0 */
247 	uint32_t ssd_lobase:16;		/* segment base 15:0 */
248 	uint32_t ssd_midbase:8;		/* segment base 23:16 */
249 	uint32_t ssd_type:4;		/* segment type */
250 	uint32_t ssd_zero:1;		/* must be zero */
251 	uint32_t ssd_dpl:2;		/* segment descriptor priority level */
252 	uint32_t ssd_p:1;		/* segment descriptor present */
253 	uint32_t ssd_hilimit:4;		/* segment limit 19:16 */
254 	uint32_t ssd_avl:1;		/* available to sw, but not used */
255 	uint32_t ssd_reserved:2;	/* unused, ignored */
256 	uint32_t ssd_gran:1;		/* limit unit (bytes vs pages) */
257 	uint32_t ssd_hibase:8;		/* segment base 31:24 */
258 } system_desc_t;
259 
260 #else	/* __amd64 */
261 
262 /*
263  * System segment descriptors for LDT and TSS segments.
264  * Long mode 128-bits wide.
265  *
266  * 32-bit LDT and TSS descriptor types are redefined to 64-bit equivalents.
267  * All other legacy types are reserved and illegal.
268  */
269 typedef struct system_desc {
270 	uint64_t ssd_lolimit:16;	/* segment limit 15:0 */
271 	uint64_t ssd_lobase:16;		/* segment base 15:0 */
272 	uint64_t ssd_midbase:8;		/* segment base 23:16 */
273 	uint64_t ssd_type:4;		/* segment type */
274 	uint64_t ssd_zero1:1;		/* must be zero */
275 	uint64_t ssd_dpl:2;		/* segment descriptor priority level */
276 	uint64_t ssd_p:1;		/* segment descriptor present */
277 	uint64_t ssd_hilimit:4;		/* segment limit 19:16 */
278 	uint64_t ssd_avl:1;		/* available to sw, but not used */
279 	uint64_t ssd_resv1:2;		/* unused, ignored */
280 	uint64_t ssd_gran:1;		/* limit unit (bytes vs pages) */
281 	uint64_t ssd_hibase:8;		/* segment base 31:24 */
282 	uint64_t ssd_hi64base:32;	/* segment base 63:32 */
283 	uint64_t ssd_resv2:8;		/* unused, ignored */
284 	uint64_t ssd_zero2:5;		/* must be zero */
285 	uint64_t ssd_resv3:19;		/* unused, ignored */
286 } system_desc_t;
287 
288 #endif	/* __amd64 */
289 
290 #define	SYSSEGD_SETLIMIT(ssd, lim)	((ssd)->ssd_lolimit = lim,	\
291 					(ssd)->ssd_hilimit = lim >> 16)
292 #if !defined(__amd64)
293 
294 /*
295  * System gate segment descriptors for interrupt, trap, call and task gates.
296  * Legacy mode 64-bits wide.
297  */
298 typedef struct gate_desc {
299 	uint32_t sgd_looffset:16;	/* segment code offset 15:0 */
300 	uint32_t sgd_selector:16;	/* target code or task selector */
301 	uint32_t sgd_stkcpy:5;		/* number of stack wds to cpy */
302 	uint32_t sgd_resv:3;		/* unused, ignored */
303 	uint32_t sgd_type:5;		/* segment type, includes S bit */
304 	uint32_t sgd_dpl:2;		/* segment descriptor priority level */
305 	uint32_t sgd_p:1;		/* segment descriptor present */
306 	uint32_t sgd_hioffset:16;	/* code seg off 31:16 */
307 } gate_desc_t;
308 
309 #define	GATESEG_GETOFFSET(sgd)		((sgd)->sgd_looffset |		\
310 					(sgd)->sgd_hioffset << 16)
311 
312 #else	/* __amd64 */
313 
314 /*
315  * System segment descriptors for interrupt, trap and call gates.
316  * Long mode 128-bits wide.
317  *
318  * 32-bit interrupt, trap and call gate types are redefined to 64-bit
319  * equivalents. Task gates along with all other legacy types are reserved
320  * and illegal.
321  */
322 typedef struct gate_desc {
323 	uint64_t sgd_looffset:16;	/* segment code offset 15:0 */
324 	uint64_t sgd_selector:16;	/* target code or task selector */
325 	uint64_t sgd_ist:3;		/* IST table index */
326 	uint64_t sgd_resv1:5;		/* unused, ignored */
327 	uint64_t sgd_type:5;		/* segment type, includes S bit */
328 	uint64_t sgd_dpl:2;		/* segment descriptor priority level */
329 	uint64_t sgd_p:1;		/* segment descriptor present */
330 	uint64_t sgd_hioffset:16;	/* segment code offset 31:16 */
331 	uint64_t sgd_hi64offset:32;	/* segment code offset 63:32 */
332 	uint64_t sgd_resv2:8;		/* unused, ignored */
333 	uint64_t sgd_zero:5;		/* call gate only: must be zero */
334 	uint64_t sgd_resv3:19;		/* unused, ignored */
335 } gate_desc_t;
336 
337 #define	GATESEG_GETOFFSET(sgd)		((sgd)->sgd_looffset |		\
338 					(sgd)->sgd_hioffset << 16 |	\
339 					(sgd)->sgd_hi64offset << 32)
340 
341 #endif	/* __amd64 */
342 
343 /*
344  * functions for initializing and updating segment descriptors.
345  */
346 #if defined(__amd64)
347 
348 extern void set_usegd(user_desc_t *, uint_t, void *, size_t, uint_t, uint_t,
349     uint_t, uint_t);
350 
351 #elif defined(__i386)
352 
353 extern void set_usegd(user_desc_t *, void *, size_t, uint_t, uint_t,
354     uint_t, uint_t);
355 
356 #endif	/* __i386 */
357 
358 extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t,
359     uint_t, uint_t);
360 
361 void set_syssegd(system_desc_t *, void *, size_t, uint_t, uint_t);
362 
363 void init_boot_gdt(user_desc_t *);
364 
365 #endif	/* _ASM */
366 
367 /*
368  * Common segment parameter defintions for granularity, default
369  * operand size and operaton mode.
370  */
371 #define	SDP_BYTES	0	/* segment limit scaled to bytes */
372 #define	SDP_PAGES	1	/* segment limit scaled to pages */
373 #define	SDP_OP32	1	/* code and data default operand = 32 bits */
374 #define	SDP_LONG	1	/* long mode code segment (64 bits) */
375 #define	SDP_SHORT	0	/* compat/legacy code segment (32 bits) */
376 /*
377  * System segments and gate types.
378  *
379  * In long mode i386 32-bit ldt, tss, call, interrupt and trap gate
380  * types are redefined into 64-bit equivalents.
381  */
382 #define	SDT_SYSNULL	 0	/* system null */
383 #define	SDT_SYS286TSS	 1	/* system 286 TSS available */
384 #define	SDT_SYSLDT	 2	/* system local descriptor table */
385 #define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
386 #define	SDT_SYS286CGT	 4	/* system 286 call gate */
387 #define	SDT_SYSTASKGT	 5	/* system task gate */
388 #define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
389 #define	SDT_SYS286TGT	 7	/* system 286 trap gate */
390 #define	SDT_SYSNULL2	 8	/* system null again */
391 #define	SDT_SYSTSS	 9	/* system TSS available */
392 #define	SDT_SYSNULL3	10	/* system null again */
393 #define	SDT_SYSTSSBSY	11	/* system TSS busy */
394 #define	SDT_SYSCGT	12	/* system call gate */
395 #define	SDT_SYSNULL4	13	/* system null again */
396 #define	SDT_SYSIGT	14	/* system interrupt gate */
397 #define	SDT_SYSTGT	15	/* system trap gate */
398 
399 /*
400  * Memory segment types.
401  *
402  * While in long mode expand-down, writable and accessed type field
403  * attributes are ignored. Only the conforming bit is loaded by hardware
404  * for long mode code segment descriptors.
405  */
406 #define	SDT_MEMRO	16	/* read only */
407 #define	SDT_MEMROA	17	/* read only accessed */
408 #define	SDT_MEMRW	18	/* read write */
409 #define	SDT_MEMRWA	19	/* read write accessed */
410 #define	SDT_MEMROD	20	/* read only expand dwn limit */
411 #define	SDT_MEMRODA	21	/* read only expand dwn limit accessed */
412 #define	SDT_MEMRWD	22	/* read write expand dwn limit */
413 #define	SDT_MEMRWDA	23	/* read write expand dwn limit accessed */
414 #define	SDT_MEME	24	/* execute only */
415 #define	SDT_MEMEA	25	/* execute only accessed */
416 #define	SDT_MEMER	26	/* execute read */
417 #define	SDT_MEMERA	27	/* execute read accessed */
418 #define	SDT_MEMEC	28	/* execute only conforming */
419 #define	SDT_MEMEAC	29	/* execute only accessed conforming */
420 #define	SDT_MEMERC	30	/* execute read conforming */
421 #define	SDT_MEMERAC	31	/* execute read accessed conforming */
422 
423 /*
424  * Entries in the Interrupt Descriptor Table (IDT)
425  */
426 #define	IDT_DE		0	/* #DE: Divide Error */
427 #define	IDT_DB		1	/* #DB: Debug */
428 #define	IDT_NMI		2	/* Nonmaskable External Interrupt */
429 #define	IDT_BP		3	/* #BP: Breakpoint */
430 #define	IDT_OF		4	/* #OF: Overflow */
431 #define	IDT_BR		5	/* #BR: Bound Range Exceeded */
432 #define	IDT_UD		6	/* #UD: Undefined/Invalid Opcode */
433 #define	IDT_NM		7	/* #NM: No Math Coprocessor */
434 #define	IDT_DF		8	/* #DF: Double Fault */
435 #define	IDT_FPUGP	9	/* Coprocessor Segment Overrun */
436 #define	IDT_TS		10	/* #TS: Invalid TSS */
437 #define	IDT_NP		11	/* #NP: Segment Not Present */
438 #define	IDT_SS		12	/* #SS: Stack Segment Fault */
439 #define	IDT_GP		13	/* #GP: General Protection Fault */
440 #define	IDT_PF		14	/* #PF: Page Fault */
441 #define	IDT_MF		16	/* #MF: FPU Floating-Point Error */
442 #define	IDT_AC		17	/* #AC: Alignment Check */
443 #define	IDT_MC		18	/* #MC: Machine Check */
444 #define	IDT_XF		19	/* #XF: SIMD Floating-Point Exception */
445 #define	NIDT		256	/* size in entries of IDT */
446 
447 /*
448  * Entries in the Global Descriptor Table (GDT)
449  *
450  * We make sure to space the system descriptors (LDT's, TSS')
451  * such that they are double gdt slot aligned. This is because
452  * in long mode system segment decriptors expand to 128 bits.
453  *
454  * GDT_LWPFS and GDT_LWPGS must be the same for both 32 and 64-bit
455  * kernels. See setup_context in libc. 64-bit processes must set
456  * %fs or %gs to null selector to use 64-bit fsbase or gsbase
457  * respectively.
458  */
459 #define	GDT_NULL	0	/* null */
460 #define	GDT_B32DATA	1	/* dboot 32 bit data descriptor */
461 #define	GDT_B32CODE	2	/* dboot 32 bit code descriptor */
462 #define	GDT_B16CODE	3	/* bios call 16 bit code descriptor */
463 #define	GDT_B16DATA	4	/* bios call 16 bit data descriptor */
464 #define	GDT_B64CODE	5	/* dboot 64 bit code descriptor */
465 #define	GDT_BGSTMP	7	/* kmdb descriptor only used early in boot */
466 
467 #if defined(__amd64)
468 
469 #define	GDT_KCODE	6	/* kernel code seg %cs */
470 #define	GDT_KDATA	7	/* kernel data seg %ds */
471 #define	GDT_U32CODE	8	/* 32-bit process on 64-bit kernel %cs */
472 #define	GDT_UDATA	9	/* user data seg %ds (32 and 64 bit) */
473 #define	GDT_UCODE	10	/* native user code  seg %cs */
474 #define	GDT_LDT		12	/* LDT for current process */
475 #define	GDT_KTSS	14	/* kernel tss */
476 #define	GDT_FS		GDT_NULL /* kernel %fs segment selector */
477 #define	GDT_GS		GDT_NULL /* kernel %gs segment selector */
478 #define	GDT_LWPFS	55	/* lwp private %fs segment selector (32-bit) */
479 #define	GDT_LWPGS	56	/* lwp private %gs segment selector (32-bit) */
480 #define	GDT_BRANDMIN	57	/* first entry in GDT for brand usage */
481 #define	GDT_BRANDMAX	61	/* last entry in GDT for brand usage */
482 #define	NGDT		62	/* number of entries in GDT */
483 
484 /*
485  * This selector is only used in the temporary GDT used to bring additional
486  * CPUs from 16-bit real mode into long mode in real_mode_start().
487  */
488 #define	TEMPGDT_KCODE64	1	/* 64-bit code selector */
489 
490 #elif defined(__i386)
491 
492 #define	GDT_LDT		40	/* LDT for current process */
493 #define	GDT_KTSS	42	/* kernel tss */
494 #define	GDT_KCODE	43	/* kernel code seg %cs */
495 #define	GDT_KDATA	44	/* kernel data seg %ds */
496 #define	GDT_UCODE	45	/* native user code  seg %cs */
497 #define	GDT_UDATA	46	/* user data seg %ds (32 and 64 bit) */
498 #define	GDT_DBFLT	47	/* double fault #DF selector */
499 #define	GDT_FS		53	/* kernel %fs segment selector */
500 #define	GDT_GS		54	/* kernel %gs segment selector */
501 #define	GDT_LWPFS	55	/* lwp private %fs segment selector */
502 #define	GDT_LWPGS	56	/* lwp private %gs segment selector */
503 #define	GDT_BRANDMIN	57	/* first entry in GDT for brand usage */
504 #define	GDT_BRANDMAX	61	/* last entry in GDT for brand usage */
505 #define	NGDT		90	/* number of entries in GDT */
506 
507 #endif	/* __i386 */
508 
509 /*
510  * Convenient selector definitions.
511  */
512 #define	KCS_SEL		SEL_GDT(GDT_KCODE, SEL_KPL)
513 #define	KDS_SEL		SEL_GDT(GDT_KDATA, SEL_KPL)
514 #define	UCS_SEL		SEL_GDT(GDT_UCODE, SEL_UPL)
515 #if defined(__amd64)
516 #define	TEMP_CS64_SEL	SEL_GDT(TEMPGDT_KCODE64, SEL_KPL)
517 #define	U32CS_SEL	SEL_GDT(GDT_U32CODE, SEL_UPL)
518 #endif	/* __amd64 */
519 #define	UDS_SEL		SEL_GDT(GDT_UDATA, SEL_UPL)
520 #define	ULDT_SEL	SEL_GDT(GDT_LDT, SEL_KPL)
521 #define	KTSS_SEL	SEL_GDT(GDT_KTSS, SEL_KPL)
522 #define	DFTSS_SEL	SEL_GDT(GDT_DBFLT, SEL_KPL)
523 #define	KFS_SEL		0
524 #define	KGS_SEL		SEL_GDT(GDT_GS, SEL_KPL)
525 #define	LWPFS_SEL	SEL_GDT(GDT_LWPFS, SEL_UPL)
526 #define	LWPGS_SEL	SEL_GDT(GDT_LWPGS, SEL_UPL)
527 #define	BRANDMIN_SEL	SEL_GDT(GDT_BRANDMIN, SEL_UPL)
528 #define	BRANDMAX_SEL	SEL_GDT(GDT_BRANDMAX, SEL_UPL)
529 
530 #define	B64CODE_SEL	SEL_GDT(GDT_B64CODE, SEL_KPL)
531 #define	B32CODE_SEL	SEL_GDT(GDT_B32CODE, SEL_KPL)
532 #define	B32DATA_SEL	SEL_GDT(GDT_B32DATA, SEL_KPL)
533 #define	B16CODE_SEL	SEL_GDT(GDT_B16CODE, SEL_KPL)
534 #define	B16DATA_SEL	SEL_GDT(GDT_B16DATA, SEL_KPL)
535 
536 /*
537  * Temporary %gs descriptor used by kmdb with -d option. Only lives
538  * in boot's GDT and is not copied into kernel's GDT from boot.
539  */
540 #define	KMDBGS_SEL	SEL_GDT(GDT_BGSTMP, SEL_KPL)
541 
542 /*
543  * Selector used for kdi_idt when kmdb has taken over the IDT.
544  */
545 #if defined(__amd64)
546 #define	KMDBCODE_SEL	B64CODE_SEL
547 #else
548 #define	KMDBCODE_SEL	B32CODE_SEL
549 #endif
550 
551 /*
552  * Entries in default Local Descriptor Table (LDT) for every process.
553  */
554 #define	LDT_SYSCALL	0	/* call gate for libc.a (obsolete) */
555 #define	LDT_SIGCALL	1	/* EOL me, call gate for static sigreturn */
556 #define	LDT_RESVD1	2	/* old user %cs */
557 #define	LDT_RESVD2	3	/* old user %ds */
558 #define	LDT_ALTSYSCALL	4	/* alternate call gate for system calls */
559 #define	LDT_ALTSIGCALL	5	/* EOL me, alternate call gate for sigreturn */
560 #define	LDT_UDBASE	6	/* user descriptor base index */
561 #define	MINNLDT		64	/* Current min solaris ldt size */
562 #define	MAXNLDT		8192	/* max solaris ldt size */
563 
564 #ifndef	_ASM
565 
566 #pragma	align	16(idt0)
567 extern	gate_desc_t	idt0[NIDT];
568 extern	desctbr_t	idt0_default_reg;
569 extern	user_desc_t	*gdt0;
570 
571 extern user_desc_t	zero_udesc;
572 extern system_desc_t	zero_sdesc;
573 
574 #if defined(__amd64)
575 extern user_desc_t	zero_u32desc;
576 #endif
577 
578 #pragma	align	16(ktss0)
579 extern struct tss ktss0;
580 
581 #if defined(__i386)
582 extern struct tss dftss0;
583 #endif	/* __i386 */
584 
585 extern void div0trap(), dbgtrap(), nmiint(), brktrap(), ovflotrap();
586 extern void boundstrap(), invoptrap(), ndptrap(), syserrtrap();
587 extern void invaltrap(), invtsstrap(), segnptrap(), stktrap();
588 extern void gptrap(), pftrap(), ndperr();
589 extern void overrun(), resvtrap();
590 extern void _start(), cmnint();
591 extern void achktrap(), mcetrap();
592 extern void xmtrap();
593 extern void fasttrap();
594 extern void sys_int80();
595 extern void brand_sys_int80();
596 extern void dtrace_ret();
597 
598 #if !defined(__amd64)
599 extern void pentium_pftrap();
600 #endif
601 
602 #endif /* _ASM */
603 
604 #ifdef	__cplusplus
605 }
606 #endif
607 
608 #endif /* _SYS_SEGMENTS_H */
609