]>
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_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
59 #include <platforms.h>
61 #include <mach_ldebug.h>
62 #include <stat_time.h>
65 * Pass field offsets to assembly code.
68 #include <kern/thread.h>
69 #include <kern/task.h>
70 #include <kern/lock.h>
71 #include <kern/locks.h>
72 #include <ipc/ipc_space.h>
73 #include <ipc/ipc_port.h>
74 #include <ipc/ipc_pset.h>
75 #include <kern/host.h>
76 #include <kern/misc_protos.h>
77 #include <i386/thread.h>
78 #include <mach/i386/vm_param.h>
80 #include <i386/pmap.h>
82 #include <i386/cpu_capabilities.h>
83 #include <machine/commpage.h>
84 #include <vm/vm_map.h>
85 #include <i386/mp_desc.h>
86 #include <i386/cpuid.h>
87 #include <pexpert/i386/boot.h>
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.
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.
103 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
106 #define DECLARE(SYM,VAL) \
107 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
109 #define DECLARE(SYM,VAL) \
110 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
123 DECLARE("AST_URGENT", AST_URGENT
);
125 /* Simple Lock structure */
126 DECLARE("SLOCK_ILK", offsetof(usimple_lock_t
, interlock
));
128 DECLARE("SLOCK_TYPE", offsetof(usimple_lock_t
, lock_type
));
129 DECLARE("SLOCK_PC", offsetof(usimple_lock_t
, debug
.lock_pc
));
130 DECLARE("SLOCK_THREAD", offsetof(usimple_lock_t
, debug
.lock_thread
));
131 DECLARE("SLOCK_DURATIONH",offsetof(usimple_lock_t
, debug
.duration
[0]));
132 DECLARE("SLOCK_DURATIONL",offsetof(usimple_lock_t
, debug
.duration
[1]));
133 DECLARE("USLOCK_TAG", USLOCK_TAG
);
134 #endif /* MACH_LDEBUG */
136 /* Mutex structure */
137 DECLARE("MUTEX_LOCKED", offsetof(mutex_t
*, lck_mtx
.lck_mtx_locked
));
138 DECLARE("MUTEX_WAITERS",offsetof(mutex_t
*, lck_mtx
.lck_mtx_waiters
));
139 DECLARE("MUTEX_PROMOTED_PRI",offsetof(mutex_t
*, lck_mtx
.lck_mtx_pri
));
141 DECLARE("MUTEX_TYPE", offsetof(mutex_t
*, type
));
142 DECLARE("MUTEX_PC", offsetof(mutex_t
*, pc
));
143 DECLARE("MUTEX_THREAD", offsetof(mutex_t
*, thread
));
144 DECLARE("MUTEX_TAG", MUTEX_TAG
);
145 #endif /* MACH_LDEBUG */
146 DECLARE("MUTEX_IND", LCK_MTX_TAG_INDIRECT
);
147 DECLARE("MUTEX_ITAG", offsetof(lck_mtx_t
*, lck_mtx_tag
));
148 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t
*, lck_mtx_ptr
));
150 DECLARE("TH_RECOVER", offsetof(thread_t
, recover
));
151 DECLARE("TH_CONTINUATION", offsetof(thread_t
, continuation
));
152 DECLARE("TH_KERNEL_STACK", offsetof(thread_t
, kernel_stack
));
154 DECLARE("TASK_MACH_EXC_PORT",
155 offsetof(task_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
157 /* These fields are being added on demand */
158 DECLARE("ACT_MACH_EXC_PORT",
159 offsetof(thread_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
161 DECLARE("ACT_TASK", offsetof(thread_t
, task
));
162 DECLARE("ACT_PCB", offsetof(thread_t
, machine
.pcb
));
163 DECLARE("ACT_MAP", offsetof(thread_t
, map
));
165 DECLARE("MAP_PMAP", offsetof(vm_map_t
, pmap
));
167 #define IKS ((size_t) (STACK_IKS(0)))
169 DECLARE("KSS_EBX", IKS
+ offsetof(struct i386_kernel_state
*, k_ebx
));
170 DECLARE("KSS_ESP", IKS
+ offsetof(struct i386_kernel_state
*, k_esp
));
171 DECLARE("KSS_EBP", IKS
+ offsetof(struct i386_kernel_state
*, k_ebp
));
172 DECLARE("KSS_EDI", IKS
+ offsetof(struct i386_kernel_state
*, k_edi
));
173 DECLARE("KSS_ESI", IKS
+ offsetof(struct i386_kernel_state
*, k_esi
));
174 DECLARE("KSS_EIP", IKS
+ offsetof(struct i386_kernel_state
*, k_eip
));
176 DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state
));
177 DECLARE("IEL_SIZE", sizeof(struct i386_exception_link
));
179 DECLARE("PCB_FPS", offsetof(pcb_t
, ims
.ifps
));
180 DECLARE("PCB_ISS", offsetof(pcb_t
, iss
));
182 DECLARE("FP_VALID", offsetof(struct i386_fpsave_state
*,fp_valid
));
183 DECLARE("FP_SAVE_STATE",
184 offsetof(struct i386_fpsave_state
*, fp_save_state
));
186 DECLARE("R_CS", offsetof(struct i386_saved_state
*, cs
));
187 DECLARE("R_SS", offsetof(struct i386_saved_state
*, ss
));
188 DECLARE("R_UESP", offsetof(struct i386_saved_state
*, uesp
));
189 DECLARE("R_EBP", offsetof(struct i386_saved_state
*, ebp
));
190 DECLARE("R_EAX", offsetof(struct i386_saved_state
*, eax
));
191 DECLARE("R_EBX", offsetof(struct i386_saved_state
*, ebx
));
192 DECLARE("R_ECX", offsetof(struct i386_saved_state
*, ecx
));
193 DECLARE("R_EDX", offsetof(struct i386_saved_state
*, edx
));
194 DECLARE("R_ESI", offsetof(struct i386_saved_state
*, esi
));
195 DECLARE("R_EDI", offsetof(struct i386_saved_state
*, edi
));
196 DECLARE("R_TRAPNO", offsetof(struct i386_saved_state
*, trapno
));
197 DECLARE("R_ERR", offsetof(struct i386_saved_state
*, err
));
198 DECLARE("R_EFLAGS", offsetof(struct i386_saved_state
*, efl
));
199 DECLARE("R_EIP", offsetof(struct i386_saved_state
*, eip
));
200 DECLARE("R_CR2", offsetof(struct i386_saved_state
*, cr2
));
201 DECLARE("ISS_SIZE", sizeof (struct i386_saved_state
));
203 DECLARE("I_ECX", offsetof(struct i386_interrupt_state
*, ecx
));
204 DECLARE("I_EIP", offsetof(struct i386_interrupt_state
*, eip
));
205 DECLARE("I_CS", offsetof(struct i386_interrupt_state
*, cs
));
206 DECLARE("I_EFL", offsetof(struct i386_interrupt_state
*, efl
));
208 DECLARE("NBPG", I386_PGBYTES
);
209 DECLARE("PAGE_SIZE", I386_PGBYTES
);
210 DECLARE("PAGE_MASK", I386_PGBYTES
-1);
211 DECLARE("PAGE_SHIFT", 12);
212 DECLARE("NKPT", NKPT
);
213 DECLARE("KPTDI", KPTDI
);
214 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS
);
215 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS
);
216 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS
);
217 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS
);
218 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE
);
220 DECLARE("COMM_PAGE_BASE_ADDR", _COMM_PAGE_BASE_ADDRESS
);
222 DECLARE("PDESHIFT", PDESHIFT
);
223 DECLARE("PTEMASK", PTEMASK
);
224 DECLARE("PTEINDX", PTEINDX
);
225 DECLARE("PTE_PFN", INTEL_PTE_PFN
);
226 DECLARE("PTE_V", INTEL_PTE_VALID
);
227 DECLARE("PTE_W", INTEL_PTE_WRITE
);
228 DECLARE("PTE_PS", INTEL_PTE_PS
);
229 DECLARE("PTE_U", INTEL_PTE_USER
);
230 DECLARE("PTE_INVALID", ~INTEL_PTE_VALID
);
231 DECLARE("CR4_PAE", CR4_PAE
);
232 DECLARE("NPGPTD", NPGPTD
);
234 DECLARE("IDTSZ", IDTSZ
);
235 DECLARE("GDTSZ", GDTSZ
);
236 DECLARE("LDTSZ", LDTSZ
);
238 DECLARE("KERNEL_CS", KERNEL_CS
);
239 DECLARE("KERNEL_DS", KERNEL_DS
);
240 DECLARE("USER_CS", USER_CS
);
241 DECLARE("USER_DS", USER_DS
);
242 DECLARE("KERNEL_TSS", KERNEL_TSS
);
243 DECLARE("KERNEL_LDT", KERNEL_LDT
);
245 DECLARE("DEBUG_TSS", DEBUG_TSS
);
246 #endif /* MACH_KDB */
247 DECLARE("CPU_DATA_GS", CPU_DATA_GS
);
250 offsetof(cpu_data_t
*, cpu_this
));
251 DECLARE("CPU_ACTIVE_THREAD",
252 offsetof(cpu_data_t
*, cpu_active_thread
));
253 DECLARE("CPU_ACTIVE_KLOADED",
254 offsetof(cpu_data_t
*, cpu_active_kloaded
));
255 DECLARE("CPU_ACTIVE_STACK",
256 offsetof(cpu_data_t
*, cpu_active_stack
));
257 DECLARE("CPU_KERNEL_STACK",
258 offsetof(cpu_data_t
*, cpu_kernel_stack
));
259 DECLARE("CPU_INT_STACK_TOP",
260 offsetof(cpu_data_t
*, cpu_int_stack_top
));
262 DECLARE("CPU_PREEMPTION_LEVEL",
263 offsetof(cpu_data_t
*, cpu_preemption_level
));
265 DECLARE("CPU_INTERRUPT_LEVEL",
266 offsetof(cpu_data_t
*, cpu_interrupt_level
));
267 DECLARE("CPU_SIMPLE_LOCK_COUNT",
268 offsetof(cpu_data_t
*,cpu_simple_lock_count
));
269 DECLARE("CPU_NUMBER_GS",
270 offsetof(cpu_data_t
*,cpu_number
));
271 DECLARE("CPU_RUNNING",
272 offsetof(cpu_data_t
*,cpu_running
));
273 DECLARE("CPU_MCOUNT_OFF",
274 offsetof(cpu_data_t
*,cpu_mcount_off
));
275 DECLARE("CPU_PENDING_AST",
276 offsetof(cpu_data_t
*,cpu_pending_ast
));
277 DECLARE("CPU_DESC_TABLEP",
278 offsetof(cpu_data_t
*,cpu_desc_tablep
));
279 DECLARE("CPU_PROCESSOR",
280 offsetof(cpu_data_t
*,cpu_processor
));
281 DECLARE("CPU_RTC_NANOTIME",
282 offsetof(cpu_data_t
*,cpu_rtc_nanotime
));
284 DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID
|INTEL_PTE_WRITE
);
285 DECLARE("PTDPTDI", PTDPTDI
);
286 DECLARE("PDESHIFT", PDESHIFT
);
287 DECLARE("PDESIZE", PDESIZE
);
288 DECLARE("PTESIZE", PTESIZE
);
289 DECLARE("APTDPTDI", APTDPTDI
);
291 DECLARE("KERNELBASEPDE",
292 (LINEAR_KERNEL_ADDRESS
>> PDESHIFT
) *
295 DECLARE("TSS_ESP0", offsetof(struct i386_tss
*, esp0
));
296 DECLARE("TSS_SS0", offsetof(struct i386_tss
*, ss0
));
297 DECLARE("TSS_LDT", offsetof(struct i386_tss
*, ldt
));
298 DECLARE("TSS_PDBR", offsetof(struct i386_tss
*, cr3
));
299 DECLARE("TSS_LINK", offsetof(struct i386_tss
*, back_link
));
301 DECLARE("K_TASK_GATE", ACC_P
|ACC_PL_K
|ACC_TASK_GATE
);
302 DECLARE("K_TRAP_GATE", ACC_P
|ACC_PL_K
|ACC_TRAP_GATE
);
303 DECLARE("U_TRAP_GATE", ACC_P
|ACC_PL_U
|ACC_TRAP_GATE
);
304 DECLARE("K_INTR_GATE", ACC_P
|ACC_PL_K
|ACC_INTR_GATE
);
305 DECLARE("K_TSS", ACC_P
|ACC_PL_K
|ACC_TSS
);
308 * usimple_lock fields
310 DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t
, interlock
));
312 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE
);
313 DECLARE("MP_GDT", offsetof(struct mp_desc_table
*, gdt
[0]));
314 DECLARE("MP_IDT", offsetof(struct mp_desc_table
*, idt
[0]));
315 DECLARE("TIMER_LOW", offsetof(struct timer
*, low_bits
));
316 DECLARE("TIMER_HIGH", offsetof(struct timer
*, high_bits
));
317 DECLARE("TIMER_HIGHCHK", offsetof(struct timer
*, high_bits_check
));
318 DECLARE("KADDR", offsetof(struct KernelBootArgs
*, kaddr
));
319 DECLARE("KSIZE", offsetof(struct KernelBootArgs
*, ksize
));
321 DECLARE("NANOTIME_BASE_TSC",
322 offsetof(commpage_nanotime_t
*, nt_base_tsc
));
323 DECLARE("NANOTIME_BASE_NS",
324 offsetof(commpage_nanotime_t
*, nt_base_ns
));
325 DECLARE("NANOTIME_SCALE",
326 offsetof(commpage_nanotime_t
*, nt_scale
));
327 DECLARE("NANOTIME_SHIFT",
328 offsetof(commpage_nanotime_t
*, nt_shift
));
329 DECLARE("NANOTIME_CHECK_TSC",
330 offsetof(commpage_nanotime_t
*, nt_check_tsc
));
333 offsetof(rtc_nanotime_t
*, rnt_tsc
));
335 offsetof(rtc_nanotime_t
*, rnt_nanos
));
337 offsetof(rtc_nanotime_t
*, rnt_scale
));
339 offsetof(rtc_nanotime_t
*, rnt_shift
));
341 /* values from kern/timer.h */
343 offsetof(struct timer
*, low_bits
));
344 DECLARE("TIMER_HIGH",
345 offsetof(struct timer
*, high_bits
));
346 DECLARE("TIMER_HIGHCHK",
347 offsetof(struct timer
*, high_bits_check
));
349 DECLARE("TIMER_TSTAMP",
350 offsetof(struct timer
*, tstamp
));
352 DECLARE("CURRENT_TIMER",
353 offsetof(struct processor
*, processor_data
.current_timer
));
355 DECLARE("SYSTEM_TIMER",
356 offsetof(struct thread
*, system_timer
));
357 DECLARE("USER_TIMER",
358 offsetof(struct thread
*, user_timer
));