]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/AT386/model_dep.c
b90ed07364b281ee59e593d67e98bf7b0b5608ab
[apple/xnu.git] / osfmk / i386 / AT386 / model_dep.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58
59 /*
60 */
61
62 /*
63 * File: model_dep.c
64 * Author: Avadis Tevanian, Jr., Michael Wayne Young
65 *
66 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
67 *
68 * Basic initialization for I386 - ISA bus machines.
69 */
70
71 #include <platforms.h>
72 #include <mach_kdb.h>
73 #include <himem.h>
74
75 #include <mach/i386/vm_param.h>
76
77 #include <string.h>
78 #include <mach/vm_param.h>
79 #include <mach/vm_prot.h>
80 #include <mach/machine.h>
81 #include <mach/time_value.h>
82 #include <kern/spl.h>
83 #include <kern/assert.h>
84 #include <kern/debug.h>
85 #include <kern/misc_protos.h>
86 #include <kern/startup.h>
87 #include <kern/clock.h>
88 #include <kern/cpu_data.h>
89 #include <kern/machine.h>
90 #include <i386/fpu.h>
91 #include <i386/ipl.h>
92 #include <i386/pio.h>
93 #include <i386/misc_protos.h>
94 #include <i386/mp.h>
95 #include <i386/mtrr.h>
96 #include <i386/postcode.h>
97 #include <pexpert/i386/boot.h>
98 #if MACH_KDB
99 #include <ddb/db_aout.h>
100 #endif /* MACH_KDB */
101
102 #include <i386/mp_desc.h>
103 #include <i386/mp.h>
104
105 #include <IOKit/IOPlatformExpert.h>
106
107 void enable_bluebox(void);
108 void disable_bluebox(void);
109
110 static void machine_conf(void);
111 #include <i386/cpuid.h>
112
113 extern int default_preemption_rate;
114 extern int max_unsafe_quanta;
115 extern int max_poll_quanta;
116 extern int idlehalt;
117 extern unsigned int panic_is_inited;
118
119 void
120 machine_startup()
121 {
122 int boot_arg;
123
124 #if 0
125 if( PE_get_hotkey( kPEControlKey ))
126 halt_in_debugger = halt_in_debugger ? 0 : 1;
127 #endif
128
129 if (PE_parse_boot_arg("debug", &boot_arg)) {
130 if (boot_arg & DB_HALT) halt_in_debugger=1;
131 if (boot_arg & DB_PRT) disableDebugOuput=FALSE;
132 if (boot_arg & DB_SLOG) systemLogDiags=TRUE;
133 if (boot_arg & DB_NMI) panicDebugging=TRUE;
134 if (boot_arg & DB_LOG_PI_SCRN) logPanicDataToScreen=TRUE;
135 }
136
137 #if NOTYET
138 hw_lock_init(&debugger_lock); /* initialize debugger lock */
139 hw_lock_init(&pbtlock); /* initialize print backtrace lock */
140 #endif
141
142 #if MACH_KDB
143 /*
144 * Initialize KDB
145 */
146 #if DB_MACHINE_COMMANDS
147 db_machine_commands_install(ppc_db_commands);
148 #endif /* DB_MACHINE_COMMANDS */
149 ddb_init();
150
151 if (boot_arg & DB_KDB)
152 current_debugger = KDB_CUR_DB;
153
154 /*
155 * Cause a breakpoint trap to the debugger before proceeding
156 * any further if the proper option bit was specified in
157 * the boot flags.
158 */
159 if (halt_in_debugger && (current_debugger == KDB_CUR_DB)) {
160 Debugger("inline call to debugger(machine_startup)");
161 halt_in_debugger = 0;
162 active_debugger =1;
163 }
164 #endif /* MACH_KDB */
165
166 if (PE_parse_boot_arg("preempt", &boot_arg)) {
167 default_preemption_rate = boot_arg;
168 }
169 if (PE_parse_boot_arg("unsafe", &boot_arg)) {
170 max_unsafe_quanta = boot_arg;
171 }
172 if (PE_parse_boot_arg("poll", &boot_arg)) {
173 max_poll_quanta = boot_arg;
174 }
175 if (PE_parse_boot_arg("yield", &boot_arg)) {
176 sched_poll_yield_shift = boot_arg;
177 }
178 if (PE_parse_boot_arg("idlehalt", &boot_arg)) {
179 idlehalt = boot_arg;
180 }
181
182 machine_conf();
183
184 #if NOTYET
185 ml_thrm_init(); /* Start thermal monitoring on this processor */
186 #endif
187
188 /*
189 * Start the system.
190 */
191 kernel_bootstrap();
192 /*NOTREACHED*/
193 }
194
195
196 static void
197 machine_conf(void)
198 {
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 /*
209 * Display CPU identification
210 */
211 cpuid_cpu_display("CPU identification", 0);
212 cpuid_feature_display("CPU features", 0);
213
214
215 smp_init();
216
217 /*
218 * Set up to use floating point.
219 */
220 init_fpu();
221
222 /*
223 * Configure clock devices.
224 */
225 clock_config();
226
227 /*
228 * Initialize MTRR from boot processor.
229 */
230 mtrr_init();
231
232 /*
233 * Set up PAT for boot processor.
234 */
235 pat_init();
236
237 /*
238 * Free lowmem pages
239 */
240 x86_lowmem_free();
241 }
242
243 /*
244 * Halt a cpu.
245 */
246 void
247 halt_cpu(void)
248 {
249 halt_all_cpus(FALSE);
250 }
251
252 int reset_mem_on_reboot = 1;
253
254 /*
255 * Halt the system or reboot.
256 */
257 void
258 halt_all_cpus(boolean_t reboot)
259 {
260 if (reboot) {
261 /*
262 * Tell the BIOS not to clear and test memory.
263 */
264 #if 0 /* XXX fixme */
265 if (!reset_mem_on_reboot)
266 *(unsigned short *)phystokv(0x472) = 0x1234;
267 #endif
268
269 printf("MACH Reboot\n");
270 PEHaltRestart( kPERestartCPU );
271 } else {
272 printf("CPU halted\n");
273 PEHaltRestart( kPEHaltCPU );
274 }
275 while(1);
276 }
277
278 /*XXX*/
279 void fc_get(mach_timespec_t *ts);
280 #include <kern/clock.h>
281 extern kern_return_t sysclk_gettime(
282 mach_timespec_t *cur_time);
283 void fc_get(mach_timespec_t *ts) {
284 (void )sysclk_gettime(ts);
285 }
286
287 void
288 Debugger(
289 const char *message)
290 {
291
292 if (!panic_is_inited) {
293 postcode(PANIC_HLT);
294 asm("hlt");
295 }
296
297 printf("Debugger called: <%s>\n", message);
298 kprintf("Debugger called: <%s>\n", message);
299
300 draw_panic_dialog();
301
302 __asm__("int3");
303 }
304
305 void
306 enable_bluebox(void)
307 {
308 }
309 void
310 disable_bluebox(void)
311 {
312 }
313
314 char *
315 machine_boot_info(char *buf, __unused vm_size_t size)
316 {
317 *buf ='\0';
318 return buf;
319 }
320