]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/genassym.c
2 * Copyright (c) 2000 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>
54 #include <mach_ldebug.h>
55 #include <stat_time.h>
58 * Pass field offsets to assembly code.
61 #include <kern/thread.h>
62 #include <kern/task.h>
63 #include <kern/lock.h>
64 #include <kern/thread_act.h>
65 #include <kern/thread_pool.h>
66 #include <ipc/ipc_space.h>
67 #include <ipc/ipc_port.h>
68 #include <ipc/ipc_pset.h>
69 #include <kern/host.h>
70 #include <kern/misc_protos.h>
71 #include <kern/syscall_emulation.h>
72 #include <i386/thread.h>
73 #include <mach/i386/vm_param.h>
75 #include <i386/pmap.h>
78 #include <vm/vm_map.h>
80 #include <i386/mp_desc.h>
83 extern void kernel_preempt_check(void);
84 cpu_data_t cpu_data
[NCPUS
];
87 * genassym.c is used to produce an
88 * assembly file which, intermingled with unuseful assembly code,
89 * has all the necessary definitions emitted. This assembly file is
90 * then postprocessed with sed to extract only these definitions
91 * and thus the final assyms.s is created.
93 * This convoluted means is necessary since the structure alignment
94 * and packing may be different between the host machine and the
95 * target so we are forced into using the cross compiler to generate
96 * the values, but we cannot run anything on the target machine.
99 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
102 #define DECLARE(SYM,VAL) \
103 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
105 #define DECLARE(SYM,VAL) \
106 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
119 DECLARE("AST_URGENT", AST_URGENT
);
125 #define SIMPLE_LOCK_TAG 0x5353
126 #define MUTEX_TAG 0x4d4d
127 DECLARE("TH_MUTEX_COUNT", offsetof(thread_t
, mutex_count
));
128 DECLARE("SIMPLE_LOCK_TAG", SIMPLE_LOCK_TAG
);
129 DECLARE("MUTEX_TAG", MUTEX_TAG
);
130 #endif /* MACH_LDEBUG */
131 DECLARE("TH_RECOVER", offsetof(thread_t
, recover
));
132 DECLARE("TH_CONTINUATION", offsetof(thread_t
, continuation
));
133 DECLARE("TH_TOP_ACT", offsetof(thread_t
, top_act
));
134 DECLARE("TH_KERNEL_STACK", offsetof(thread_t
, kernel_stack
));
136 DECLARE("TASK_EMUL", offsetof(task_t
, eml_dispatch
));
137 DECLARE("TASK_MACH_EXC_PORT",
138 offsetof(task_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
140 /* These fields are being added on demand */
141 DECLARE("ACT_MACH_EXC_PORT",
142 offsetof(thread_act_t
, exc_actions
[EXC_MACH_SYSCALL
].port
));
144 DECLARE("ACT_THREAD", offsetof(thread_act_t
, thread
));
145 DECLARE("ACT_TASK", offsetof(thread_act_t
, task
));
146 DECLARE("ACT_PCB", offsetof(thread_act_t
, mact
.pcb
));
147 DECLARE("ACT_KLOADED", offsetof(thread_act_t
, kernel_loaded
));
148 DECLARE("ACT_KLOADING", offsetof(thread_act_t
, kernel_loading
));
149 DECLARE("ACT_LOWER", offsetof(thread_act_t
, lower
));
150 DECLARE("ACT_MAP", offsetof(thread_act_t
, map
));
152 DECLARE("MAP_PMAP", offsetof(vm_map_t
, pmap
));
154 /* XXX Until rpc buffers move from kernel stack to activation */
155 DECLARE("RPC_CLIENT_BUF_SIZE",
156 2 * RPC_KBUF_SIZE
* sizeof(int) +
157 RPC_DESC_COUNT
* sizeof(rpc_copy_state_data_t
) +
160 DECLARE("HOST_NAME", offsetof(host_t
, host_self
));
162 DECLARE("DISP_MIN", offsetof(eml_dispatch_t
, disp_min
));
163 DECLARE("DISP_COUNT", offsetof(eml_dispatch_t
, disp_count
));
164 DECLARE("DISP_VECTOR", offsetof(eml_dispatch_t
, disp_vector
[0]));
166 #define IKS ((size_t) (STACK_IKS(0)))
168 DECLARE("KSS_EBX", IKS
+ offsetof(struct i386_kernel_state
*, k_ebx
));
169 DECLARE("KSS_ESP", IKS
+ offsetof(struct i386_kernel_state
*, k_esp
));
170 DECLARE("KSS_EBP", IKS
+ offsetof(struct i386_kernel_state
*, k_ebp
));
171 DECLARE("KSS_EDI", IKS
+ offsetof(struct i386_kernel_state
*, k_edi
));
172 DECLARE("KSS_ESI", IKS
+ offsetof(struct i386_kernel_state
*, k_esi
));
173 DECLARE("KSS_EIP", IKS
+ offsetof(struct i386_kernel_state
*, k_eip
));
175 DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state
));
176 DECLARE("IEL_SIZE", sizeof(struct i386_exception_link
));
178 DECLARE("PCB_FPS", offsetof(pcb_t
, ims
.ifps
));
179 DECLARE("PCB_ISS", offsetof(pcb_t
, iss
));
181 DECLARE("FP_VALID", offsetof(struct i386_fpsave_state
*,fp_valid
));
182 DECLARE("FP_SAVE_STATE",
183 offsetof(struct i386_fpsave_state
*, fp_save_state
));
185 DECLARE("R_CS", offsetof(struct i386_saved_state
*, cs
));
186 DECLARE("R_SS", offsetof(struct i386_saved_state
*, ss
));
187 DECLARE("R_UESP", offsetof(struct i386_saved_state
*, uesp
));
188 DECLARE("R_EBP", offsetof(struct i386_saved_state
*, ebp
));
189 DECLARE("R_EAX", offsetof(struct i386_saved_state
*, eax
));
190 DECLARE("R_EBX", offsetof(struct i386_saved_state
*, ebx
));
191 DECLARE("R_ECX", offsetof(struct i386_saved_state
*, ecx
));
192 DECLARE("R_EDX", offsetof(struct i386_saved_state
*, edx
));
193 DECLARE("R_ESI", offsetof(struct i386_saved_state
*, esi
));
194 DECLARE("R_EDI", offsetof(struct i386_saved_state
*, edi
));
195 DECLARE("R_TRAPNO", offsetof(struct i386_saved_state
*, trapno
));
196 DECLARE("R_ERR", offsetof(struct i386_saved_state
*, err
));
197 DECLARE("R_EFLAGS", offsetof(struct i386_saved_state
*, efl
));
198 DECLARE("R_EIP", offsetof(struct i386_saved_state
*, eip
));
199 DECLARE("R_CR2", offsetof(struct i386_saved_state
*, cr2
));
200 DECLARE("ISS_SIZE", sizeof (struct i386_saved_state
));
202 DECLARE("I_ECX", offsetof(struct i386_interrupt_state
*, ecx
));
203 DECLARE("I_EIP", offsetof(struct i386_interrupt_state
*, eip
));
204 DECLARE("I_CS", offsetof(struct i386_interrupt_state
*, cs
));
205 DECLARE("I_EFL", offsetof(struct i386_interrupt_state
*, efl
));
207 DECLARE("NBPG", I386_PGBYTES
);
208 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS
);
209 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS
);
210 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS
);
211 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS
);
212 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE
);
214 DECLARE("PDESHIFT", PDESHIFT
);
215 DECLARE("PTESHIFT", PTESHIFT
);
216 DECLARE("PTEMASK", PTEMASK
);
218 DECLARE("PTE_PFN", INTEL_PTE_PFN
);
219 DECLARE("PTE_V", INTEL_PTE_VALID
);
220 DECLARE("PTE_W", INTEL_PTE_WRITE
);
221 DECLARE("PTE_INVALID", ~INTEL_PTE_VALID
);
223 DECLARE("IDTSZ", IDTSZ
);
224 DECLARE("GDTSZ", GDTSZ
);
225 DECLARE("LDTSZ", LDTSZ
);
227 DECLARE("KERNEL_CS", KERNEL_CS
);
228 DECLARE("KERNEL_DS", KERNEL_DS
);
229 DECLARE("USER_CS", USER_CS
);
230 DECLARE("USER_DS", USER_DS
);
231 DECLARE("KERNEL_TSS", KERNEL_TSS
);
232 DECLARE("KERNEL_LDT", KERNEL_LDT
);
234 DECLARE("DEBUG_TSS", DEBUG_TSS
);
235 #endif /* MACH_KDB */
237 DECLARE("CPU_DATA", CPU_DATA
);
238 DECLARE("CPD_ACTIVE_THREAD",
239 offsetof(cpu_data_t
*, active_thread
));
241 DECLARE("CPD_PREEMPTION_LEVEL",
242 offsetof(cpu_data_t
*, preemption_level
));
244 DECLARE("CPD_INTERRUPT_LEVEL",
245 offsetof(cpu_data_t
*, interrupt_level
));
246 DECLARE("CPD_SIMPLE_LOCK_COUNT",
247 offsetof(cpu_data_t
*,simple_lock_count
));
249 DECLARE("PTES_PER_PAGE", NPTES
);
250 DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID
|INTEL_PTE_WRITE
);
252 DECLARE("KERNELBASEPDE",
253 (LINEAR_KERNEL_ADDRESS
>> PDESHIFT
) *
256 DECLARE("TSS_ESP0", offsetof(struct i386_tss
*, esp0
));
257 DECLARE("TSS_SS0", offsetof(struct i386_tss
*, ss0
));
258 DECLARE("TSS_LDT", offsetof(struct i386_tss
*, ldt
));
259 DECLARE("TSS_PDBR", offsetof(struct i386_tss
*, cr3
));
260 DECLARE("TSS_LINK", offsetof(struct i386_tss
*, back_link
));
262 DECLARE("K_TASK_GATE", ACC_P
|ACC_PL_K
|ACC_TASK_GATE
);
263 DECLARE("K_TRAP_GATE", ACC_P
|ACC_PL_K
|ACC_TRAP_GATE
);
264 DECLARE("U_TRAP_GATE", ACC_P
|ACC_PL_U
|ACC_TRAP_GATE
);
265 DECLARE("K_INTR_GATE", ACC_P
|ACC_PL_K
|ACC_INTR_GATE
);
266 DECLARE("K_TSS", ACC_P
|ACC_PL_K
|ACC_TSS
);
269 * usimple_lock fields
271 DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t
, interlock
));
273 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE
);
275 DECLARE("MP_GDT", offsetof(struct mp_desc_table
*, gdt
[0]));
276 DECLARE("MP_IDT", offsetof(struct mp_desc_table
*, idt
[0]));
277 #endif /* NCPUS > 1 */
279 DECLARE("LOW_BITS", offsetof(struct timer
*, low_bits
));
280 DECLARE("HIGH_BITS", offsetof(struct timer
*, high_bits
));
281 DECLARE("HIGH_BITS_CHECK", offsetof(struct timer
*, high_bits_check
));
282 DECLARE("TIMER_HIGH_UNIT", TIMER_HIGH_UNIT
);
283 DECLARE("TH_SYS_TIMER", offsetof(struct timer
*, system_timer
));
284 DECLARE("TH_USER_TIMER", offsetof(struct timer
*, user_timer
));
291 /* Dummy to keep linker quiet */
293 kernel_preempt_check(void)