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