]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/seg.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / i386 / seg.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 #ifndef _I386_SEG_H_
54 #define _I386_SEG_H_
55
56 #include <mach_kdb.h>
57 #include <stdint.h>
58 #include <architecture/i386/sel.h>
59
60 /*
61 * i386 segmentation.
62 */
63
64 static inline uint16_t
65 sel_to_selector(sel_t sel)
66 {
67 union {
68 sel_t sel;
69 uint16_t selector;
70 } tconv;
71
72 tconv.sel = sel;
73
74 return (tconv.selector);
75 }
76
77 static inline sel_t
78 selector_to_sel(uint16_t selector)
79 {
80 union {
81 uint16_t selector;
82 sel_t sel;
83 } tconv;
84
85 tconv.selector = selector;
86
87 return (tconv.sel);
88 }
89
90 #define LDTSZ 15 /* size of the kernel ldt in entries*/
91
92 #if MACH_KDB
93 #ifdef MACH_BSD
94 #define GDTSZ 14
95 #else
96 #define GDTSZ 11
97 #endif
98 #else /* MACH_KDB */
99 #ifdef MACH_BSD
100 #define GDTSZ 13
101 #else
102 #define GDTSZ 10
103 #endif
104 #endif /* MACH_KDB */
105
106 /*
107 * Interrupt table is always 256 entries long.
108 */
109 #define IDTSZ 256
110
111 #ifndef __ASSEMBLER__
112
113 #include <sys/cdefs.h>
114
115 /*
116 * Real segment descriptor.
117 */
118 struct real_descriptor {
119 unsigned int limit_low:16, /* limit 0..15 */
120 base_low:16, /* base 0..15 */
121 base_med:8, /* base 16..23 */
122 access:8, /* access byte */
123 limit_high:4, /* limit 16..19 */
124 granularity:4, /* granularity */
125 base_high:8; /* base 24..31 */
126 };
127
128 struct real_gate {
129 unsigned int offset_low:16, /* offset 0..15 */
130 selector:16,
131 word_count:8,
132 access:8,
133 offset_high:16; /* offset 16..31 */
134 };
135
136 /*
137 * We build descriptors and gates in a 'fake' format to let the
138 * fields be contiguous. We shuffle them into the real format
139 * at runtime.
140 */
141 struct fake_descriptor {
142 unsigned int offset:32; /* offset */
143 unsigned int lim_or_seg:20; /* limit */
144 /* or segment, for gate */
145 unsigned int size_or_wdct:4; /* size/granularity */
146 /* word count, for gate */
147 unsigned int access:8; /* access */
148 };
149
150 /*
151 * Boot-time data for master (or only) CPU
152 */
153 extern struct fake_descriptor idt[IDTSZ];
154 extern struct fake_descriptor gdt[GDTSZ];
155 extern struct fake_descriptor ldt[LDTSZ];
156 extern struct i386_tss ktss;
157
158 __BEGIN_DECLS
159
160 #if MACH_KDB
161 extern char db_stack_store[];
162 extern char db_task_stack_store[];
163 extern struct i386_tss dbtss;
164 extern void db_task_start(void);
165 #endif /* MACH_KDB */
166
167 __END_DECLS
168
169 #endif /*__ASSEMBLER__*/
170
171 #define SZ_32 0x4 /* 32-bit segment */
172 #define SZ_G 0x8 /* 4K limit field */
173
174 #define ACC_A 0x01 /* accessed */
175 #define ACC_TYPE 0x1e /* type field: */
176
177 #define ACC_TYPE_SYSTEM 0x00 /* system descriptors: */
178
179 #define ACC_LDT 0x02 /* LDT */
180 #define ACC_CALL_GATE_16 0x04 /* 16-bit call gate */
181 #define ACC_TASK_GATE 0x05 /* task gate */
182 #define ACC_TSS 0x09 /* task segment */
183 #define ACC_CALL_GATE 0x0c /* call gate */
184 #define ACC_INTR_GATE 0x0e /* interrupt gate */
185 #define ACC_TRAP_GATE 0x0f /* trap gate */
186
187 #define ACC_TSS_BUSY 0x02 /* task busy */
188
189 #define ACC_TYPE_USER 0x10 /* user descriptors */
190
191 #define ACC_DATA 0x10 /* data */
192 #define ACC_DATA_W 0x12 /* data, writable */
193 #define ACC_DATA_E 0x14 /* data, expand-down */
194 #define ACC_DATA_EW 0x16 /* data, expand-down,
195 writable */
196 #define ACC_CODE 0x18 /* code */
197 #define ACC_CODE_R 0x1a /* code, readable */
198 #define ACC_CODE_C 0x1c /* code, conforming */
199 #define ACC_CODE_CR 0x1e /* code, conforming,
200 readable */
201 #define ACC_PL 0x60 /* access rights: */
202 #define ACC_PL_K 0x00 /* kernel access only */
203 #define ACC_PL_U 0x60 /* user access */
204 #define ACC_P 0x80 /* segment present */
205
206 /*
207 * Components of a selector
208 */
209 #define SEL_LDTS 0x04 /* local selector */
210 #define SEL_PL 0x03 /* privilege level: */
211 #define SEL_PL_K 0x00 /* kernel selector */
212 #define SEL_PL_U 0x03 /* user selector */
213
214 /*
215 * Convert selector to descriptor table index.
216 */
217 #define sel_idx(sel) (selector_to_sel(sel).index)
218
219 #define NULL_SEG 0
220
221 /*
222 * User descriptors for MACH - 32-bit flat address space
223 */
224 #define USER_SCALL 0x07 /* system call gate */
225 #define USER_RPC 0x0f /* mach rpc call gate */
226 #define USER_CS 0x17 /* user code segment */
227 #define USER_DS 0x1f /* user data segment */
228 #define USER_CTHREAD 0x27 /* user cthread area */
229 #define USER_SETTABLE 0x2f /* start of user settable ldt entries */
230 #define USLDTSZ 10 /* number of user settable entries */
231
232 /*
233 * Kernel descriptors for MACH - 32-bit flat address space.
234 */
235 #define KERNEL_CS 0x08 /* kernel code */
236 #define KERNEL_DS 0x10 /* kernel data */
237 #define KERNEL_LDT 0x18 /* master LDT */
238 #define KERNEL_TSS 0x20 /* master TSS (uniprocessor) */
239 #ifdef MACH_BSD
240 #define BSD_SCALL_SEL 0x28 /* BSD System calls */
241 #define MK25_SCALL_SEL 0x30 /* MK25 System Calls */
242 #define MACHDEP_SCALL_SEL 0x38 /* Machdep SYstem calls */
243 #else
244 #define USER_LDT 0x28 /* place for per-thread LDT */
245 #define USER_TSS 0x30 /* place for per-thread TSS
246 that holds IO bitmap */
247 #define FPE_CS 0x38 /* floating-point emulator code */
248 #endif
249 #define USER_FPREGS 0x40 /* user-mode access to saved
250 floating-point registers */
251 #define CPU_DATA_GS 0x48 /* per-cpu data */
252
253 #ifdef MACH_BSD
254 #define USER_LDT 0x58
255 #define USER_TSS 0x60
256 #define FPE_CS 0x68
257 #endif
258
259 #if MACH_KDB
260 #define DEBUG_TSS 0x50 /* debug TSS (uniprocessor) */
261 #endif
262
263 #endif /* _I386_SEG_H_ */