2 * Copyright (c) 2003 Apple Computer, 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@
29 #ifndef _PPC_CHUD_XNU_H_
30 #define _PPC_CHUD_XNU_H_
34 #include <mach/boolean.h>
35 #include <mach/mach_types.h>
37 #pragma mark **** version ****
38 uint32_t chudxnu_version(void);
40 #pragma mark **** task ****
41 // ********************************************************************************
43 // ********************************************************************************
44 int chudxnu_pid_for_task(task_t task
);
45 task_t
chudxnu_task_for_pid(int pid
);
46 int chudxnu_current_pid(void);
48 kern_return_t
chudxnu_task_read(task_t task
, void *kernaddr
, uint64_t usraddr
, vm_size_t size
);
49 kern_return_t
chudxnu_task_write(task_t task
, uint64_t useraddr
, void *kernaddr
, vm_size_t size
);
50 kern_return_t
chudxnu_kern_read(void *destaddr
, vm_offset_t srcaddr
, vm_size_t size
);
51 kern_return_t
chudxnu_kern_write(vm_offset_t destaddr
, void *srcaddr
, vm_size_t size
);
53 boolean_t
chudxnu_is_64bit_task(task_t task
);
55 #pragma mark **** thread ****
56 // ********************************************************************************
58 // ********************************************************************************
59 kern_return_t
chudxnu_bind_thread(thread_t thread
, int cpu
);
61 kern_return_t
chudxnu_unbind_thread(thread_t thread
);
63 kern_return_t
chudxnu_thread_get_state( thread_t thread
,
64 thread_flavor_t flavor
,
65 thread_state_t tstate
,
66 mach_msg_type_number_t
*count
,
69 kern_return_t
chudxnu_thread_set_state( thread_t thread
,
70 thread_flavor_t flavor
,
71 thread_state_t tstate
,
72 mach_msg_type_number_t count
,
75 kern_return_t
chudxnu_thread_user_state_available(thread_t thread
);
78 kern_return_t
chudxnu_thread_get_callstack( thread_t thread
,
80 mach_msg_type_number_t
*count
,
83 kern_return_t
chudxnu_thread_get_callstack64(thread_t thread
,
85 mach_msg_type_number_t
*count
,
88 task_t
chudxnu_current_task(void);
89 thread_t
chudxnu_current_thread(void);
91 task_t
chudxnu_task_for_thread(thread_t thread
);
93 kern_return_t
chudxnu_all_tasks(task_array_t
*task_list
,
94 mach_msg_type_number_t
*count
);
95 kern_return_t
chudxnu_free_task_list(task_array_t
*task_list
,
96 mach_msg_type_number_t
*count
);
98 kern_return_t
chudxnu_all_threads( thread_array_t
*thread_list
,
99 mach_msg_type_number_t
*count
);
100 kern_return_t
chudxnu_task_threads( task_t task
,
101 thread_array_t
*thread_list
,
102 mach_msg_type_number_t
*count
);
103 kern_return_t
chudxnu_free_thread_list(thread_array_t
*thread_list
,
104 mach_msg_type_number_t
*count
);
106 kern_return_t
chudxnu_thread_info( thread_t thread
,
107 thread_flavor_t flavor
,
108 thread_info_t thread_info_out
,
109 mach_msg_type_number_t
*thread_info_count
);
111 kern_return_t
chudxnu_thread_last_context_switch(thread_t thread
, uint64_t *timestamp
);
114 #pragma mark **** memory ****
115 // ********************************************************************************
117 // ********************************************************************************
119 uint64_t chudxnu_avail_memory_size(void);
120 uint64_t chudxnu_phys_memory_size(void);
122 vm_offset_t
chudxnu_io_map(uint64_t phys_addr
, vm_size_t size
);
124 uint32_t chudxnu_phys_addr_wimg(uint64_t phys_addr
);
126 #pragma mark **** cpu ****
127 // ********************************************************************************
129 // ********************************************************************************
130 int chudxnu_avail_cpu_count(void);
131 int chudxnu_phys_cpu_count(void);
132 int chudxnu_cpu_number(void);
134 kern_return_t
chudxnu_enable_cpu(int cpu
, boolean_t enable
);
136 kern_return_t
chudxnu_enable_cpu_nap(int cpu
, boolean_t enable
);
137 boolean_t
chudxnu_cpu_nap_enabled(int cpu
);
139 boolean_t
chudxnu_get_interrupts_enabled(void);
140 boolean_t
chudxnu_set_interrupts_enabled(boolean_t enable
);
141 boolean_t
chudxnu_at_interrupt_context(void);
142 void chudxnu_cause_interrupt(void);
144 kern_return_t
chudxnu_set_shadowed_spr(int cpu
, int spr
, uint32_t val
);
145 kern_return_t
chudxnu_set_shadowed_spr64(int cpu
, int spr
, uint64_t val
);
147 uint32_t chudxnu_get_orig_cpu_l2cr(int cpu
);
148 uint32_t chudxnu_get_orig_cpu_l3cr(int cpu
);
150 kern_return_t
chudxnu_read_spr(int cpu
, int spr
, uint32_t *val_p
);
151 kern_return_t
chudxnu_read_spr64(int cpu
, int spr
, uint64_t *val_p
);
152 kern_return_t
chudxnu_write_spr(int cpu
, int spr
, uint32_t val
);
153 kern_return_t
chudxnu_write_spr64(int cpu
, int spr
, uint64_t val
);
155 void chudxnu_flush_caches(void);
156 void chudxnu_enable_caches(boolean_t enable
);
158 kern_return_t
chudxnu_perfmon_acquire_facility(task_t
);
159 kern_return_t
chudxnu_perfmon_release_facility(task_t
);
161 uint32_t * chudxnu_get_branch_trace_buffer(uint32_t *entries
);
165 uint32_t hwMachineChecks
;
168 uint32_t hwExternals
;
169 uint32_t hwAlignments
;
171 uint32_t hwFloatPointUnavailable
;
172 uint32_t hwDecrementers
;
174 uint32_t hwSystemCalls
;
176 uint32_t hwFloatingPointAssists
;
177 uint32_t hwPerformanceMonitors
;
179 uint32_t hwInstBreakpoints
;
180 uint32_t hwSystemManagements
;
181 uint32_t hwAltivecAssists
;
183 uint32_t hwSoftPatches
;
184 uint32_t hwMaintenances
;
185 uint32_t hwInstrumentations
;
188 kern_return_t
chudxnu_get_cpu_rupt_counters(int cpu
, rupt_counters_t
*rupts
);
189 kern_return_t
chudxnu_clear_cpu_rupt_counters(int cpu
);
191 kern_return_t
chudxnu_passup_alignment_exceptions(boolean_t enable
);
193 kern_return_t
chudxnu_scom_read(uint32_t reg
, uint64_t *data
);
194 kern_return_t
chudxnu_scom_write(uint32_t reg
, uint64_t data
);
196 #pragma mark **** callbacks ****
197 // ********************************************************************************
199 // ********************************************************************************
201 void chudxnu_cancel_all_callbacks(void);
203 // cpu timer - each cpu has its own callback
204 typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t
)(thread_flavor_t flavor
, thread_state_t tstate
, mach_msg_type_number_t count
);
205 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
206 kern_return_t
chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu
207 kern_return_t
chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus
209 // trap callback - one callback for system
210 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
);
211 kern_return_t
chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func
);
212 kern_return_t
chudxnu_trap_callback_cancel(void);
214 // interrupt callback - one callback for system
215 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
);
216 kern_return_t
chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func
);
217 kern_return_t
chudxnu_interrupt_callback_cancel(void);
219 // ast callback - one callback for system
220 typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t
)(thread_flavor_t flavor
, thread_state_t tstate
, mach_msg_type_number_t count
);
221 kern_return_t
chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func
);
222 kern_return_t
chudxnu_perfmon_ast_callback_cancel(void);
223 kern_return_t
chudxnu_perfmon_ast_send(void);
224 kern_return_t
chudxnu_perfmon_ast_send_urgent(boolean_t urgent
);
226 // cpusig callback - one callback for system
227 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
);
228 kern_return_t
chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func
);
229 kern_return_t
chudxnu_cpusig_callback_cancel(void);
230 kern_return_t
chudxnu_cpusig_send(int otherCPU
, uint32_t request
);
232 // kdebug callback - one callback for system
233 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
);
234 kern_return_t
chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func
);
235 kern_return_t
chudxnu_kdebug_callback_cancel(void);
237 // timer callback - multiple callbacks
238 typedef kern_return_t (*chudxnu_timer_callback_func_t
)(uint32_t param0
, uint32_t param1
);
239 typedef void * chud_timer_t
;
240 chud_timer_t
chudxnu_timer_alloc(chudxnu_timer_callback_func_t func
, uint32_t param0
);
241 kern_return_t
chudxnu_timer_callback_enter(chud_timer_t timer
, uint32_t param1
, uint32_t time
, uint32_t units
);
242 kern_return_t
chudxnu_timer_callback_cancel(chud_timer_t timer
);
243 kern_return_t
chudxnu_timer_free(chud_timer_t timer
);
245 // CHUD systemcall callback - one callback for system
246 typedef kern_return_t (*chudxnu_syscall_callback_func_t
)(thread_flavor_t flavor
, thread_state_t tstate
, mach_msg_type_number_t count
);
247 kern_return_t
chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func
);
248 kern_return_t
chudxnu_syscall_callback_cancel(void);
250 // ********************************************************************************
252 // ********************************************************************************
253 kern_return_t
chudxnu_bind_current_thread(int cpu
);
255 kern_return_t
chudxnu_unbind_current_thread(void);
257 kern_return_t
chudxnu_current_thread_get_callstack(uint32_t *callStack
,
258 mach_msg_type_number_t
*count
,
259 boolean_t user_only
);
261 thread_t
chudxnu_current_act(void);
263 // thread timer callback - one callback for system
264 typedef kern_return_t (*chudxnu_thread_timer_callback_func_t
)(uint32_t param
);
265 kern_return_t
chudxnu_thread_timer_callback_enter(chudxnu_thread_timer_callback_func_t func
, uint32_t param
, uint32_t time
, uint32_t units
);
266 kern_return_t
chudxnu_thread_timer_callback_cancel(void);
268 #endif /* _PPC_CHUD_XNU_H_ */