]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/thread.h
xnu-3789.70.16.tar.gz
[apple/xnu.git] / osfmk / i386 / thread.h
index faab785af5fdfa3a91aedfbb6c2d059ce6f4e168..1fea8c2d8d8c85209d22173e6ab7963854940575 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -71,7 +71,7 @@
 #include <mach/i386/fp_reg.h>
 #include <mach/thread_status.h>
 
-#include <kern/lock.h>
+#include <kern/simple_lock.h>
 
 #include <i386/iopb.h>
 #include <i386/seg.h>
 
 #include <i386/cpu_data.h>
 
-
-/*
- *     i386_saved_state:
- *
- *     Has been exported to servers.  See: mach/i386/thread_status.h
- *
- *     This structure corresponds to the state of user registers
- *     as saved upon kernel entry.  It lives in the pcb.
- *     It is also pushed onto the stack for exceptions in the kernel.
- *     For performance, it is also used directly in syscall exceptions
- *     if the server has requested i386_THREAD_STATE flavor for the exception
- *     port.
- */
-
-/*
- *     Save area for user floating-point state.
- *     Allocated only when necessary.
- */
-
-typedef        enum {
-               FXSAVE32 = 1,
-               FXSAVE64 = 2,
-               XSAVE32  = 3,
-               XSAVE64  = 4,
-               FP_UNUSED = 5
-       } fp_save_layout_t;
-
-
+#include <machine/pal_routines.h>
 
 /*
  *     x86_kernel_state:
@@ -116,94 +89,79 @@ typedef    enum {
  *     as saved in a context-switch.  It lives at the base of the stack.
  */
 
-#ifdef __i386__
 struct x86_kernel_state {
-       int                     k_ebx;  /* kernel context */
-       int                     k_esp;
-       int                     k_ebp;
-       int                     k_edi;
-       int                     k_esi;
-       int                     k_eip;
-       /*
-        * Kernel stacks are 16-byte aligned with a 4-byte i386_exception_link at
-        * the top, followed by an x86_kernel_state.  After both structs have
-        * been pushed, we want to be 16-byte aligned.  A dummy int gets us there.
-        */
-       int                     dummy;
+       uint64_t        k_rbx;  /* kernel context */
+       uint64_t        k_rsp;
+       uint64_t        k_rbp;
+       uint64_t        k_r12;
+       uint64_t        k_r13;
+       uint64_t        k_r14;
+       uint64_t        k_r15;
+       uint64_t        k_rip;
 };
-#else
-struct x86_kernel_state {
-       unsigned long k_rbx;    /* kernel context */
-       unsigned long k_rsp;
-       unsigned long k_rbp;
-       unsigned long k_r12;
-       unsigned long k_r13;
-       unsigned long k_r14;
-       unsigned long k_r15;
-       unsigned long k_rip;
-       unsigned long dummy;
-};
-#endif
-
-typedef struct pcb {
-       void                    *sf;
-       x86_saved_state_t       *iss;
-       void                    *ifps;
-#ifdef MACH_BSD
-       uint64_t        cthread_self;           /* for use of cthread package */
-        struct real_descriptor cthread_desc;
-       unsigned long  uldt_selector;          /* user ldt selector to set */
-       struct real_descriptor uldt_desc;      /* the actual user setable ldt data */
-#endif
-       decl_simple_lock_data(,lock);
-       uint64_t        iss_pte0;
-       uint64_t        iss_pte1;
-       void            *ids;
-       uint32_t        arg_store_valid;
-} *pcb_t;
 
 /*
  * Maps state flavor to number of words in the state:
  */
-__private_extern__ unsigned int _MachineStateCount[];
+extern unsigned int _MachineStateCount[];
 
