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