]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/genassym.c
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
51 #include <platforms.h>
53 #include <mach_ldebug.h>
54 #include <stat_time.h>
57 * Pass field offsets to assembly code.
60 #include <kern/thread.h>
61 #include <kern/task.h>
62 #include <kern/lock.h>
63 #include <kern/locks.h>
64 #include <ipc/ipc_space.h>
65 #include <ipc/ipc_port.h>
66 #include <ipc/ipc_pset.h>
67 #include <kern/host.h>
68 #include <kern/misc_protos.h>
69 #include <i386/thread.h>
70 #include <mach/i386/vm_param.h>
72 #include <i386/pmap.h>
74 #include <i386/cpu_capabilities.h>
75 #include <machine/commpage.h>
76 #include <vm/vm_map.h>
77 #include <i386/mp_desc.h>
78 #include <i386/cpuid.h>
79 #include <pexpert/i386/boot.h>
82 * genassym.c is used to produce an
83 * assembly file which, intermingled with unuseful assembly code,
84 * has all the necessary definitions emitted. This assembly file is
85 * then postprocessed with sed to extract only these definitions
86 * and thus the final assyms.s is created.
88 * This convoluted means is necessary since the structure alignment
89 * and packing may be different between the host machine and the
90 * target so we are forced into using the cross compiler to generate
91 * the values, but we cannot run anything on the target machine.
95 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
98 #define DECLARE(SYM,VAL) \
99 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
101 #define DECLARE(SYM,VAL) \
102 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
115 DECLARE("AST_URGENT", AST_URGENT
);
117 /* Simple Lock structure */
118 DECLARE("SLOCK_ILK", offsetof(usimple_lock_t
, interlock
));
120 DECLARE("SLOCK_TYPE", offsetof(usimple_lock_t
, lock_type
));
121 DECLARE("SLOCK_PC", offsetof(usimple_lock_t
, debug
.lock_pc
));
122 DECLARE("SLOCK_THREAD", offsetof(usimple_lock_t
, debug
.lock_thread
));
123 DECLARE("SLOCK_DURATIONH",offsetof(usimple_lock_t
, debug
.duration
[0]));
124 DECLARE("SLOCK_DURATIONL",offsetof(usimple_lock_t
, debug
.duration
[1]));
125 DECLARE("USLOCK_TAG", USLOCK_TAG
);
126 #endif /* MACH_LDEBUG */
128 /* Mutex structure */
129 DECLARE("MUTEX_LOCKED", offsetof(mutex_t
*, lck_mtx
.lck_mtx_locked
));
130 DECLARE("MUTEX_WAITERS",offsetof(mutex_t
*, lck_mtx
.lck_mtx_waiters
));
131 DECLARE("MUTEX_PROMOTED_PRI",offsetof(mutex_t
*, lck_mtx
.lck_mtx_pri
));
133 DECLARE("MUTEX_TYPE", offsetof(mutex_t
*, type
));
134 DECLARE("MUTEX_PC", offsetof(mutex_t
*, pc
));
135 DECLARE("MUTEX_THREAD", offsetof(mutex_t
*, thread
));
136 DECLARE("MUTEX_TAG", MUTEX_TAG
);
137 #endif /* MACH_LDEBUG */
138 DECLARE("MUTEX_IND", LCK_MTX_TAG_INDIRECT
);
139 DECLARE("MUTEX_ITAG", offsetof(lck_mtx_t
*, lck_mtx_tag
));
140 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t
*, lck_mtx_ptr
));
142 DECLARE("TH_RECOVER", offsetof(thread_t
, recover
));
143 DECLARE("TH_CONTINUATION", offsetof(thread_t
, continuation
));
144 DECLARE("TH_KERNEL_STACK", offsetof(thread_t
, kernel_stack
));
146 DECLARE("TASK_MACH_EXC_PORT",
147 offsetof(task_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
149 /* These fields are being added on demand */
150 DECLARE("ACT_MACH_EXC_PORT",
151 offsetof(thread_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
153 DECLARE("ACT_TASK", offsetof(thread_t
, task
));
154 DECLARE("ACT_PCB", offsetof(thread_t
, machine
.pcb
));
155 DECLARE("ACT_MAP", offsetof(thread_t
, map
));
157 DECLARE("MAP_PMAP", offsetof(vm_map_t
, pmap
));
159 #define IKS ((size_t) (STACK_IKS(0)))
161 DECLARE("KSS_EBX", IKS
+ offsetof(struct i386_kernel_state
*, k_ebx
));
162 DECLARE("KSS_ESP", IKS
+ offsetof(struct i386_kernel_state
*, k_esp
));
163 DECLARE("KSS_EBP", IKS
+ offsetof(struct i386_kernel_state
*, k_ebp
));
164 DECLARE("KSS_EDI", IKS
+ offsetof(struct i386_kernel_state
*, k_edi
));
165 DECLARE("KSS_ESI", IKS
+ offsetof(struct i386_kernel_state
*, k_esi
));
166 DECLARE("KSS_EIP", IKS
+ offsetof(struct i386_kernel_state
*, k_eip
));
168 DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state
));
169 DECLARE("IEL_SIZE", sizeof(struct i386_exception_link
));
171 DECLARE("PCB_FPS", offsetof(pcb_t
, ims
.ifps
));
172 DECLARE("PCB_ISS", offsetof(pcb_t
, iss
));
174 DECLARE("FP_VALID", offsetof(struct i386_fpsave_state
*,fp_valid
));
175 DECLARE("FP_SAVE_STATE",
176 offsetof(struct i386_fpsave_state
*, fp_save_state
));
178 DECLARE("R_CS", offsetof(struct i386_saved_state
*, cs
));
179 DECLARE("R_SS", offsetof(struct i386_saved_state
*, ss
));
180 DECLARE("R_UESP", offsetof(struct i386_saved_state
*, uesp
));
181 DECLARE("R_EBP", offsetof(struct i386_saved_state
*, ebp
));
182 DECLARE("R_EAX", offsetof(struct i386_saved_state
*, eax
));
183 DECLARE("R_EBX", offsetof(struct i386_saved_state
*, ebx
));
184 DECLARE("R_ECX", offsetof(struct i386_saved_state
*, ecx
));
185 DECLARE("R_EDX", offsetof(struct i386_saved_state
*, edx
));
186 DECLARE("R_ESI", offsetof(struct i386_saved_state
*, esi
));
187 DECLARE("R_EDI", offsetof(struct i386_saved_state
*, edi
));
188 DECLARE("R_TRAPNO", offsetof(struct i386_saved_state
*, trapno
));
189 DECLARE("R_ERR", offsetof(struct i386_saved_state
*, err
));
190 DECLARE("R_EFLAGS", offsetof(struct i386_saved_state
*, efl
));
191 DECLARE("R_EIP", offsetof(struct i386_saved_state
*, eip
));
192 DECLARE("R_CR2", offsetof(struct i386_saved_state
*, cr2
));
193 DECLARE("ISS_SIZE", sizeof (struct i386_saved_state
));
195 DECLARE("I_ECX", offsetof(struct i386_interrupt_state
*, ecx
));
196 DECLARE("I_EIP", offsetof(struct i386_interrupt_state
*, eip
));
197 DECLARE("I_CS", offsetof(struct i386_interrupt_state
*, cs
));
198 DECLARE("I_EFL", offsetof(struct i386_interrupt_state
*, efl
));
200 DECLARE("NBPG", I386_PGBYTES
);
201 DECLARE("PAGE_SIZE", I386_PGBYTES
);
202 DECLARE("PAGE_MASK", I386_PGBYTES
-1);
203 DECLARE("PAGE_SHIFT", 12);
204 DECLARE("NKPT", NKPT
);
205 DECLARE("KPTDI", KPTDI
);
206 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS
);
207 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS
);
208 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS
);
209 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS
);
210 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE
);
212 DECLARE("COMM_PAGE_BASE_ADDR", _COMM_PAGE_BASE_ADDRESS
);
214 DECLARE("PDESHIFT", PDESHIFT
);
215 DECLARE("PTEMASK", PTEMASK
);
216 DECLARE("PTEINDX", PTEINDX
);
217 DECLARE("PTE_PFN", INTEL_PTE_PFN
);
218 DECLARE("PTE_V", INTEL_PTE_VALID
);
219 DECLARE("PTE_W", INTEL_PTE_WRITE
);
220 DECLARE("PTE_PS", INTEL_PTE_PS
);
221 DECLARE("PTE_U", INTEL_PTE_USER
);
222 DECLARE("PTE_INVALID", ~INTEL_PTE_VALID
);
223 DECLARE("CR4_PAE", CR4_PAE
);
224 DECLARE("NPGPTD", NPGPTD
);
226 DECLARE("IDTSZ", IDTSZ
);
227 DECLARE("GDTSZ", GDTSZ
);
228 DECLARE("LDTSZ", LDTSZ
);
230 DECLARE("KERNEL_CS", KERNEL_CS
);
231 DECLARE("KERNEL_DS", KERNEL_DS
);
232 DECLARE("USER_CS", USER_CS
);
233 DECLARE("USER_DS", USER_DS
);
234 DECLARE("KERNEL_TSS", KERNEL_TSS
);
235 DECLARE("KERNEL_LDT", KERNEL_LDT
);
237 DECLARE("DEBUG_TSS", DEBUG_TSS
);
238 #endif /* MACH_KDB */
239 DECLARE("CPU_DATA_GS", CPU_DATA_GS
);
242 offsetof(cpu_data_t
*, cpu_this
));
243 DECLARE("CPU_ACTIVE_THREAD",
244 offsetof(cpu_data_t
*, cpu_active_thread
));
245 DECLARE("CPU_ACTIVE_KLOADED",
246 offsetof(cpu_data_t
*, cpu_active_kloaded
));
247 DECLARE("CPU_ACTIVE_STACK",
248 offsetof(cpu_data_t
*, cpu_active_stack
));
249 DECLARE("CPU_KERNEL_STACK",
250 offsetof(cpu_data_t
*, cpu_kernel_stack
));
251 DECLARE("CPU_INT_STACK_TOP",
252 offsetof(cpu_data_t
*, cpu_int_stack_top
));
254 DECLARE("CPU_PREEMPTION_LEVEL",
255 offsetof(cpu_data_t
*, cpu_preemption_level
));
257 DECLARE("CPU_INTERRUPT_LEVEL",
258 offsetof(cpu_data_t
*, cpu_interrupt_level
));
259 DECLARE("CPU_SIMPLE_LOCK_COUNT",
260 offsetof(cpu_data_t
*,cpu_simple_lock_count
));
261 DECLARE("CPU_NUMBER_GS",
262 offsetof(cpu_data_t
*,cpu_number
));
263 DECLARE("CPU_RUNNING",
264 offsetof(cpu_data_t
*,cpu_running
));
265 DECLARE("CPU_MCOUNT_OFF",
266 offsetof(cpu_data_t
*,cpu_mcount_off
));
267 DECLARE("CPU_PENDING_AST",
268 offsetof(cpu_data_t
*,cpu_pending_ast
));
269 DECLARE("CPU_DESC_TABLEP",
270 offsetof(cpu_data_t
*,cpu_desc_tablep
));
271 DECLARE("CPU_PROCESSOR",
272 offsetof(cpu_data_t
*,cpu_processor
));
273 DECLARE("CPU_RTC_NANOTIME",
274 offsetof(cpu_data_t
*,cpu_rtc_nanotime
));
276 DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID
|INTEL_PTE_WRITE
);
277 DECLARE("PTDPTDI", PTDPTDI
);
278 DECLARE("PDESHIFT", PDESHIFT
);
279 DECLARE("PDESIZE", PDESIZE
);
280 DECLARE("PTESIZE", PTESIZE
);
281 DECLARE("APTDPTDI", APTDPTDI
);
283 DECLARE("KERNELBASEPDE",
284 (LINEAR_KERNEL_ADDRESS
>> PDESHIFT
) *
287 DECLARE("TSS_ESP0", offsetof(struct i386_tss
*, esp0
));
288 DECLARE("TSS_SS0", offsetof(struct i386_tss
*, ss0
));
289 DECLARE("TSS_LDT", offsetof(struct i386_tss
*, ldt
));
290 DECLARE("TSS_PDBR", offsetof(struct i386_tss
*, cr3
));
291 DECLARE("TSS_LINK", offsetof(struct i386_tss
*, back_link
));
293 DECLARE("K_TASK_GATE", ACC_P
|ACC_PL_K
|ACC_TASK_GATE
);
294 DECLARE("K_TRAP_GATE", ACC_P
|ACC_PL_K
|ACC_TRAP_GATE
);
295 DECLARE("U_TRAP_GATE", ACC_P
|ACC_PL_U
|ACC_TRAP_GATE
);
296 DECLARE("K_INTR_GATE", ACC_P
|ACC_PL_K
|ACC_INTR_GATE
);
297 DECLARE("K_TSS", ACC_P
|ACC_PL_K
|ACC_TSS
);
300 * usimple_lock fields
302 DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t
, interlock
));
304 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE
);
305 DECLARE("MP_GDT", offsetof(struct mp_desc_table
*, gdt
[0]));
306 DECLARE("MP_IDT", offsetof(struct mp_desc_table
*, idt
[0]));
307 DECLARE("TIMER_LOW", offsetof(struct timer
*, low_bits
));
308 DECLARE("TIMER_HIGH", offsetof(struct timer
*, high_bits
));
309 DECLARE("TIMER_HIGHCHK", offsetof(struct timer
*, high_bits_check
));
310 DECLARE("KADDR", offsetof(struct KernelBootArgs
*, kaddr
));
311 DECLARE("KSIZE", offsetof(struct KernelBootArgs
*, ksize
));
313 DECLARE("NANOTIME_BASE_TSC",
314 offsetof(commpage_nanotime_t
*, nt_base_tsc
));
315 DECLARE("NANOTIME_BASE_NS",
316 offsetof(commpage_nanotime_t
*, nt_base_ns
));
317 DECLARE("NANOTIME_SCALE",
318 offsetof(commpage_nanotime_t
*, nt_scale
));
319 DECLARE("NANOTIME_SHIFT",
320 offsetof(commpage_nanotime_t
*, nt_shift
));
321 DECLARE("NANOTIME_CHECK_TSC",
322 offsetof(commpage_nanotime_t
*, nt_check_tsc
));
325 offsetof(rtc_nanotime_t
*, rnt_tsc
));
327 offsetof(rtc_nanotime_t
*, rnt_nanos
));
329 offsetof(rtc_nanotime_t
*, rnt_scale
));
331 offsetof(rtc_nanotime_t
*, rnt_shift
));
333 /* values from kern/timer.h */
335 offsetof(struct timer
*, low_bits
));
336 DECLARE("TIMER_HIGH",
337 offsetof(struct timer
*, high_bits
));
338 DECLARE("TIMER_HIGHCHK",
339 offsetof(struct timer
*, high_bits_check
));
341 DECLARE("TIMER_TSTAMP",
342 offsetof(struct timer
*, tstamp
));
344 DECLARE("CURRENT_TIMER",
345 offsetof(struct processor
*, processor_data
.current_timer
));
347 DECLARE("SYSTEM_TIMER",
348 offsetof(struct thread
*, system_timer
));
349 DECLARE("USER_TIMER",
350 offsetof(struct thread
*, user_timer
));