|
|
1.1 root 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 [email protected]
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>
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>
74: #include <i386/seg.h>
75: #include <i386/pmap.h>
76: #include <i386/tss.h>
77: #include <mach/rpc.h>
78: #include <vm/vm_map.h>
79: #if NCPUS > 1
80: #include <i386/mp_desc.h>
81: #endif
82:
83: extern void kernel_preempt_check(void);
84: cpu_data_t cpu_data[NCPUS];
85:
86: /*
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.
92: *
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.
97: */
98:
99: #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER)
100:
101: #if 0
102: #define DECLARE(SYM,VAL) \
103: __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
104: #else
105: #define DECLARE(SYM,VAL) \
106: __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
107: #endif
108:
109: int main(
110: int argc,
111: char ** argv);
112:
113: int
114: main(
115: int argc,
116: char **argv)
117: {
118:
119: DECLARE("AST_URGENT", AST_URGENT);
120:
121: #if MACH_LDEBUG
122: /*
123: * XXX
124: */
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));
135:
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));
139:
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));
143:
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));
151:
152: DECLARE("MAP_PMAP", offsetof(vm_map_t, pmap));
153:
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) +
158: 40 * sizeof(int));
159:
160: DECLARE("HOST_NAME", offsetof(host_t, host_self));
161:
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]));
165:
166: #define IKS ((size_t) (STACK_IKS(0)))
167:
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));
174:
175: DECLARE("IKS_SIZE", sizeof(struct i386_kernel_state));
176: DECLARE("IEL_SIZE", sizeof(struct i386_exception_link));
177:
178: DECLARE("PCB_FPS", offsetof(pcb_t, ims.ifps));
179: DECLARE("PCB_ISS", offsetof(pcb_t, iss));
180:
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));
184:
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));
201:
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));
206:
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);
213:
214: DECLARE("PDESHIFT", PDESHIFT);
215: DECLARE("PTESHIFT", PTESHIFT);
216: DECLARE("PTEMASK", PTEMASK);
217:
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);
222:
223: DECLARE("IDTSZ", IDTSZ);
224: DECLARE("GDTSZ", GDTSZ);
225: DECLARE("LDTSZ", LDTSZ);
226:
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);
233: #if MACH_KDB
234: DECLARE("DEBUG_TSS", DEBUG_TSS);
235: #endif /* MACH_KDB */
236:
237: DECLARE("CPU_DATA", CPU_DATA);
238: DECLARE("CPD_ACTIVE_THREAD",
239: offsetof(cpu_data_t *, active_thread));
240: #if MACH_RT
241: DECLARE("CPD_PREEMPTION_LEVEL",
242: offsetof(cpu_data_t *, preemption_level));
243: #endif /* MACH_RT */
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));
248:
249: DECLARE("PTES_PER_PAGE", NPTES);
250: DECLARE("INTEL_PTE_KERNEL", INTEL_PTE_VALID|INTEL_PTE_WRITE);
251:
252: DECLARE("KERNELBASEPDE",
253: (LINEAR_KERNEL_ADDRESS >> PDESHIFT) *
254: sizeof(pt_entry_t));
255:
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));
261:
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);
267:
268: /*
269: * usimple_lock fields
270: */
271: DECLARE("USL_INTERLOCK", offsetof(usimple_lock_t, interlock));
272:
273: DECLARE("INTSTACK_SIZE", INTSTACK_SIZE);
274: #if NCPUS > 1
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 */
278: #if !STAT_TIME
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));
285: #endif
286:
287: return (0);
288: }
289:
290:
291: /* Dummy to keep linker quiet */
292: void
293: kernel_preempt_check(void)
294: {
295: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.