-#define USER_STATE(ThrAct)     ((ThrAct)->machine.pcb->iss)
-#define USER_REGS32(ThrAct)    (saved_state32(USER_STATE(ThrAct)))
-#define USER_REGS64(ThrAct)    (saved_state64(USER_STATE(ThrAct)))
-
-#define        user_pc(ThrAct)         (is_saved_state32(USER_STATE(ThrAct)) ? \
-                                       USER_REGS32(ThrAct)->eip :      \
-                                       USER_REGS64(ThrAct)->isf.rip )
+/*
+ * The machine-dependent thread state - registers and all platform-dependent
+ * state - is saved in the machine thread structure which is embedded in
+ * the thread data structure. For historical reasons this is also referred to
+ * as the PCB.
+ */
+struct machine_thread {
+       x86_saved_state_t       *iss;
+       void                    *ifps;
+       void                    *ids;
+       decl_simple_lock_data(,lock);           /* protects ifps and ids */
+       uint64_t                iss_pte0;
+       uint64_t                iss_pte1;
 
+#ifdef MACH_BSD
+       uint64_t                cthread_self;   /* for use of cthread package */
+        struct real_descriptor cthread_desc;
+       unsigned long           uldt_selector;  /* user ldt selector to set */
+       struct real_descriptor  uldt_desc;      /* actual user setable ldt */
+#endif
 
-struct machine_thread {
-       /*
-        * pointer to process control block
-        *      (actual storage may as well be here, too)
+       struct pal_pcb          pal_pcb;
+       uint32_t                specFlags;
+       /* N.B.: These "specFlags" are read-modify-written non-atomically within
+        * the copyio routine. So conceivably any exception that modifies the
+        * flags in a persistent manner could be clobbered if it occurs within
+        * a copyio context. For now, the only other flag here is OnProc which
+        * is not modified except at context switch.
         */
-       struct pcb xxx_pcb;
-       pcb_t pcb;
-
-       uint32_t        specFlags;
 #define                OnProc          0x1
 #define                CopyIOActive    0x2 /* Checked to ensure DTrace actions do not re-enter copyio(). */
-  
+       uint64_t                thread_gpu_ns;
 #if NCOPY_WINDOWS > 0
-
         struct {
                user_addr_t     user_base;
        } copy_window[NCOPY_WINDOWS];
-        int            nxt_window;
-        int            copyio_state;
+        int                    nxt_window;
+        int                    copyio_state;
 #define                WINDOWS_DIRTY   0
 #define                WINDOWS_CLEAN   1
 #define                WINDOWS_CLOSED  2
 #define                WINDOWS_OPENED  3
-        uint64_t       physwindow_pte;
-        int            physwindow_busy;
+        uint64_t               physwindow_pte;
+        int                    physwindow_busy;
 #endif
 };
+typedef struct machine_thread *pcb_t;
 
+#define        THREAD_TO_PCB(Thr)      (&(Thr)->machine)
+
+#define USER_STATE(Thr)                ((Thr)->machine.iss)
+#define USER_REGS32(Thr)       (saved_state32(USER_STATE(Thr)))
+#define USER_REGS64(Thr)       (saved_state64(USER_STATE(Thr)))
+
+#define        user_pc(Thr)            (is_saved_state32(USER_STATE(Thr)) ?    \
+                                       USER_REGS32(Thr)->eip :         \
+                                       USER_REGS64(Thr)->isf.rip )
 
 extern void *get_user_regs(thread_t);
 
@@ -211,33 +169,20 @@ extern void *act_thread_csave(void);
 extern void act_thread_catt(void *ctx);
 extern void act_thread_cfree(void *ctx);
 
-/*
- *     i386_exception_link:
- *
- *     This structure lives at the high end of the kernel stack.
- *     It points to the current thread`s user registers.
- */
-struct i386_exception_link {
-       x86_saved_state_t       *saved_state;
-};
-
+#define FIND_PERFCONTROL_STATE(th)     (PERFCONTROL_STATE_NULL)
 
 /*
  *     On the kernel stack is:
  *     stack:  ...
- *             struct i386_exception_link (pointer to user state)
  *             struct x86_kernel_state
  *     stack+kernel_stack_size
  */
 
 #define STACK_IKS(stack)       \
        ((struct x86_kernel_state *)((stack) + kernel_stack_size) - 1)
-#define STACK_IEL(stack)       \
-       ((struct i386_exception_link *)STACK_IKS(stack) - 1)
 
 /*
- * Return the current stack depth
- * including x86_kernel_state and i386_exception_link
+ * Return the current stack depth including x86_kernel_state
  */
 static inline vm_offset_t
 current_stack_depth(void)
@@ -253,7 +198,6 @@ current_stack_depth(void)
 #endif
        return (current_cpu_datap()->cpu_kernel_stack
                + sizeof(struct x86_kernel_state)
-               + sizeof(struct i386_exception_link *)
                - stack_ptr); 
 }
 
@@ -263,11 +207,4 @@ current_stack_depth(void)
  */
 #define        GET_RETURN_PC(addr)     (__builtin_return_address(0))
 
-/*
- * Defining this indicates that MD code will supply an exception()
- * routine, conformant with kern/exception.c (dependency alert!)
- * but which does wonderfully fast, machine-dependent magic.
- */
-#define MACHINE_FAST_EXCEPTION 1
-
 #endif /* _I386_THREAD_H_ */