X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/e5568f75972dfc723778653c11cb6b4dc825716a..316670eb35587141e969394ae8537d66b9211e80:/osfmk/i386/mp_desc.h diff --git a/osfmk/i386/mp_desc.h b/osfmk/i386/mp_desc.h index fd85e29ad..3b8ef7ea1 100644 --- a/osfmk/i386/mp_desc.h +++ b/osfmk/i386/mp_desc.h @@ -1,23 +1,29 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2009 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * 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. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * 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 OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * 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_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -54,8 +60,9 @@ #ifndef _I386_MP_DESC_H_ #define _I386_MP_DESC_H_ -#include -#include +#include + +__BEGIN_DECLS /* * Multiprocessor i386/i486 systems use a separate copy of the @@ -72,44 +79,62 @@ /* * The descriptor tables are together in a structure * allocated one per processor (except for the boot processor). - * Note that dbtss could be conditionalized on MACH_KDB, but - * doing so increases misconfiguration risk. */ -struct mp_desc_table { - struct fake_descriptor idt[IDTSZ]; /* IDT */ - struct fake_descriptor gdt[GDTSZ]; /* GDT */ - struct fake_descriptor ldt[LDTSZ]; /* LDT */ - struct i386_tss ktss; - struct i386_tss dbtss; -}; +typedef struct cpu_desc_table { + struct fake_descriptor idt[IDTSZ] __attribute__ ((aligned (16))); + struct fake_descriptor gdt[GDTSZ] __attribute__ ((aligned (16))); + struct i386_tss ktss __attribute__ ((aligned (16))); + struct sysenter_stack sstk; +} cpu_desc_table_t; -/* - * They are pointed to by a per-processor array. - */ -extern struct mp_desc_table *mp_desc_table[NCPUS]; +typedef struct cpu_desc_table64 { +#if !__x86_64__ + struct fake_descriptor64 idt[IDTSZ] __attribute__ ((aligned (16))); +#endif + struct fake_descriptor gdt[GDTSZ] __attribute__ ((aligned (16))); + struct x86_64_tss ktss __attribute__ ((aligned (16))); + struct sysenter_stack sstk __attribute__ ((aligned (16))); + uint8_t dfstk[PAGE_SIZE] __attribute__ ((aligned (16))); +} cpu_desc_table64_t; -/* - * The kernel TSS gets its own pointer. - */ -extern struct i386_tss *mp_ktss[NCPUS]; -#if MACH_KDB -extern struct i386_tss *mp_dbtss[NCPUS]; -#endif /* MACH_KDB */ +#define current_gdt() (current_cpu_datap()->cpu_desc_index.cdi_gdt.ptr) +#define current_idt() (current_cpu_datap()->cpu_desc_index.cdi_idt.ptr) +#define current_ldt() (current_cpu_datap()->cpu_desc_index.cdi_ldt) +#define current_ktss() (current_cpu_datap()->cpu_desc_index.cdi_ktss) +#define current_sstk() (current_cpu_datap()->cpu_desc_index.cdi_sstk) -/* - * So does the GDT and IDT. - */ -extern struct fake_descriptor *mp_gdt[NCPUS]; -extern struct fake_descriptor *mp_idt[NCPUS]; -extern struct fake_descriptor *mp_ldt[NCPUS]; +#define current_ktss64() ((struct x86_64_tss *) current_ktss()) +#define current_sstk64() ((addr64_t *) current_sstk()) +#define gdt_desc_p(sel) \ + (&((struct real_descriptor *)current_gdt())[sel_idx(sel)]) +#define ldt_desc_p(sel) \ + (&((struct real_descriptor *)current_ldt())[sel_idx(sel)]) -/* - * Each CPU calls this routine to set up its descriptor tables. - */ +extern void cpu_mode_init(cpu_data_t *cdp); + +extern void cpu_desc_init(cpu_data_t *cdp); +extern void cpu_desc_init64(cpu_data_t *cdp); +extern void cpu_desc_load(cpu_data_t *cdp); +extern void cpu_desc_load64(cpu_data_t *cdp); + +extern boolean_t +valid_user_data_selector(uint16_t selector); + +extern boolean_t +valid_user_code_selector(uint16_t selector); + +extern boolean_t +valid_user_stack_selector(uint16_t selector); + +extern boolean_t +valid_user_segment_selectors(uint16_t cs, + uint16_t ss, + uint16_t ds, + uint16_t es, + uint16_t fs, + uint16_t gs); -extern struct mp_desc_table * mp_desc_init( - int cpu); -extern void interrupt_stack_alloc(void); +__END_DECLS -#endif /* _I386_MP_DESC_H_ */ +#endif /* _X86_64_MP_DESC_H_ */