]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
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 | |
18 | * under the License. | |
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 | ||
81 | extern void kernel_preempt_check(void); | |
82 | cpu_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 | ||
97 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER) | |
98 | ||
99 | #if 0 | |
100 | #define DECLARE(SYM,VAL) \ | |
101 | __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL))) | |
102 | #else | |
103 | #define DECLARE(SYM,VAL) \ | |
104 | __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL))) | |
105 | #endif | |
106 | ||
107 | int main( | |
108 | int argc, | |
109 | char ** argv); | |
110 | ||
111 | int | |
112 | main( | |
113 | int argc, | |
114 | char **argv) | |
115 | { | |
116 | ||
117 | DECLARE("AST_URGENT", AST_URGENT); | |
118 | ||
119 | #if MACH_LDEBUG | |
120 | /* | |
121 | * XXX | |
122 | */ | |
123 | #define SIMPLE_LOCK_TAG 0x5353 | |
124 | #define MUTEX_TAG 0x4d4d | |
125 | DECLARE("TH_MUTEX_COUNT", offsetof(thread_t, mutex_count)); | |
126 | DECLARE("SIMPLE_LOCK_TAG", SIMPLE_LOCK_TAG); | |
127 | DECLARE("MUTEX_TAG", MUTEX_TAG); | |
128 | #endif /* MACH_LDEBUG */ | |
129 | DECLARE("TH_RECOVER", offsetof(thread_t, recover)); | |
130 | DECLARE("TH_CONTINUATION", offsetof(thread_t, continuation)); | |
131 | DECLARE("TH_TOP_ACT", offsetof(thread_t, top_act)); | |
132 | DECLARE("TH_KERNEL_STACK", offsetof(thread_t, kernel_stack)); | |
133 | ||
134 | DECLARE("TASK_EMUL", offsetof(task_t, eml_dispatch)); | |
135 | DECLARE("TASK_MACH_EXC_PORT", | |
136 | offsetof(task_t, exc_actions[EXC_MACH_SYSCALL].port)); | |
137 | ||
138 | /* These fields are being added on demand */ | |
139 | DECLARE("ACT_MACH_EXC_PORT", | |
140 | offsetof(thread_act_t, exc_actions[EXC_MACH_SYSCALL].port)); | |
141 | ||
142 | DECLARE("ACT_THREAD", offsetof(thread_act_t, thread)); | |
143 | DECLARE("ACT_TASK", offsetof(thread_act_t, task)); | |
144 | DECLARE("ACT_PCB", offsetof(thread_act_t, mact.pcb)); | |
145 | DECLARE("ACT_KLOADED", offsetof(thread_act_t, kernel_loaded)); | |
146 | DECLARE("ACT_KLOADING", offsetof(thread_act_t, kernel_loading)); | |
147 | DECLARE("ACT_LOWER", offsetof(thread_act_t, lower)); | |
148 | DECLARE("ACT_MAP", offsetof(thread_act_t, map)); | |
149 | ||
150 | DECLARE("MAP_PMAP", offsetof(vm_map_t, pmap)); | |
151 | ||
1c79356b A |
152 | DECLARE("HOST_NAME", offsetof(host_t, host_self)); |
153 | ||
154 | DECLARE("DISP_MIN", offsetof(eml_dispatch_t, disp_min)); | |
155 | DECLARE("DISP_COUNT", offsetof(eml_dispatch_t, disp_count)); | |
156 | DECLARE("DISP_VECTOR", offsetof(eml_dispatch_t, disp_vector[0])); | |
157 | ||
158 | #define IKS ((size_t) (STACK_IKS(0))) | |
159 | ||
160 | DECLARE("KSS_EBX", IKS + offsetof(struct i386_kernel_state *, k_ebx)); | |
161 | DECLARE("KSS_ESP", IKS + offsetof(struct i386_kernel_state *, k_esp)); | |
162 | DECLARE("KSS_EBP", IKS + offsetof(struct i386_kernel_state *, k_ebp)); | |
163 | DECLARE("KSS_EDI", IKS + offsetof(struct i386_kernel_state *, k_edi)); | |
164 | DECLARE("KSS_ESI", IKS + offsetof(struct i386_kernel_state *, k_esi)); | |
165 | DECLARE("KSS_EIP", IKS + offsetof(struct i386_kernel_state *, k_eip)); | |
166 | ||
167 | DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state)); | |
168 | DECLARE("IEL_SIZE", sizeof(struct i386_exception_link)); | |
169 | ||
170 | DECLARE("PCB_FPS", offsetof(pcb_t, ims.ifps)); | |
171 | DECLARE("PCB_ISS", offsetof(pcb_t, iss)); | |
172 | ||
173 | DECLARE("FP_VALID", offsetof(struct i386_fpsave_state *,fp_valid)); | |
174 | DECLARE("FP_SAVE_STATE", | |
175 | offsetof(struct i386_fpsave_state *, fp_save_state)); | |
176 | ||
177 | DECLARE("R_CS", offsetof(struct i386_saved_state *, cs)); | |
178 | DECLARE("R_SS", offsetof(struct i386_saved_state *, ss)); | |
179 | DECLARE("R_UESP", offsetof(struct i386_saved_state *, uesp)); | |
180 | DECLARE("R_EBP", offsetof(struct i386_saved_state *, ebp)); | |
181 | DECLARE("R_EAX", offsetof(struct i386_saved_state *, eax)); | |
182 | DECLARE("R_EBX", offsetof(struct i386_saved_state *, ebx)); | |
183 | DECLARE("R_ECX", offsetof(struct i386_saved_state *, ecx)); | |
184 | DECLARE("R_EDX", offsetof(struct i386_saved_state *, edx)); | |
185 | DECLARE("R_ESI", offsetof(struct i386_saved_state *, esi)); | |
186 | DECLARE("R_EDI", offsetof(struct i386_saved_state *, edi)); | |
187 | DECLARE("R_TRAPNO", offsetof(struct i386_saved_state *, trapno)); | |
188 | DECLARE("R_ERR", offsetof(struct i386_saved_state *, err)); | |
189 | DECLARE("R_EFLAGS", offsetof(struct i386_saved_state *, efl)); | |
190 | DECLARE("R_EIP", offsetof(struct i386_saved_state *, eip)); | |
191 | DECLARE("R_CR2", offsetof(struct i386_saved_state *, cr2)); | |
192 | DECLARE("ISS_SIZE", sizeof (struct i386_saved_state)); | |
193 | ||
194 | DECLARE("I_ECX", offsetof(struct i386_interrupt_state *, ecx)); | |
195 | DECLARE("I_EIP", offsetof(struct i386_interrupt_state *, eip)); | |
196 | DECLARE("I_CS", offsetof(struct i386_interrupt_state *, cs)); | |
197 | DECLARE("I_EFL", offsetof(struct i386_interrupt_state *, efl)); | |
198 | ||
199 | DECLARE("NBPG", I386_PGBYTES); | |
200 | DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS); | |
201 | DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS); | |
202 | DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS); | |
203 | DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS); | |
204 | DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE); | |
205 | ||
206 | DECLARE("PDESHIFT", PDESHIFT); | |
207 | DECLARE("PTESHIFT", PTESHIFT); | |
208 | DECLARE("PTEMASK", PTEMASK); | |
209 | ||
210 | DECLARE("PTE_PFN", INTEL_PTE_PFN); | |
211 | DECLARE("PTE_V", INTEL_PTE_VALID); | |
212 | DECLARE("PTE_W", INTEL_PTE_WRITE); | |
213 | DECLARE("PTE_INVALID", ~INTEL_PTE_VALID); | |
214 | ||
215 | DECLARE("IDTSZ", IDTSZ); | |
216 | DECLARE("GDTSZ", GDTSZ); | |
217 | DECLARE("LDTSZ", LDTSZ); | |
218 | ||
219 | DECLARE("KERNEL_CS", KERNEL_CS); | |
220 | DECLARE("KERNEL_DS", KERNEL_DS); | |
221 | DECLARE("USER_CS", USER_CS); | |
222 | DECLARE("USER_DS", USER_DS); | |
223 | DECLARE("KERNEL_TSS", KERNEL_TSS); | |
224 | DECLARE("KERNEL_LDT", KERNEL_LDT); | |
225 | #if MACH_KDB | |
226 | DECLARE("DEBUG_TSS", DEBUG_TSS); | |
227 | #endif /* MACH_KDB */ | |
228 | ||
229 | DECLARE("CPU_DATA", CPU_DATA); | |
230 | DECLARE("CPD_ACTIVE_THREAD", | |
231 | offsetof(cpu_data_t *, active_thread)); | |
232 | #if MACH_RT | |
233 | DECLARE("CPD_PREEMPTION_LEVEL", | |
234 | offsetof(cpu_data_t *, preemption_level)); | |
235 | #endif /* MACH_RT */ | |
236 | DECLARE("CPD_INTERRUPT_LEVEL", | |
237 | offsetof(cpu_data_t *, interrupt_level)); | |
238 | DECLARE("CPD_SIMPLE_LOCK_COUNT", | |
239 | offsetof(cpu_data_t *,simple_lock_count)); | |
240 | ||
241 | DECLARE("PTES_PER_PAGE", NPTES); | |
242 | DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID|INTEL_PTE_WRITE); | |
243 | ||
244 | DECLARE("KERNELBASEPDE", | |
245 | (LINEAR_KERNEL_ADDRESS >> PDESHIFT) * | |
246 | sizeof(pt_entry_t)); | |
247 | ||
248 | DECLARE("TSS_ESP0", offsetof(struct i386_tss *, esp0)); | |
249 | DECLARE("TSS_SS0", offsetof(struct i386_tss *, ss0)); | |
250 | DECLARE("TSS_LDT", offsetof(struct i386_tss *, ldt)); | |
251 | DECLARE("TSS_PDBR", offsetof(struct i386_tss *, cr3)); | |
252 | DECLARE("TSS_LINK", offsetof(struct i386_tss *, back_link)); | |
253 | ||
254 | DECLARE("K_TASK_GATE", ACC_P|ACC_PL_K|ACC_TASK_GATE); | |
255 | DECLARE("K_TRAP_GATE", ACC_P|ACC_PL_K|ACC_TRAP_GATE); | |
256 | DECLARE("U_TRAP_GATE", ACC_P|ACC_PL_U|ACC_TRAP_GATE); | |
257 | DECLARE("K_INTR_GATE", ACC_P|ACC_PL_K|ACC_INTR_GATE); | |
258 | DECLARE("K_TSS", ACC_P|ACC_PL_K|ACC_TSS); | |
259 | ||
260 | /* | |
261 | * usimple_lock fields | |
262 | */ | |
263 | DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t, interlock)); | |
264 | ||
265 | DECLARE("INTSTACK_SIZE", INTSTACK_SIZE); | |
266 | #if NCPUS > 1 | |
267 | DECLARE("MP_GDT", offsetof(struct mp_desc_table *, gdt[0])); | |
268 | DECLARE("MP_IDT", offsetof(struct mp_desc_table *, idt[0])); | |
269 | #endif /* NCPUS > 1 */ | |
270 | #if !STAT_TIME | |
271 | DECLARE("LOW_BITS", offsetof(struct timer *, low_bits)); | |
272 | DECLARE("HIGH_BITS", offsetof(struct timer *, high_bits)); | |
273 | DECLARE("HIGH_BITS_CHECK", offsetof(struct timer *, high_bits_check)); | |
274 | DECLARE("TIMER_HIGH_UNIT", TIMER_HIGH_UNIT); | |
275 | DECLARE("TH_SYS_TIMER", offsetof(struct timer *, system_timer)); | |
276 | DECLARE("TH_USER_TIMER", offsetof(struct timer *, user_timer)); | |
277 | #endif | |
278 | ||
279 | return (0); | |
280 | } | |
281 | ||
282 | ||
283 | /* Dummy to keep linker quiet */ | |
284 | void | |
285 | kernel_preempt_check(void) | |
286 | { | |
287 | } |