]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm/genassym.c
xnu-4570.71.2.tar.gz
[apple/xnu.git] / osfmk / arm / genassym.c
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56
57 #include <stddef.h>
58
59 #include <mach_ldebug.h>
60
61 /*
62 * Pass field offsets to assembly code.
63 */
64 #include <kern/ast.h>
65 #include <kern/thread.h>
66 #include <kern/task.h>
67 #include <kern/locks.h>
68 #include <ipc/ipc_space.h>
69 #include <ipc/ipc_port.h>
70 #include <ipc/ipc_pset.h>
71 #include <kern/host.h>
72 #include <kern/misc_protos.h>
73 #include <kern/syscall_sw.h>
74 #include <arm/thread.h>
75 #include <mach/arm/vm_param.h>
76 #include <arm/pmap.h>
77 #include <arm/trap.h>
78 #include <arm/cpu_data_internal.h>
79 #include <arm/cpu_capabilities.h>
80 #include <arm/cpu_internal.h>
81 #include <arm/rtclock.h>
82 #include <machine/commpage.h>
83 #include <vm/vm_map.h>
84 #include <pexpert/arm/boot.h>
85 #include <arm/proc_reg.h>
86 #include <prng/random.h>
87
88 #if CONFIG_DTRACE
89 #define NEED_DTRACE_DEFS
90 #include <../bsd/sys/lockstat.h>
91 #endif /* CONFIG_DTRACE */
92
93 /*
94 * genassym.c is used to produce an
95 * assembly file which, intermingled with unuseful assembly code,
96 * has all the necessary definitions emitted. This assembly file is
97 * then postprocessed with sed to extract only these definitions
98 * and thus the final assyms.s is created.
99 *
100 * This convoluted means is necessary since the structure alignment
101 * and packing may be different between the host machine and the
102 * target so we are forced into using the cross compiler to generate
103 * the values, but we cannot run anything on the target machine.
104 */
105
106 #define DECLARE(SYM,VAL) \
107 __asm("DEFINITION__define__" SYM ":\t .ascii \"%0\"" : : "n" ((u_int)(VAL)))
108
109
110 int main(
111 int argc,
112 char ** argv);
113
114 int
115 main(
116 int argc,
117 char **argv)
118 {
119
120 DECLARE("T_PREFETCH_ABT", T_PREFETCH_ABT);
121 DECLARE("T_DATA_ABT", T_DATA_ABT);
122
123 DECLARE("AST_URGENT", AST_URGENT);
124 DECLARE("AST_PREEMPTION", AST_PREEMPTION);
125
126 DECLARE("TH_RECOVER", offsetof(struct thread, recover));
127 DECLARE("TH_CONTINUATION", offsetof(struct thread, continuation));
128 DECLARE("TH_KERNEL_STACK", offsetof(struct thread, kernel_stack));
129 DECLARE("TH_KSTACKPTR", offsetof(struct thread, machine.kstackptr));
130 DECLARE("TH_UTHREAD", offsetof(struct thread, uthread));
131
132 DECLARE("TASK_MACH_EXC_PORT",
133 offsetof(struct task, exc_actions[EXC_MACH_SYSCALL].port));
134
135 /* These fields are being added on demand */
136 DECLARE("ACT_TASK", offsetof(struct thread, task));
137 DECLARE("ACT_PCBDATA", offsetof(struct thread, machine.PcbData));
138 #if __ARM_VFP__
139 DECLARE("ACT_UVFP", offsetof(struct thread, machine.uVFPdata));
140 DECLARE("ACT_KVFP", offsetof(struct thread, machine.kVFPdata));
141 #endif
142 DECLARE("TH_CTH_SELF", offsetof(struct thread, machine.cthread_self));
143 DECLARE("TH_CTH_DATA", offsetof(struct thread, machine.cthread_data));
144 DECLARE("ACT_PCBDATA_PC", offsetof(struct thread, machine.PcbData.pc));
145 DECLARE("ACT_PCBDATA_R0", offsetof(struct thread, machine.PcbData.r[0]));
146 DECLARE("ACT_PREEMPT_CNT", offsetof(struct thread, machine.preemption_count));
147 DECLARE("ACT_CPUDATAP", offsetof(struct thread, machine.CpuDatap));
148 DECLARE("ACT_MAP", offsetof(struct thread, map));
149 #if __ARM_USER_PROTECT__
150 DECLARE("ACT_UPTW_TTC", offsetof(struct thread, machine.uptw_ttc));
151 DECLARE("ACT_UPTW_TTB", offsetof(struct thread, machine.uptw_ttb));
152 DECLARE("ACT_KPTW_TTB", offsetof(struct thread, machine.kptw_ttb));
153 DECLARE("ACT_ASID", offsetof(struct thread, machine.asid));
154 #endif
155 DECLARE("ACT_DEBUGDATA", offsetof(struct thread, machine.DebugData));
156 DECLARE("TH_IOTIER_OVERRIDE", offsetof(struct thread, iotier_override));
157 DECLARE("TH_RWLOCK_CNT", offsetof(struct thread, rwlock_count));
158 DECLARE("TH_SCHED_FLAGS", offsetof(struct thread, sched_flags));
159 DECLARE("TH_SFLAG_RW_PROMOTED", TH_SFLAG_RW_PROMOTED);
160
161 DECLARE("TH_MACH_SYSCALLS", offsetof(struct thread, syscalls_mach));
162 DECLARE("TH_UNIX_SYSCALLS", offsetof(struct thread, syscalls_unix));
163 DECLARE("TASK_BSD_INFO", offsetof(struct task, bsd_info));
164
165 DECLARE("MACH_TRAP_TABLE_COUNT", MACH_TRAP_TABLE_COUNT);
166 DECLARE("MACH_TRAP_TABLE_ENTRY_SIZE", sizeof(mach_trap_t));
167
168 DECLARE("MAP_PMAP", offsetof(struct _vm_map, pmap));
169
170 DECLARE("SS_SIZE", sizeof(struct arm_saved_state));
171 DECLARE("SS_LR", offsetof(struct arm_saved_state, lr));
172 DECLARE("SS_CPSR", offsetof(struct arm_saved_state, cpsr));
173 DECLARE("SS_PC", offsetof(struct arm_saved_state, pc));
174 DECLARE("SS_R0", offsetof(struct arm_saved_state, r[0]));
175 DECLARE("SS_R4", offsetof(struct arm_saved_state, r[4]));
176 DECLARE("SS_R9", offsetof(struct arm_saved_state, r[9]));
177 DECLARE("SS_R12", offsetof(struct arm_saved_state, r[12]));
178 DECLARE("SS_SP", offsetof(struct arm_saved_state, sp));
179 DECLARE("SS_STATUS", offsetof(struct arm_saved_state, fsr));
180 DECLARE("SS_VADDR", offsetof(struct arm_saved_state, far));
181 DECLARE("SS_EXC", offsetof(struct arm_saved_state, exception));
182
183 #if __ARM_VFP__
184 DECLARE("VSS_SIZE", sizeof(struct arm_vfpsaved_state));
185 DECLARE("VSS_FPSCR", offsetof(struct arm_vfpsaved_state, fpscr));
186 DECLARE("VSS_FPEXC", offsetof(struct arm_vfpsaved_state, fpexc));
187
188 DECLARE("EXC_CTX_SIZE", sizeof(struct arm_saved_state) +
189 sizeof(struct arm_vfpsaved_state) +
190 VFPSAVE_ALIGN);
191 DECLARE("VSS_ALIGN", VFPSAVE_ALIGN);
192 #else
193 DECLARE("EXC_CTX_SIZE", sizeof(struct arm_saved_state));
194 #endif
195
196
197 DECLARE("PGBYTES", ARM_PGBYTES);
198 DECLARE("PGSHIFT", ARM_PGSHIFT);
199 DECLARE("PGMASK", ARM_PGMASK);
200
201 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS);
202 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS);
203 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS);
204 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE);
205
206 DECLARE("KERN_INVALID_ADDRESS", KERN_INVALID_ADDRESS);
207
208 DECLARE("MAX_CPUS", MAX_CPUS);
209
210 DECLARE("cdeSize",
211 sizeof(struct cpu_data_entry));
212
213 DECLARE("cdSize",
214 sizeof(struct cpu_data));
215
216 DECLARE("CPU_ACTIVE_THREAD",
217 offsetof(cpu_data_t, cpu_active_thread));
218 DECLARE("CPU_ACTIVE_STACK",
219 offsetof(cpu_data_t, cpu_active_stack));
220 DECLARE("CPU_ISTACKPTR",
221 offsetof(cpu_data_t, istackptr));
222 DECLARE("CPU_INTSTACK_TOP",
223 offsetof(cpu_data_t, intstack_top));
224 DECLARE("CPU_FIQSTACKPTR",
225 offsetof(cpu_data_t, fiqstackptr));
226 DECLARE("CPU_FIQSTACK_TOP",
227 offsetof(cpu_data_t, fiqstack_top));
228 DECLARE("CPU_NUMBER_GS",
229 offsetof(cpu_data_t,cpu_number));
230 DECLARE("CPU_IDENT",
231 offsetof(cpu_data_t,cpu_ident));
232 DECLARE("CPU_RUNNING",
233 offsetof(cpu_data_t,cpu_running));
234 DECLARE("CPU_MCOUNT_OFF",
235 offsetof(cpu_data_t,cpu_mcount_off));
236 DECLARE("CPU_PENDING_AST",
237 offsetof(cpu_data_t,cpu_pending_ast));
238 DECLARE("CPU_PROCESSOR",
239 offsetof(cpu_data_t,cpu_processor));
240 DECLARE("CPU_CACHE_DISPATCH",
241 offsetof(cpu_data_t,cpu_cache_dispatch));
242 DECLARE("CPU_BASE_TIMEBASE_LOW",
243 offsetof(cpu_data_t,cpu_base_timebase_low));
244 DECLARE("CPU_BASE_TIMEBASE_HIGH",
245 offsetof(cpu_data_t,cpu_base_timebase_high));
246 DECLARE("CPU_TIMEBASE_LOW",
247 offsetof(cpu_data_t,cpu_timebase_low));
248 DECLARE("CPU_TIMEBASE_HIGH",
249 offsetof(cpu_data_t,cpu_timebase_high));
250 DECLARE("CPU_DECREMENTER",
251 offsetof(cpu_data_t,cpu_decrementer));
252 DECLARE("CPU_GET_DECREMENTER_FUNC",
253 offsetof(cpu_data_t,cpu_get_decrementer_func));
254 DECLARE("CPU_SET_DECREMENTER_FUNC",
255 offsetof(cpu_data_t,cpu_set_decrementer_func));
256 DECLARE("CPU_GET_FIQ_HANDLER",
257 offsetof(cpu_data_t,cpu_get_fiq_handler));
258 DECLARE("CPU_TBD_HARDWARE_ADDR",
259 offsetof(cpu_data_t,cpu_tbd_hardware_addr));
260 DECLARE("CPU_TBD_HARDWARE_VAL",
261 offsetof(cpu_data_t,cpu_tbd_hardware_val));
262 DECLARE("CPU_INT_STATE",
263 offsetof(cpu_data_t,cpu_int_state));
264 DECLARE("INTERRUPT_HANDLER",
265 offsetof(cpu_data_t,interrupt_handler));
266 DECLARE("INTERRUPT_TARGET",
267 offsetof(cpu_data_t,interrupt_target));
268 DECLARE("INTERRUPT_REFCON",
269 offsetof(cpu_data_t,interrupt_refCon));
270 DECLARE("INTERRUPT_NUB",
271 offsetof(cpu_data_t,interrupt_nub));
272 DECLARE("INTERRUPT_SOURCE",
273 offsetof(cpu_data_t,interrupt_source));
274 DECLARE("CPU_USER_DEBUG",
275 offsetof(cpu_data_t, cpu_user_debug));
276 DECLARE("CPU_STAT_IRQ",
277 offsetof(cpu_data_t, cpu_stat.irq_ex_cnt));
278 DECLARE("CPU_STAT_IRQ_WAKE",
279 offsetof(cpu_data_t, cpu_stat.irq_ex_cnt_wake));
280 DECLARE("CPU_RESET_HANDLER",
281 offsetof(cpu_data_t, cpu_reset_handler));
282 DECLARE("CPU_RESET_ASSIST",
283 offsetof(cpu_data_t, cpu_reset_assist));
284 DECLARE("RTCLOCK_DATAP",
285 offsetof(cpu_data_t, rtclock_datap));
286 #ifdef __arm__
287 DECLARE("CPU_EXC_VECTORS",
288 offsetof(cpu_data_t, cpu_exc_vectors));
289 #endif
290
291 DECLARE("RTCLOCKDataSize",
292 sizeof(rtclock_data_t));
293 DECLARE("RTCLOCK_ADJ_ABSTIME_LOW",
294 offsetof(rtclock_data_t, rtc_adj.abstime_val.low));
295 DECLARE("RTCLOCK_ADJ_ABSTIME_HIGH",
296 offsetof(rtclock_data_t, rtc_adj.abstime_val.high));
297 DECLARE("RTCLOCK_BASE_ABSTIME_LOW",
298 offsetof(rtclock_data_t, rtc_base.abstime_val.low));
299 DECLARE("RTCLOCK_BASE_ABSTIME_HIGH",
300 offsetof(rtclock_data_t, rtc_base.abstime_val.high));
301 DECLARE("RTCLOCK_TB_FUNC",
302 offsetof(rtclock_data_t, rtc_timebase_func));
303 DECLARE("RTCLOCK_TB_ADDR",
304 offsetof(rtclock_data_t, rtc_timebase_addr));
305 DECLARE("RTCLOCK_TB_VAL",
306 offsetof(rtclock_data_t, rtc_timebase_val));
307
308 DECLARE("SIGPdec", SIGPdec);
309
310 DECLARE("rhdSize",
311 sizeof(struct reset_handler_data));
312
313 DECLARE("CPU_DATA_ENTRIES", offsetof(struct reset_handler_data, cpu_data_entries));
314 DECLARE("BOOT_ARGS", offsetof(struct reset_handler_data, boot_args));
315 DECLARE("ASSIST_RESET_HANDLER", offsetof(struct reset_handler_data, assist_reset_handler));
316
317 DECLARE("CPU_DATA_PADDR", offsetof(struct cpu_data_entry, cpu_data_paddr));
318
319
320 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE);
321
322 /* values from kern/timer.h */
323 DECLARE("TIMER_LOW",
324 offsetof(struct timer, low_bits));
325 DECLARE("TIMER_HIGH",
326 offsetof(struct timer, high_bits));
327 DECLARE("TIMER_HIGHCHK",
328 offsetof(struct timer, high_bits_check));
329 DECLARE("TIMER_TSTAMP",
330 offsetof(struct timer, tstamp));
331 DECLARE("THREAD_TIMER",
332 offsetof(struct processor, processor_data.thread_timer));
333 DECLARE("KERNEL_TIMER",
334 offsetof(struct processor, processor_data.kernel_timer));
335 DECLARE("SYSTEM_STATE",
336 offsetof(struct processor, processor_data.system_state));
337 DECLARE("USER_STATE",
338 offsetof(struct processor, processor_data.user_state));
339 DECLARE("CURRENT_STATE",
340 offsetof(struct processor, processor_data.current_state));
341
342 DECLARE("SYSTEM_TIMER",
343 offsetof(struct thread, system_timer));
344 DECLARE("USER_TIMER",
345 offsetof(struct thread, user_timer));
346
347 #if !CONFIG_SKIP_PRECISE_USER_KERNEL_TIME
348 DECLARE("PRECISE_USER_KERNEL_TIME",
349 offsetof(struct thread, precise_user_kernel_time));
350 #endif
351
352 DECLARE("BA_VIRT_BASE",
353 offsetof(struct boot_args, virtBase));
354 DECLARE("BA_PHYS_BASE",
355 offsetof(struct boot_args, physBase));
356 DECLARE("BA_MEM_SIZE",
357 offsetof(struct boot_args, memSize));
358 DECLARE("BA_TOP_OF_KERNEL_DATA",
359 offsetof(struct boot_args, topOfKernelData));
360
361 DECLARE("ENTROPY_INDEX_PTR",
362 offsetof(entropy_data_t, index_ptr));
363 DECLARE("ENTROPY_BUFFER",
364 offsetof(entropy_data_t, buffer));
365 DECLARE("ENTROPY_DATA_SIZE", sizeof(struct entropy_data));
366
367 return (0);
368 }