]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/genassym.c
8dfdecddaedf90221c0655fa52dfeff252e0105d
[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
89 /*
90 * genassym.c is used to produce an
91 * assembly file which, intermingled with unuseful assembly code,
92 * has all the necessary definitions emitted. This assembly file is
93 * then postprocessed with sed to extract only these definitions
94 * and thus the final assyms.s is created.
95 *
96 * This convoluted means is necessary since the structure alignment
97 * and packing may be different between the host machine and the
98 * target so we are forced into using the cross compiler to generate
99 * the values, but we cannot run anything on the target machine.
100 */
101
102 #define DECLARE(SYM, VAL) \
103 __asm("DEFINITION__define__" SYM ":\t .ascii \"%0\"" : : "i" ((u_long)(VAL)))
104
105
106 int main(int argc,
107 char ** argv);
108
109 int
110 main(int argc,
111 char ** argv)
112 {
113 DECLARE("AST_URGENT", AST_URGENT);
114
115 DECLARE("TH_RECOVER", offsetof(struct thread, recover));
116 DECLARE("TH_KSTACKPTR", offsetof(struct thread, machine.kstackptr));
117 #if defined(HAS_APPLE_PAC)
118 DECLARE("TH_ROP_PID", offsetof(struct thread, machine.rop_pid));
119 DECLARE("TH_DISABLE_USER_JOP", offsetof(struct thread, machine.disable_user_jop));
120 #endif /* defined(HAS_APPLE_PAC) */
121
122 /* These fields are being added on demand */
123 DECLARE("ACT_CONTEXT", offsetof(struct thread, machine.contextData));
124 DECLARE("TH_CTH_SELF", offsetof(struct thread, machine.cthread_self));
125 DECLARE("TH_CTH_DATA", offsetof(struct thread, machine.cthread_data));
126 DECLARE("ACT_PREEMPT_CNT", offsetof(struct thread, machine.preemption_count));
127 DECLARE("ACT_CPUDATAP", offsetof(struct thread, machine.CpuDatap));
128 DECLARE("ACT_DEBUGDATA", offsetof(struct thread, machine.DebugData));
129 DECLARE("TH_IOTIER_OVERRIDE", offsetof(struct thread, iotier_override));
130 DECLARE("TH_RWLOCK_CNT", offsetof(struct thread, rwlock_count));
131
132 #if defined(HAS_APPLE_PAC)
133 DECLARE("TASK_ROP_PID", offsetof(struct task, rop_pid));
134 #endif /* defined(HAS_APPLE_PAC) */
135
136 DECLARE("ARM_CONTEXT_SIZE", sizeof(arm_context_t));
137
138 DECLARE("SS_FLAVOR", offsetof(arm_context_t, ss.ash.flavor));
139 DECLARE("ARM_SAVED_STATE64", ARM_SAVED_STATE64);
140 DECLARE("ARM_SAVED_STATE64_COUNT", ARM_SAVED_STATE64_COUNT);
141
142 DECLARE("SS64_X0", offsetof(arm_context_t, ss.ss_64.x[0]));
143 DECLARE("SS64_X2", offsetof(arm_context_t, ss.ss_64.x[2]));
144 DECLARE("SS64_X4", offsetof(arm_context_t, ss.ss_64.x[4]));
145 DECLARE("SS64_X6", offsetof(arm_context_t, ss.ss_64.x[6]));
146 DECLARE("SS64_X8", offsetof(arm_context_t, ss.ss_64.x[8]));
147 DECLARE("SS64_X10", offsetof(arm_context_t, ss.ss_64.x[10]));
148 DECLARE("SS64_X12", offsetof(arm_context_t, ss.ss_64.x[12]));
149 DECLARE("SS64_X14", offsetof(arm_context_t, ss.ss_64.x[14]));
150 DECLARE("SS64_X16", offsetof(arm_context_t, ss.ss_64.x[16]));
151 DECLARE("SS64_X18", offsetof(arm_context_t, ss.ss_64.x[18]));
152 DECLARE("SS64_X19", offsetof(arm_context_t, ss.ss_64.x[19]));
153 DECLARE("SS64_X20", offsetof(arm_context_t, ss.ss_64.x[20]));
154 DECLARE("SS64_X21", offsetof(arm_context_t, ss.ss_64.x[21]));
155 DECLARE("SS64_X22", offsetof(arm_context_t, ss.ss_64.x[22]));
156 DECLARE("SS64_X23", offsetof(arm_context_t, ss.ss_64.x[23]));
157 DECLARE("SS64_X24", offsetof(arm_context_t, ss.ss_64.x[24]));
158 DECLARE("SS64_X25", offsetof(arm_context_t, ss.ss_64.x[25]));
159 DECLARE("SS64_X26", offsetof(arm_context_t, ss.ss_64.x[26]));
160 DECLARE("SS64_X27", offsetof(arm_context_t, ss.ss_64.x[27]));
161 DECLARE("SS64_X28", offsetof(arm_context_t, ss.ss_64.x[28]));
162 DECLARE("SS64_FP", offsetof(arm_context_t, ss.ss_64.fp));
163 DECLARE("SS64_LR", offsetof(arm_context_t, ss.ss_64.lr));
164 DECLARE("SS64_SP", offsetof(arm_context_t, ss.ss_64.sp));
165 DECLARE("SS64_PC", offsetof(arm_context_t, ss.ss_64.pc));
166 DECLARE("SS64_CPSR", offsetof(arm_context_t, ss.ss_64.cpsr));
167 DECLARE("SS64_FAR", offsetof(arm_context_t, ss.ss_64.far));
168 DECLARE("SS64_ESR", offsetof(arm_context_t, ss.ss_64.esr));
169 #if defined(HAS_APPLE_PAC)
170 DECLARE("SS64_JOPHASH", offsetof(arm_context_t, ss.ss_64.jophash));
171 #endif /* defined(HAS_APPLE_PAC) */
172
173 DECLARE("NS_FLAVOR", offsetof(arm_context_t, ns.nsh.flavor));
174 DECLARE("NS_COUNT", offsetof(arm_context_t, ns.nsh.count));
175 DECLARE("ARM_NEON_SAVED_STATE64", ARM_NEON_SAVED_STATE64);
176 DECLARE("ARM_NEON_SAVED_STATE64_COUNT", ARM_NEON_SAVED_STATE64_COUNT);
177
178 DECLARE("NS64_D8", offsetof(arm_context_t, ns.ns_64.v.d[8]));
179 DECLARE("NS64_D9", offsetof(arm_context_t, ns.ns_64.v.d[9]));
180 DECLARE("NS64_D10", offsetof(arm_context_t, ns.ns_64.v.d[10]));
181 DECLARE("NS64_D11", offsetof(arm_context_t, ns.ns_64.v.d[11]));
182 DECLARE("NS64_D12", offsetof(arm_context_t, ns.ns_64.v.d[12]));
183 DECLARE("NS64_D13", offsetof(arm_context_t, ns.ns_64.v.d[13]));
184 DECLARE("NS64_D14", offsetof(arm_context_t, ns.ns_64.v.d[14]));
185 DECLARE("NS64_D15", offsetof(arm_context_t, ns.ns_64.v.d[15]));
186
187 DECLARE("NS64_Q0", offsetof(arm_context_t, ns.ns_64.v.q[0]));
188 DECLARE("NS64_Q2", offsetof(arm_context_t, ns.ns_64.v.q[2]));
189 DECLARE("NS64_Q4", offsetof(arm_context_t, ns.ns_64.v.q[4]));
190 DECLARE("NS64_Q6", offsetof(arm_context_t, ns.ns_64.v.q[6]));
191 DECLARE("NS64_Q8", offsetof(arm_context_t, ns.ns_64.v.q[8]));
192 DECLARE("NS64_Q10", offsetof(arm_context_t, ns.ns_64.v.q[10]));
193 DECLARE("NS64_Q12", offsetof(arm_context_t, ns.ns_64.v.q[12]));
194 DECLARE("NS64_Q14", offsetof(arm_context_t, ns.ns_64.v.q[14]));
195 DECLARE("NS64_Q16", offsetof(arm_context_t, ns.ns_64.v.q[16]));
196 DECLARE("NS64_Q18", offsetof(arm_context_t, ns.ns_64.v.q[18]));
197 DECLARE("NS64_Q20", offsetof(arm_context_t, ns.ns_64.v.q[20]));
198 DECLARE("NS64_Q22", offsetof(arm_context_t, ns.ns_64.v.q[22]));
199 DECLARE("NS64_Q24", offsetof(arm_context_t, ns.ns_64.v.q[24]));
200 DECLARE("NS64_Q26", offsetof(arm_context_t, ns.ns_64.v.q[26]));
201 DECLARE("NS64_Q28", offsetof(arm_context_t, ns.ns_64.v.q[28]));
202 DECLARE("NS64_Q30", offsetof(arm_context_t, ns.ns_64.v.q[30]));
203 DECLARE("NS64_FPSR", offsetof(arm_context_t, ns.ns_64.fpsr));
204 DECLARE("NS64_FPCR", offsetof(arm_context_t, ns.ns_64.fpcr));
205
206
207 DECLARE("PGBYTES", ARM_PGBYTES);
208 DECLARE("PGSHIFT", ARM_PGSHIFT);
209
210 DECLARE("VM_MIN_KERNEL_ADDRESS", VM_MIN_KERNEL_ADDRESS);
211 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE);
212 DECLARE("TBI_MASK", TBI_MASK);
213
214 DECLARE("MAX_CPUS", MAX_CPUS);
215
216 DECLARE("cdeSize", sizeof(struct cpu_data_entry));
217
218 DECLARE("cdSize", sizeof(struct cpu_data));
219
220 DECLARE("CPU_ACTIVE_THREAD", offsetof(cpu_data_t, cpu_active_thread));
221 DECLARE("CPU_ISTACKPTR", offsetof(cpu_data_t, istackptr));
222 DECLARE("CPU_INTSTACK_TOP", offsetof(cpu_data_t, intstack_top));
223 DECLARE("CPU_EXCEPSTACK_TOP", offsetof(cpu_data_t, excepstack_top));
224 #if __ARM_KERNEL_PROTECT__
225 DECLARE("CPU_EXC_VECTORS", offsetof(cpu_data_t, cpu_exc_vectors));
226 #endif /* __ARM_KERNEL_PROTECT__ */
227 DECLARE("CPU_NUMBER_GS", offsetof(cpu_data_t, cpu_number));
228 DECLARE("CPU_PENDING_AST", offsetof(cpu_data_t, cpu_pending_ast));
229 DECLARE("CPU_INT_STATE", offsetof(cpu_data_t, cpu_int_state));
230 DECLARE("CPU_USER_DEBUG", offsetof(cpu_data_t, cpu_user_debug));
231 DECLARE("CPU_STAT_IRQ", offsetof(cpu_data_t, cpu_stat.irq_ex_cnt));
232 DECLARE("CPU_STAT_IRQ_WAKE", offsetof(cpu_data_t, cpu_stat.irq_ex_cnt_wake));
233 DECLARE("CPU_RESET_HANDLER", offsetof(cpu_data_t, cpu_reset_handler));
234 DECLARE("CPU_PHYS_ID", offsetof(cpu_data_t, cpu_phys_id));
235 DECLARE("CLUSTER_MASTER", offsetof(cpu_data_t, cluster_master));
236
237 DECLARE("RTCLOCKDataSize", sizeof(rtclock_data_t));
238
239 DECLARE("rhdSize", sizeof(struct reset_handler_data));
240 #if WITH_CLASSIC_S2R || !__arm64__
241 DECLARE("stSize", sizeof(SleepToken));
242 #endif /* WITH_CLASSIC_S2R || !__arm64__ */
243
244 DECLARE("CPU_DATA_ENTRIES", offsetof(struct reset_handler_data, cpu_data_entries));
245
246 DECLARE("CPU_DATA_PADDR", offsetof(struct cpu_data_entry, cpu_data_paddr));
247
248 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE);
249 DECLARE("EXCEPSTACK_SIZE", EXCEPSTACK_SIZE);
250
251 DECLARE("PAGE_MAX_SIZE", PAGE_MAX_SIZE);
252
253 DECLARE("BA_VIRT_BASE", offsetof(struct boot_args, virtBase));
254 DECLARE("BA_PHYS_BASE", offsetof(struct boot_args, physBase));
255 DECLARE("BA_MEM_SIZE", offsetof(struct boot_args, memSize));
256 DECLARE("BA_TOP_OF_KERNEL_DATA", offsetof(struct boot_args, topOfKernelData));
257 DECLARE("BA_BOOT_FLAGS", offsetof(struct boot_args, bootFlags));
258
259 DECLARE("SR_RESTORE_TCR_EL1", offsetof(struct sysreg_restore, tcr_el1));
260
261
262
263 #if defined(HAS_APPLE_PAC)
264 DECLARE("CPU_ROP_KEY", offsetof(cpu_data_t, rop_key));
265 #endif /* defined(HAS_APPLE_PAC) */
266
267 return 0;
268 }