]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/cpu_data.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_data.h
index e061888d7d237f06ac1dd44e04728c863bbde21a..9578cc80b1ce75728c9a5b7c418a2302a5e155d5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 
 #include <mach_assert.h>
 
-#if    defined(__GNUC__)
-
 #include <kern/assert.h>
 #include <kern/kern_types.h>
+#include <kern/queue.h>
 #include <kern/processor.h>
 #include <kern/pms.h>
 #include <pexpert/pexpert.h>
 #include <mach/i386/thread_status.h>
+#include <mach/i386/vm_param.h>
 #include <i386/rtclock.h>
 #include <i386/pmCPU.h>
 #include <i386/cpu_topology.h>
 
+#if CONFIG_VMX
 #include <i386/vmx/vmx_cpu.h>
+#endif
 
 /*
  * Data structures referenced (anonymously) from per-cpu data:
@@ -61,35 +63,26 @@ struct mca_state;
  * Data structures embedded in per-cpu data:
  */
 typedef struct rtclock_timer {
-       uint64_t        deadline;
-       boolean_t       is_set;
-       boolean_t       has_expired;
+       queue_head_t    queue;
+       uint64_t                deadline;
+       boolean_t               is_set;
+       boolean_t               has_expired;
 } rtclock_timer_t;
 
-typedef struct rtc_nanotime {
-       uint64_t        tsc_base;               /* timestamp */
-       uint64_t        ns_base;                /* nanoseconds */
-       uint32_t        scale;                  /* tsc -> nanosec multiplier */
-       uint32_t        shift;                  /* tsc -> nanosec shift/div */
-                                               /* shift is overloaded with
-                                                * lower 32bits of tsc_freq
-                                                * on slower machines (SLOW_TSC_THRESHOLD) */
-       uint32_t        generation;             /* 0 == being updated */
-       uint32_t        spare1;
-} rtc_nanotime_t;
-
-#define        SLOW_TSC_THRESHOLD      1000067800      /* TSC is too slow for regular nanotime() algorithm */
 
