/*
- * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
*/
#ifndef _I386_SEG_H_
#define _I386_SEG_H_
-
-#include <mach_kdb.h>
-#ifndef ASSEMBLER
+#ifndef __ASSEMBLER__
#include <stdint.h>
#include <mach/vm_types.h>
#include <architecture/i386/sel.h>
#define LDTSZ_MIN SEL_TO_INDEX(USER_SETTABLE)
/* kernel ldt entries */
-#if MACH_KDB
#define GDTSZ 19
-#else
-#define GDTSZ 18
-#endif
/*
* Interrupt table is always 256 entries long.
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
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 */
uint32_t access:8; /* access */
uint32_t reserved:32; /* reserved/zero */
};
-#define FAKE_UBER64(addr32) { (uint32_t) (addr32), KERNEL_UBER_BASE_HI32 }
-#define FAKE_COMPAT(addr32) { (uint32_t) (addr32), 0x0 }
-#define UBER64(addr32) ((addr64_t) (uintptr_t)addr32 + KERNEL_UBER_BASE)
+
+typedef struct __attribute__((packed)) {
+ uint16_t size;
+ void *ptr;
+} x86_64_desc_register_t;
/*
* 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
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);
-#endif /* MACH_KDB */
-
__END_DECLS
#endif /*__ASSEMBLER__*/
#define NULL_SEG 0
-/*
- * User descriptors for MACH - 32-bit flat address space
- */
-#define SYSENTER_CS 0x07 /* sysenter kernel code segment */
-#define SYSENTER_DS 0x0f /* sysenter kernel data segment */
-#define USER_CS 0x17 /* user code segment
- Must be SYSENTER_CS+16 for sysexit */
-/* Special case: sysenter with EFL_TF (trace bit) set - use iret not sysexit */
-#define SYSENTER_TF_CS (USER_CS|0x10000)
-#define USER_DS 0x1f /* user data segment
- Must be SYSENTER_CS+24 for sysexit */
-#define USER64_CS 0x27 /* 64-bit user code segment
- Must be USER_CS+16 for sysret */
-#define USER64_DS USER_DS /* 64-bit user data segment == 32-bit */
-#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.
+ * Kernel descriptors for MACH - 64-bit flat address space.
*/
-#define KERNEL_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 */
-#define KERNEL_TSS 0x28 /* master TSS */
-#define KERNEL_TSS_2 0x30 /* master TSS expanded for 64-bit */
+#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 */
-#define MC_TSS 0x38 /* machine-check handler TSS */
-#define CPU_DATA_GS 0x48 /* per-cpu data */
-
-#define DF_TSS 0x50 /* double-fault handler TSS */
-
-#define USER_LDT 0x58
-#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 */
-
-#define KERNEL64_CS 0x80 /* kernel 64-bit code */
-#define KERNEL64_SS 0x88 /* kernel 64-bit (syscall) stack */
+#define SYSENTER_TF_CS (USER_CS|0x10000)
+#define SYSENTER_DS KERNEL64_SS /* sysenter kernel data segment */
-#if MACH_KDB
-#define DEBUG_TSS 0x90 /* debug TSS (uniprocessor) */
+#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
-#ifndef __ASSEMBLER__
-struct __gdt_desc_struct {
- unsigned short size;
- unsigned long address __attribute__((packed));
- unsigned short pad;
-} __attribute__ ((packed));
-
-struct __idt_desc_struct {
- unsigned short size;
- unsigned long address __attribute__((packed));
- unsigned short pad;
-} __attribute__ ((packed));
-#endif /* __ASSEMBLER__ */
-
#endif /* _I386_SEG_H_ */