]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/chud/i386/chud_cpu_i386.c
xnu-1228.tar.gz
[apple/xnu.git] / osfmk / chud / i386 / chud_cpu_i386.c
index 12d91f3b41ac91ad0133e3c71ac3d6de2f0a5cf6..8510249dc7d217e1db24de672f463e83cb6af8b6 100644 (file)
@@ -1,24 +1,31 @@
 /*
- * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
  *
- * @APPLE_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 Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * @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 OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
+ * 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_OSREFERENCE_LICENSE_HEADER_END@
  */
+
 #include <mach/mach_types.h>
 #include <mach/mach_host.h>
 
@@ -29,6 +36,8 @@
 #include <i386/machine_routines.h>
 #include <i386/perfmon.h>
 #include <i386/mp.h>
+#include <i386/trap.h>
+#include <mach/i386/syscall_sw.h>
 
 #include <chud/chud_xnu.h>
 
@@ -40,7 +49,7 @@ extern kern_return_t processor_exit(processor_t     processor); // osfmk/kern/pr
 __private_extern__
 kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
 {
-    chudxnu_unbind_thread(current_thread());
+    chudxnu_unbind_thread(current_thread(), 0);
        
     if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check
         return KERN_FAILURE;
@@ -52,41 +61,14 @@ kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
                        return KERN_FAILURE;
 
         if(enable) {
-                       // make sure it isn't already running
-                       if(processor->state == PROCESSOR_OFF_LINE || 
-                               processor->state == PROCESSOR_SHUTDOWN) {
-                               return processor_start(processor);
-                       }
-                       return KERN_SUCCESS;    // it's already running
+            return processor_start(processor);
         } else {
-                       // make sure it hasn't already exited
-                       if(processor->state != PROCESSOR_OFF_LINE &&
-                               processor->state != PROCESSOR_SHUTDOWN) {
-                               return processor_exit(processor);
-                       }
-                       return KERN_SUCCESS;
+            return processor_exit(processor);
         }
     }
     return KERN_FAILURE;
 }
 
-#pragma mark **** cache flush ****
-
-__private_extern__
-void
-chudxnu_flush_caches(void)
-{
-/* XXX */
-}
-
-__private_extern__
-void
-chudxnu_enable_caches(boolean_t enable)
-{
-#pragma unused (enable)
-/* XXX */
-}
-
 #pragma mark **** perfmon facility ****
 
 __private_extern__ kern_return_t
@@ -101,10 +83,10 @@ chudxnu_perfmon_release_facility(task_t task)
     return pmc_release(task);
 }
 
-#pragma mark **** rupt counters ****
+#pragma mark **** interrupt counters ****
 
 __private_extern__ kern_return_t
-chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
+chudxnu_get_cpu_interrupt_counters(int cpu, rupt_counters_t *rupts)
 {
     if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
         return KERN_FAILURE;
@@ -115,28 +97,43 @@ chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
         cpu_data_t     *per_proc;
 
         per_proc = cpu_data_ptr[cpu];
-        rupts->hwResets = 0;
-        rupts->hwMachineChecks = 0;
+               // For now, we'll call an NMI a 'reset' interrupt
+        rupts->hwResets = per_proc->cpu_hwIntCnt[T_NMI];
+        rupts->hwMachineChecks = per_proc->cpu_hwIntCnt[T_MACHINE_CHECK];
         rupts->hwDSIs = 0;
         rupts->hwISIs = 0;
+               // we could accumulate 0x20-0x7f, but that'd likely overflow...
         rupts->hwExternals = 0;
-        rupts->hwAlignments = 0;
+               // This appears to be wrong.
+        rupts->hwAlignments = 0; //per_proc->cpu_hwIntCnt[0x11];
         rupts->hwPrograms = 0;
-        rupts->hwFloatPointUnavailable = 0;
-        rupts->hwDecrementers = 0;
-        rupts->hwIOErrors = 0;
-        rupts->hwSystemCalls = 0;
-        rupts->hwTraces = 0;
+        rupts->hwFloatPointUnavailable = per_proc->cpu_hwIntCnt[T_NO_FPU];
+               // osfmk/i386/mp.h
+        rupts->hwDecrementers = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(TIMER)];
+               // LAPIC_ERROR == IO ERROR??
+        rupts->hwIOErrors = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(ERROR)];
+
+               // accumulate all system call types
+               // osfmk/mach/i386/syscall_sw.h
+        rupts->hwSystemCalls = per_proc->cpu_hwIntCnt[UNIX_INT]  +
+                       per_proc->cpu_hwIntCnt[MACH_INT] +
+                       per_proc->cpu_hwIntCnt[MACHDEP_INT] +
+                       per_proc->cpu_hwIntCnt[DIAG_INT];
+
+        rupts->hwTraces = per_proc->cpu_hwIntCnt[T_DEBUG]; // single steps == traces??
         rupts->hwFloatingPointAssists = 0;
-        rupts->hwPerformanceMonitors = 0;
+               // osfmk/i386/mp.h
+        rupts->hwPerformanceMonitors =
+                       per_proc->cpu_hwIntCnt[LAPIC_VECTOR(PERFCNT)];
         rupts->hwAltivecs = 0;
-        rupts->hwInstBreakpoints = 0;
+        rupts->hwInstBreakpoints = per_proc->cpu_hwIntCnt[T_INT3];
         rupts->hwSystemManagements = 0;
         rupts->hwAltivecAssists = 0;
-        rupts->hwThermal = 0;
+        rupts->hwThermal = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(THERMAL)];
         rupts->hwSoftPatches = 0;
         rupts->hwMaintenances = 0;
-        rupts->hwInstrumentations = 0;
+               // Watchpoint == instrumentation
+               rupts->hwInstrumentations = per_proc->cpu_hwIntCnt[T_WATCHPOINT]; 
 
         ml_set_interrupts_enabled(oldlevel);
         return KERN_SUCCESS;
@@ -146,15 +143,32 @@ chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
 }
 
 __private_extern__ kern_return_t
-chudxnu_clear_cpu_rupt_counters(int cpu)
+chudxnu_clear_cpu_interrupt_counters(int cpu)
 {
     if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
         return KERN_FAILURE;
     }
+       cpu_data_t      *per_proc;
+
+       per_proc = cpu_data_ptr[cpu];
+
+       bzero((char *)per_proc->cpu_hwIntCnt, sizeof(uint32_t)*256);
 
-/*
- * XXX
- *    bzero((char *)&(cpu_data_ptr[cpu]->hwCtrs), sizeof(struct hwCtrs));
- */
     return KERN_SUCCESS;
 }
+
+#pragma mark *** deprecated ***
+
+//DEPRECATED
+__private_extern__ kern_return_t
+chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
+{
+       return chudxnu_get_cpu_interrupt_counters(cpu, rupts);
+}
+
+//DEPRECATED
+__private_extern__ kern_return_t
+chudxnu_clear_cpu_rupt_counters(int cpu)
+{
+       return chudxnu_clear_cpu_interrupt_counters(cpu);
+}