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