]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/genassym.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / osfmk / arm64 / 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/misc_protos.h>
77 #include <arm/pmap.h>
78 #include <arm/trap.h>
79 #include <arm/cpu_data_internal.h>
80 #include <arm/cpu_capabilities.h>
81 #include <arm/cpu_internal.h>
82 #include <arm/rtclock.h>
83 #include <machine/commpage.h>
84 #include <vm/vm_map.h>
85 #include <pexpert/arm64/boot.h>
86 #include <arm64/proc_reg.h>
87 #include <prng/random.h>
88 #if HIBERNATION
89 #include <IOKit/IOHibernatePrivate.h>
90 #include <machine/pal_hibernate.h>
91 #endif /* HIBERNATION */
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\"" : : "i" ((u_long)(VAL)))
108
109
110 int main(int argc,
111 char ** argv);
112
113 int
114 main(int argc,
115 char ** argv)
116 {
117 DECLARE("AST_URGENT", AST_URGENT);
118
119 DECLARE("TH_RECOVER", offsetof(struct thread, recover));
120 DECLARE("TH_KSTACKPTR", offsetof(struct thread, machine.kstackptr));
121 DECLARE("TH_THREAD_ID", offsetof(struct thread, thread_id));
122 #if defined(HAS_APPLE_PAC)
123 DECLARE("TH_ROP_PID", offsetof(struct thread, machine.rop_pid));
124 DECLARE("TH_JOP_PID", offsetof(struct thread, machine.jop_pid));
125 DECLARE("TH_DISABLE_USER_JOP", offsetof(struct thread, machine.disable_user_jop));
126 #endif /* defined(HAS_APPLE_PAC) */
127
128 /* These fields are being added on demand */
129 DECLARE("ACT_CONTEXT", offsetof(struct thread, machine.contextData));
130 DECLARE("TH_CTH_SELF", offsetof(struct thread, machine.cthread_self));
131 DECLARE("ACT_PREEMPT_CNT", offsetof(struct thread, machine.preemption_count));
132 DECLARE("ACT_CPUDATAP", offsetof(struct thread, machine.CpuDatap));
133 DECLARE("ACT_DEBUGDATA", offsetof(struct thread, machine.DebugData));
134 DECLARE("TH_IOTIER_OVERRIDE", offsetof(struct thread, iotier_override));
135 DECLARE("TH_RWLOCK_CNT", offsetof(struct thread, rwlock_count));
136 DECLARE("TH_TMP_ALLOC_CNT", offsetof(struct thread, t_temp_alloc_count));
137 DECLARE("TH_TASK", offsetof(struct thread, task));
138
139 #if defined(HAS_APPLE_PAC)
140 DECLARE("TASK_ROP_PID", offsetof(struct task, rop_pid));
141 DECLARE("TASK_JOP_PID", offsetof(struct task, jop_pid));
142 #endif /* defined(HAS_APPLE_PAC) */
143
144
145 DECLARE("ARM_CONTEXT_SIZE", sizeof(arm_context_t));
146
147 DECLARE("SS_FLAVOR", offsetof(arm_context_t, ss.ash.flavor));
148 DECLARE("ARM_SAVED_STATE64", ARM_SAVED_STATE64);
149 DECLARE("ARM_SAVED_STATE64_COUNT", ARM_SAVED_STATE64_COUNT);
150
151 DECLARE("SS64_X0", offsetof(arm_context_t, ss.ss_64.x[0]));
152 DECLARE("SS64_X2", offsetof(arm_context_t, ss.ss_64.x[2]));
153 DECLARE("SS64_X4", offsetof(arm_context_t, ss.ss_64.x[4]));
154 DECLARE("SS64_X6", offsetof(arm_context_t, ss.ss_64.x[6]));
155 DECLARE("SS64_X8", offsetof(arm_context_t, ss.ss_64.x[8]));
156 DECLARE("SS64_X10", offsetof(arm_context_t, ss.ss_64.x[10]));
157 DECLARE("SS64_X12", offsetof(arm_context_t, ss.ss_64.x[12]));
158 DECLARE("SS64_X14", offsetof(arm_context_t, ss.ss_64.x[14]));
159 DECLARE("SS64_X15", offsetof(arm_context_t, ss.ss_64.x[15]));
160 DECLARE("SS64_X16", offsetof(arm_context_t, ss.ss_64.x[16]));
161 DECLARE("SS64_X18", offsetof(arm_context_t, ss.ss_64.x[18]));
162 DECLARE("SS64_X19", offsetof(arm_context_t, ss.ss_64.x[19]));
163 DECLARE("SS64_X20", offsetof(arm_context_t, ss.ss_64.x[20]));
164 DECLARE("SS64_X21", offsetof(arm_context_t, ss.ss_64.x[21]));
165 DECLARE("SS64_X22", offsetof(arm_context_t, ss.ss_64.x[22]));
166 DECLARE("SS64_X23", offsetof(arm_context_t, ss.ss_64.x[23]));
167 DECLARE("SS64_X24", offsetof(arm_context_t, ss.ss_64.x[24]));
168 DECLARE("SS64_X25", offsetof(arm_context_t, ss.ss_64.x[25]));
169 DECLARE("SS64_X26", offsetof(arm_context_t, ss.ss_64.x[26]));
170 DECLARE("SS64_X27", offsetof(arm_context_t, ss.ss_64.x[27]));
171 DECLARE("SS64_X28", offsetof(arm_context_t, ss.ss_64.x[28]));
172 DECLARE("SS64_FP", offsetof(arm_context_t, ss.ss_64.fp));
173 DECLARE("SS64_LR", offsetof(arm_context_t, ss.ss_64.lr));
174 DECLARE("SS64_SP", offsetof(arm_context_t, ss.ss_64.sp));
175 DECLARE("SS64_PC", offsetof(arm_context_t, ss.ss_64.pc));
176 DECLARE("SS64_CPSR", offsetof(arm_context_t, ss.ss_64.cpsr));
177 DECLARE("SS64_FAR", offsetof(arm_context_t, ss.ss_64.far));
178 DECLARE("SS64_ESR", offsetof(arm_context_t, ss.ss_64.esr));
179 #if defined(HAS_APPLE_PAC)
180 DECLARE("SS64_JOPHASH", offsetof(arm_context_t, ss.ss_64.jophash));
181 #endif /* defined(HAS_APPLE_PAC) */
182
183 DECLARE("NS_FLAVOR", offsetof(arm_context_t, ns.nsh.flavor));
184 DECLARE("NS_COUNT", offsetof(arm_context_t, ns.nsh.count));
185 DECLARE("ARM_NEON_SAVED_STATE64", ARM_NEON_SAVED_STATE64);
186 DECLARE("ARM_NEON_SAVED_STATE64_COUNT", ARM_NEON_SAVED_STATE64_COUNT);
187
188 DECLARE("NS64_D8", offsetof(arm_context_t, ns.ns_64.v.d[8]));
189 DECLARE("NS64_D9", offsetof(arm_context_t, ns.ns_64.v.d[9]));
190 DECLARE("NS64_D10", offsetof(arm_context_t, ns.ns_64.v.d[10]));
191 DECLARE("NS64_D11", offsetof(arm_context_t, ns.ns_64.v.d[11]));
192 DECLARE("NS64_D12", offsetof(arm_context_t, ns.ns_64.v.d[12]));
193 DECLARE("NS64_D13", offsetof(arm_context_t, ns.ns_64.v.d[13]));
194 DECLARE("NS64_D14", offsetof(arm_context_t, ns.ns_64.v.d[14]));
195 DECLARE("NS64_D15", offsetof(arm_context_t, ns.ns_64.v.d[15]));
196
197 DECLARE("NS64_Q0", offsetof(arm_context_t, ns.ns_64.v.q[0]));
198 DECLARE("NS64_Q2", offsetof(arm_context_t, ns.ns_64.v.q[2]));
199 DECLARE("NS64_Q4", offsetof(arm_context_t, ns.ns_64.v.q[4]));
200 DECLARE("NS64_Q6", offsetof(arm_context_t, ns.ns_64.v.q[6]));
201 DECLARE("NS64_Q8", offsetof(arm_context_t, ns.ns_64.v.q[8]));
202 DECLARE("NS64_Q10", offsetof(arm_context_t, ns.ns_64.v.q[10]));
203 DECLARE("NS64_Q12", offsetof(arm_context_t, ns.ns_64.v.q[12]));
204 DECLARE("NS64_Q14", offsetof(arm_context_t, ns.ns_64.v.q[14]));
205 DECLARE("NS64_Q16", offsetof(arm_context_t, ns.ns_64.v.q[16]));
206 DECLARE("NS64_Q18", offsetof(arm_context_t, ns.ns_64.v.q[18]));
207 DECLARE("NS64_Q20", offsetof(arm_context_t, ns.ns_64.v.q[20]));
208 DECLARE("NS64_Q22", offsetof(arm_context_t, ns.ns_64.v.q[22]));
209 DECLARE("NS64_Q24", offsetof(arm_context_t, ns.ns_64.v.q[24]));
210 DECLARE("NS64_Q26", offsetof(arm_context_t, ns.ns_64.v.q[26]));
211 DECLARE("NS64_Q28", offsetof(arm_context_t, ns.ns_64.v.q[28]));
212 DECLARE("NS64_Q30", offsetof(arm_context_t, ns.ns_64.v.q[30]));
213 DECLARE("NS64_FPSR", offsetof(arm_context_t, ns.ns_64.fpsr));
214 DECLARE("NS64_FPCR", offsetof(arm_context_t, ns.ns_64.fpcr));
215
216 DECLARE("ARM_KERNEL_CONTEXT_SIZE", sizeof(arm_kernel_context_t));
217
218 DECLARE("SS64_KERNEL_X16", offsetof(arm_kernel_context_t, ss.x[0]));
219 DECLARE("SS64_KERNEL_X17", offsetof(arm_kernel_context_t, ss.x[1]));
220 DECLARE("SS64_KERNEL_X19", offsetof(arm_kernel_context_t, ss.x[2]));
221 DECLARE("SS64_KERNEL_X20", offsetof(arm_kernel_context_t, ss.x[3]));
222 DECLARE("SS64_KERNEL_X21", offsetof(arm_kernel_context_t, ss.x[4]));
223 DECLARE("SS64_KERNEL_X22", offsetof(arm_kernel_context_t, ss.x[5]));
224 DECLARE("SS64_KERNEL_X23", offsetof(arm_kernel_context_t, ss.x[6]));
225 DECLARE("SS64_KERNEL_X24", offsetof(arm_kernel_context_t, ss.x[7]));
226 DECLARE("SS64_KERNEL_X25", offsetof(arm_kernel_context_t, ss.x[8]));
227 DECLARE("SS64_KERNEL_X26", offsetof(arm_kernel_context_t, ss.x[9]));
228 DECLARE("SS64_KERNEL_X27", offsetof(arm_kernel_context_t, ss.x[10]));
229 DECLARE("SS64_KERNEL_X28", offsetof(arm_kernel_context_t, ss.x[11]));
230 DECLARE("SS64_KERNEL_FP", offsetof(arm_kernel_context_t, ss.fp));
231 DECLARE("SS64_KERNEL_LR", offsetof(arm_kernel_context_t, ss.lr));
232 DECLARE("SS64_KERNEL_SP", offsetof(arm_kernel_context_t, ss.sp));
233 DECLARE("SS64_KERNEL_PC", offsetof(arm_kernel_context_t, ss.pc));
234 DECLARE("SS64_KERNEL_CPSR", offsetof(arm_kernel_context_t, ss.cpsr));
235 #if defined(HAS_APPLE_PAC)
236 DECLARE("SS64_KERNEL_JOPHASH", offsetof(arm_kernel_context_t, ss.jophash));
237 #endif /* defined(HAS_APPLE_PAC) */
238
239 DECLARE("NS64_KERNEL_D8", offsetof(arm_kernel_context_t, ns.d[0]));
240 DECLARE("NS64_KERNEL_D9", offsetof(arm_kernel_context_t, ns.d[1]));
241 DECLARE("NS64_KERNEL_D10", offsetof(arm_kernel_context_t, ns.d[2]));
242 DECLARE("NS64_KERNEL_D11", offsetof(arm_kernel_context_t, ns.d[3]));
243 DECLARE("NS64_KERNEL_D12", offsetof(arm_kernel_context_t, ns.d[4]));
244 DECLARE("NS64_KERNEL_D13", offsetof(arm_kernel_context_t, ns.d[5]));
245 DECLARE("NS64_KERNEL_D14", offsetof(arm_kernel_context_t, ns.d[6]));
246 DECLARE("NS64_KERNEL_D15", offsetof(arm_kernel_context_t, ns.d[7]));
247
248 DECLARE("NS64_KERNEL_FPCR", offsetof(arm_kernel_context_t, ns.fpcr));
249
250
251
252 DECLARE("PGBYTES", ARM_PGBYTES);
253 DECLARE("PGSHIFT", ARM_PGSHIFT);
254
255 DECLARE("VM_MIN_KERNEL_ADDRESS", VM_MIN_KERNEL_ADDRESS);
256 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE);
257 DECLARE("TBI_MASK", TBI_MASK);
258
259 DECLARE("cdeSize", sizeof(struct cpu_data_entry));
260
261 DECLARE("cdSize", sizeof(struct cpu_data));
262
263 DECLARE("CPU_ACTIVE_THREAD", offsetof(cpu_data_t, cpu_active_thread));
264 DECLARE("CPU_ISTACKPTR", offsetof(cpu_data_t, istackptr));
265 DECLARE("CPU_INTSTACK_TOP", offsetof(cpu_data_t, intstack_top));
266 DECLARE("CPU_EXCEPSTACK_TOP", offsetof(cpu_data_t, excepstack_top));
267 #if __ARM_KERNEL_PROTECT__
268 DECLARE("CPU_EXC_VECTORS", offsetof(cpu_data_t, cpu_exc_vectors));
269 #endif /* __ARM_KERNEL_PROTECT__ */
270 DECLARE("CPU_NUMBER_GS", offsetof(cpu_data_t, cpu_number));
271 DECLARE("CPU_PENDING_AST", offsetof(cpu_data_t, cpu_pending_ast));
272 DECLARE("CPU_INT_STATE", offsetof(cpu_data_t, cpu_int_state));
273 DECLARE("CPU_USER_DEBUG", offsetof(cpu_data_t, cpu_user_debug));
274 DECLARE("CPU_STAT_IRQ", offsetof(cpu_data_t, cpu_stat.irq_ex_cnt));
275 DECLARE("CPU_STAT_IRQ_WAKE", offsetof(cpu_data_t, cpu_stat.irq_ex_cnt_wake));
276 DECLARE("CPU_RESET_HANDLER", offsetof(cpu_data_t, cpu_reset_handler));
277 DECLARE("CPU_PHYS_ID", offsetof(cpu_data_t, cpu_phys_id));
278
279 DECLARE("RTCLOCKDataSize", sizeof(rtclock_data_t));
280
281 DECLARE("rhdSize", sizeof(struct reset_handler_data));
282 #if WITH_CLASSIC_S2R || !__arm64__
283 DECLARE("stSize", sizeof(SleepToken));
284 #endif /* WITH_CLASSIC_S2R || !__arm64__ */
285
286 DECLARE("CPU_DATA_ENTRIES", offsetof(struct reset_handler_data, cpu_data_entries));
287
288 DECLARE("CPU_DATA_PADDR", offsetof(struct cpu_data_entry, cpu_data_paddr));
289
290 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE);
291 DECLARE("EXCEPSTACK_SIZE", EXCEPSTACK_SIZE);
292
293 DECLARE("PAGE_MAX_SHIFT", PAGE_MAX_SHIFT);
294 DECLARE("PAGE_MAX_SIZE", PAGE_MAX_SIZE);
295
296 DECLARE("BA_VIRT_BASE", offsetof(struct boot_args, virtBase));
297 DECLARE("BA_PHYS_BASE", offsetof(struct boot_args, physBase));
298 DECLARE("BA_MEM_SIZE", offsetof(struct boot_args, memSize));
299 DECLARE("BA_TOP_OF_KERNEL_DATA", offsetof(struct boot_args, topOfKernelData));
300 DECLARE("BA_BOOT_FLAGS", offsetof(struct boot_args, bootFlags));
301
302 DECLARE("SR_RESTORE_TCR_EL1", offsetof(struct sysreg_restore, tcr_el1));
303
304 #if XNU_MONITOR
305 DECLARE("PMAP_CPU_DATA_PPL_STATE", offsetof(struct pmap_cpu_data, ppl_state));
306 DECLARE("PMAP_CPU_DATA_ARRAY_ENTRY_SIZE", sizeof(struct pmap_cpu_data_array_entry));
307 DECLARE("PMAP_CPU_DATA_PPL_STACK", offsetof(struct pmap_cpu_data, ppl_stack));
308 DECLARE("PMAP_CPU_DATA_KERN_SAVED_SP", offsetof(struct pmap_cpu_data, ppl_kern_saved_sp));
309 DECLARE("PMAP_CPU_DATA_SAVE_AREA", offsetof(struct pmap_cpu_data, save_area));
310 DECLARE("PMAP_COUNT", PMAP_COUNT);
311 #endif /* XNU_MONITOR */
312
313
314 #if defined(HAS_APPLE_PAC)
315 DECLARE("CPU_ROP_KEY", offsetof(cpu_data_t, rop_key));
316 DECLARE("CPU_JOP_KEY", offsetof(cpu_data_t, jop_key));
317 #if __has_feature(ptrauth_function_pointer_type_discrimination)
318 DECLARE("THREAD_CONTINUE_T_DISC", __builtin_ptrauth_type_discriminator(thread_continue_t));
319 #else
320 DECLARE("THREAD_CONTINUE_T_DISC", 0);
321 #endif /* __has_feature(ptrauth_function_pointer_type_discrimination) */
322 #endif /* defined(HAS_APPLE_PAC) */
323
324
325 #if __ARM_ARCH_8_5__
326 DECLARE("CPU_SYNC_ON_CSWITCH", offsetof(cpu_data_t, sync_on_cswitch));
327 #endif /* __ARM_ARCH_8_5__ */
328
329 #if HIBERNATION
330 DECLARE("HIBHDR_STACKOFFSET", offsetof(IOHibernateImageHeader, restore1StackOffset));
331 DECLARE("HIBTRAMP_TTBR0", offsetof(pal_hib_tramp_result_t, ttbr0));
332 DECLARE("HIBTRAMP_TTBR1", offsetof(pal_hib_tramp_result_t, ttbr1));
333 DECLARE("HIBTRAMP_MEMSLIDE", offsetof(pal_hib_tramp_result_t, memSlide));
334 DECLARE("HIBGLOBALS_KERNELSLIDE", offsetof(pal_hib_globals_t, kernelSlide));
335 #endif /* HIBERNATION */
336
337 return 0;
338 }