]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/genassym.c
xnu-344.21.73.tar.gz
[apple/xnu.git] / osfmk / i386 / genassym.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217
A
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53
54#include <platforms.h>
55#include <cpus.h>
56#include <mach_kdb.h>
57#include <mach_ldebug.h>
58#include <stat_time.h>
59
60/*
61 * Pass field offsets to assembly code.
62 */
63#include <kern/ast.h>
64#include <kern/thread.h>
65#include <kern/task.h>
66#include <kern/lock.h>
67#include <kern/thread_act.h>
1c79356b
A
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_emulation.h>
74#include <i386/thread.h>
75#include <mach/i386/vm_param.h>
76#include <i386/seg.h>
77#include <i386/pmap.h>
78#include <i386/tss.h>
1c79356b
A
79#include <vm/vm_map.h>
80#if NCPUS > 1
81#include <i386/mp_desc.h>
82#endif
83
84extern void kernel_preempt_check(void);
85cpu_data_t cpu_data[NCPUS];
86
87/*
88 * genassym.c is used to produce an
89 * assembly file which, intermingled with unuseful assembly code,
90 * has all the necessary definitions emitted. This assembly file is
91 * then postprocessed with sed to extract only these definitions
92 * and thus the final assyms.s is created.
93 *
94 * This convoluted means is necessary since the structure alignment
95 * and packing may be different between the host machine and the
96 * target so we are forced into using the cross compiler to generate
97 * the values, but we cannot run anything on the target machine.
98 */
99
100#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
101
102#if 0
103#define DECLARE(SYM,VAL) \
104 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
105#else
106#define DECLARE(SYM,VAL) \
107 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
108#endif
109
110int main(
111 int argc,
112 char ** argv);
113
114int
115main(
116 int argc,
117 char **argv)
118{
119
120 DECLARE("AST_URGENT", AST_URGENT);
121
122#if MACH_LDEBUG
123 /*
124 * XXX
125 */
126#define SIMPLE_LOCK_TAG 0x5353
127#define MUTEX_TAG 0x4d4d
128 DECLARE("TH_MUTEX_COUNT", offsetof(thread_t, mutex_count));
129 DECLARE("SIMPLE_LOCK_TAG", SIMPLE_LOCK_TAG);
130 DECLARE("MUTEX_TAG", MUTEX_TAG);
131#endif /* MACH_LDEBUG */
132 DECLARE("TH_RECOVER", offsetof(thread_t, recover));
133 DECLARE("TH_CONTINUATION", offsetof(thread_t, continuation));
134 DECLARE("TH_TOP_ACT", offsetof(thread_t, top_act));
135 DECLARE("TH_KERNEL_STACK", offsetof(thread_t, kernel_stack));
136
137 DECLARE("TASK_EMUL", offsetof(task_t, eml_dispatch));
138 DECLARE("TASK_MACH_EXC_PORT",
139 offsetof(task_t, exc_actions[EXC_MACH_SYSCALL].port));
140
141 /* These fields are being added on demand */
142 DECLARE("ACT_MACH_EXC_PORT",
143 offsetof(thread_act_t, exc_actions[EXC_MACH_SYSCALL].port));
144
145 DECLARE("ACT_THREAD", offsetof(thread_act_t, thread));
146 DECLARE("ACT_TASK", offsetof(thread_act_t, task));
147 DECLARE("ACT_PCB", offsetof(thread_act_t, mact.pcb));
148 DECLARE("ACT_KLOADED", offsetof(thread_act_t, kernel_loaded));
149 DECLARE("ACT_KLOADING", offsetof(thread_act_t, kernel_loading));
150 DECLARE("ACT_LOWER", offsetof(thread_act_t, lower));
151 DECLARE("ACT_MAP", offsetof(thread_act_t, map));
152
153 DECLARE("MAP_PMAP", offsetof(vm_map_t, pmap));
154
1c79356b
A
155 DECLARE("HOST_NAME", offsetof(host_t, host_self));
156
157 DECLARE("DISP_MIN", offsetof(eml_dispatch_t, disp_min));
158 DECLARE("DISP_COUNT", offsetof(eml_dispatch_t, disp_count));
159 DECLARE("DISP_VECTOR", offsetof(eml_dispatch_t, disp_vector[0]));
160
161#define IKS ((size_t) (STACK_IKS(0)))
162
163 DECLARE("KSS_EBX", IKS + offsetof(struct i386_kernel_state *, k_ebx));
164 DECLARE("KSS_ESP", IKS + offsetof(struct i386_kernel_state *, k_esp));
165 DECLARE("KSS_EBP", IKS + offsetof(struct i386_kernel_state *, k_ebp));
166 DECLARE("KSS_EDI", IKS + offsetof(struct i386_kernel_state *, k_edi));
167 DECLARE("KSS_ESI", IKS + offsetof(struct i386_kernel_state *, k_esi));
168 DECLARE("KSS_EIP", IKS + offsetof(struct i386_kernel_state *, k_eip));
169
170 DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state));
171 DECLARE("IEL_SIZE", sizeof(struct i386_exception_link));
172
173 DECLARE("PCB_FPS", offsetof(pcb_t, ims.ifps));
174 DECLARE("PCB_ISS", offsetof(pcb_t, iss));
175
176 DECLARE("FP_VALID", offsetof(struct i386_fpsave_state *,fp_valid));
177 DECLARE("FP_SAVE_STATE",
178 offsetof(struct i386_fpsave_state *, fp_save_state));
179
180 DECLARE("R_CS", offsetof(struct i386_saved_state *, cs));
181 DECLARE("R_SS", offsetof(struct i386_saved_state *, ss));
182 DECLARE("R_UESP", offsetof(struct i386_saved_state *, uesp));
183 DECLARE("R_EBP", offsetof(struct i386_saved_state *, ebp));
184 DECLARE("R_EAX", offsetof(struct i386_saved_state *, eax));
185 DECLARE("R_EBX", offsetof(struct i386_saved_state *, ebx));
186 DECLARE("R_ECX", offsetof(struct i386_saved_state *, ecx));
187 DECLARE("R_EDX", offsetof(struct i386_saved_state *, edx));
188 DECLARE("R_ESI", offsetof(struct i386_saved_state *, esi));
189 DECLARE("R_EDI", offsetof(struct i386_saved_state *, edi));
190 DECLARE("R_TRAPNO", offsetof(struct i386_saved_state *, trapno));
191 DECLARE("R_ERR", offsetof(struct i386_saved_state *, err));
192 DECLARE("R_EFLAGS", offsetof(struct i386_saved_state *, efl));
193 DECLARE("R_EIP", offsetof(struct i386_saved_state *, eip));
194 DECLARE("R_CR2", offsetof(struct i386_saved_state *, cr2));
195 DECLARE("ISS_SIZE", sizeof (struct i386_saved_state));
196
197 DECLARE("I_ECX", offsetof(struct i386_interrupt_state *, ecx));
198 DECLARE("I_EIP", offsetof(struct i386_interrupt_state *, eip));
199 DECLARE("I_CS", offsetof(struct i386_interrupt_state *, cs));
200 DECLARE("I_EFL", offsetof(struct i386_interrupt_state *, efl));
201
202 DECLARE("NBPG", I386_PGBYTES);
203 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS);
204 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS);
205 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS);
206 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS);
207 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE);
208
209 DECLARE("PDESHIFT", PDESHIFT);
210 DECLARE("PTESHIFT", PTESHIFT);
211 DECLARE("PTEMASK", PTEMASK);
212
213 DECLARE("PTE_PFN", INTEL_PTE_PFN);
214 DECLARE("PTE_V", INTEL_PTE_VALID);
215 DECLARE("PTE_W", INTEL_PTE_WRITE);
216 DECLARE("PTE_INVALID", ~INTEL_PTE_VALID);
217
218 DECLARE("IDTSZ", IDTSZ);
219 DECLARE("GDTSZ", GDTSZ);
220 DECLARE("LDTSZ", LDTSZ);
221
222 DECLARE("KERNEL_CS", KERNEL_CS);
223 DECLARE("KERNEL_DS", KERNEL_DS);
224 DECLARE("USER_CS", USER_CS);
225 DECLARE("USER_DS", USER_DS);
226 DECLARE("KERNEL_TSS", KERNEL_TSS);
227 DECLARE("KERNEL_LDT", KERNEL_LDT);
228#if MACH_KDB
229 DECLARE("DEBUG_TSS", DEBUG_TSS);
230#endif /* MACH_KDB */
231
232 DECLARE("CPU_DATA", CPU_DATA);
233 DECLARE("CPD_ACTIVE_THREAD",
234 offsetof(cpu_data_t *, active_thread));
235#if MACH_RT
236 DECLARE("CPD_PREEMPTION_LEVEL",
237 offsetof(cpu_data_t *, preemption_level));
238#endif /* MACH_RT */
239 DECLARE("CPD_INTERRUPT_LEVEL",
240 offsetof(cpu_data_t *, interrupt_level));
241 DECLARE("CPD_SIMPLE_LOCK_COUNT",
242 offsetof(cpu_data_t *,simple_lock_count));
243
244 DECLARE("PTES_PER_PAGE", NPTES);
245 DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID|INTEL_PTE_WRITE);
246
247 DECLARE("KERNELBASEPDE",
248 (LINEAR_KERNEL_ADDRESS >> PDESHIFT) *
249 sizeof(pt_entry_t));
250
251 DECLARE("TSS_ESP0", offsetof(struct i386_tss *, esp0));
252 DECLARE("TSS_SS0", offsetof(struct i386_tss *, ss0));
253 DECLARE("TSS_LDT", offsetof(struct i386_tss *, ldt));
254 DECLARE("TSS_PDBR", offsetof(struct i386_tss *, cr3));
255 DECLARE("TSS_LINK", offsetof(struct i386_tss *, back_link));
256
257 DECLARE("K_TASK_GATE", ACC_P|ACC_PL_K|ACC_TASK_GATE);
258 DECLARE("K_TRAP_GATE", ACC_P|ACC_PL_K|ACC_TRAP_GATE);
259 DECLARE("U_TRAP_GATE", ACC_P|ACC_PL_U|ACC_TRAP_GATE);
260 DECLARE("K_INTR_GATE", ACC_P|ACC_PL_K|ACC_INTR_GATE);
261 DECLARE("K_TSS", ACC_P|ACC_PL_K|ACC_TSS);
262
263 /*
264 * usimple_lock fields
265 */
266 DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t, interlock));
267
268 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE);
269#if NCPUS > 1
270 DECLARE("MP_GDT", offsetof(struct mp_desc_table *, gdt[0]));
271 DECLARE("MP_IDT", offsetof(struct mp_desc_table *, idt[0]));
272#endif /* NCPUS > 1 */
273#if !STAT_TIME
274 DECLARE("LOW_BITS", offsetof(struct timer *, low_bits));
275 DECLARE("HIGH_BITS", offsetof(struct timer *, high_bits));
276 DECLARE("HIGH_BITS_CHECK", offsetof(struct timer *, high_bits_check));
277 DECLARE("TIMER_HIGH_UNIT", TIMER_HIGH_UNIT);
278 DECLARE("TH_SYS_TIMER", offsetof(struct timer *, system_timer));
279 DECLARE("TH_USER_TIMER", offsetof(struct timer *, user_timer));
280#endif
281
282 return (0);
283}
284
285
286/* Dummy to keep linker quiet */
287void
288kernel_preempt_check(void)
289{
290}