]>
Commit | Line | Data |
---|---|---|
0c530ab8 | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2003-2008 Apple Inc. All rights reserved. |
0c530ab8 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0c530ab8 | 5 | * |
2d21ac55 A |
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. | |
0c530ab8 | 14 | * |
2d21ac55 A |
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. | |
0c530ab8 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
0c530ab8 A |
27 | */ |
28 | ||
29 | #ifndef _CHUD_XNU_H_ | |
30 | #define _CHUD_XNU_H_ | |
31 | ||
0c530ab8 A |
32 | #include <stdint.h> |
33 | #include <mach/boolean.h> | |
34 | #include <mach/mach_types.h> | |
b0d623f7 | 35 | #include <kern/thread_call.h> |
0c530ab8 | 36 | |
39236c6e A |
37 | /* Unslide the provided pointer if it's a kernel address. */ |
38 | static inline uint64_t | |
39 | chudxnu_vm_unslide( uint64_t ptr, int kaddr ) | |
40 | { | |
41 | if( !kaddr ) | |
42 | return ptr; | |
43 | ||
44 | return VM_KERNEL_UNSLIDE(ptr); | |
45 | } | |
46 | ||
b0d623f7 | 47 | #if 0 |
0c530ab8 | 48 | #pragma mark **** version **** |
b0d623f7 | 49 | #endif |
0c530ab8 A |
50 | extern uint32_t chudxnu_version(void); |
51 | ||
b0d623f7 | 52 | #if 0 |
0c530ab8 | 53 | #pragma mark **** task **** |
b0d623f7 | 54 | #endif |
0c530ab8 A |
55 | // ******************************************************************************** |
56 | // task | |
57 | // ******************************************************************************** | |
0c530ab8 A |
58 | extern kern_return_t chudxnu_task_read(task_t task, void *kernaddr, uint64_t usraddr, vm_size_t size); |
59 | extern kern_return_t chudxnu_task_write(task_t task, uint64_t useraddr, void *kernaddr, vm_size_t size); | |
60 | extern kern_return_t chudxnu_kern_read(void *destaddr, vm_offset_t srcaddr, vm_size_t size); | |
61 | extern kern_return_t chudxnu_kern_write(vm_offset_t destaddr, void *srcaddr, vm_size_t size); | |
62 | ||
63 | extern boolean_t chudxnu_is_64bit_task(task_t task); | |
64 | ||
b0d623f7 | 65 | #if 0 |
0c530ab8 | 66 | #pragma mark **** thread **** |
b0d623f7 | 67 | #endif |
0c530ab8 A |
68 | // ******************************************************************************** |
69 | // thread | |
70 | // ******************************************************************************** | |
2d21ac55 A |
71 | extern kern_return_t chudxnu_bind_thread(thread_t thread, int cpu, int options); |
72 | extern kern_return_t chudxnu_unbind_thread(thread_t thread, int options); | |
0c530ab8 A |
73 | |
74 | extern kern_return_t chudxnu_thread_get_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t *count, boolean_t user_only); | |
75 | extern kern_return_t chudxnu_thread_set_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count, boolean_t user_only); | |
0c530ab8 | 76 | |
0c530ab8 | 77 | extern kern_return_t chudxnu_thread_get_callstack64(thread_t thread, uint64_t *callStack, mach_msg_type_number_t *count, boolean_t user_only); |
39236c6e | 78 | extern kern_return_t chudxnu_thread_get_callstack64_kperf(thread_t thread, uint64_t *callStack, mach_msg_type_number_t *count, boolean_t user_only); |
0c530ab8 | 79 | |
b0d623f7 | 80 | #if 0 |
0c530ab8 | 81 | #pragma mark **** memory **** |
b0d623f7 | 82 | #endif |
0c530ab8 A |
83 | // ******************************************************************************** |
84 | // memory | |
85 | // ******************************************************************************** | |
86 | ||
87 | extern uint64_t chudxnu_avail_memory_size(void); | |
88 | extern uint64_t chudxnu_phys_memory_size(void); | |
89 | extern uint64_t chudxnu_free_memory_size(void); | |
2d21ac55 | 90 | extern uint64_t chudxnu_inactive_memory_size(void); |
0c530ab8 | 91 | |
b0d623f7 | 92 | #if 0 |
0c530ab8 | 93 | #pragma mark **** cpu **** |
b0d623f7 | 94 | #endif |
0c530ab8 A |
95 | // ******************************************************************************** |
96 | // cpu | |
97 | // ******************************************************************************** | |
2d21ac55 | 98 | extern int chudxnu_logical_cpu_count(void); |
0c530ab8 A |
99 | extern int chudxnu_phys_cpu_count(void); |
100 | extern int chudxnu_cpu_number(void); | |
101 | ||
102 | extern kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable); | |
103 | ||
0c530ab8 | 104 | extern boolean_t chudxnu_set_interrupts_enabled(boolean_t enable); |
0c530ab8 A |
105 | extern void chudxnu_cause_interrupt(void); |
106 | ||
107 | extern void chudxnu_enable_preemption(void); | |
108 | extern void chudxnu_disable_preemption(void); | |
109 | extern int chudxnu_get_preemption_level(void); | |
110 | ||
0c530ab8 A |
111 | extern kern_return_t chudxnu_perfmon_acquire_facility(task_t); |
112 | extern kern_return_t chudxnu_perfmon_release_facility(task_t); | |
113 | ||
0c530ab8 A |
114 | typedef struct { |
115 | uint32_t hwResets; | |
116 | uint32_t hwMachineChecks; | |
117 | uint32_t hwDSIs; | |
118 | uint32_t hwISIs; | |
119 | uint32_t hwExternals; | |
120 | uint32_t hwAlignments; | |
121 | uint32_t hwPrograms; | |
122 | uint32_t hwFloatPointUnavailable; | |
123 | uint32_t hwDecrementers; | |
124 | uint32_t hwIOErrors; | |
125 | uint32_t hwSystemCalls; | |
126 | uint32_t hwTraces; | |
127 | uint32_t hwFloatingPointAssists; | |
128 | uint32_t hwPerformanceMonitors; | |
129 | uint32_t hwAltivecs; | |
130 | uint32_t hwInstBreakpoints; | |
131 | uint32_t hwSystemManagements; | |
132 | uint32_t hwAltivecAssists; | |
133 | uint32_t hwThermal; | |
134 | uint32_t hwSoftPatches; | |
135 | uint32_t hwMaintenances; | |
136 | uint32_t hwInstrumentations; | |
b0d623f7 | 137 | } interrupt_counters_t; |
0c530ab8 | 138 | |
b0d623f7 | 139 | extern kern_return_t chudxnu_get_cpu_interrupt_counters(int cpu, interrupt_counters_t *rupts); |
2d21ac55 | 140 | extern kern_return_t chudxnu_clear_cpu_interrupt_counters(int cpu); |
0c530ab8 | 141 | |
b0d623f7 | 142 | #if 0 |
0c530ab8 | 143 | #pragma mark **** callbacks **** |
b0d623f7 | 144 | #endif |
0c530ab8 A |
145 | // ******************************************************************************** |
146 | // callbacks | |
147 | // ******************************************************************************** | |
148 | ||
149 | extern void chudxnu_cancel_all_callbacks(void); | |
150 | ||
151 | // cpu timer - each cpu has its own callback | |
152 | typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
153 | extern kern_return_t chudxnu_cpu_timer_callback_enter(chudxnu_cpu_timer_callback_func_t func, uint32_t time, uint32_t units); // callback is entered on current cpu | |
154 | extern kern_return_t chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu | |
155 | extern kern_return_t chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus | |
156 | ||
157 | enum { | |
158 | PPC_TRAP_PROGRAM = 0x700, | |
159 | PPC_TRAP_TRACE = 0xD00, | |
160 | PPC_TRAP_PERFMON = 0xF00, | |
161 | }; | |
162 | ||
163 | enum { | |
164 | X86_TRAP_DEBUG = 0x1, | |
165 | }; | |
166 | ||
167 | // trap callback - one callback for system | |
168 | typedef kern_return_t (*chudxnu_trap_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
169 | extern kern_return_t chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func); | |
170 | extern kern_return_t chudxnu_trap_callback_cancel(void); | |
171 | ||
172 | enum { | |
173 | PPC_INTERRUPT_DECREMENTER = 0x900, | |
174 | PPC_INTERRUPT_INTERRUPT = 0x500, | |
175 | PPC_INTERRUPT_CPU_SIGNAL = 0x2200, | |
176 | }; | |
177 | ||
178 | enum { | |
179 | X86_INTERRUPT_PERFMON = 0xB, | |
180 | }; | |
181 | ||
182 | // interrupt callback - one callback for system | |
183 | typedef kern_return_t (*chudxnu_interrupt_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
184 | extern kern_return_t chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func); | |
185 | extern kern_return_t chudxnu_interrupt_callback_cancel(void); | |
186 | ||
187 | // ast callback - one callback for system | |
188 | typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
189 | extern kern_return_t chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func); | |
190 | extern kern_return_t chudxnu_perfmon_ast_callback_cancel(void); | |
0c530ab8 A |
191 | extern kern_return_t chudxnu_perfmon_ast_send_urgent(boolean_t urgent); |
192 | ||
193 | // cpusig callback - one callback for system | |
194 | typedef kern_return_t (*chudxnu_cpusig_callback_func_t)(int request, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
195 | extern kern_return_t chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func); | |
196 | extern kern_return_t chudxnu_cpusig_callback_cancel(void); | |
197 | extern kern_return_t chudxnu_cpusig_send(int otherCPU, uint32_t request); | |
198 | ||
199 | // kdebug callback - one callback for system | |
b0d623f7 | 200 | typedef kern_return_t (*chudxnu_kdebug_callback_func_t)(uint32_t debugid, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4); |
0c530ab8 A |
201 | extern kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func); |
202 | extern kern_return_t chudxnu_kdebug_callback_cancel(void); | |
203 | ||
204 | // timer callback - multiple callbacks | |
b0d623f7 | 205 | typedef kern_return_t (*chudxnu_timer_callback_func_t)(thread_call_param_t param0, thread_call_param_t param1); |
0c530ab8 | 206 | typedef void * chud_timer_t; |
b0d623f7 A |
207 | extern chud_timer_t chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, thread_call_param_t param0); |
208 | extern kern_return_t chudxnu_timer_callback_enter(chud_timer_t timer, thread_call_param_t param1, uint32_t time, uint32_t units); | |
0c530ab8 A |
209 | extern kern_return_t chudxnu_timer_callback_cancel(chud_timer_t timer); |
210 | extern kern_return_t chudxnu_timer_free(chud_timer_t timer); | |
211 | ||
212 | // CHUD systemcall callback - one callback for system | |
b0d623f7 | 213 | typedef kern_return_t (*chudxnu_syscall_callback_func_t)(uint64_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5); |
0c530ab8 A |
214 | extern kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func); |
215 | extern kern_return_t chudxnu_syscall_callback_cancel(void); | |
216 | ||
217 | // ******************************************************************************** | |
218 | // DEPRECATED | |
219 | // ******************************************************************************** | |
2d21ac55 | 220 | extern kern_return_t chudxnu_thread_get_callstack(thread_t thread, uint32_t *callStack, mach_msg_type_number_t *count, boolean_t user_only); |
0c530ab8 | 221 | |
b0d623f7 A |
222 | extern kern_return_t chudxnu_set_shadowed_spr(int cpu, int spr, uint32_t val); |
223 | extern kern_return_t chudxnu_set_shadowed_spr64(int cpu, int spr, uint64_t val); | |
0c530ab8 | 224 | |
2d21ac55 A |
225 | extern kern_return_t chudxnu_enable_cpu_nap(int cpu, boolean_t enable); |
226 | extern boolean_t chudxnu_cpu_nap_enabled(int cpu); | |
227 | ||
2d21ac55 A |
228 | extern kern_return_t chudxnu_read_spr(int cpu, int spr, uint32_t *val_p); |
229 | extern kern_return_t chudxnu_read_spr64(int cpu, int spr, uint64_t *val_p); | |
230 | extern kern_return_t chudxnu_write_spr(int cpu, int spr, uint32_t val); | |
231 | extern kern_return_t chudxnu_write_spr64(int cpu, int spr, uint64_t val); | |
232 | ||
0c530ab8 | 233 | #endif /* _CHUD_XNU_H_ */ |