]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e | 2 | * Copyright (c) 2000-2012 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
36 | * Permission to use, copy, modify and distribute this software and its |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
0a7de745 | 41 | * |
1c79356b A |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. | |
55 | */ | |
0a7de745 A |
56 | #ifndef _I386_SEG_H_ |
57 | #define _I386_SEG_H_ | |
b0d623f7 | 58 | #ifndef __ASSEMBLER__ |
91447636 | 59 | #include <stdint.h> |
0c530ab8 | 60 | #include <mach/vm_types.h> |
91447636 | 61 | #include <architecture/i386/sel.h> |
1c79356b A |
62 | |
63 | /* | |
64 | * i386 segmentation. | |
65 | */ | |
66 | ||
91447636 | 67 | static inline uint16_t |
0a7de745 | 68 | sel_to_selector(sel_t sel) |
91447636 | 69 | { |
0a7de745 A |
70 | union { |
71 | sel_t sel; | |
72 | uint16_t selector; | |
73 | } tconv; | |
74 | ||
75 | tconv.sel = sel; | |
76 | ||
77 | return tconv.selector; | |
91447636 A |
78 | } |
79 | ||
80 | static inline sel_t | |
81 | selector_to_sel(uint16_t selector) | |
82 | { | |
0a7de745 A |
83 | union { |
84 | uint16_t selector; | |
85 | sel_t sel; | |
86 | } tconv; | |
87 | ||
88 | tconv.selector = selector; | |
89 | ||
90 | return tconv.sel; | |
91447636 A |
91 | } |
92 | ||
0a7de745 A |
93 | #define LDTSZ_MAX 8192 /* maximal size of the kernel ldt in entries */ |
94 | #define LDTSZ_DFL (128) | |
95 | #define LDTSZ (LDTSZ_MAX) | |
96 | #define LDTSZ_MIN SEL_TO_INDEX(USER_SETTABLE) | |
97 | /* kernel ldt entries */ | |
91447636 | 98 | |
0a7de745 | 99 | #define GDTSZ 19 |
91447636 A |
100 | |
101 | /* | |
102 | * Interrupt table is always 256 entries long. | |
103 | */ | |
0a7de745 | 104 | #define IDTSZ 256 |
91447636 | 105 | |
91447636 A |
106 | #include <sys/cdefs.h> |
107 | ||
1c79356b A |
108 | /* |
109 | * Real segment descriptor. | |
110 | */ | |
111 | struct real_descriptor { | |
0a7de745 A |
112 | uint32_t limit_low:16, /* limit 0..15 */ |
113 | base_low:16, /* base 0..15 */ | |
114 | base_med:8, /* base 16..23 */ | |
115 | access:8, /* access byte */ | |
116 | limit_high:4, /* limit 16..19 */ | |
117 | granularity:4, /* granularity */ | |
118 | base_high:8; /* base 24..31 */ | |
1c79356b | 119 | }; |
0c530ab8 | 120 | struct real_descriptor64 { |
0a7de745 A |
121 | uint32_t limit_low16:16, /* limit 0..15 */ |
122 | base_low16:16, /* base 0..15 */ | |
123 | base_med8:8, /* base 16..23 */ | |
124 | access8:8, /* access byte */ | |
125 | limit_high4:4, /* limit 16..19 */ | |
126 | granularity4:4, /* granularity */ | |
127 | base_high8:8, /* base 24..31 */ | |
128 | base_top32:32, /* base 32..63 */ | |
129 | reserved32:32; /* reserved/zero */ | |
0c530ab8 | 130 | }; |
1c79356b | 131 | struct real_gate { |
0a7de745 A |
132 | uint32_t offset_low:16, /* offset 0..15 */ |
133 | selector:16, | |
134 | word_count:8, | |
135 | access:8, | |
136 | offset_high:16; /* offset 16..31 */ | |
1c79356b | 137 | }; |
0c530ab8 | 138 | struct real_gate64 { |
0a7de745 A |
139 | uint32_t offset_low16:16, /* offset 0..15 */ |
140 | selector16:16, | |
141 | IST:3, | |
142 | zeroes5:5, | |
143 | access8:8, | |
144 | offset_high16:16, /* offset 16..31 */ | |
145 | offset_top32:32, /* offset 32..63 */ | |
146 | reserved32:32; /* reserved/zero */ | |
0c530ab8 | 147 | }; |
1c79356b | 148 | |
0a7de745 | 149 | #define MAKE_REAL_DESCRIPTOR(base, lim, gran, acc) {\ |
b0d623f7 A |
150 | .limit_low = lim & 0xffff, \ |
151 | .limit_high = (lim >> 16) & 0xf, \ | |
152 | .base_low = base & 0xffff, \ | |
153 | .base_med = (base >> 16) & 0xff, \ | |
154 | .base_high = (base >> 24) & 0xff, \ | |
155 | .access = acc, \ | |
156 | .granularity = gran \ | |
157 | } | |
158 | ||
1c79356b A |
159 | /* |
160 | * We build descriptors and gates in a 'fake' format to let the | |
161 | * fields be contiguous. We shuffle them into the real format | |
162 | * at runtime. | |
163 | */ | |
164 | struct fake_descriptor { | |
0a7de745 A |
165 | uint32_t offset:32; /* offset */ |
166 | uint32_t lim_or_seg:20; /* limit */ | |
167 | /* or segment, for gate */ | |
168 | uint32_t size_or_wdct:4; /* size/granularity */ | |
169 | /* word count, for gate */ | |
170 | uint32_t access:8; /* access */ | |
4452a7af | 171 | }; |
0c530ab8 | 172 | struct fake_descriptor64 { |
0a7de745 A |
173 | uint64_t offset64; /* offset [0..31,32..63] */ |
174 | uint32_t lim_or_seg:20; /* limit */ | |
175 | /* or segment, for gate */ | |
176 | uint32_t size_or_IST:4; /* size/granularity */ | |
177 | /* IST for gates */ | |
178 | uint32_t access:8; /* access */ | |
179 | uint32_t reserved:32; /* reserved/zero */ | |
0c530ab8 | 180 | }; |
91447636 | 181 | |
5ba3f43e | 182 | typedef struct __attribute__((packed)) { |
0a7de745 A |
183 | uint16_t size; |
184 | void *ptr; | |
5ba3f43e A |
185 | } x86_64_desc_register_t; |
186 | ||
5c9f4661 A |
187 | |
188 | ||
91447636 A |
189 | /* |
190 | * Boot-time data for master (or only) CPU | |
191 | */ | |
0a7de745 A |
192 | extern struct real_descriptor master_gdt[GDTSZ]; |
193 | extern struct real_descriptor master_ldt[]; | |
194 | extern struct i386_tss master_ktss; | |
195 | extern struct sysenter_stack master_sstk; | |
0c530ab8 | 196 | |
0a7de745 A |
197 | extern struct fake_descriptor64 master_idt64[IDTSZ]; |
198 | extern struct x86_64_tss master_ktss64; | |
91447636 A |
199 | |
200 | __BEGIN_DECLS | |
201 | ||
0a7de745 A |
202 | extern char df_task_stack[]; |
203 | extern char df_task_stack_end[]; | |
204 | extern struct i386_tss master_dftss; | |
205 | extern void df_task_start(void); | |
0c530ab8 | 206 | |
0a7de745 A |
207 | extern char mc_task_stack[]; |
208 | extern char mc_task_stack_end[]; | |
209 | extern struct i386_tss master_mctss; | |
210 | extern void mc_task_start(void); | |
0c530ab8 | 211 | |
91447636 A |
212 | __END_DECLS |
213 | ||
0a7de745 | 214 | #endif /*__ASSEMBLER__*/ |
1c79356b | 215 | |
0a7de745 A |
216 | #define SZ_64 0x2 /* 64-bit segment */ |
217 | #define SZ_32 0x4 /* 32-bit segment */ | |
218 | #define SZ_G 0x8 /* 4K limit field */ | |
1c79356b | 219 | |
0a7de745 A |
220 | #define ACC_A 0x01 /* accessed */ |
221 | #define ACC_TYPE 0x1e /* type field: */ | |
1c79356b | 222 | |
0a7de745 | 223 | #define ACC_TYPE_SYSTEM 0x00 /* system descriptors: */ |
1c79356b | 224 | |
0a7de745 A |
225 | #define ACC_LDT 0x02 /* LDT */ |
226 | #define ACC_CALL_GATE_16 0x04 /* 16-bit call gate */ | |
227 | #define ACC_TASK_GATE 0x05 /* task gate */ | |
228 | #define ACC_TSS 0x09 /* task segment */ | |
229 | #define ACC_CALL_GATE 0x0c /* call gate */ | |
230 | #define ACC_INTR_GATE 0x0e /* interrupt gate */ | |
231 | #define ACC_TRAP_GATE 0x0f /* trap gate */ | |
1c79356b | 232 | |
0a7de745 | 233 | #define ACC_TSS_BUSY 0x02 /* task busy */ |
1c79356b | 234 | |
0a7de745 | 235 | #define ACC_TYPE_USER 0x10 /* user descriptors */ |
1c79356b | 236 | |
0a7de745 A |
237 | #define ACC_DATA 0x10 /* data */ |
238 | #define ACC_DATA_W 0x12 /* data, writable */ | |
239 | #define ACC_DATA_E 0x14 /* data, expand-down */ | |
240 | #define ACC_DATA_EW 0x16 /* data, expand-down, | |
241 | * writable */ | |
242 | #define ACC_CODE 0x18 /* code */ | |
243 | #define ACC_CODE_R 0x1a /* code, readable */ | |
244 | #define ACC_CODE_C 0x1c /* code, conforming */ | |
245 | #define ACC_CODE_CR 0x1e /* code, conforming, | |
246 | * readable */ | |
247 | #define ACC_PL 0x60 /* access rights: */ | |
248 | #define ACC_PL_K 0x00 /* kernel access only */ | |
249 | #define ACC_PL_U 0x60 /* user access */ | |
250 | #define ACC_P 0x80 /* segment present */ | |
1c79356b A |
251 | |
252 | /* | |
253 | * Components of a selector | |
254 | */ | |
0a7de745 A |
255 | #define SEL_LDTS 0x04 /* local selector */ |
256 | #define SEL_PL 0x03 /* privilege level: */ | |
257 | #define SEL_PL_K 0x00 /* kernel selector */ | |
258 | #define SEL_PL_U 0x03 /* user selector */ | |
1c79356b A |
259 | |
260 | /* | |
261 | * Convert selector to descriptor table index. | |
262 | */ | |
0a7de745 A |
263 | #define sel_idx(sel) (selector_to_sel(sel).index) |
264 | #define SEL_TO_INDEX(s) ((s)>>3) | |
91447636 | 265 | |
0a7de745 | 266 | #define NULL_SEG 0 |
1c79356b | 267 | |
0c530ab8 | 268 | |
b0d623f7 A |
269 | /* |
270 | * Kernel descriptors for MACH - 64-bit flat address space. | |
271 | */ | |
0a7de745 A |
272 | #define KERNEL64_CS 0x08 /* 1: K64 code */ |
273 | #define SYSENTER_CS 0x0b /* U32 sysenter pseudo-segment */ | |
274 | #define KERNEL64_SS 0x10 /* 2: KERNEL64_CS+8 for syscall */ | |
275 | #define USER_CS 0x1b /* 3: U32 code */ | |
276 | #define USER_DS 0x23 /* 4: USER_CS+8 for sysret */ | |
277 | #define USER64_CS 0x2b /* 5: USER_CS+16 for sysret */ | |
278 | #define USER64_DS USER_DS /* U64 data pseudo-segment */ | |
279 | #define KERNEL_LDT 0x30 /* 6: */ | |
280 | /* 7: other 8 bytes of KERNEL_LDT */ | |
281 | #define KERNEL_TSS 0x40 /* 8: */ | |
282 | /* 9: other 8 bytes of KERNEL_TSS */ | |
283 | #define KERNEL32_CS 0x50 /* 10: */ | |
284 | #define USER_LDT 0x58 /* 11: */ | |
285 | /* 12: other 8 bytes of USER_LDT */ | |
286 | #define KERNEL_DS 0x68 /* 13: 32-bit kernel data */ | |
287 | ||
288 | ||
289 | #define SYSENTER_TF_CS (USER_CS|0x10000) | |
290 | #define SYSENTER_DS KERNEL64_SS /* sysenter kernel data segment */ | |
291 | ||
292 | #endif /* _I386_SEG_H_ */ | |
b0d623f7 A |
293 | #ifdef __x86_64__ |
294 | /* | |
295 | * 64-bit kernel LDT descriptors | |
296 | */ | |
0a7de745 A |
297 | #define SYSCALL_CS 0x07 /* syscall pseudo-segment */ |
298 | #define USER_CTHREAD 0x0f /* user cthread area */ | |
299 | #define USER_SETTABLE 0x1f /* start of user settable ldt entries */ | |
b0d623f7 | 300 | #endif |