2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 #include <mach/boolean.h>
34 #include <mach/mach_types.h>
36 #pragma mark **** version ****
37 extern uint32_t chudxnu_version(void);
39 #pragma mark **** task ****
40 // ********************************************************************************
42 // ********************************************************************************
43 extern int chudxnu_pid_for_task(task_t task
);
44 extern task_t
chudxnu_task_for_pid(int pid
);
45 extern int chudxnu_current_pid(void);
47 extern kern_return_t
chudxnu_task_read(task_t task
, void *kernaddr
, uint64_t usraddr
, vm_size_t size
);
48 extern kern_return_t
chudxnu_task_write(task_t task
, uint64_t useraddr
, void *kernaddr
, vm_size_t size
);
49 extern kern_return_t
chudxnu_kern_read(void *destaddr
, vm_offset_t srcaddr
, vm_size_t size
);
50 extern kern_return_t
chudxnu_kern_write(vm_offset_t destaddr
, void *srcaddr
, vm_size_t size
);
52 extern boolean_t
chudxnu_is_64bit_task(task_t task
);
54 #pragma mark **** thread ****
55 // ********************************************************************************
57 // ********************************************************************************
58 extern kern_return_t
chudxnu_bind_thread(thread_t thread
, int cpu
, int options
);
59 extern kern_return_t
chudxnu_unbind_thread(thread_t thread
, int options
);
61 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
);
62 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
);
63 extern kern_return_t
chudxnu_thread_user_state_available(thread_t thread
);
65 extern kern_return_t
chudxnu_thread_get_callstack64(thread_t thread
, uint64_t *callStack
, mach_msg_type_number_t
*count
, boolean_t user_only
);
67 extern task_t
chudxnu_current_task(void);
68 extern thread_t
chudxnu_current_thread(void);
70 extern task_t
chudxnu_task_for_thread(thread_t thread
);
72 extern kern_return_t
chudxnu_all_tasks(task_array_t
*task_list
, mach_msg_type_number_t
*count
);
73 extern kern_return_t
chudxnu_free_task_list(task_array_t
*task_list
, mach_msg_type_number_t
*count
);
75 extern kern_return_t
chudxnu_all_threads(thread_array_t
*thread_list
, mach_msg_type_number_t
*count
);
76 extern kern_return_t
chudxnu_task_threads(task_t task
, thread_array_t
*thread_list
, mach_msg_type_number_t
*count
);
77 extern kern_return_t
chudxnu_free_thread_list(thread_array_t
*thread_list
, mach_msg_type_number_t
*count
);
79 extern kern_return_t
chudxnu_thread_info( thread_t thread
, thread_flavor_t flavor
, thread_info_t thread_info_out
, mach_msg_type_number_t
*thread_info_count
);
81 extern kern_return_t
chudxnu_thread_last_context_switch(thread_t thread
, uint64_t *timestamp
);
83 extern boolean_t
chudxnu_thread_set_marked(thread_t thread
, boolean_t marked
);
84 extern boolean_t
chudxnu_thread_get_marked(thread_t thread
);
85 extern boolean_t
chudxnu_thread_get_idle(thread_t thread
);
87 #pragma mark **** memory ****
88 // ********************************************************************************
90 // ********************************************************************************
92 extern uint64_t chudxnu_avail_memory_size(void);
93 extern uint64_t chudxnu_phys_memory_size(void);
94 extern uint64_t chudxnu_free_memory_size(void);
95 extern uint64_t chudxnu_inactive_memory_size(void);
97 #pragma mark **** cpu ****
98 // ********************************************************************************
100 // ********************************************************************************
101 extern int chudxnu_logical_cpu_count(void);
102 extern int chudxnu_phys_cpu_count(void);
103 extern int chudxnu_cpu_number(void);
105 extern kern_return_t
chudxnu_enable_cpu(int cpu
, boolean_t enable
);
107 extern boolean_t
chudxnu_get_interrupts_enabled(void);
108 extern boolean_t
chudxnu_set_interrupts_enabled(boolean_t enable
);
109 extern boolean_t
chudxnu_at_interrupt_context(void);
110 extern void chudxnu_cause_interrupt(void);
112 extern void chudxnu_enable_preemption(void);
113 extern void chudxnu_disable_preemption(void);
114 extern int chudxnu_get_preemption_level(void);
116 extern kern_return_t
chudxnu_set_shadowed_spr(int cpu
, int spr
, uint32_t val
);
117 extern kern_return_t
chudxnu_set_shadowed_spr64(int cpu
, int spr
, uint64_t val
);
119 extern kern_return_t
chudxnu_perfmon_acquire_facility(task_t
);
120 extern kern_return_t
chudxnu_perfmon_release_facility(task_t
);
124 uint32_t hwMachineChecks
;
127 uint32_t hwExternals
;
128 uint32_t hwAlignments
;
130 uint32_t hwFloatPointUnavailable
;
131 uint32_t hwDecrementers
;
133 uint32_t hwSystemCalls
;
135 uint32_t hwFloatingPointAssists
;
136 uint32_t hwPerformanceMonitors
;
138 uint32_t hwInstBreakpoints
;
139 uint32_t hwSystemManagements
;
140 uint32_t hwAltivecAssists
;
142 uint32_t hwSoftPatches
;
143 uint32_t hwMaintenances
;
144 uint32_t hwInstrumentations
;
147 extern kern_return_t
chudxnu_get_cpu_interrupt_counters(int cpu
, rupt_counters_t
*rupts
);
148 extern kern_return_t
chudxnu_clear_cpu_interrupt_counters(int cpu
);
150 #pragma mark **** callbacks ****
151 // ********************************************************************************
153 // ********************************************************************************
155 extern void chudxnu_cancel_all_callbacks(void);
157 // cpu timer - each cpu has its own callback
158 typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t
)(thread_flavor_t flavor
, thread_state_t tstate
, mach_msg_type_number_t count
);
159 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
160 extern kern_return_t
chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu
161 extern kern_return_t
chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus
164 PPC_TRAP_PROGRAM
= 0x700,
165 PPC_TRAP_TRACE
= 0xD00,
166 PPC_TRAP_PERFMON
= 0xF00,
170 X86_TRAP_DEBUG
= 0x1,
173 // trap callback - one callback for system
174 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
);
175 extern kern_return_t
chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func
);
176 extern kern_return_t
chudxnu_trap_callback_cancel(void);
179 PPC_INTERRUPT_DECREMENTER
= 0x900,
180 PPC_INTERRUPT_INTERRUPT
= 0x500,
181 PPC_INTERRUPT_CPU_SIGNAL
= 0x2200,
185 X86_INTERRUPT_PERFMON
= 0xB,
188 // interrupt callback - one callback for system
189 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
);
190 extern kern_return_t
chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func
);
191 extern kern_return_t
chudxnu_interrupt_callback_cancel(void);
193 // ast callback - one callback for system
194 typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t
)(thread_flavor_t flavor
, thread_state_t tstate
, mach_msg_type_number_t count
);
195 extern kern_return_t
chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func
);
196 extern kern_return_t
chudxnu_perfmon_ast_callback_cancel(void);
197 extern kern_return_t
chudxnu_perfmon_ast_send_urgent(boolean_t urgent
);
199 // cpusig callback - one callback for system
200 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
);
201 extern kern_return_t
chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func
);
202 extern kern_return_t
chudxnu_cpusig_callback_cancel(void);
203 extern kern_return_t
chudxnu_cpusig_send(int otherCPU
, uint32_t request
);
205 // kdebug callback - one callback for system
206 typedef kern_return_t (*chudxnu_kdebug_callback_func_t
)(uint32_t debugid
, uint32_t arg0
, uint32_t arg1
, uint32_t arg2
, uint32_t arg3
, uint32_t arg4
);
207 extern kern_return_t
chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func
);
208 extern kern_return_t
chudxnu_kdebug_callback_cancel(void);
210 // timer callback - multiple callbacks
211 typedef kern_return_t (*chudxnu_timer_callback_func_t
)(uint32_t param0
, uint32_t param1
);
212 typedef void * chud_timer_t
;
213 extern chud_timer_t
chudxnu_timer_alloc(chudxnu_timer_callback_func_t func
, uint32_t param0
);
214 extern kern_return_t
chudxnu_timer_callback_enter(chud_timer_t timer
, uint32_t param1
, uint32_t time
, uint32_t units
);
215 extern kern_return_t
chudxnu_timer_callback_cancel(chud_timer_t timer
);
216 extern kern_return_t
chudxnu_timer_free(chud_timer_t timer
);
218 // CHUD systemcall callback - one callback for system
219 typedef kern_return_t (*chudxnu_syscall_callback_func_t
)(uint32_t code
, uint32_t arg0
, uint32_t arg1
, uint32_t arg2
, uint32_t arg3
, uint32_t arg4
);
220 extern kern_return_t
chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func
);
221 extern kern_return_t
chudxnu_syscall_callback_cancel(void);
224 typedef kern_return_t (*chudxnu_dtrace_callback_t
)(uint64_t selector
, uint64_t *args
, uint32_t count
);
225 extern kern_return_t
chudxnu_dtrace_callback(uint64_t selector
, uint64_t *args
, uint32_t count
);
226 extern void chudxnu_dtrace_callback_enter(chudxnu_dtrace_callback_t fn
);
227 extern void chudxnu_dtrace_callback_cancel(void);
229 // ********************************************************************************
231 // ********************************************************************************
232 extern kern_return_t
chudxnu_perfmon_ast_send(void);
233 extern kern_return_t
chudxnu_thread_get_callstack(thread_t thread
, uint32_t *callStack
, mach_msg_type_number_t
*count
, boolean_t user_only
);
235 extern vm_offset_t
chudxnu_io_map(uint64_t phys_addr
, vm_size_t size
);
236 extern uint32_t chudxnu_phys_addr_wimg(uint64_t phys_addr
);
238 extern int chudxnu_avail_cpu_count(void);
240 extern kern_return_t
chudxnu_enable_cpu_nap(int cpu
, boolean_t enable
);
241 extern boolean_t
chudxnu_cpu_nap_enabled(int cpu
);
243 extern uint32_t chudxnu_get_orig_cpu_l2cr(int cpu
);
244 extern uint32_t chudxnu_get_orig_cpu_l3cr(int cpu
);
246 extern kern_return_t
chudxnu_read_spr(int cpu
, int spr
, uint32_t *val_p
);
247 extern kern_return_t
chudxnu_read_spr64(int cpu
, int spr
, uint64_t *val_p
);
248 extern kern_return_t
chudxnu_write_spr(int cpu
, int spr
, uint32_t val
);
249 extern kern_return_t
chudxnu_write_spr64(int cpu
, int spr
, uint64_t val
);
251 extern kern_return_t
chudxnu_get_cpu_rupt_counters(int cpu
, rupt_counters_t
*rupts
);
252 extern kern_return_t
chudxnu_clear_cpu_rupt_counters(int cpu
);
254 extern kern_return_t
chudxnu_passup_alignment_exceptions(boolean_t enable
);
256 extern kern_return_t
chudxnu_scom_read(uint32_t reg
, uint64_t *data
);
257 extern kern_return_t
chudxnu_scom_write(uint32_t reg
, uint64_t data
);
259 extern void chudxnu_flush_caches(void);
260 extern void chudxnu_enable_caches(boolean_t enable
);
262 #endif /* _CHUD_XNU_H_ */