]> git.saurik.com Git - apple/xnu.git/blame - osfmk/chud/i386/chud_cpu_i386.c
xnu-1228.15.4.tar.gz
[apple/xnu.git] / osfmk / chud / i386 / chud_cpu_i386.c
CommitLineData
0c530ab8 1/*
2d21ac55 2 * Copyright (c) 2003-2007 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>
37#include <i386/perfmon.h>
593a1d5f 38#include <i386/lapic.h>
0c530ab8 39#include <i386/mp.h>
2d21ac55
A
40#include <i386/trap.h>
41#include <mach/i386/syscall_sw.h>
0c530ab8
A
42
43#include <chud/chud_xnu.h>
44
45#pragma mark **** cpu enable/disable ****
46
47extern kern_return_t processor_start(processor_t processor); // osfmk/kern/processor.c
48extern kern_return_t processor_exit(processor_t processor); // osfmk/kern/processor.c
49
50__private_extern__
51kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable)
52{
2d21ac55 53 chudxnu_unbind_thread(current_thread(), 0);
0c530ab8
A
54
55 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) // sanity check
56 return KERN_FAILURE;
57
58 if((cpu_data_ptr[cpu] != NULL) && cpu != master_cpu) {
59 processor_t processor = cpu_to_processor(cpu);
60
61 if(processor == master_processor) // don't mess with the boot processor
62 return KERN_FAILURE;
63
64 if(enable) {
2d21ac55 65 return processor_start(processor);
0c530ab8 66 } else {
2d21ac55 67 return processor_exit(processor);
0c530ab8
A
68 }
69 }
70 return KERN_FAILURE;
71}
72
0c530ab8
A
73#pragma mark **** perfmon facility ****
74
75__private_extern__ kern_return_t
76chudxnu_perfmon_acquire_facility(task_t task)
77{
78 return pmc_acquire(task);
79}
80
81__private_extern__ kern_return_t
82chudxnu_perfmon_release_facility(task_t task)
83{
84 return pmc_release(task);
85}
86
2d21ac55 87#pragma mark **** interrupt counters ****
0c530ab8
A
88
89__private_extern__ kern_return_t
2d21ac55 90chudxnu_get_cpu_interrupt_counters(int cpu, rupt_counters_t *rupts)
0c530ab8
A
91{
92 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
93 return KERN_FAILURE;
94 }
95
96 if(rupts) {
97 boolean_t oldlevel = ml_set_interrupts_enabled(FALSE);
98 cpu_data_t *per_proc;
99
100 per_proc = cpu_data_ptr[cpu];
2d21ac55
A
101 // For now, we'll call an NMI a 'reset' interrupt
102 rupts->hwResets = per_proc->cpu_hwIntCnt[T_NMI];
103 rupts->hwMachineChecks = per_proc->cpu_hwIntCnt[T_MACHINE_CHECK];
0c530ab8
A
104 rupts->hwDSIs = 0;
105 rupts->hwISIs = 0;
2d21ac55 106 // we could accumulate 0x20-0x7f, but that'd likely overflow...
0c530ab8 107 rupts->hwExternals = 0;
2d21ac55
A
108 // This appears to be wrong.
109 rupts->hwAlignments = 0; //per_proc->cpu_hwIntCnt[0x11];
0c530ab8 110 rupts->hwPrograms = 0;
2d21ac55
A
111 rupts->hwFloatPointUnavailable = per_proc->cpu_hwIntCnt[T_NO_FPU];
112 // osfmk/i386/mp.h
113 rupts->hwDecrementers = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(TIMER)];
114 // LAPIC_ERROR == IO ERROR??
115 rupts->hwIOErrors = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(ERROR)];
116
117 // accumulate all system call types
118 // osfmk/mach/i386/syscall_sw.h
119 rupts->hwSystemCalls = per_proc->cpu_hwIntCnt[UNIX_INT] +
120 per_proc->cpu_hwIntCnt[MACH_INT] +
121 per_proc->cpu_hwIntCnt[MACHDEP_INT] +
122 per_proc->cpu_hwIntCnt[DIAG_INT];
123
124 rupts->hwTraces = per_proc->cpu_hwIntCnt[T_DEBUG]; // single steps == traces??
0c530ab8 125 rupts->hwFloatingPointAssists = 0;
2d21ac55
A
126 // osfmk/i386/mp.h
127 rupts->hwPerformanceMonitors =
128 per_proc->cpu_hwIntCnt[LAPIC_VECTOR(PERFCNT)];
0c530ab8 129 rupts->hwAltivecs = 0;
2d21ac55 130 rupts->hwInstBreakpoints = per_proc->cpu_hwIntCnt[T_INT3];
0c530ab8
A
131 rupts->hwSystemManagements = 0;
132 rupts->hwAltivecAssists = 0;
2d21ac55 133 rupts->hwThermal = per_proc->cpu_hwIntCnt[LAPIC_VECTOR(THERMAL)];
0c530ab8
A
134 rupts->hwSoftPatches = 0;
135 rupts->hwMaintenances = 0;
2d21ac55
A
136 // Watchpoint == instrumentation
137 rupts->hwInstrumentations = per_proc->cpu_hwIntCnt[T_WATCHPOINT];
0c530ab8
A
138
139 ml_set_interrupts_enabled(oldlevel);
140 return KERN_SUCCESS;
141 } else {
142 return KERN_FAILURE;
143 }
144}
145
146__private_extern__ kern_return_t
2d21ac55 147chudxnu_clear_cpu_interrupt_counters(int cpu)
0c530ab8
A
148{
149 if(cpu < 0 || (unsigned int)cpu >= real_ncpus) { // sanity check
150 return KERN_FAILURE;
151 }
2d21ac55
A
152 cpu_data_t *per_proc;
153
154 per_proc = cpu_data_ptr[cpu];
155
156 bzero((char *)per_proc->cpu_hwIntCnt, sizeof(uint32_t)*256);
0c530ab8 157
0c530ab8
A
158 return KERN_SUCCESS;
159}
2d21ac55
A
160
161#pragma mark *** deprecated ***
162
163//DEPRECATED
164__private_extern__ kern_return_t
165chudxnu_get_cpu_rupt_counters(int cpu, rupt_counters_t *rupts)
166{
167 return chudxnu_get_cpu_interrupt_counters(cpu, rupts);
168}
169
170//DEPRECATED
171__private_extern__ kern_return_t
172chudxnu_clear_cpu_rupt_counters(int cpu)
173{
174 return chudxnu_clear_cpu_interrupt_counters(cpu);
175}