]> git.saurik.com Git - apple/xnu.git/blame - osfmk/chud/i386/chud_cpu_i386.c
xnu-2422.1.72.tar.gz
[apple/xnu.git] / osfmk / chud / i386 / chud_cpu_i386.c
CommitLineData
0c530ab8 1/*
b0d623f7 2 * Copyright (c) 2003-2009 Apple Inc. All rights reserved.
0c530ab8 3 *
2d21ac55
A
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
0c530ab8
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
0c530ab8 27 */
2d21ac55 28
0c530ab8
A
29#include <mach/mach_types.h>
30#include <mach/mach_host.h>
31
32#include <kern/host.h>
33#include <kern/processor.h>
34
35#include <i386/cpu_data.h>
36#include <i386/machine_routines.h>
593a1d5f 37#include <i386/lapic.h>
0c530ab8 38#include <i386/mp.h>
2d21ac55
A
39#include <i386/trap.h>
40#include <mach/i386/syscall_sw.h>
0c530ab8
A
41
42#include <chud/chud_xnu.h>
43
b0d623f7 44#if 0
0c530ab8 45#pragma mark **** cpu enable/disable ****
b0d623f7 46#endif
0c530ab8
A
47
48extern kern_return_t processor_start(processor_t processor); // osfmk/kern/processor.c
49extern kern_return_t processor_exit(processor_t processor); // osfmk/kern/processor.c
50
51__private_extern__
52kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
53{
2d21ac55 54 chudxnu_unbind_thread(current_thread(), 0);
0c530ab8
A
55
56 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check
57 return KERN_FAILURE;
58
59 if((cpu_data_ptr[cpu] != NULL) && cpu != master_cpu) {
60 processor_t processor = cpu_to_processor(cpu);
61
62 if(processor == master_processor) // don't mess with the boot processor
63 return KERN_FAILURE;
64
65 if(enable) {
2d21ac55 66 return processor_start(processor);
0c530ab8 67 } else {
2d21ac55 68 return processor_exit(processor);
0c530ab8
A
69 }
70 }
71 return KERN_FAILURE;
72}
73
b0d623f7 74#if 0
0c530ab8 75#pragma mark **** perfmon facility ****
b0d623f7 76#endif
0c530ab8
A
77
78__private_extern__ kern_return_t
b0d623f7 79chudxnu_perfmon_acquire_facility(task_t task __unused)
0c530ab8 80{
b0d623f7 81 return KERN_SUCCESS;
0c530ab8
A
82}
83
84__private_extern__ kern_return_t
b0d623f7 85chudxnu_perfmon_release_facility(task_t task __unused)
0c530ab8 86{
b0d623f7 87 return KERN_SUCCESS;
0c530ab8
A
88}
89
b0d623f7 90#if 0
2d21ac55 91#pragma mark **** interrupt counters ****
b0d623f7 92#endif
0c530ab8
A
93
94__private_extern__ kern_return_t
b0d623f7 95chudxnu_get_cpu_interrupt_counters(int cpu, interrupt_counters_t *rupts)
0c530ab8
A
96{
97 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
98 return KERN_FAILURE;
99 }
100
101 if(rupts) {
102 boolean_t oldlevel = ml_set_interrupts_enabled(FALSE);
103 cpu_data_t *per_proc;
104
105 per_proc = cpu_data_ptr[cpu];
2d21ac55
A
106 // For now, we'll call an NMI a 'reset' interrupt
107 rupts->hwResets = per_proc->cpu_hwIntCnt[T_NMI];
108 rupts->hwMachineChecks = per_proc->cpu_hwIntCnt[T_MACHINE_CHECK];
0c530ab8
A
109 rupts->hwDSIs = 0;
110 rupts->hwISIs = 0;
2d21ac55 111 // we could accumulate 0x20-0x7f, but that'd likely overflow...
0c530ab8 112 rupts->hwExternals = 0;
2d21ac55
A
113 // This appears to be wrong.
114 rupts->hwAlignments = 0; //per_proc->cpu_hwIntCnt[0x11];
0c530ab8 115 rupts->hwPrograms = 0;
2d21ac55
A
116 rupts->hwFloatPointUnavailable = per_proc->cpu_hwIntCnt[T_NO_FPU];
117 // osfmk/i386/mp.h
118 rupts->hwDecrementers = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(TIMER)];
119 // LAPIC_ERROR == IO ERROR??
120 rupts->hwIOErrors = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(ERROR)];
121
122 // accumulate all system call types
123 // osfmk/mach/i386/syscall_sw.h
124 rupts->hwSystemCalls = per_proc->cpu_hwIntCnt[UNIX_INT] +
125 per_proc->cpu_hwIntCnt[MACH_INT] +
126 per_proc->cpu_hwIntCnt[MACHDEP_INT] +
127 per_proc->cpu_hwIntCnt[DIAG_INT];
128
129 rupts->hwTraces = per_proc->cpu_hwIntCnt[T_DEBUG]; // single steps == traces??
0c530ab8 130 rupts->hwFloatingPointAssists = 0;
2d21ac55
A
131 // osfmk/i386/mp.h
132 rupts->hwPerformanceMonitors =
133 per_proc->cpu_hwIntCnt[LAPIC_VECTOR(PERFCNT)];
0c530ab8 134 rupts->hwAltivecs = 0;
2d21ac55 135 rupts->hwInstBreakpoints = per_proc->cpu_hwIntCnt[T_INT3];
0c530ab8
A
136 rupts->hwSystemManagements = 0;
137 rupts->hwAltivecAssists = 0;
2d21ac55 138 rupts->hwThermal = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(THERMAL)];
0c530ab8
A
139 rupts->hwSoftPatches = 0;
140 rupts->hwMaintenances = 0;
2d21ac55
A
141 // Watchpoint == instrumentation
142 rupts->hwInstrumentations = per_proc->cpu_hwIntCnt[T_WATCHPOINT];
0c530ab8
A
143
144 ml_set_interrupts_enabled(oldlevel);
145 return KERN_SUCCESS;
146 } else {
147 return KERN_FAILURE;
148 }
149}
150
151__private_extern__ kern_return_t
2d21ac55 152chudxnu_clear_cpu_interrupt_counters(int cpu)
0c530ab8
A
153{
154 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
155 return KERN_FAILURE;
156 }
2d21ac55
A
157 cpu_data_t *per_proc;
158
159 per_proc = cpu_data_ptr[cpu];
160
161 bzero((char *)per_proc->cpu_hwIntCnt, sizeof(uint32_t)*256);
0c530ab8 162
0c530ab8
A
163 return KERN_SUCCESS;
164}
2d21ac55 165