X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/5d5c5d0d5b79ade9a973d55186ffda2638ba2b6e..13f56ec4e58bf8687e2a68032c093c0213dd519b:/osfmk/i386/seg.h diff --git a/osfmk/i386/seg.h b/osfmk/i386/seg.h index 3545d993c..df191c5d1 100644 --- a/osfmk/i386/seg.h +++ b/osfmk/i386/seg.h @@ -1,31 +1,29 @@ /* - * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2009 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. The rights granted to you under the - * License may not be used to create, or enable the creation or - * redistribution of, unlawful or unlicensed copies of an Apple operating - * system, or to circumvent, violate, or enable the circumvention or - * violation of, any terms of an Apple operating system software license - * agreement. - * - * Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and * limitations under the License. - * - * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -55,13 +53,14 @@ * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ -/* - */ - #ifndef _I386_SEG_H_ #define _I386_SEG_H_ - +#ifdef MACH_KERNEL #include +#else +#define MACH_KDB 0 +#endif /* MACH_KERNEL */ +#ifndef __ASSEMBLER__ #include #include #include @@ -97,12 +96,17 @@ selector_to_sel(uint16_t selector) } #define LDTSZ 8192 /* size of the kernel ldt in entries */ -#define LDTSZ_MIN 17 /* kernel ldt entries used by the system */ +#define LDTSZ_MIN SEL_TO_INDEX(USER_SETTABLE) + /* kernel ldt entries */ #if MACH_KDB -#define GDTSZ 19 +#define GDTSZ 20 #else -#define GDTSZ 18 +#define GDTSZ 19 +#endif + +#ifdef __x86_64__ +#define PROT_MODE_GDT_SIZE 48 /* size of prot_mode_gdt in bytes */ #endif /* @@ -110,8 +114,6 @@ selector_to_sel(uint16_t selector) */ #define IDTSZ 256 -#ifndef __ASSEMBLER__ - #include /* @@ -155,6 +157,16 @@ struct real_gate64 { reserved32:32; /* reserved/zero */ }; +#define MAKE_REAL_DESCRIPTOR(base,lim,gran,acc) { \ + .limit_low = lim & 0xffff, \ + .limit_high = (lim >> 16) & 0xf, \ + .base_low = base & 0xffff, \ + .base_med = (base >> 16) & 0xff, \ + .base_high = (base >> 24) & 0xff, \ + .access = acc, \ + .granularity = gran \ +} + /* * We build descriptors and gates in a 'fake' format to let the * fields be contiguous. We shuffle them into the real format @@ -169,7 +181,7 @@ struct fake_descriptor { uint32_t access:8; /* access */ }; struct fake_descriptor64 { - uint32_t offset[2]; /* offset [0..31,32..63] */ + uint64_t offset64; /* offset [0..31,32..63] */ uint32_t lim_or_seg:20; /* limit */ /* or segment, for gate */ uint32_t size_or_IST:4; /* size/granularity */ @@ -177,22 +189,22 @@ struct fake_descriptor64 { uint32_t access:8; /* access */ uint32_t reserved:32; /* reserved/zero */ }; +#ifdef __i386__ #define FAKE_UBER64(addr32) { (uint32_t) (addr32), KERNEL_UBER_BASE_HI32 } #define FAKE_COMPAT(addr32) { (uint32_t) (addr32), 0x0 } -#define UBER64(addr32) ((addr64_t) addr32 + KERNEL_UBER_BASE) +#define UBER64(addr32) ((addr64_t) (uintptr_t)addr32 + KERNEL_UBER_BASE) +#endif /* * Boot-time data for master (or only) CPU */ extern struct fake_descriptor master_idt[IDTSZ]; -extern struct fake_descriptor master_gdt[GDTSZ]; -extern struct fake_descriptor master_ldt[LDTSZ]; +extern struct real_descriptor master_gdt[GDTSZ]; +extern struct real_descriptor master_ldt[LDTSZ]; extern struct i386_tss master_ktss; extern struct sysenter_stack master_sstk; extern struct fake_descriptor64 master_idt64[IDTSZ]; -extern struct fake_descriptor64 kernel_ldt_desc64; -extern struct fake_descriptor64 kernel_tss_desc64; extern struct x86_64_tss master_ktss64; __BEGIN_DECLS @@ -208,7 +220,6 @@ extern struct i386_tss master_mctss; extern void mc_task_start(void); #if MACH_KDB -extern char db_stack_store[]; extern char db_task_stack_store[]; extern struct i386_tss master_dbtss; extern void db_task_start(void); @@ -270,6 +281,7 @@ __END_DECLS #define NULL_SEG 0 +#ifdef __i386__ /* * User descriptors for MACH - 32-bit flat address space */ @@ -287,12 +299,11 @@ __END_DECLS #define SYSCALL_CS 0x2f /* 64-bit syscall pseudo-segment */ #define USER_CTHREAD 0x37 /* user cthread area */ #define USER_SETTABLE 0x3f /* start of user settable ldt entries */ -#define USLDTSZ 10 /* number of user settable entries */ /* * Kernel descriptors for MACH - 32-bit flat address space. */ -#define KERNEL_CS 0x08 /* kernel code */ +#define KERNEL32_CS 0x08 /* kernel code */ #define KERNEL_DS 0x10 /* kernel data */ #define KERNEL_LDT 0x18 /* master LDT */ #define KERNEL_LDT_2 0x20 /* master LDT expanded for 64-bit */ @@ -309,27 +320,52 @@ __END_DECLS #define USER_TSS 0x60 #define FPE_CS 0x68 -#define USER_WINDOW_SEL 0x70 /* window for copyin/copyout */ -#define PHYS_WINDOW_SEL 0x78 /* window for copyin/copyout */ +#else // __x86_64__ -#define KERNEL64_CS 0x80 /* kernel 64-bit code */ -#define KERNEL64_SS 0x88 /* kernel 64-bit (syscall) stack */ +/* + * Kernel descriptors for MACH - 64-bit flat address space. + */ +#define KERNEL64_CS 0x08 /* 1: K64 code */ +#define SYSENTER_CS 0x0b /* U32 sysenter pseudo-segment */ +#define KERNEL64_SS 0x10 /* 2: KERNEL64_CS+8 for syscall */ +#define USER_CS 0x1b /* 3: U32 code */ +#define USER_DS 0x23 /* 4: USER_CS+8 for sysret */ +#define USER64_CS 0x2b /* 5: USER_CS+16 for sysret */ +#define USER64_DS USER_DS /* U64 data pseudo-segment */ +#define KERNEL_LDT 0x30 /* 6: */ + /* 7: other 8 bytes of KERNEL_LDT */ +#define KERNEL_TSS 0x40 /* 8: */ + /* 9: other 8 bytes of KERNEL_TSS */ +#define KERNEL32_CS 0x50 /* 10: */ +#define USER_LDT 0x58 /* 11: */ + /* 12: other 8 bytes of USER_LDT */ +#define KERNEL_DS 0x68 /* 13: 32-bit kernel data */ -#if MACH_KDB -#define DEBUG_TSS 0x90 /* debug TSS (uniprocessor) */ #endif -struct __gdt_desc_struct { - unsigned short size; - unsigned long address __attribute__((packed)); - unsigned short pad; -} __attribute__ ((packed)); +#ifdef __i386__ +#if !defined(USER_WINDOW_SEL) +#define USER_WINDOW_SEL 0x70 /* 14: window for copyin/copyout */ +#define PHYS_WINDOW_SEL 0x78 /* 15: window for copyin/copyout */ +#endif +#define KERNEL64_CS 0x80 /* 16: kernel 64-bit code */ +#define KERNEL64_SS 0x88 /* 17: kernel 64-bit (syscall) stack */ +#else // __x86_64__ +#define SYSENTER_TF_CS (USER_CS|0x10000) +#define SYSENTER_DS KERNEL64_SS /* sysenter kernel data segment */ +#endif -struct __idt_desc_struct { - unsigned short size; - unsigned long address __attribute__((packed)); - unsigned short pad; -} __attribute__ ((packed)); +#if MACH_KDB +#define DEBUG_TSS 0x90 /* 18: debug TSS (uniprocessor) */ +#endif +#ifdef __x86_64__ +/* + * 64-bit kernel LDT descriptors + */ +#define SYSCALL_CS 0x07 /* syscall pseudo-segment */ +#define USER_CTHREAD 0x0f /* user cthread area */ +#define USER_SETTABLE 0x1f /* start of user settable ldt entries */ +#endif #endif /* _I386_SEG_H_ */