xref: /minix3/sys/arch/i386/include/segments.h (revision 6c8f7fc3bac7ab5f78ee27de8bed706631d8c836)
1*6c8f7fc3SBen Gras /*	$NetBSD: segments.h,v 1.54 2011/04/26 15:51:23 joerg Exp $	*/
2*6c8f7fc3SBen Gras 
3*6c8f7fc3SBen Gras /*-
4*6c8f7fc3SBen Gras  * Copyright (c) 1990 The Regents of the University of California.
5*6c8f7fc3SBen Gras  * All rights reserved.
6*6c8f7fc3SBen Gras  *
7*6c8f7fc3SBen Gras  * This code is derived from software contributed to Berkeley by
8*6c8f7fc3SBen Gras  * William Jolitz.
9*6c8f7fc3SBen Gras  *
10*6c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
11*6c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
12*6c8f7fc3SBen Gras  * are met:
13*6c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
14*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
15*6c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
16*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
17*6c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
18*6c8f7fc3SBen Gras  * 3. Neither the name of the University nor the names of its contributors
19*6c8f7fc3SBen Gras  *    may be used to endorse or promote products derived from this software
20*6c8f7fc3SBen Gras  *    without specific prior written permission.
21*6c8f7fc3SBen Gras  *
22*6c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*6c8f7fc3SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*6c8f7fc3SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*6c8f7fc3SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*6c8f7fc3SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*6c8f7fc3SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*6c8f7fc3SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*6c8f7fc3SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*6c8f7fc3SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*6c8f7fc3SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*6c8f7fc3SBen Gras  * SUCH DAMAGE.
33*6c8f7fc3SBen Gras  *
34*6c8f7fc3SBen Gras  *	@(#)segments.h	7.1 (Berkeley) 5/9/91
35*6c8f7fc3SBen Gras  */
36*6c8f7fc3SBen Gras 
37*6c8f7fc3SBen Gras /*-
38*6c8f7fc3SBen Gras  * Copyright (c) 1995, 1997
39*6c8f7fc3SBen Gras  *	Charles M. Hannum.  All rights reserved.
40*6c8f7fc3SBen Gras  * Copyright (c) 1989, 1990 William F. Jolitz
41*6c8f7fc3SBen Gras  *
42*6c8f7fc3SBen Gras  * This code is derived from software contributed to Berkeley by
43*6c8f7fc3SBen Gras  * William Jolitz.
44*6c8f7fc3SBen Gras  *
45*6c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
46*6c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
47*6c8f7fc3SBen Gras  * are met:
48*6c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
49*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
50*6c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
51*6c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
52*6c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
53*6c8f7fc3SBen Gras  * 3. All advertising materials mentioning features or use of this software
54*6c8f7fc3SBen Gras  *    must display the following acknowledgement:
55*6c8f7fc3SBen Gras  *	This product includes software developed by the University of
56*6c8f7fc3SBen Gras  *	California, Berkeley and its contributors.
57*6c8f7fc3SBen Gras  * 4. Neither the name of the University nor the names of its contributors
58*6c8f7fc3SBen Gras  *    may be used to endorse or promote products derived from this software
59*6c8f7fc3SBen Gras  *    without specific prior written permission.
60*6c8f7fc3SBen Gras  *
61*6c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62*6c8f7fc3SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63*6c8f7fc3SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64*6c8f7fc3SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65*6c8f7fc3SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66*6c8f7fc3SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67*6c8f7fc3SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68*6c8f7fc3SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69*6c8f7fc3SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70*6c8f7fc3SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71*6c8f7fc3SBen Gras  * SUCH DAMAGE.
72*6c8f7fc3SBen Gras  *
73*6c8f7fc3SBen Gras  *	@(#)segments.h	7.1 (Berkeley) 5/9/91
74*6c8f7fc3SBen Gras  */
75*6c8f7fc3SBen Gras 
76*6c8f7fc3SBen Gras /*
77*6c8f7fc3SBen Gras  * 386 Segmentation Data Structures and definitions
78*6c8f7fc3SBen Gras  *	William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
79*6c8f7fc3SBen Gras  */
80*6c8f7fc3SBen Gras 
81*6c8f7fc3SBen Gras #ifndef _I386_SEGMENTS_H_
82*6c8f7fc3SBen Gras #define _I386_SEGMENTS_H_
83*6c8f7fc3SBen Gras #ifdef _KERNEL_OPT
84*6c8f7fc3SBen Gras #include "opt_xen.h"
85*6c8f7fc3SBen Gras #endif
86*6c8f7fc3SBen Gras 
87*6c8f7fc3SBen Gras /*
88*6c8f7fc3SBen Gras  * Selectors
89*6c8f7fc3SBen Gras  */
90*6c8f7fc3SBen Gras 
91*6c8f7fc3SBen Gras #define	ISPL(s)		((s) & SEL_RPL)	/* what is the priority level of a selector */
92*6c8f7fc3SBen Gras #ifndef XEN
93*6c8f7fc3SBen Gras #define	SEL_KPL		0		/* kernel privilege level */
94*6c8f7fc3SBen Gras #else
95*6c8f7fc3SBen Gras #define	SEL_XEN		0		/* Xen privilege level */
96*6c8f7fc3SBen Gras #define	SEL_KPL		1		/* kernel privilege level */
97*6c8f7fc3SBen Gras #endif /* XEN */
98*6c8f7fc3SBen Gras #define	SEL_UPL		3		/* user privilege level */
99*6c8f7fc3SBen Gras #define	SEL_RPL		3		/* requester's privilege level mask */
100*6c8f7fc3SBen Gras #ifdef XEN
101*6c8f7fc3SBen Gras #define	CHK_UPL		2		/* user privilege level mask */
102*6c8f7fc3SBen Gras #else
103*6c8f7fc3SBen Gras #define CHK_UPL		SEL_RPL
104*6c8f7fc3SBen Gras #endif /* XEN */
105*6c8f7fc3SBen Gras #define	ISLDT(s)	((s) & SEL_LDT)	/* is it local or global */
106*6c8f7fc3SBen Gras #define	SEL_LDT		4		/* local descriptor table */
107*6c8f7fc3SBen Gras #define	IDXSEL(s)	(((s) >> 3) & 0x1fff)		/* index of selector */
108*6c8f7fc3SBen Gras #define	IDXSELN(s)	(((s) >> 3))			/* index of selector */
109*6c8f7fc3SBen Gras #define	GSEL(s,r)	(((s) << 3) | r)		/* a global selector */
110*6c8f7fc3SBen Gras #define	LSEL(s,r)	(((s) << 3) | r | SEL_LDT)	/* a local selector */
111*6c8f7fc3SBen Gras #define	GSYSSEL(s,r)	GSEL(s,r)	/* compat with amd64 */
112*6c8f7fc3SBen Gras 
113*6c8f7fc3SBen Gras #if defined(_KERNEL_OPT)
114*6c8f7fc3SBen Gras #include "opt_vm86.h"
115*6c8f7fc3SBen Gras #endif
116*6c8f7fc3SBen Gras 
117*6c8f7fc3SBen Gras #ifdef VM86
118*6c8f7fc3SBen Gras #define	USERMODE(c, f)		(ISPL(c) == SEL_UPL || ((f) & PSL_VM) != 0)
119*6c8f7fc3SBen Gras #define	KERNELMODE(c, f)	(ISPL(c) == SEL_KPL && ((f) & PSL_VM) == 0)
120*6c8f7fc3SBen Gras #else
121*6c8f7fc3SBen Gras #define	USERMODE(c, f)		(ISPL(c) == SEL_UPL)
122*6c8f7fc3SBen Gras #define	KERNELMODE(c, f)	(ISPL(c) == SEL_KPL)
123*6c8f7fc3SBen Gras #endif
124*6c8f7fc3SBen Gras 
125*6c8f7fc3SBen Gras #ifndef _LOCORE
126*6c8f7fc3SBen Gras 
127*6c8f7fc3SBen Gras #if __GNUC__ == 2 && __GNUC_MINOR__ < 7
128*6c8f7fc3SBen Gras #pragma pack(1)
129*6c8f7fc3SBen Gras #endif
130*6c8f7fc3SBen Gras 
131*6c8f7fc3SBen Gras /*
132*6c8f7fc3SBen Gras  * Memory and System segment descriptors
133*6c8f7fc3SBen Gras  */
134*6c8f7fc3SBen Gras struct segment_descriptor {
135*6c8f7fc3SBen Gras 	unsigned sd_lolimit:16;		/* segment extent (lsb) */
136*6c8f7fc3SBen Gras 	unsigned sd_lobase:24;		/* segment base address (lsb) */
137*6c8f7fc3SBen Gras 	unsigned sd_type:5;		/* segment type */
138*6c8f7fc3SBen Gras 	unsigned sd_dpl:2;		/* segment descriptor priority level */
139*6c8f7fc3SBen Gras 	unsigned sd_p:1;		/* segment descriptor present */
140*6c8f7fc3SBen Gras 	unsigned sd_hilimit:4;		/* segment extent (msb) */
141*6c8f7fc3SBen Gras 	unsigned sd_xx:2;		/* unused */
142*6c8f7fc3SBen Gras 	unsigned sd_def32:1;		/* default 32 vs 16 bit size */
143*6c8f7fc3SBen Gras 	unsigned sd_gran:1;		/* limit granularity (byte/page) */
144*6c8f7fc3SBen Gras 	unsigned sd_hibase:8;		/* segment base address (msb) */
145*6c8f7fc3SBen Gras } __packed;
146*6c8f7fc3SBen Gras 
147*6c8f7fc3SBen Gras /*
148*6c8f7fc3SBen Gras  * Gate descriptors (e.g. indirect descriptors)
149*6c8f7fc3SBen Gras  */
150*6c8f7fc3SBen Gras struct gate_descriptor {
151*6c8f7fc3SBen Gras 	unsigned gd_looffset:16;	/* gate offset (lsb) */
152*6c8f7fc3SBen Gras 	unsigned gd_selector:16;	/* gate segment selector */
153*6c8f7fc3SBen Gras 	unsigned gd_stkcpy:5;		/* number of stack wds to cpy */
154*6c8f7fc3SBen Gras 	unsigned gd_xx:3;		/* unused */
155*6c8f7fc3SBen Gras 	unsigned gd_type:5;		/* segment type */
156*6c8f7fc3SBen Gras 	unsigned gd_dpl:2;		/* segment descriptor priority level */
157*6c8f7fc3SBen Gras 	unsigned gd_p:1;		/* segment descriptor present */
158*6c8f7fc3SBen Gras 	unsigned gd_hioffset:16;	/* gate offset (msb) */
159*6c8f7fc3SBen Gras } __packed;
160*6c8f7fc3SBen Gras 
161*6c8f7fc3SBen Gras struct ldt_descriptor {
162*6c8f7fc3SBen Gras 	vaddr_t ld_base;
163*6c8f7fc3SBen Gras 	uint32_t ld_entries;
164*6c8f7fc3SBen Gras } __packed;
165*6c8f7fc3SBen Gras 
166*6c8f7fc3SBen Gras /*
167*6c8f7fc3SBen Gras  * Generic descriptor
168*6c8f7fc3SBen Gras  */
169*6c8f7fc3SBen Gras union descriptor {
170*6c8f7fc3SBen Gras 	struct segment_descriptor sd;
171*6c8f7fc3SBen Gras 	struct gate_descriptor gd;
172*6c8f7fc3SBen Gras 	struct ldt_descriptor ld;
173*6c8f7fc3SBen Gras 	uint32_t raw[2];
174*6c8f7fc3SBen Gras 	uint64_t raw64;
175*6c8f7fc3SBen Gras } __packed;
176*6c8f7fc3SBen Gras 
177*6c8f7fc3SBen Gras /*
178*6c8f7fc3SBen Gras  * region descriptors, used to load gdt/idt tables before segments yet exist.
179*6c8f7fc3SBen Gras  */
180*6c8f7fc3SBen Gras struct region_descriptor {
181*6c8f7fc3SBen Gras 	unsigned rd_limit:16;		/* segment extent */
182*6c8f7fc3SBen Gras 	unsigned rd_base:32;		/* base address  */
183*6c8f7fc3SBen Gras } __packed;
184*6c8f7fc3SBen Gras 
185*6c8f7fc3SBen Gras #if __GNUC__ == 2 && __GNUC_MINOR__ < 7
186*6c8f7fc3SBen Gras #pragma pack(4)
187*6c8f7fc3SBen Gras #endif
188*6c8f7fc3SBen Gras 
189*6c8f7fc3SBen Gras #ifdef _KERNEL
190*6c8f7fc3SBen Gras extern union descriptor *gdt, *ldt;
191*6c8f7fc3SBen Gras extern struct gate_descriptor *idt;
192*6c8f7fc3SBen Gras 
193*6c8f7fc3SBen Gras void setgate(struct gate_descriptor *, void *, int, int, int, int);
194*6c8f7fc3SBen Gras void setregion(struct region_descriptor *, void *, size_t);
195*6c8f7fc3SBen Gras void setsegment(struct segment_descriptor *, const void *, size_t, int, int,
196*6c8f7fc3SBen Gras     int, int);
197*6c8f7fc3SBen Gras void setgdt(int, const void *, size_t, int, int, int, int);
198*6c8f7fc3SBen Gras void unsetgate(struct gate_descriptor *);
199*6c8f7fc3SBen Gras void cpu_init_idt(void);
200*6c8f7fc3SBen Gras void update_descriptor(union descriptor *, union descriptor *);
201*6c8f7fc3SBen Gras 
202*6c8f7fc3SBen Gras #if !defined(XEN)
203*6c8f7fc3SBen Gras void idt_init(void);
204*6c8f7fc3SBen Gras void idt_vec_reserve(int);
205*6c8f7fc3SBen Gras int idt_vec_alloc(int, int);
206*6c8f7fc3SBen Gras void idt_vec_set(int, void (*)(void));
207*6c8f7fc3SBen Gras void idt_vec_free(int);
208*6c8f7fc3SBen Gras #endif
209*6c8f7fc3SBen Gras 
210*6c8f7fc3SBen Gras #endif /* _KERNEL */
211*6c8f7fc3SBen Gras 
212*6c8f7fc3SBen Gras #endif /* !_LOCORE */
213*6c8f7fc3SBen Gras 
214*6c8f7fc3SBen Gras /* system segments and gate types */
215*6c8f7fc3SBen Gras #define	SDT_SYSNULL	 0	/* system null */
216*6c8f7fc3SBen Gras #define	SDT_SYS286TSS	 1	/* system 286 TSS available */
217*6c8f7fc3SBen Gras #define	SDT_SYSLDT	 2	/* system local descriptor table */
218*6c8f7fc3SBen Gras #define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
219*6c8f7fc3SBen Gras #define	SDT_SYS286CGT	 4	/* system 286 call gate */
220*6c8f7fc3SBen Gras #define	SDT_SYSTASKGT	 5	/* system task gate */
221*6c8f7fc3SBen Gras #define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
222*6c8f7fc3SBen Gras #define	SDT_SYS286TGT	 7	/* system 286 trap gate */
223*6c8f7fc3SBen Gras #define	SDT_SYSNULL2	 8	/* system null again */
224*6c8f7fc3SBen Gras #define	SDT_SYS386TSS	 9	/* system 386 TSS available */
225*6c8f7fc3SBen Gras #define	SDT_SYSNULL3	10	/* system null again */
226*6c8f7fc3SBen Gras #define	SDT_SYS386BSY	11	/* system 386 TSS busy */
227*6c8f7fc3SBen Gras #define	SDT_SYS386CGT	12	/* system 386 call gate */
228*6c8f7fc3SBen Gras #define	SDT_SYSNULL4	13	/* system null again */
229*6c8f7fc3SBen Gras #define	SDT_SYS386IGT	14	/* system 386 interrupt gate */
230*6c8f7fc3SBen Gras #define	SDT_SYS386TGT	15	/* system 386 trap gate */
231*6c8f7fc3SBen Gras 
232*6c8f7fc3SBen Gras /* memory segment types */
233*6c8f7fc3SBen Gras #define	SDT_MEMRO	16	/* memory read only */
234*6c8f7fc3SBen Gras #define	SDT_MEMROA	17	/* memory read only accessed */
235*6c8f7fc3SBen Gras #define	SDT_MEMRW	18	/* memory read write */
236*6c8f7fc3SBen Gras #define	SDT_MEMRWA	19	/* memory read write accessed */
237*6c8f7fc3SBen Gras #define	SDT_MEMROD	20	/* memory read only expand dwn limit */
238*6c8f7fc3SBen Gras #define	SDT_MEMRODA	21	/* memory read only expand dwn limit accessed */
239*6c8f7fc3SBen Gras #define	SDT_MEMRWD	22	/* memory read write expand dwn limit */
240*6c8f7fc3SBen Gras #define	SDT_MEMRWDA	23	/* memory read write expand dwn limit acessed */
241*6c8f7fc3SBen Gras #define	SDT_MEME	24	/* memory execute only */
242*6c8f7fc3SBen Gras #define	SDT_MEMEA	25	/* memory execute only accessed */
243*6c8f7fc3SBen Gras #define	SDT_MEMER	26	/* memory execute read */
244*6c8f7fc3SBen Gras #define	SDT_MEMERA	27	/* memory execute read accessed */
245*6c8f7fc3SBen Gras #define	SDT_MEMEC	28	/* memory execute only conforming */
246*6c8f7fc3SBen Gras #define	SDT_MEMEAC	29	/* memory execute only accessed conforming */
247*6c8f7fc3SBen Gras #define	SDT_MEMERC	30	/* memory execute read conforming */
248*6c8f7fc3SBen Gras #define	SDT_MEMERAC	31	/* memory execute read accessed conforming */
249*6c8f7fc3SBen Gras 
250*6c8f7fc3SBen Gras #define SDTYPE(p)	(((const struct segment_descriptor *)(p))->sd_type)
251*6c8f7fc3SBen Gras /* is memory segment descriptor pointer ? */
252*6c8f7fc3SBen Gras #define ISMEMSDP(s)	(SDTYPE(s) >= SDT_MEMRO && \
253*6c8f7fc3SBen Gras 			 SDTYPE(s) <= SDT_MEMERAC)
254*6c8f7fc3SBen Gras 
255*6c8f7fc3SBen Gras /* is 286 gate descriptor pointer ? */
256*6c8f7fc3SBen Gras #define IS286GDP(s)	(SDTYPE(s) >= SDT_SYS286CGT && \
257*6c8f7fc3SBen Gras 			 SDTYPE(s) < SDT_SYS286TGT)
258*6c8f7fc3SBen Gras 
259*6c8f7fc3SBen Gras /* is 386 gate descriptor pointer ? */
260*6c8f7fc3SBen Gras #define IS386GDP(s)	(SDTYPE(s) >= SDT_SYS386CGT && \
261*6c8f7fc3SBen Gras 			 SDTYPE(s) < SDT_SYS386TGT)
262*6c8f7fc3SBen Gras 
263*6c8f7fc3SBen Gras /* is gate descriptor pointer ? */
264*6c8f7fc3SBen Gras #define ISGDP(s)	(IS286GDP(s) || IS386GDP(s))
265*6c8f7fc3SBen Gras 
266*6c8f7fc3SBen Gras /* is segment descriptor pointer ? */
267*6c8f7fc3SBen Gras #define ISSDP(s)	(ISMEMSDP(s) || !ISGDP(s))
268*6c8f7fc3SBen Gras 
269*6c8f7fc3SBen Gras /* is system segment descriptor pointer ? */
270*6c8f7fc3SBen Gras #define ISSYSSDP(s)	(!ISMEMSDP(s) && !ISGDP(s))
271*6c8f7fc3SBen Gras 
272*6c8f7fc3SBen Gras /*
273*6c8f7fc3SBen Gras  * Segment Protection Exception code bits
274*6c8f7fc3SBen Gras  */
275*6c8f7fc3SBen Gras #define	SEGEX_EXT	0x01	/* recursive or externally induced */
276*6c8f7fc3SBen Gras #define	SEGEX_IDT	0x02	/* interrupt descriptor table */
277*6c8f7fc3SBen Gras #define	SEGEX_TI	0x04	/* local descriptor table */
278*6c8f7fc3SBen Gras 
279*6c8f7fc3SBen Gras /*
280*6c8f7fc3SBen Gras  * Entries in the Interrupt Descriptor Table (IDT)
281*6c8f7fc3SBen Gras  */
282*6c8f7fc3SBen Gras #define	NIDT	256
283*6c8f7fc3SBen Gras #define	NRSVIDT	32		/* reserved entries for CPU exceptions */
284*6c8f7fc3SBen Gras 
285*6c8f7fc3SBen Gras /*
286*6c8f7fc3SBen Gras  * Entries in the Global Descriptor Table (GDT).
287*6c8f7fc3SBen Gras  *
288*6c8f7fc3SBen Gras  * NB: If you change GBIOSCODE/GBIOSDATA, you *must* rebuild arch/i386/
289*6c8f7fc3SBen Gras  * bioscall/biostramp.inc, as that relies on GBIOSCODE/GBIOSDATA and a
290*6c8f7fc3SBen Gras  * normal kernel build does not rebuild it (it's merely included whole-
291*6c8f7fc3SBen Gras  * sale from i386/bioscall.s)
292*6c8f7fc3SBen Gras  *
293*6c8f7fc3SBen Gras  * Also, note that the GEXTBIOSDATA_SEL selector is special, as it maps
294*6c8f7fc3SBen Gras  * to the value 0x0040 (when created as a KPL global selector).  Some
295*6c8f7fc3SBen Gras  * BIOSes reference the extended BIOS data area at segment 0040 in a non
296*6c8f7fc3SBen Gras  * relocatable fashion (even when in protected mode); mapping the zero page
297*6c8f7fc3SBen Gras  * via the GEXTBIOSDATA_SEL allows these buggy BIOSes to continue to work
298*6c8f7fc3SBen Gras  * under NetBSD.
299*6c8f7fc3SBen Gras  *
300*6c8f7fc3SBen Gras  * The order if the first 5 descriptors is special; the sysenter/sysexit
301*6c8f7fc3SBen Gras  * instructions depend on them.
302*6c8f7fc3SBen Gras  */
303*6c8f7fc3SBen Gras #define	GNULL_SEL	0	/* Null descriptor */
304*6c8f7fc3SBen Gras #define	GCODE_SEL	1	/* Kernel code descriptor */
305*6c8f7fc3SBen Gras #define	GDATA_SEL	2	/* Kernel data descriptor */
306*6c8f7fc3SBen Gras #define	GUCODE_SEL	3	/* User code descriptor */
307*6c8f7fc3SBen Gras #define	GUDATA_SEL	4	/* User data descriptor */
308*6c8f7fc3SBen Gras #define	GLDT_SEL	5	/* Default LDT descriptor */
309*6c8f7fc3SBen Gras #define GCPU_SEL	6	/* per-CPU segment */
310*6c8f7fc3SBen Gras #define	GEXTBIOSDATA_SEL 8	/* magic to catch BIOS refs to EBDA */
311*6c8f7fc3SBen Gras #define	GAPM32CODE_SEL	9	/* 3 APM segments must be consecutive */
312*6c8f7fc3SBen Gras #define	GAPM16CODE_SEL	10	/* and in the specified order: code32 */
313*6c8f7fc3SBen Gras #define	GAPMDATA_SEL	11	/* code16 and then data per APM spec */
314*6c8f7fc3SBen Gras #define	GBIOSCODE_SEL	12
315*6c8f7fc3SBen Gras #define	GBIOSDATA_SEL	13
316*6c8f7fc3SBen Gras #define	GPNPBIOSCODE_SEL 14
317*6c8f7fc3SBen Gras #define	GPNPBIOSDATA_SEL 15
318*6c8f7fc3SBen Gras #define	GPNPBIOSSCRATCH_SEL 16
319*6c8f7fc3SBen Gras #define	GPNPBIOSTRAMP_SEL 17
320*6c8f7fc3SBen Gras #define GTRAPTSS_SEL	18
321*6c8f7fc3SBen Gras #define GIPITSS_SEL	19
322*6c8f7fc3SBen Gras #define GUCODEBIG_SEL	20	/* User code with executable stack */
323*6c8f7fc3SBen Gras #define	GUFS_SEL	21	/* Per-thread %fs */
324*6c8f7fc3SBen Gras #define	GUGS_SEL	22	/* Per-thread %gs */
325*6c8f7fc3SBen Gras #define	NGDT		23
326*6c8f7fc3SBen Gras 
327*6c8f7fc3SBen Gras /*
328*6c8f7fc3SBen Gras  * Entries in the Local Descriptor Table (LDT).
329*6c8f7fc3SBen Gras  * DO NOT ADD KERNEL DATA/CODE SEGMENTS TO THIS TABLE.
330*6c8f7fc3SBen Gras  */
331*6c8f7fc3SBen Gras #define	LSYS5CALLS_SEL	0	/* iBCS system call gate */
332*6c8f7fc3SBen Gras #define	LSYS5SIGR_SEL	1	/* iBCS sigreturn gate */
333*6c8f7fc3SBen Gras #define	LUCODE_SEL	2	/* User code descriptor */
334*6c8f7fc3SBen Gras #define	LUDATA_SEL	3	/* User data descriptor */
335*6c8f7fc3SBen Gras #define	LSOL26CALLS_SEL	4	/* Solaris 2.6 system call gate */
336*6c8f7fc3SBen Gras #define	LUCODEBIG_SEL	5	/* User code with executable stack */
337*6c8f7fc3SBen Gras #define	LBSDICALLS_SEL	16	/* BSDI system call gate */
338*6c8f7fc3SBen Gras #define	NLDT		17
339*6c8f7fc3SBen Gras 
340*6c8f7fc3SBen Gras #endif /* _I386_SEGMENTS_H_ */
341