]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/AT386/model_dep.c
xnu-517.tar.gz
[apple/xnu.git] / osfmk / i386 / AT386 / model_dep.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
31 * All Rights Reserved.
32 *
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.
38 *
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.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53
54 /*
55 */
56
57 /*
58 * File: model_dep.c
59 * Author: Avadis Tevanian, Jr., Michael Wayne Young
60 *
61 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
62 *
63 * Basic initialization for I386 - ISA bus machines.
64 */
65
66 #include <cpus.h>
67 #include <platforms.h>
68 #include <mach_kdb.h>
69 #include <himem.h>
70 #include <fast_idle.h>
71
72 #include <mach/i386/vm_param.h>
73
74 #include <string.h>
75 #include <mach/vm_param.h>
76 #include <mach/vm_prot.h>
77 #include <mach/machine.h>
78 #include <mach/time_value.h>
79 #include <kern/spl.h>
80 #include <kern/assert.h>
81 #include <kern/debug.h>
82 #include <kern/misc_protos.h>
83 #include <kern/startup.h>
84 #include <kern/clock.h>
85 #include <kern/time_out.h>
86 #include <kern/cpu_data.h>
87 #include <i386/fpu.h>
88 #include <i386/ipl.h>
89 #include <i386/pio.h>
90 #include <i386/misc_protos.h>
91 #include <i386/rtclock_entries.h>
92 #include <i386/mp.h>
93 #include <pexpert/i386/boot.h>
94 #if MACH_KDB
95 #include <ddb/db_aout.h>
96 #endif /* MACH_KDB */
97
98 #if NCPUS > 1
99 #include <i386/mp_desc.h>
100 #endif /* NCPUS */
101
102 #if NCPUS > 1
103 #include <i386/mp.h>
104 #endif /* NCPUS > 1 */
105
106 #include <IOKit/IOPlatformExpert.h>
107
108 static void machine_conf(void);
109 #include <i386/cpuid.h>
110
111 void
112 machine_startup()
113 {
114 int boot_arg;
115
116 #if 0
117 if( PE_get_hotkey( kPEControlKey ))
118 halt_in_debugger = halt_in_debugger ? 0 : 1;
119 #endif
120
121 if (PE_parse_boot_arg("debug", &boot_arg)) {
122 if (boot_arg & DB_HALT) halt_in_debugger=1;
123 if (boot_arg & DB_PRT) disableDebugOuput=FALSE;
124 if (boot_arg & DB_SLOG) systemLogDiags=TRUE;
125 if (boot_arg & DB_NMI) panicDebugging=TRUE;
126 if (boot_arg & DB_LOG_PI_SCRN) logPanicDataToScreen=TRUE;
127 }
128
129 #if NOTYET
130 hw_lock_init(&debugger_lock); /* initialize debugger lock */
131 hw_lock_init(&pbtlock); /* initialize print backtrace lock */
132 #endif
133
134 #if MACH_KDB
135 /*
136 * Initialize KDB
137 */
138 #if DB_MACHINE_COMMANDS
139 db_machine_commands_install(ppc_db_commands);
140 #endif /* DB_MACHINE_COMMANDS */
141 ddb_init();
142
143 if (boot_arg & DB_KDB)
144 current_debugger = KDB_CUR_DB;
145
146 /*
147 * Cause a breakpoint trap to the debugger before proceeding
148 * any further if the proper option bit was specified in
149 * the boot flags.
150 */
151 if (halt_in_debugger && (current_debugger == KDB_CUR_DB)) {
152 Debugger("inline call to debugger(machine_startup)");
153 halt_in_debugger = 0;
154 active_debugger =1;
155 }
156 #endif /* MACH_KDB */
157
158 if (PE_parse_boot_arg("preempt", &boot_arg)) {
159 extern int default_preemption_rate;
160
161 default_preemption_rate = boot_arg;
162 }
163 if (PE_parse_boot_arg("unsafe", &boot_arg)) {
164 extern int max_unsafe_quanta;
165
166 max_unsafe_quanta = boot_arg;
167 }
168 if (PE_parse_boot_arg("poll", &boot_arg)) {
169 extern int max_poll_quanta;
170
171 max_poll_quanta = boot_arg;
172 }
173 if (PE_parse_boot_arg("yield", &boot_arg)) {
174 extern int sched_poll_yield_shift;
175
176 sched_poll_yield_shift = boot_arg;
177 }
178
179 machine_conf();
180
181 #if NOTYET
182 ml_thrm_init(); /* Start thermal monitoring on this processor */
183 #endif
184
185 /*
186 * Start the system.
187 */
188 setup_main();
189
190 /* Should never return */
191 }
192
193
194 static void
195 machine_conf(void)
196 {
197 machine_info.max_cpus = NCPUS;
198 machine_info.avail_cpus = 1;
199 machine_info.memory_size = mem_size;
200 }
201
202 /*
203 * Find devices. The system is alive.
204 */
205 void
206 machine_init(void)
207 {
208 int unit;
209 const char *p;
210 int n;
211
212 /*
213 * Display CPU identification
214 */
215 cpuid_cpu_display("CPU identification", 0);
216 cpuid_feature_display("CPU features", 0);
217
218
219 #if NCPUS > 1
220 smp_init();
221 #endif
222
223 /*
224 * Set up to use floating point.
225 */
226 init_fpu();
227
228 /*
229 * Configure clock devices.
230 */
231 clock_config();
232 }
233
234 /*
235 * Halt a cpu.
236 */
237 void
238 halt_cpu(void)
239 {
240 halt_all_cpus(FALSE);
241 }
242
243 int reset_mem_on_reboot = 1;
244
245 /*
246 * Halt the system or reboot.
247 */
248 void
249 halt_all_cpus(boolean_t reboot)
250 {
251 if (reboot) {
252 /*
253 * Tell the BIOS not to clear and test memory.
254 */
255 if (!reset_mem_on_reboot)
256 *(unsigned short *)phystokv(0x472) = 0x1234;
257
258 printf("MACH Reboot\n");
259 PEHaltRestart( kPERestartCPU );
260 } else {
261 printf("CPU halted\n");
262 PEHaltRestart( kPEHaltCPU );
263 }
264 while(1);
265 }
266
267 /*XXX*/
268 void fc_get(mach_timespec_t *ts);
269 #include <kern/clock.h>
270 #include <i386/rtclock_entries.h>
271 extern kern_return_t sysclk_gettime(
272 mach_timespec_t *cur_time);
273 void fc_get(mach_timespec_t *ts) {
274 (void )sysclk_gettime(ts);
275 }
276
277 void
278 Debugger(
279 const char *message)
280 {
281 printf("Debugger called: <%s>\n", message);
282
283 draw_panic_dialog();
284
285 __asm__("int3");
286 }
287
288 void
289 display_syscall(int syscall)
290 {
291 printf("System call happened %d\n", syscall);
292 }
293
294 #if XPR_DEBUG && (NCPUS == 1)
295
296 extern kern_return_t sysclk_gettime_interrupts_disabled(
297 mach_timespec_t *cur_time);
298
299 int xpr_time(void)
300 {
301 mach_timespec_t time;
302
303 sysclk_gettime_interrupts_disabled(&time);
304 return(time.tv_sec*1000000 + time.tv_nsec/1000);
305 }
306 #endif /* XPR_DEBUG && (NCPUS == 1) */
307
308 enable_bluebox()
309 {
310 }
311 disable_bluebox()
312 {
313 }
314
315 char *
316 machine_boot_info(char *buf, vm_size_t size)
317 {
318 *buf ='\0';
319 return buf;
320 }
321