+#if defined(__i386__)
 
 typedef struct {
        struct i386_tss         *cdi_ktss;
 #if    MACH_KDB
        struct i386_tss         *cdi_dbtss;
 #endif /* MACH_KDB */
-       struct fake_descriptor  *cdi_gdt;
-       struct fake_descriptor  *cdi_idt;
-       struct fake_descriptor  *cdi_ldt;
-       vm_offset_t             cdi_sstk;
+       struct __attribute__((packed)) {
+               uint16_t size;
+               struct fake_descriptor *ptr;
+       } cdi_gdt, cdi_idt;
+       struct fake_descriptor  *cdi_ldt;
+       vm_offset_t                             cdi_sstk;
 } cpu_desc_index_t;
 
 typedef enum {
@@ -98,6 +91,31 @@ typedef enum {
        TASK_MAP_64BIT_SHARED           /* 64-bit, kernel-shared addr space */
 } task_map_t;
 
+#elif defined(__x86_64__)
+
+
+typedef struct {
+       struct x86_64_tss               *cdi_ktss;
+#if    MACH_KDB
+       struct x86_64_tss               *cdi_dbtss;
+#endif /* MACH_KDB */
+       struct __attribute__((packed)) {
+               uint16_t size;
+               void *ptr;
+       } cdi_gdt, cdi_idt;
+       struct fake_descriptor  *cdi_ldt;
+       vm_offset_t                             cdi_sstk;
+} cpu_desc_index_t;
+
+typedef enum {
+       TASK_MAP_32BIT,                 /* 32-bit user, compatibility mode */ 
+       TASK_MAP_64BIT,                 /* 64-bit user thread, shared space */ 
+} task_map_t;
+
+#else
+#error Unsupported architecture
+#endif
+
 /*
  * This structure is used on entry into the (uber-)kernel on syscall from
  * a 64-bit user. It contains the address of the machine state save area
@@ -110,6 +128,7 @@ typedef struct {
         addr64_t       cu_user_gs_base;
 } cpu_uber_t;
 
+
 /*
  * Per-cpu data.
  *
@@ -144,19 +163,20 @@ typedef struct cpu_data
        int                     cpu_subtype;
        int                     cpu_threadtype;
        int                     cpu_running;
-       uint64_t                rtclock_intr_deadline;
        rtclock_timer_t         rtclock_timer;
        boolean_t               cpu_is64bit;
        task_map_t              cpu_task_map;
-       addr64_t                cpu_task_cr3;
-       addr64_t                cpu_active_cr3;
+       volatile addr64_t       cpu_task_cr3;
+       volatile addr64_t       cpu_active_cr3;
        addr64_t                cpu_kernel_cr3;
        cpu_uber_t              cpu_uber;
        void                    *cpu_chud;
        void                    *cpu_console_buf;
        struct x86_lcpu         lcpu;
        struct processor        *cpu_processor;
+#if NCOPY_WINDOWS > 0
        struct cpu_pmap         *cpu_pmap;
+#endif
        struct cpu_desc_table   *cpu_desc_tablep;
        struct fake_descriptor  *cpu_ldtp;
        cpu_desc_index_t        cpu_desc_index;
@@ -174,18 +194,27 @@ typedef struct cpu_data
        boolean_t               cpu_boot_complete;
        int                     cpu_hibernate;
 
+#if NCOPY_WINDOWS > 0
        vm_offset_t             cpu_copywindow_base;
        uint64_t                *cpu_copywindow_pdp;
 
        vm_offset_t             cpu_physwindow_base;
        uint64_t                *cpu_physwindow_ptep;
        void                    *cpu_hi_iss;
-       boolean_t               cpu_tlb_invalid;
-       uint32_t                cpu_hwIntCnt[256];              /* Interrupt counts */
+#endif
+
+
+
+       volatile boolean_t      cpu_tlb_invalid;
+       uint32_t                cpu_hwIntCnt[256];      /* Interrupt counts */
        uint64_t                cpu_dr7; /* debug control register */
        uint64_t                cpu_int_event_time;     /* intr entry/exit time */
+#if CONFIG_VMX
        vmx_cpu_t               cpu_vmx;                /* wonderful world of virtualization */
+#endif
+#if CONFIG_MCA
        struct mca_state        *cpu_mca_state;         /* State at MC fault */
+#endif
        uint64_t                cpu_uber_arg_store;     /* Double mapped address
                                                         * of current thread's
                                                         * uu_arg array.
@@ -195,8 +224,9 @@ typedef struct cpu_data
                                                           * arg store
                                                           * validity flag.
                                                           */
-
-                                                         
+       rtc_nanotime_t          *cpu_nanotime;          /* Nanotime info */
+       thread_t                csw_old_thread;
+       thread_t                csw_new_thread;
 } cpu_data_t;
 
 extern cpu_data_t      *cpu_data_ptr[];  
@@ -208,7 +238,7 @@ extern cpu_data_t   cpu_data_master;
 #endif /* offsetof */
 #define CPU_DATA_GET(member,type)                                      \
        type ret;                                                       \
-       __asm__ volatile ("movl %%gs:%P1,%0"                            \
+       __asm__ volatile ("mov %%gs:%P1,%0"                             \
                : "=r" (ret)                                            \
                : "i" (offsetof(cpu_data_t,member)));                   \
        return ret;
@@ -226,12 +256,16 @@ get_active_thread(void)
 #define current_thread_fast()          get_active_thread()
 #define current_thread()               current_thread_fast()
 
+#if defined(__i386__)
 static inline boolean_t
 get_is64bit(void)
 {
        CPU_DATA_GET(cpu_is64bit, boolean_t)
 }
 #define cpu_mode_is64bit()             get_is64bit()
+#elif defined(__x86_64__)
+#define cpu_mode_is64bit()             TRUE
+#endif
 
 static inline int
 get_preemption_level(void)
@@ -259,6 +293,7 @@ get_cpu_phys_number(void)
        CPU_DATA_GET(cpu_phys_number,int)
 }
 
+
 static inline void
 disable_preemption(void)
 {
@@ -319,14 +354,9 @@ current_cpu_datap(void)
 static inline cpu_data_t *
 cpu_datap(int cpu)
 {
-       assert(cpu_data_ptr[cpu]);
        return cpu_data_ptr[cpu];
 }
 
 extern cpu_data_t *cpu_data_alloc(boolean_t is_boot_cpu);
 
-#else  /* !defined(__GNUC__) */
-
-#endif /* defined(__GNUC__) */
-
 #endif /* I386_CPU_DATA */