X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8ad349bb6ed4a0be06e34c92be0d98b92e078db4..b0d623f7f2ae71ed96e60569f61f9a9a27016e80:/osfmk/mach/i386/thread_status.h diff --git a/osfmk/mach/i386/thread_status.h b/osfmk/mach/i386/thread_status.h index 7d0839649..558d1c071 100644 --- a/osfmk/mach/i386/thread_status.h +++ b/osfmk/mach/i386/thread_status.h @@ -1,31 +1,29 @@ /* - * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2006 Apple Computer, 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@ @@ -69,42 +67,33 @@ #ifndef _MACH_I386_THREAD_STATUS_H_ #define _MACH_I386_THREAD_STATUS_H_ +#include #include #include #include -#include /* FIXME */ -#include /* FIXME */ +#include + /* - * i386_thread_state this is the structure that is exported - * to user threads for use in status/mutate - * calls. This structure should never - * change. - * - * i386_float_state exported to use threads for access to - * floating point registers. Try not to - * change this one, either. - * - * i386_isa_port_map_state exported to user threads to allow - * selective in/out operations + * the i386_xxxx form is kept for legacy purposes since these types + * are externally known... eventually they should be deprecated. + * our internal implementation has moved to the following naming convention * - * i386_v86_assist_state - * - * thread_syscall_state + * x86_xxxx32 names are used to deal with 32 bit states + * x86_xxxx64 names are used to deal with 64 bit states + * x86_xxxx names are used to deal with either 32 or 64 bit states + * via a self-describing mechanism */ -/* THREAD_STATE_FLAVOR_LIST 0 */ -#define i386_NEW_THREAD_STATE 1 /* used to be i386_THREAD_STATE */ -#define i386_FLOAT_STATE 2 -#define i386_ISA_PORT_MAP_STATE 3 -#define i386_V86_ASSIST_STATE 4 -#define i386_REGS_SEGS_STATE 5 -#define THREAD_SYSCALL_STATE 6 -#define THREAD_STATE_NONE 7 -#define i386_SAVED_STATE 8 - +/* + * these are the legacy names which should be deprecated in the future + * they are externally known which is the only reason we don't just get + * rid of them + */ +#define i386_THREAD_STATE 1 +#define i386_FLOAT_STATE 2 +#define i386_EXCEPTION_STATE 3 /* - * x86-64 compatibility * THREAD_STATE_FLAVOR_LIST 0 * these are the supported flavors */ @@ -120,8 +109,13 @@ #define x86_DEBUG_STATE32 10 #define x86_DEBUG_STATE64 11 #define x86_DEBUG_STATE 12 +#define THREAD_STATE_NONE 13 - +/* + * Largest state on this machine: + * (be sure mach/machine/thread_state.h matches!) + */ +#define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX /* * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed @@ -129,59 +123,187 @@ * platform. The macro must be manually updated to include all of the valid * exception flavors as defined above. */ -#define VALID_THREAD_STATE_FLAVOR(x) \ - ((x == i386_NEW_THREAD_STATE) || \ - (x == i386_FLOAT_STATE) || \ - (x == i386_ISA_PORT_MAP_STATE) || \ - (x == i386_V86_ASSIST_STATE) || \ - (x == i386_REGS_SEGS_STATE) || \ - (x == THREAD_SYSCALL_STATE) || \ - (x == THREAD_STATE_NONE) || \ - (x == i386_SAVED_STATE)) +#define VALID_THREAD_STATE_FLAVOR(x) \ + ((x == x86_THREAD_STATE32) || \ + (x == x86_FLOAT_STATE32) || \ + (x == x86_EXCEPTION_STATE32) || \ + (x == x86_DEBUG_STATE32) || \ + (x == x86_THREAD_STATE64) || \ + (x == x86_FLOAT_STATE64) || \ + (x == x86_EXCEPTION_STATE64) || \ + (x == x86_DEBUG_STATE64) || \ + (x == x86_THREAD_STATE) || \ + (x == x86_FLOAT_STATE) || \ + (x == x86_EXCEPTION_STATE) || \ + (x == x86_DEBUG_STATE) || \ + (x == THREAD_STATE_NONE)) +struct x86_state_hdr { + int flavor; + int count; +}; +typedef struct x86_state_hdr x86_state_hdr_t; /* - * x86-64 compatibility + * Default segment register values. */ -struct x86_state_hdr { - int flavor; - int count; + +#define USER_CODE_SELECTOR 0x0017 +#define USER_DATA_SELECTOR 0x001f +#define KERN_CODE_SELECTOR 0x0008 +#define KERN_DATA_SELECTOR 0x0010 + +/* + * to be deprecated in the future + */ +typedef _STRUCT_X86_THREAD_STATE32 i386_thread_state_t; +#define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ + ( sizeof (i386_thread_state_t) / sizeof (int) )) + +typedef _STRUCT_X86_THREAD_STATE32 x86_thread_state32_t; +#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_thread_state32_t) / sizeof (int) )) + +/* + * to be deprecated in the future + */ +typedef _STRUCT_X86_FLOAT_STATE32 i386_float_state_t; +#define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \ + (sizeof(i386_float_state_t)/sizeof(unsigned int))) + +typedef _STRUCT_X86_FLOAT_STATE32 x86_float_state32_t; +#define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \ + (sizeof(x86_float_state32_t)/sizeof(unsigned int))) + +/* + * to be deprecated in the future + */ +typedef _STRUCT_X86_EXCEPTION_STATE32 i386_exception_state_t; +#define i386_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ + ( sizeof (i386_exception_state_t) / sizeof (int) )) + +typedef _STRUCT_X86_EXCEPTION_STATE32 x86_exception_state32_t; +#define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_exception_state32_t) / sizeof (int) )) + +#define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT + +typedef _STRUCT_X86_DEBUG_STATE32 x86_debug_state32_t; +#define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_debug_state32_t) / sizeof (int) )) + +#define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT + +typedef _STRUCT_X86_THREAD_STATE64 x86_thread_state64_t; +#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_thread_state64_t) / sizeof (int) )) + +typedef _STRUCT_X86_FLOAT_STATE64 x86_float_state64_t; +#define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \ + (sizeof(x86_float_state64_t)/sizeof(unsigned int))) + +typedef _STRUCT_X86_EXCEPTION_STATE64 x86_exception_state64_t; +#define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_exception_state64_t) / sizeof (int) )) + +#define X86_EXCEPTION_STATE64_COUNT x86_EXCEPTION_STATE64_COUNT + +typedef _STRUCT_X86_DEBUG_STATE64 x86_debug_state64_t; +#define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_debug_state64_t) / sizeof (int) )) + +#define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT + +/* + * Combined thread, float and exception states + */ +struct x86_thread_state { + x86_state_hdr_t tsh; + union { + x86_thread_state32_t ts32; + x86_thread_state64_t ts64; + } uts; +}; + +struct x86_float_state { + x86_state_hdr_t fsh; + union { + x86_float_state32_t fs32; + x86_float_state64_t fs64; + } ufs; }; -typedef struct x86_state_hdr x86_state_hdr_t; +struct x86_exception_state { + x86_state_hdr_t esh; + union { + x86_exception_state32_t es32; + x86_exception_state64_t es64; + } ues; +}; + +struct x86_debug_state { + x86_state_hdr_t dsh; + union { + x86_debug_state32_t ds32; + x86_debug_state64_t ds64; + } uds; +}; + +typedef struct x86_thread_state x86_thread_state_t; +#define x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_thread_state_t) / sizeof (int) )) + +typedef struct x86_float_state x86_float_state_t; +#define x86_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \ + (sizeof(x86_float_state_t)/sizeof(unsigned int))) + +typedef struct x86_exception_state x86_exception_state_t; +#define x86_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ + (sizeof(x86_exception_state_t)/sizeof(unsigned int))) + +typedef struct x86_debug_state x86_debug_state_t; +#define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ + (sizeof(x86_debug_state_t)/sizeof(unsigned int))) /* - * This structure is used for both - * i386_THREAD_STATE and i386_REGS_SEGS_STATE. + * Machine-independent way for servers and Mach's exception mechanism to + * choose the most efficient state flavor for exception RPC's: */ -struct i386_new_thread_state { - unsigned int gs; - unsigned int fs; - unsigned int es; - unsigned int ds; - unsigned int edi; - unsigned int esi; - unsigned int ebp; - unsigned int esp; - unsigned int ebx; - unsigned int edx; - unsigned int ecx; - unsigned int eax; - unsigned int eip; - unsigned int cs; - unsigned int efl; - unsigned int uesp; - unsigned int ss; +#define MACHINE_THREAD_STATE x86_THREAD_STATE +#define MACHINE_THREAD_STATE_COUNT x86_THREAD_STATE_COUNT + +/* + * when reloading the segment registers on + * a return out of the kernel, we may take + * a GeneralProtection or SegmentNotPresent + * fault if one or more of the segment + * registers in the saved state was improperly + * specified via an x86_THREAD_STATE32 call + * the frame we push on top of the existing + * save area looks like this... we need to + * carry this as part of the save area + * in case we get hit so that we have a big + * enough stack + */ +struct x86_seg_load_fault32 { + unsigned int trapno; + unsigned int err; + unsigned int eip; + unsigned int cs; + unsigned int efl; }; -#define i386_NEW_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof (struct i386_new_thread_state)/sizeof(unsigned int))) + +#ifdef XNU_KERNEL_PRIVATE + +#define x86_SAVED_STATE32 THREAD_STATE_NONE + 1 +#define x86_SAVED_STATE64 THREAD_STATE_NONE + 2 /* * Subset of saved state stored by processor on kernel-to-kernel * trap. (Used by ddb to examine state guaranteed to be present * on all traps into debugger.) */ -struct i386_saved_state_from_kernel { +struct x86_saved_state32_from_kernel { unsigned int gs; unsigned int fs; unsigned int es; @@ -189,8 +311,7 @@ struct i386_saved_state_from_kernel { unsigned int edi; unsigned int esi; unsigned int ebp; - unsigned int esp; /* kernel esp stored by pusha - - we save cr2 here later */ + unsigned int cr2; /* kernel esp stored by pusha - we save cr2 here later */ unsigned int ebx; unsigned int edx; unsigned int ecx; @@ -207,7 +328,7 @@ struct i386_saved_state_from_kernel { * state flavor is most efficient for exception RPC's to kernel-loaded * servers, because copying can be avoided: */ -struct i386_saved_state { +struct x86_saved_state32 { unsigned int gs; unsigned int fs; unsigned int es; @@ -215,8 +336,7 @@ struct i386_saved_state { unsigned int edi; unsigned int esi; unsigned int ebp; - unsigned int esp; /* kernel esp stored by pusha - - we save cr2 here later */ + unsigned int cr2; /* kernel esp stored by pusha - we save cr2 here later */ unsigned int ebx; unsigned int edx; unsigned int ecx; @@ -228,480 +348,188 @@ struct i386_saved_state { unsigned int efl; unsigned int uesp; unsigned int ss; - struct v86_segs { - unsigned int v86_es; /* virtual 8086 segment registers */ - unsigned int v86_ds; - unsigned int v86_fs; - unsigned int v86_gs; - } v86_segs; -#define i386_SAVED_ARGV_COUNT 7 - unsigned int argv_status; /* Boolean flag indicating whether or - * not Mach copied in the args */ - unsigned int argv[i386_SAVED_ARGV_COUNT]; - /* The return address, and the first several - * function call args from the stack, for - * efficient syscall exceptions */ }; -#define i386_SAVED_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof (struct i386_saved_state)/sizeof(unsigned int))) -#define i386_REGS_SEGS_STATE_COUNT i386_SAVED_STATE_COUNT +typedef struct x86_saved_state32 x86_saved_state32_t; -/* - * Machine-independent way for servers and Mach's exception mechanism to - * choose the most efficient state flavor for exception RPC's: - */ -#define MACHINE_THREAD_STATE i386_SAVED_STATE -#define MACHINE_THREAD_STATE_COUNT 144 +#define x86_SAVED_STATE32_COUNT ((mach_msg_type_number_t) \ + (sizeof (x86_saved_state32_t)/sizeof(unsigned int))) -/* - * Largest state on this machine: - * (be sure mach/machine/thread_state.h matches!) - */ -#define THREAD_MACHINE_STATE_MAX THREAD_STATE_MAX - -/* - * Floating point state. - * - * fpkind tells in what way floating point operations are supported. - * See the values for fp_kind in . - * - * If the kind is FP_NO, then calls to set the state will fail, and - * thread_getstatus will return garbage for the rest of the state. - * If "initialized" is false, then the rest of the state is garbage. - * Clients can set "initialized" to false to force the coprocessor to - * be reset. - * "exc_status" is non-zero if the thread has noticed (but not - * proceeded from) a coprocessor exception. It contains the status - * word with the exception bits set. The status word in "fp_status" - * will have the exception bits turned off. If an exception bit in - * "fp_status" is turned on, then "exc_status" should be zero. This - * happens when the coprocessor exception is noticed after the system - * has context switched to some other thread. - * - * If kind is FP_387, then "state" is a i387_state. Other kinds might - * also use i387_state, but somebody will have to verify it (XXX). - * Note that the registers are ordered from top-of-stack down, not - * according to physical register number. - */ - -/* - * x86-64 compatibility - */ -/* defn of 80bit x87 FPU or MMX register */ -struct mmst_reg { - char mmst_reg[10]; - char mmst_rsrv[6]; +#pragma pack(4) +struct x86_saved_state32_tagged { + uint32_t tag; + struct x86_saved_state32 state; }; - - -/* defn of 128 bit XMM regs */ -struct xmm_reg { - char xmm_reg[16]; -}; - -#define FP_STATE_BYTES 512 - -struct i386_float_state { - int fpkind; /* FP_NO..FP_387 (readonly) */ - int initialized; - unsigned char hw_state[FP_STATE_BYTES]; /* actual "hardware" state */ - int exc_status; /* exception status (readonly) */ +typedef struct x86_saved_state32_tagged x86_saved_state32_tagged_t; + +struct x86_sframe32 { + /* + * in case we throw a fault reloading + * segment registers on a return out of + * the kernel... the 'slf' state is only kept + * long enough to rejigger (i.e. restore + * the save area to its original state) + * the save area and throw the appropriate + * kernel trap pointing to the 'ssf' state + */ + struct x86_seg_load_fault32 slf; + struct x86_saved_state32_tagged ssf; }; -#define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(struct i386_float_state)/sizeof(unsigned int))) +typedef struct x86_sframe32 x86_sframe32_t; /* - * x86-64 compatibility + * This is the state pushed onto the 64-bit interrupt stack + * on any exception/trap/interrupt. */ -typedef struct { - int fpu_reserved[2]; - fp_control_t fpu_fcw; /* x87 FPU control word */ - fp_status_t fpu_fsw; /* x87 FPU status word */ - uint8_t fpu_ftw; /* x87 FPU tag word */ - uint8_t fpu_rsrv1; /* reserved */ - uint16_t fpu_fop; /* x87 FPU Opcode */ - uint32_t fpu_ip; /* x87 FPU Instruction Pointer offset */ - uint16_t fpu_cs; /* x87 FPU Instruction Pointer Selector */ - uint16_t fpu_rsrv2; /* reserved */ - uint32_t fpu_dp; /* x87 FPU Instruction Operand(Data) Pointer offset */ - uint16_t fpu_ds; /* x87 FPU Instruction Operand(Data) Pointer Selector */ - uint16_t fpu_rsrv3; /* reserved */ - uint32_t fpu_mxcsr; /* MXCSR Register state */ - uint32_t fpu_mxcsrmask; /* MXCSR mask */ - struct mmst_reg fpu_stmm0; /* ST0/MM0 */ - struct mmst_reg fpu_stmm1; /* ST1/MM1 */ - struct mmst_reg fpu_stmm2; /* ST2/MM2 */ - struct mmst_reg fpu_stmm3; /* ST3/MM3 */ - struct mmst_reg fpu_stmm4; /* ST4/MM4 */ - struct mmst_reg fpu_stmm5; /* ST5/MM5 */ - struct mmst_reg fpu_stmm6; /* ST6/MM6 */ - struct mmst_reg fpu_stmm7; /* ST7/MM7 */ - struct xmm_reg fpu_xmm0; /* XMM 0 */ - struct xmm_reg fpu_xmm1; /* XMM 1 */ - struct xmm_reg fpu_xmm2; /* XMM 2 */ - struct xmm_reg fpu_xmm3; /* XMM 3 */ - struct xmm_reg fpu_xmm4; /* XMM 4 */ - struct xmm_reg fpu_xmm5; /* XMM 5 */ - struct xmm_reg fpu_xmm6; /* XMM 6 */ - struct xmm_reg fpu_xmm7; /* XMM 7 */ - char fpu_rsrv4[14*16]; /* reserved */ - int fpu_reserved1; -} i386_float_state_t; - - -#define FP_old_STATE_BYTES ((mach_msg_type_number_t) \ - (sizeof (struct i386_fp_save) + sizeof (struct i386_fp_regs))) - -struct i386_old_float_state { - int fpkind; /* FP_NO..FP_387 (readonly) */ - int initialized; - unsigned char hw_state[FP_old_STATE_BYTES]; /* actual "hardware" state */ - int exc_status; /* exception status (readonly) */ +struct x86_64_intr_stack_frame { + uint32_t trapno; +#if defined(__LP64__) && defined(KERNEL) + uint32_t _pad; + uint64_t trapfn; +#else + uint32_t trapfn; +#endif + uint64_t err; + uint64_t rip; + uint64_t cs; + uint64_t rflags; + uint64_t rsp; + uint64_t ss; }; -#define i386_old_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(struct i386_old_float_state)/sizeof(unsigned int))) - - -#define PORT_MAP_BITS 0x400 -struct i386_isa_port_map_state { - unsigned char pm[PORT_MAP_BITS>>3]; -}; - -#define i386_ISA_PORT_MAP_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(struct i386_isa_port_map_state)/sizeof(unsigned int))) +typedef struct x86_64_intr_stack_frame x86_64_intr_stack_frame_t; /* - * V8086 assist supplies a pointer to an interrupt - * descriptor table in task space. + * This defines the state saved before entry into compatibility mode. + * The machine state is pushed automatically and the compat state is + * synthethized in the exception handling code. */ -struct i386_v86_assist_state { - unsigned int int_table; /* interrupt table address */ - int int_count; /* interrupt table size */ +struct x86_saved_state_compat32 { + struct x86_saved_state32_tagged iss32; +#if defined(__LP64__) && defined(KERNEL) +#else + uint32_t pad_for_16byte_alignment[2]; +#endif + struct x86_64_intr_stack_frame isf64; }; - -struct v86_interrupt_table { - unsigned int count; /* count of pending interrupts */ - unsigned short mask; /* ignore this interrupt if true */ - unsigned short vec; /* vector to take */ +typedef struct x86_saved_state_compat32 x86_saved_state_compat32_t; + +struct x86_sframe_compat32 { + struct x86_64_intr_stack_frame slf; +#if defined(__LP64__) && defined(KERNEL) +#else + uint32_t pad_for_16byte_alignment[2]; +#endif + struct x86_saved_state_compat32 ssf; + uint32_t empty[4]; }; - -#define i386_V86_ASSIST_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(struct i386_v86_assist_state)/sizeof(unsigned int))) - -struct thread_syscall_state { - unsigned eax; - unsigned edx; - unsigned efl; - unsigned eip; - unsigned esp; -}; - -#define i386_THREAD_SYSCALL_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(struct thread_syscall_state) / sizeof(unsigned int))) +typedef struct x86_sframe_compat32 x86_sframe_compat32_t; /* - * Main thread state consists of - * general registers, segment registers, - * eip and eflags. + * thread state format for task running in 64bit long mode + * in long mode, the same hardware frame is always pushed regardless + * of whether there was a change in privlege level... therefore, there + * is no need for an x86_saved_state64_from_kernel variant */ - -#define i386_THREAD_STATE -1 - -typedef struct { - unsigned int eax; - unsigned int ebx; - unsigned int ecx; - unsigned int edx; - unsigned int edi; - unsigned int esi; - unsigned int ebp; - unsigned int esp; - unsigned int ss; - unsigned int eflags; - unsigned int eip; - unsigned int cs; - unsigned int ds; - unsigned int es; - unsigned int fs; - unsigned int gs; -} i386_thread_state_t; - -#define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (i386_thread_state_t) / sizeof (int) )) - -/* - * x86-64 compatibility - */ -typedef i386_thread_state_t x86_thread_state32_t; -#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_thread_state32_t) / sizeof (int) )) - - - - -struct x86_thread_state64 { - uint64_t rax; - uint64_t rbx; - uint64_t rcx; - uint64_t rdx; - uint64_t rdi; - uint64_t rsi; - uint64_t rbp; - uint64_t rsp; - uint64_t r8; - uint64_t r9; - uint64_t r10; - uint64_t r11; - uint64_t r12; - uint64_t r13; - uint64_t r14; - uint64_t r15; - uint64_t rip; - uint64_t rflags; - uint64_t cs; - uint64_t fs; - uint64_t gs; -} ; - - -typedef struct x86_thread_state64 x86_thread_state64_t; -#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_thread_state64_t) / sizeof (int) )) - - - - -struct x86_thread_state { - x86_state_hdr_t tsh; - union { - x86_thread_state32_t ts32; - x86_thread_state64_t ts64; - } uts; -} ; - - -typedef struct x86_thread_state x86_thread_state_t; -#define x86_THREAD_STATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_thread_state_t) / sizeof (int) )) - - - -/* - * Default segment register values. - */ - -#define USER_CODE_SELECTOR 0x0017 -#define USER_DATA_SELECTOR 0x001f -#define KERN_CODE_SELECTOR 0x0008 -#define KERN_DATA_SELECTOR 0x0010 - -/* - * Thread floating point state - * includes FPU environment as - * well as the register stack. - */ - -#define i386_THREAD_FPSTATE -2 - -typedef struct { - fp_env_t environ; - fp_stack_t stack; -} i386_thread_fpstate_t; - -#define i386_THREAD_FPSTATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (i386_thread_fpstate_t) / sizeof (int) )) - - -/* - * x86-64 compatibility - */ -typedef i386_float_state_t x86_float_state32_t; -#define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \ - (sizeof(x86_float_state32_t)/sizeof(unsigned int))) - - -struct x86_float_state64 { - int fpu_reserved[2]; - fp_control_t fpu_fcw; /* x87 FPU control word */ - fp_status_t fpu_fsw; /* x87 FPU status word */ - uint8_t fpu_ftw; /* x87 FPU tag word */ - uint8_t fpu_rsrv1; /* reserved */ - uint16_t fpu_fop; /* x87 FPU Opcode */ - uint32_t fpu_ip; /* x87 FPU Instruction Pointer offset */ - uint16_t fpu_cs; /* x87 FPU Instruction Pointer Selector */ - uint16_t fpu_rsrv2; /* reserved */ - uint32_t fpu_dp; /* x87 FPU Instruction Operand(Data) Pointer offset */ - uint16_t fpu_ds; /* x87 FPU Instruction Operand(Data) Pointer Selector */ - uint16_t fpu_rsrv3; /* reserved */ - uint32_t fpu_mxcsr; /* MXCSR Register state */ - uint32_t fpu_mxcsrmask; /* MXCSR mask */ - struct mmst_reg fpu_stmm0; /* ST0/MM0 */ - struct mmst_reg fpu_stmm1; /* ST1/MM1 */ - struct mmst_reg fpu_stmm2; /* ST2/MM2 */ - struct mmst_reg fpu_stmm3; /* ST3/MM3 */ - struct mmst_reg fpu_stmm4; /* ST4/MM4 */ - struct mmst_reg fpu_stmm5; /* ST5/MM5 */ - struct mmst_reg fpu_stmm6; /* ST6/MM6 */ - struct mmst_reg fpu_stmm7; /* ST7/MM7 */ - struct xmm_reg fpu_xmm0; /* XMM 0 */ - struct xmm_reg fpu_xmm1; /* XMM 1 */ - struct xmm_reg fpu_xmm2; /* XMM 2 */ - struct xmm_reg fpu_xmm3; /* XMM 3 */ - struct xmm_reg fpu_xmm4; /* XMM 4 */ - struct xmm_reg fpu_xmm5; /* XMM 5 */ - struct xmm_reg fpu_xmm6; /* XMM 6 */ - struct xmm_reg fpu_xmm7; /* XMM 7 */ - struct xmm_reg fpu_xmm8; /* XMM 8 */ - struct xmm_reg fpu_xmm9; /* XMM 9 */ - struct xmm_reg fpu_xmm10; /* XMM 10 */ - struct xmm_reg fpu_xmm11; /* XMM 11 */ - struct xmm_reg fpu_xmm12; /* XMM 12 */ - struct xmm_reg fpu_xmm13; /* XMM 13 */ - struct xmm_reg fpu_xmm14; /* XMM 14 */ - struct xmm_reg fpu_xmm15; /* XMM 15 */ - char fpu_rsrv4[6*16]; /* reserved */ - int fpu_reserved1; +struct x86_saved_state64 { + /* + * saved state organized to reflect the + * system call ABI register convention + * so that we can just pass a pointer + * to the saved state when calling through + * to the actual system call functions + * the ABI limits us to 6 args passed in + * registers... I've add v_arg6 - v_arg8 + * to accomodate our most 'greedy' system + * calls (both BSD and MACH)... the individual + * system call handlers will fill these in + * via copyin if needed... + */ + uint64_t rdi; /* arg0 for system call */ + uint64_t rsi; + uint64_t rdx; + uint64_t r10; + uint64_t r8; + uint64_t r9; /* arg5 for system call */ + uint64_t v_arg6; + uint64_t v_arg7; + uint64_t v_arg8; + + uint64_t cr2; + uint64_t r15; + uint64_t r14; + uint64_t r13; + uint64_t r12; + uint64_t r11; + uint64_t rbp; + uint64_t rbx; + uint64_t rcx; + uint64_t rax; + + uint32_t gs; + uint32_t fs; +#ifdef __x86_64__ + uint32_t _pad_for_alignment[3]; +#endif + struct x86_64_intr_stack_frame isf; }; +typedef struct x86_saved_state64 x86_saved_state64_t; +#define x86_SAVED_STATE64_COUNT ((mach_msg_type_number_t) \ + (sizeof (struct x86_saved_state64)/sizeof(unsigned int))) -typedef struct x86_float_state64 x86_float_state64_t; -#define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \ - (sizeof(x86_float_state64_t)/sizeof(unsigned int))) - - - - -struct x86_float_state { - x86_state_hdr_t fsh; - union { - x86_float_state32_t fs32; - x86_float_state64_t fs64; - } ufs; -} ; - - -typedef struct x86_float_state x86_float_state_t; -#define x86_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_float_state_t) / sizeof (int) )) - - - -/* - * Extra state that may be - * useful to exception handlers. - */ - -#define i386_THREAD_EXCEPTSTATE -3 - -typedef struct { - unsigned int trapno; - err_code_t err; -} i386_thread_exceptstate_t; - -#define i386_THREAD_EXCEPTSTATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (i386_thread_exceptstate_t) / sizeof (int) )) - - -/* - * x86-64 compatibility - */ -struct i386_exception_state { - unsigned int trapno; - unsigned int err; - unsigned int faultvaddr; -}; - -typedef struct i386_exception_state x86_exception_state32_t; -#define x86_EXCEPTION_STATE32_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_exception_state32_t) / sizeof (int) )) - -struct x86_debug_state32 { - unsigned int dr0; - unsigned int dr1; - unsigned int dr2; - unsigned int dr3; - unsigned int dr4; - unsigned int dr5; - unsigned int dr6; - unsigned int dr7; -}; - -typedef struct x86_debug_state32 x86_debug_state32_t; -#define x86_DEBUG_STATE32_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_debug_state32_t) / sizeof (int) )) -#define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT - - -struct x86_exception_state64 { - unsigned int trapno; - unsigned int err; - uint64_t faultvaddr; +struct x86_saved_state64_tagged { + uint32_t tag; + x86_saved_state64_t state; }; - -typedef struct x86_exception_state64 x86_exception_state64_t; -#define x86_EXCEPTION_STATE64_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_exception_state64_t) / sizeof (int) )) - - -struct x86_debug_state64 { - uint64_t dr0; - uint64_t dr1; - uint64_t dr2; - uint64_t dr3; - uint64_t dr4; - uint64_t dr5; - uint64_t dr6; - uint64_t dr7; -}; - - -typedef struct x86_debug_state64 x86_debug_state64_t; -#define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_debug_state64_t) / sizeof (int) )) - -#define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT - - - -struct x86_exception_state { - x86_state_hdr_t esh; - union { - x86_exception_state32_t es32; - x86_exception_state64_t es64; - } ues; -} ; - - -typedef struct x86_exception_state x86_exception_state_t; -#define x86_EXCEPTION_STATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (x86_exception_state_t) / sizeof (int) )) - -struct x86_debug_state { - x86_state_hdr_t dsh; - union { - x86_debug_state32_t ds32; - x86_debug_state64_t ds64; - } uds; +typedef struct x86_saved_state64_tagged x86_saved_state64_tagged_t; + +struct x86_sframe64 { + struct x86_64_intr_stack_frame slf; +#ifdef __i386__ + uint32_t _pad_for_alignment[3]; +#endif + struct x86_saved_state64_tagged ssf; }; +typedef struct x86_sframe64 x86_sframe64_t; - - -typedef struct x86_debug_state x86_debug_state_t; -#define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \ - (sizeof(x86_debug_state_t)/sizeof(unsigned int))) - +extern uint32_t get_eflags_exportmask(void); /* - * Per-thread variable used - * to store 'self' id for cthreads. + * Unified, tagged saved state: */ - -#define i386_THREAD_CTHREADSTATE -4 - typedef struct { - unsigned int self; -} i386_thread_cthreadstate_t; - -#define i386_THREAD_CTHREADSTATE_COUNT ((mach_msg_type_number_t) \ - ( sizeof (i386_thread_cthreadstate_t) / sizeof (int) )) + uint32_t flavor; + union { + x86_saved_state32_t ss_32; + x86_saved_state64_t ss_64; + } uss; +} x86_saved_state_t; +#define ss_32 uss.ss_32 +#define ss_64 uss.ss_64 +#pragma pack() + +static inline boolean_t +is_saved_state64(x86_saved_state_t *iss) +{ + return (iss->flavor == x86_SAVED_STATE64); +} + +static inline boolean_t +is_saved_state32(x86_saved_state_t *iss) +{ + return (iss->flavor == x86_SAVED_STATE32); +} + +static inline x86_saved_state32_t * +saved_state32(x86_saved_state_t *iss) +{ + return &iss->ss_32; +} + +static inline x86_saved_state64_t * +saved_state64(x86_saved_state_t *iss) +{ + return &iss->ss_64; +} + +#endif /* XNU_KERNEL_PRIVATE */ #endif /* _MACH_I386_THREAD_STATUS_H_ */