]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/cpu_data.h
xnu-1228.5.18.tar.gz
[apple/xnu.git] / osfmk / i386 / cpu_data.h
index b380d19c6e8d4215d34535b48ccddb11463e14a3..e061888d7d237f06ac1dd44e04728c863bbde21a 100644 (file)
@@ -1,14 +1,19 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
  *
- * @APPLE_LICENSE_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. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * 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
@@ -18,7 +23,7 @@
  * 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@
 #include <kern/assert.h>
 #include <kern/kern_types.h>
 #include <kern/processor.h>
+#include <kern/pms.h>
 #include <pexpert/pexpert.h>
+#include <mach/i386/thread_status.h>
+#include <i386/rtclock.h>
+#include <i386/pmCPU.h>
+#include <i386/cpu_topology.h>
 
+#include <i386/vmx/vmx_cpu.h>
 
 /*
  * Data structures referenced (anonymously) from per-cpu data:
  */
-struct cpu_core;
 struct cpu_cons_buffer;
-struct mp_desc_table;
+struct cpu_desc_table;
+struct mca_state;
 
 
 /*
@@ -55,15 +66,21 @@ typedef struct rtclock_timer {
        boolean_t       has_expired;
 } rtclock_timer_t;
 
-typedef struct {
-       uint64_t        rnt_tsc;                /* timestamp */
-       uint64_t        rnt_nanos;              /* nanoseconds */
-       uint32_t        rnt_scale;              /* tsc -> nanosec multiplier */
-       uint32_t        rnt_shift;              /* tsc -> nanosec shift/div */
-       uint64_t        rnt_step_tsc;           /* tsc when scale applied */
-       uint64_t        rnt_step_nanos;         /* ns  when scale applied */
+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 */
+
+
 typedef struct {
        struct i386_tss         *cdi_ktss;
 #if    MACH_KDB
@@ -72,8 +89,26 @@ typedef struct {
        struct fake_descriptor  *cdi_gdt;
        struct fake_descriptor  *cdi_idt;
        struct fake_descriptor  *cdi_ldt;
+       vm_offset_t             cdi_sstk;
 } cpu_desc_index_t;
 
+typedef enum {
+       TASK_MAP_32BIT,                 /* 32-bit, compatibility mode */ 
+       TASK_MAP_64BIT,                 /* 64-bit, separate address space */ 
+       TASK_MAP_64BIT_SHARED           /* 64-bit, kernel-shared addr space */
+} task_map_t;
+
+/*
+ * 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
+ * for the current thread and a temporary place to save the user's rsp
+ * before loading this address into rsp.
+ */
+typedef struct {
+       addr64_t        cu_isf;         /* thread->pcb->iss.isf */
+       uint64_t        cu_tmp;         /* temporary scratch */ 
+        addr64_t       cu_user_gs_base;
+} cpu_uber_t;
 
 /*
  * Per-cpu data.
@@ -92,9 +127,9 @@ typedef struct cpu_data
 {
        struct cpu_data         *cpu_this;              /* pointer to myself */
        thread_t                cpu_active_thread;
-       thread_t                cpu_active_kloaded;
-       vm_offset_t             cpu_active_stack;
-       vm_offset_t             cpu_kernel_stack;
+       void                    *cpu_int_state;         /* interrupt state */
+       vm_offset_t             cpu_active_stack;       /* kernel stack base */
+       vm_offset_t             cpu_kernel_stack;       /* kernel stack top */
        vm_offset_t             cpu_int_stack_top;
        int                     cpu_preemption_level;
        int                     cpu_simple_lock_count;
@@ -109,34 +144,68 @@ typedef struct cpu_data
        int                     cpu_subtype;
        int                     cpu_threadtype;
        int                     cpu_running;
-       struct cpu_core         *cpu_core;              /* cpu's parent core */
-       uint64_t                cpu_rtc_tick_deadline;
-       uint64_t                cpu_rtc_intr_deadline;
-       rtclock_timer_t         cpu_rtc_timer;
-       rtc_nanotime_t          cpu_rtc_nanotime;
+       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;
+       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;
        struct cpu_pmap         *cpu_pmap;
-       struct mp_desc_table    *cpu_desc_tablep;
+       struct cpu_desc_table   *cpu_desc_tablep;
+       struct fake_descriptor  *cpu_ldtp;
        cpu_desc_index_t        cpu_desc_index;
-       boolean_t               cpu_iflag;
+       int                     cpu_ldt;
 #ifdef MACH_KDB
        /* XXX Untested: */
        int                     cpu_db_pass_thru;
        vm_offset_t             cpu_db_stacks;
-       struct i386_saved_state *cpu_kdb_saved_state;
+       void                    *cpu_kdb_saved_state;
        spl_t                   cpu_kdb_saved_ipl;
        int                     cpu_kdb_is_slave;
        int                     cpu_kdb_active;
 #endif /* MACH_KDB */
-        int                     cpu_hibernate;
+       boolean_t               cpu_iflag;
+       boolean_t               cpu_boot_complete;
+       int                     cpu_hibernate;
+
+       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 */
+       uint64_t                cpu_dr7; /* debug control register */
+       uint64_t                cpu_int_event_time;     /* intr entry/exit time */
+       vmx_cpu_t               cpu_vmx;                /* wonderful world of virtualization */
+       struct mca_state        *cpu_mca_state;         /* State at MC fault */
+       uint64_t                cpu_uber_arg_store;     /* Double mapped address
+                                                        * of current thread's
+                                                        * uu_arg array.
+                                                        */
+       uint64_t                cpu_uber_arg_store_valid; /* Double mapped
+                                                          * address of pcb
+                                                          * arg store
+                                                          * validity flag.
+                                                          */
+
+                                                         
 } cpu_data_t;
 
 extern cpu_data_t      *cpu_data_ptr[];  
 extern cpu_data_t      cpu_data_master;  
 
 /* Macro to generate inline bodies to retrieve per-cpu data fields. */
+#ifndef offsetof
 #define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif /* offsetof */
 #define CPU_DATA_GET(member,type)                                      \
        type ret;                                                       \
        __asm__ volatile ("movl %%gs:%P1,%0"                            \
@@ -157,6 +226,13 @@ get_active_thread(void)
 #define current_thread_fast()          get_active_thread()
 #define current_thread()               current_thread_fast()
 
+static inline boolean_t
+get_is64bit(void)
+{
+       CPU_DATA_GET(cpu_is64bit, boolean_t)
+}
+#define cpu_mode_is64bit()             get_is64bit()
+
 static inline int
 get_preemption_level(void)
 {
@@ -182,11 +258,6 @@ get_cpu_phys_number(void)
 {
        CPU_DATA_GET(cpu_phys_number,int)
 }
-static inline struct
-cpu_core * get_cpu_core(void)
-{
-       CPU_DATA_GET(cpu_core,struct cpu_core *)
-}
 
 static inline void
 disable_preemption(void)