]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/genassym.c
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
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.
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.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
54 #include <platforms.h>
57 #include <mach_ldebug.h>
58 #include <stat_time.h>
61 * Pass field offsets to assembly code.
64 #include <kern/thread.h>
65 #include <kern/task.h>
66 #include <kern/lock.h>
67 #include <kern/thread_act.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_emulation.h>
74 #include <i386/thread.h>
75 #include <mach/i386/vm_param.h>
77 #include <i386/pmap.h>
79 #include <vm/vm_map.h>
81 #include <i386/mp_desc.h>
84 extern void kernel_preempt_check(void);
85 cpu_data_t cpu_data
[NCPUS
];
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.
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.
101 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
104 #define DECLARE(SYM,VAL) \
105 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
107 #define DECLARE(SYM,VAL) \
108 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
121 DECLARE("AST_URGENT", AST_URGENT
);
123 /* Simple Lock structure */
124 DECLARE("SLOCK_ILK", offsetof(usimple_lock_t
, interlock
));
126 DECLARE("SLOCK_TYPE", offsetof(usimple_lock_t
, lock_type
));
127 DECLARE("SLOCK_PC", offsetof(usimple_lock_t
, debug
.lock_pc
));
128 DECLARE("SLOCK_THREAD", offsetof(usimple_lock_t
, debug
.lock_thread
));
129 DECLARE("SLOCK_DURATIONH",offsetof(usimple_lock_t
, debug
.duration
[0]));
130 DECLARE("SLOCK_DURATIONL",offsetof(usimple_lock_t
, debug
.duration
[1]));
131 DECLARE("USLOCK_TAG", USLOCK_TAG
);
132 #endif /* MACH_LDEBUG */
134 /* Mutex structure */
135 DECLARE("MUTEX_LOCKED", offsetof(mutex_t
*, locked
));
136 DECLARE("MUTEX_WAITERS",offsetof(mutex_t
*, waiters
));
137 DECLARE("MUTEX_PROMOTED_PRI",offsetof(mutex_t
*, promoted_pri
));
139 DECLARE("MUTEX_TYPE", offsetof(mutex_t
*, type
));
140 DECLARE("MUTEX_PC", offsetof(mutex_t
*, pc
));
141 DECLARE("MUTEX_THREAD", offsetof(mutex_t
*, thread
));
142 DECLARE("MUTEX_TAG", MUTEX_TAG
);
143 #endif /* MACH_LDEBUG */
146 DECLARE("TH_MUTEX_COUNT", offsetof(thread_t
, mutex_count
));
147 #endif /* MACH_LDEBUG */
148 DECLARE("TH_RECOVER", offsetof(thread_t
, recover
));
149 DECLARE("TH_CONTINUATION", offsetof(thread_t
, continuation
));
150 DECLARE("TH_TOP_ACT", offsetof(thread_t
, top_act
));
151 DECLARE("TH_KERNEL_STACK", offsetof(thread_t
, kernel_stack
));
153 DECLARE("TASK_EMUL", offsetof(task_t
, eml_dispatch
));
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_act_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
161 DECLARE("ACT_THREAD", offsetof(thread_act_t
, thread
));
162 DECLARE("ACT_TASK", offsetof(thread_act_t
, task
));
163 DECLARE("ACT_PCB", offsetof(thread_act_t
, mact
.pcb
));
164 DECLARE("ACT_LOWER", offsetof(thread_act_t
, lower
));
165 DECLARE("ACT_MAP", offsetof(thread_act_t
, map
));
167 DECLARE("MAP_PMAP", offsetof(vm_map_t
, pmap
));
169 DECLARE("DISP_MIN", offsetof(eml_dispatch_t
, disp_min
));
170 DECLARE("DISP_COUNT", offsetof(eml_dispatch_t
, disp_count
));
171 DECLARE("DISP_VECTOR", offsetof(eml_dispatch_t
, disp_vector
[0]));
173 #define IKS ((size_t) (STACK_IKS(0)))
175 DECLARE("KSS_EBX", IKS
+ offsetof(struct i386_kernel_state
*, k_ebx
));
176 DECLARE("KSS_ESP", IKS
+ offsetof(struct i386_kernel_state
*, k_esp
));
177 DECLARE("KSS_EBP", IKS
+ offsetof(struct i386_kernel_state
*, k_ebp
));
178 DECLARE("KSS_EDI", IKS
+ offsetof(struct i386_kernel_state
*, k_edi
));
179 DECLARE("KSS_ESI", IKS
+ offsetof(struct i386_kernel_state
*, k_esi
));
180 DECLARE("KSS_EIP", IKS
+ offsetof(struct i386_kernel_state
*, k_eip
));
182 DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state
));
183 DECLARE("IEL_SIZE", sizeof(struct i386_exception_link
));
185 DECLARE("PCB_FPS", offsetof(pcb_t
, ims
.ifps
));
186 DECLARE("PCB_ISS", offsetof(pcb_t
, iss
));
188 DECLARE("FP_VALID", offsetof(struct i386_fpsave_state
*,fp_valid
));
189 DECLARE("FP_SAVE_STATE",
190 offsetof(struct i386_fpsave_state
*, fp_save_state
));
192 DECLARE("R_CS", offsetof(struct i386_saved_state
*, cs
));
193 DECLARE("R_SS", offsetof(struct i386_saved_state
*, ss
));
194 DECLARE("R_UESP", offsetof(struct i386_saved_state
*, uesp
));
195 DECLARE("R_EBP", offsetof(struct i386_saved_state
*, ebp
));
196 DECLARE("R_EAX", offsetof(struct i386_saved_state
*, eax
));
197 DECLARE("R_EBX", offsetof(struct i386_saved_state
*, ebx
));
198 DECLARE("R_ECX", offsetof(struct i386_saved_state
*, ecx
));
199 DECLARE("R_EDX", offsetof(struct i386_saved_state
*, edx
));
200 DECLARE("R_ESI", offsetof(struct i386_saved_state
*, esi
));
201 DECLARE("R_EDI", offsetof(struct i386_saved_state
*, edi
));
202 DECLARE("R_TRAPNO", offsetof(struct i386_saved_state
*, trapno
));
203 DECLARE("R_ERR", offsetof(struct i386_saved_state
*, err
));
204 DECLARE("R_EFLAGS", offsetof(struct i386_saved_state
*, efl
));
205 DECLARE("R_EIP", offsetof(struct i386_saved_state
*, eip
));
206 DECLARE("R_CR2", offsetof(struct i386_saved_state
*, cr2
));
207 DECLARE("ISS_SIZE", sizeof (struct i386_saved_state
));
209 DECLARE("I_ECX", offsetof(struct i386_interrupt_state
*, ecx
));
210 DECLARE("I_EIP", offsetof(struct i386_interrupt_state
*, eip
));
211 DECLARE("I_CS", offsetof(struct i386_interrupt_state
*, cs
));
212 DECLARE("I_EFL", offsetof(struct i386_interrupt_state
*, efl
));
214 DECLARE("NBPG", I386_PGBYTES
);
215 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS
);
216 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS
);
217 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS
);
218 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS
);
219 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE
);
221 DECLARE("PDESHIFT", PDESHIFT
);
222 DECLARE("PTESHIFT", PTESHIFT
);
223 DECLARE("PTEMASK", PTEMASK
);
225 DECLARE("PTE_PFN", INTEL_PTE_PFN
);
226 DECLARE("PTE_V", INTEL_PTE_VALID
);
227 DECLARE("PTE_W", INTEL_PTE_WRITE
);
228 DECLARE("PTE_INVALID", ~INTEL_PTE_VALID
);
230 DECLARE("IDTSZ", IDTSZ
);
231 DECLARE("GDTSZ", GDTSZ
);
232 DECLARE("LDTSZ", LDTSZ
);
234 DECLARE("KERNEL_CS", KERNEL_CS
);
235 DECLARE("KERNEL_DS", KERNEL_DS
);
236 DECLARE("USER_CS", USER_CS
);
237 DECLARE("USER_DS", USER_DS
);
238 DECLARE("KERNEL_TSS", KERNEL_TSS
);
239 DECLARE("KERNEL_LDT", KERNEL_LDT
);
241 DECLARE("DEBUG_TSS", DEBUG_TSS
);
242 #endif /* MACH_KDB */
244 DECLARE("CPU_DATA", CPU_DATA
);
245 DECLARE("CPD_ACTIVE_THREAD",
246 offsetof(cpu_data_t
*, active_thread
));
248 DECLARE("CPD_PREEMPTION_LEVEL",
249 offsetof(cpu_data_t
*, preemption_level
));
251 DECLARE("CPD_INTERRUPT_LEVEL",
252 offsetof(cpu_data_t
*, interrupt_level
));
253 DECLARE("CPD_SIMPLE_LOCK_COUNT",
254 offsetof(cpu_data_t
*,simple_lock_count
));
255 DECLARE("CPD_CPU_NUMBER",
256 offsetof(cpu_data_t
*,cpu_number
));
257 DECLARE("CPD_CPU_PHYS_NUMBER",
258 offsetof(cpu_data_t
*,cpu_phys_number
));
259 DECLARE("CPD_CPU_STATUS",
260 offsetof(cpu_data_t
*,cpu_status
));
261 DECLARE("CPD_MCOUNT_OFF",
262 offsetof(cpu_data_t
*,mcount_off
));
264 DECLARE("PTES_PER_PAGE", NPTES
);
265 DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID
|INTEL_PTE_WRITE
);
267 DECLARE("KERNELBASEPDE",
268 (LINEAR_KERNEL_ADDRESS
>> PDESHIFT
) *
271 DECLARE("TSS_ESP0", offsetof(struct i386_tss
*, esp0
));
272 DECLARE("TSS_SS0", offsetof(struct i386_tss
*, ss0
));
273 DECLARE("TSS_LDT", offsetof(struct i386_tss
*, ldt
));
274 DECLARE("TSS_PDBR", offsetof(struct i386_tss
*, cr3
));
275 DECLARE("TSS_LINK", offsetof(struct i386_tss
*, back_link
));
277 DECLARE("K_TASK_GATE", ACC_P
|ACC_PL_K
|ACC_TASK_GATE
);
278 DECLARE("K_TRAP_GATE", ACC_P
|ACC_PL_K
|ACC_TRAP_GATE
);
279 DECLARE("U_TRAP_GATE", ACC_P
|ACC_PL_U
|ACC_TRAP_GATE
);
280 DECLARE("K_INTR_GATE", ACC_P
|ACC_PL_K
|ACC_INTR_GATE
);
281 DECLARE("K_TSS", ACC_P
|ACC_PL_K
|ACC_TSS
);
284 * usimple_lock fields
286 DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t
, interlock
));
288 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE
);
290 DECLARE("MP_GDT", offsetof(struct mp_desc_table
*, gdt
[0]));
291 DECLARE("MP_IDT", offsetof(struct mp_desc_table
*, idt
[0]));
292 #endif /* NCPUS > 1 */
294 DECLARE("LOW_BITS", offsetof(struct timer
*, low_bits
));
295 DECLARE("HIGH_BITS", offsetof(struct timer
*, high_bits
));
296 DECLARE("HIGH_BITS_CHECK", offsetof(struct timer
*, high_bits_check
));
297 DECLARE("TIMER_HIGH_UNIT", TIMER_HIGH_UNIT
);
298 DECLARE("TH_SYS_TIMER", offsetof(struct timer
*, system_timer
));
299 DECLARE("TH_USER_TIMER", offsetof(struct timer
*, user_timer
));
306 /* Dummy to keep linker quiet */
308 kernel_preempt_check(void)