2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
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.
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.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
66 #include <mach/vm_types.h>
67 #include <architecture/i386/sel.h>
73 static inline uint16_t
74 sel_to_selector(sel_t sel
)
83 return (tconv
.selector
);
87 selector_to_sel(uint16_t selector
)
94 tconv
.selector
= selector
;
99 #define LDTSZ 8192 /* size of the kernel ldt in entries */
100 #define LDTSZ_MIN 17 /* kernel ldt entries used by the system */
109 * Interrupt table is always 256 entries long.
113 #ifndef __ASSEMBLER__
115 #include <sys/cdefs.h>
118 * Real segment descriptor.
120 struct real_descriptor
{
121 uint32_t limit_low
:16, /* limit 0..15 */
122 base_low
:16, /* base 0..15 */
123 base_med
:8, /* base 16..23 */
124 access
:8, /* access byte */
125 limit_high
:4, /* limit 16..19 */
126 granularity
:4, /* granularity */
127 base_high
:8; /* base 24..31 */
129 struct real_descriptor64
{
130 uint32_t limit_low16
:16, /* limit 0..15 */
131 base_low16
:16, /* base 0..15 */
132 base_med8
:8, /* base 16..23 */
133 access8
:8, /* access byte */
134 limit_high4
:4, /* limit 16..19 */
135 granularity4
:4, /* granularity */
136 base_high8
:8, /* base 24..31 */
137 base_top32
:32, /* base 32..63 */
138 reserved32
:32; /* reserved/zero */
141 uint32_t offset_low
:16, /* offset 0..15 */
145 offset_high
:16; /* offset 16..31 */
148 uint32_t offset_low16
:16, /* offset 0..15 */
153 offset_high16
:16, /* offset 16..31 */
154 offset_top32
:32, /* offset 32..63 */
155 reserved32
:32; /* reserved/zero */
159 * We build descriptors and gates in a 'fake' format to let the
160 * fields be contiguous. We shuffle them into the real format
163 struct fake_descriptor
{
164 uint32_t offset
:32; /* offset */
165 uint32_t lim_or_seg
:20; /* limit */
166 /* or segment, for gate */
167 uint32_t size_or_wdct
:4; /* size/granularity */
168 /* word count, for gate */
169 uint32_t access
:8; /* access */
171 struct fake_descriptor64
{
172 uint32_t offset
[2]; /* offset [0..31,32..63] */
173 uint32_t lim_or_seg
:20; /* limit */
174 /* or segment, for gate */
175 uint32_t size_or_IST
:4; /* size/granularity */
177 uint32_t access
:8; /* access */
178 uint32_t reserved
:32; /* reserved/zero */
180 #define FAKE_UBER64(addr32) { (uint32_t) (addr32), KERNEL_UBER_BASE_HI32 }
181 #define FAKE_COMPAT(addr32) { (uint32_t) (addr32), 0x0 }
182 #define UBER64(addr32) ((addr64_t) addr32 + KERNEL_UBER_BASE)
185 * Boot-time data for master (or only) CPU
187 extern struct fake_descriptor master_idt
[IDTSZ
];
188 extern struct fake_descriptor master_gdt
[GDTSZ
];
189 extern struct fake_descriptor master_ldt
[LDTSZ
];
190 extern struct i386_tss master_ktss
;
191 extern struct sysenter_stack master_sstk
;
193 extern struct fake_descriptor64 master_idt64
[IDTSZ
];
194 extern struct fake_descriptor64 kernel_ldt_desc64
;
195 extern struct fake_descriptor64 kernel_tss_desc64
;
196 extern struct x86_64_tss master_ktss64
;
200 extern char df_task_stack
[];
201 extern char df_task_stack_end
[];
202 extern struct i386_tss master_dftss
;
203 extern void df_task_start(void);
205 extern char mc_task_stack
[];
206 extern char mc_task_stack_end
[];
207 extern struct i386_tss master_mctss
;
208 extern void mc_task_start(void);
211 extern char db_stack_store
[];
212 extern char db_task_stack_store
[];
213 extern struct i386_tss master_dbtss
;
214 extern void db_task_start(void);
215 #endif /* MACH_KDB */
219 #endif /*__ASSEMBLER__*/
221 #define SZ_64 0x2 /* 64-bit segment */
222 #define SZ_32 0x4 /* 32-bit segment */
223 #define SZ_G 0x8 /* 4K limit field */
225 #define ACC_A 0x01 /* accessed */
226 #define ACC_TYPE 0x1e /* type field: */
228 #define ACC_TYPE_SYSTEM 0x00 /* system descriptors: */
230 #define ACC_LDT 0x02 /* LDT */
231 #define ACC_CALL_GATE_16 0x04 /* 16-bit call gate */
232 #define ACC_TASK_GATE 0x05 /* task gate */
233 #define ACC_TSS 0x09 /* task segment */
234 #define ACC_CALL_GATE 0x0c /* call gate */
235 #define ACC_INTR_GATE 0x0e /* interrupt gate */
236 #define ACC_TRAP_GATE 0x0f /* trap gate */
238 #define ACC_TSS_BUSY 0x02 /* task busy */
240 #define ACC_TYPE_USER 0x10 /* user descriptors */
242 #define ACC_DATA 0x10 /* data */
243 #define ACC_DATA_W 0x12 /* data, writable */
244 #define ACC_DATA_E 0x14 /* data, expand-down */
245 #define ACC_DATA_EW 0x16 /* data, expand-down,
247 #define ACC_CODE 0x18 /* code */
248 #define ACC_CODE_R 0x1a /* code, readable */
249 #define ACC_CODE_C 0x1c /* code, conforming */
250 #define ACC_CODE_CR 0x1e /* code, conforming,
252 #define ACC_PL 0x60 /* access rights: */
253 #define ACC_PL_K 0x00 /* kernel access only */
254 #define ACC_PL_U 0x60 /* user access */
255 #define ACC_P 0x80 /* segment present */
258 * Components of a selector
260 #define SEL_LDTS 0x04 /* local selector */
261 #define SEL_PL 0x03 /* privilege level: */
262 #define SEL_PL_K 0x00 /* kernel selector */
263 #define SEL_PL_U 0x03 /* user selector */
266 * Convert selector to descriptor table index.
268 #define sel_idx(sel) (selector_to_sel(sel).index)
269 #define SEL_TO_INDEX(s) ((s)>>3)
274 * User descriptors for MACH - 32-bit flat address space
276 #define SYSENTER_CS 0x07 /* sysenter kernel code segment */
277 #define SYSENTER_DS 0x0f /* sysenter kernel data segment */
278 #define USER_CS 0x17 /* user code segment
279 Must be SYSENTER_CS+16 for sysexit */
280 /* Special case: sysenter with EFL_TF (trace bit) set - use iret not sysexit */
281 #define SYSENTER_TF_CS (USER_CS|0x10000)
282 #define USER_DS 0x1f /* user data segment
283 Must be SYSENTER_CS+24 for sysexit */
284 #define USER64_CS 0x27 /* 64-bit user code segment
285 Must be USER_CS+16 for sysret */
286 #define USER64_DS USER_DS /* 64-bit user data segment == 32-bit */
287 #define SYSCALL_CS 0x2f /* 64-bit syscall pseudo-segment */
288 #define USER_CTHREAD 0x37 /* user cthread area */
289 #define USER_SETTABLE 0x3f /* start of user settable ldt entries */
290 #define USLDTSZ 10 /* number of user settable entries */
293 * Kernel descriptors for MACH - 32-bit flat address space.
295 #define KERNEL_CS 0x08 /* kernel code */
296 #define KERNEL_DS 0x10 /* kernel data */
297 #define KERNEL_LDT 0x18 /* master LDT */
298 #define KERNEL_LDT_2 0x20 /* master LDT expanded for 64-bit */
299 #define KERNEL_TSS 0x28 /* master TSS */
300 #define KERNEL_TSS_2 0x30 /* master TSS expanded for 64-bit */
302 #define MC_TSS 0x38 /* machine-check handler TSS */
304 #define CPU_DATA_GS 0x48 /* per-cpu data */
306 #define DF_TSS 0x50 /* double-fault handler TSS */
308 #define USER_LDT 0x58
309 #define USER_TSS 0x60
312 #define USER_WINDOW_SEL 0x70 /* window for copyin/copyout */
313 #define PHYS_WINDOW_SEL 0x78 /* window for copyin/copyout */
315 #define KERNEL64_CS 0x80 /* kernel 64-bit code */
316 #define KERNEL64_SS 0x88 /* kernel 64-bit (syscall) stack */
319 #define DEBUG_TSS 0x90 /* debug TSS (uniprocessor) */
322 struct __gdt_desc_struct
{
324 unsigned long address
__attribute__((packed
));
326 } __attribute__ ((packed
));
328 struct __idt_desc_struct
{
330 unsigned long address
__attribute__((packed
));
332 } __attribute__ ((packed
));
335 #endif /* _I386_SEG_H_ */