FreeBSD/Linux Kernel Cross Reference
sys/i386/seg.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * Copyright (c) 1991 IBM Corporation
5 * All Rights Reserved.
6 *
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation,
12 * and that the name IBM not be used in advertising or publicity
13 * pertaining to distribution of the software without specific, written
14 * prior permission.
15 *
16 * CARNEGIE MELLON AND IBM ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON AND IBM DISCLAIM ANY LIABILITY OF ANY KIND FOR
18 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie Mellon
28 * the rights to redistribute these changes.
29 */
30
31 /*
32 * HISTORY
33 * $Log: seg.h,v $
34 * Revision 2.8 93/02/04 07:57:09 danner
35 * Merge in PS2 support.
36 * [92/02/22 dbg@ibm]
37 *
38 * Revision 2.7 92/01/03 20:08:46 dbg
39 * Add USER_LDT and USER_FPREGS. Add defines for selector bits.
40 * [91/08/20 dbg]
41 *
42 * Revision 2.6 91/05/14 16:15:59 mrt
43 * Correcting copyright
44 *
45 * Revision 2.5 91/05/08 12:41:48 dbg
46 * Added USER_TSS for TSS that holds IO permission bitmap.
47 * Removed space for descriptors 8..38.
48 * Added real_descriptor, real_gate, sel_idx.
49 * [91/04/26 14:38:07 dbg]
50 *
51 * Revision 2.4 91/02/05 17:14:28 mrt
52 * Changed to new Mach copyright
53 * [91/02/01 17:37:46 mrt]
54 *
55 * Revision 2.3 90/08/27 21:58:13 dbg
56 * Created, to replace old file with same name.
57 * [90/07/25 dbg]
58 *
59 */
60
61 #ifndef _I386_SEG_H_
62 #define _I386_SEG_H_
63
64 #include <platforms.h>
65
66 /*
67 * i386 segmentation.
68 */
69
70 /*
71 * Real segment descriptor.
72 */
73 struct real_descriptor {
74 unsigned int limit_low:16, /* limit 0..15 */
75 base_low:16, /* base 0..15 */
76 base_med:8, /* base 16..23 */
77 access:8, /* access byte */
78 limit_high:4, /* limit 16..19 */
79 granularity:4, /* granularity */
80 base_high:8; /* base 24..31 */
81 };
82
83 struct real_gate {
84 unsigned int offset_low:16, /* offset 0..15 */
85 selector:16,
86 word_count:8,
87 access:8,
88 offset_high:16; /* offset 16..31 */
89 };
90
91 /*
92 * We build descriptors and gates in a 'fake' format to let the
93 * fields be contiguous. We shuffle them into the real format
94 * at runtime.
95 */
96 struct fake_descriptor {
97 unsigned int offset:32; /* offset */
98 unsigned int lim_or_seg:20; /* limit */
99 /* or segment, for gate */
100 unsigned int size_or_wdct:4; /* size/granularity */
101 /* word count, for gate */
102 unsigned int access:8; /* access */
103 };
104
105 #define SZ_32 0x4 /* 32-bit segment */
106 #define SZ_G 0x8 /* 4K limit field */
107
108 #define ACC_A 0x01 /* accessed */
109 #define ACC_TYPE 0x1e /* type field: */
110
111 #define ACC_TYPE_SYSTEM 0x00 /* system descriptors: */
112
113 #define ACC_LDT 0x02 /* LDT */
114 #define ACC_CALL_GATE_16 0x04 /* 16-bit call gate */
115 #define ACC_TASK_GATE 0x05 /* task gate */
116 #define ACC_TSS 0x09 /* task segment */
117 #define ACC_CALL_GATE 0x0c /* call gate */
118 #define ACC_INTR_GATE 0x0e /* interrupt gate */
119 #define ACC_TRAP_GATE 0x0f /* trap gate */
120
121 #define ACC_TSS_BUSY 0x02 /* task busy */
122
123 #define ACC_TYPE_USER 0x10 /* user descriptors */
124
125 #define ACC_DATA 0x10 /* data */
126 #define ACC_DATA_W 0x12 /* data, writable */
127 #define ACC_DATA_E 0x14 /* data, expand-down */
128 #define ACC_DATA_EW 0x16 /* data, expand-down,
129 writable */
130 #define ACC_CODE 0x18 /* code */
131 #define ACC_CODE_R 0x1a /* code, readable */
132 #define ACC_CODE_C 0x1c /* code, conforming */
133 #define ACC_CODE_CR 0x1e /* code, conforming,
134 readable */
135 #define ACC_PL 0x60 /* access rights: */
136 #define ACC_PL_K 0x00 /* kernel access only */
137 #define ACC_PL_U 0x60 /* user access */
138 #define ACC_P 0x80 /* segment present */
139
140 /*
141 * Components of a selector
142 */
143 #define SEL_LDT 0x04 /* local selector */
144 #define SEL_PL 0x03 /* privilege level: */
145 #define SEL_PL_K 0x00 /* kernel selector */
146 #define SEL_PL_U 0x03 /* user selector */
147
148 /*
149 * Convert selector to descriptor table index.
150 */
151 #define sel_idx(sel) ((sel)>>3)
152
153 /*
154 * User descriptors for MACH - 32-bit flat address space
155 */
156 #define USER_SCALL 0x07 /* system call gate */
157 #define USER_CS 0x17 /* user code segment */
158 #define USER_DS 0x1f /* user data segment */
159
160 #define LDTSZ 4
161
162 /*
163 * Kernel descriptors for MACH - 32-bit flat address space.
164 */
165 #define KERNEL_CS 0x08 /* kernel code */
166 #define KERNEL_DS 0x10 /* kernel data */
167 #define KERNEL_LDT 0x18 /* master LDT */
168 #define KERNEL_TSS 0x20 /* master TSS (uniprocessor) */
169 #define USER_LDT 0x28 /* place for per-thread LDT */
170 #define USER_TSS 0x30 /* place for per-thread TSS
171 that holds IO bitmap */
172 #define FPE_CS 0x38 /* floating-point emulator code */
173 #define USER_FPREGS 0x40 /* user-mode access to saved
174 floating-point registers */
175
176 #ifdef PS2
177 #define ABIOS_INT_RET 0x48 /* 16 bit return selector for ABIOS */
178 #define ABIOS_TH_RET 0x50 /* 16 bit return selector for ABIOS */
179 #define ABIOS_INT_SS 0x58 /* ABIOS interrupt stack selector */
180 #define ABIOS_TH_SS 0x60 /* ABIOS current stack selector */
181 #define ABIOS_FIRST_AVAIL_SEL \
182 0x68 /* first selector for ABIOS
183 to allocate */
184 #define GDTSZ 0x300 /* size of gdt table */
185 #else /* PS2 */
186 #define GDTSZ 9
187 #endif /* PS2 */
188
189 /*
190 * Interrupt table is always 256 entries long.
191 */
192 #define IDTSZ 256
193
194 /*
195 * Make_gdt_desc converts a segment base address, limit, access1, and access2
196 * fields into a gdt descriptor entry.
197 */
198
199 #define make_gdt_desc(sel, base, limit, acc1, acc2) \
200 { \
201 struct real_descriptor *g; \
202 g = (struct real_descriptor *) (((char *)gdt) + sel); \
203 g->limit_low = limit & 0xffff; \
204 g->base_low = base & 0xffff; \
205 g->base_med = (base >> 16) & 0xff; \
206 g->access = acc1 | ACC_P; \
207 g->limit_high= limit >> 16; \
208 g->granularity = acc2; \
209 g->base_high = base >> 24; \
210 }
211
212 #endif /* _I386_SEG_H_ */
Cache object: 43f7fc2fed716077a66d6aca055b64e7
|