]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/AT386/model_dep.c
xnu-792.24.17.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 * 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,1989, 1988 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 /*
52 */
53
54 /*
55 * File: model_dep.c
56 * Author: Avadis Tevanian, Jr., Michael Wayne Young
57 *
58 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
59 *
60 * Basic initialization for I386 - ISA bus machines.
61 */
62
63 #include <platforms.h>
64 #include <mach_kdb.h>
65 #include <himem.h>
66
67 #include <mach/i386/vm_param.h>
68
69 #include <string.h>
70 #include <mach/vm_param.h>
71 #include <mach/vm_prot.h>
72 #include <mach/machine.h>
73 #include <mach/time_value.h>
74 #include <kern/spl.h>
75 #include <kern/assert.h>
76 #include <kern/debug.h>
77 #include <kern/misc_protos.h>
78 #include <kern/startup.h>
79 #include <kern/clock.h>
80 #include <kern/cpu_data.h>
81 #include <kern/machine.h>
82 #include <i386/fpu.h>
83 #include <i386/ipl.h>
84 #include <i386/pio.h>
85 #include <i386/misc_protos.h>
86 #include <i386/mp.h>
87 #include <i386/mtrr.h>
88 #include <i386/postcode.h>
89 #include <pexpert/i386/boot.h>
90 #if MACH_KDB
91 #include <ddb/db_aout.h>
92 #endif /* MACH_KDB */
93
94 #include <i386/mp_desc.h>
95 #include <i386/mp.h>
96
97 #include <IOKit/IOPlatformExpert.h>
98
99 void enable_bluebox(void);
100 void disable_bluebox(void);
101
102 static void machine_conf(void);
103 #include <i386/cpuid.h>
104
105 extern int default_preemption_rate;
106 extern int max_unsafe_quanta;
107 extern int max_poll_quanta;
108 extern int idlehalt;
109 extern unsigned int panic_is_inited;
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 default_preemption_rate = boot_arg;
160 }
161 if (PE_parse_boot_arg("unsafe", &boot_arg)) {
162 max_unsafe_quanta = boot_arg;
163 }
164 if (PE_parse_boot_arg("poll", &boot_arg)) {
165 max_poll_quanta = boot_arg;
166 }
167 if (PE_parse_boot_arg("yield", &boot_arg)) {
168 sched_poll_yield_shift = boot_arg;
169 }
170 if (PE_parse_boot_arg("idlehalt", &boot_arg)) {
171 idlehalt = boot_arg;
172 }
173
174 machine_conf();
175
176 #if NOTYET
177 ml_thrm_init(); /* Start thermal monitoring on this processor */
178 #endif
179
180 /*
181 * Start the system.
182 */
183 kernel_bootstrap();
184 /*NOTREACHED*/
185 }
186
187
188 static void
189 machine_conf(void)
190 {
191 machine_info.memory_size = mem_size;
192 }
193
194 /*
195 * Find devices. The system is alive.
196 */
197 void
198 machine_init(void)
199 {
200 /*
201 * Display CPU identification
202 */
203 cpuid_cpu_display("CPU identification", 0);
204 cpuid_feature_display("CPU features", 0);
205
206
207 smp_init();
208
209 /*
210 * Set up to use floating point.
211 */
212 init_fpu();
213
214 /*
215 * Configure clock devices.
216 */
217 clock_config();
218
219 /*
220 * Initialize MTRR from boot processor.
221 */
222 mtrr_init();
223
224 /*
225 * Set up PAT for boot processor.
226 */
227 pat_init();
228
229 /*
230 * Free lowmem pages
231 */
232 x86_lowmem_free();
233 }
234
235 /*
236 * Halt a cpu.
237 */
238 void
239 halt_cpu(void)
240 {
241 halt_all_cpus(FALSE);
242 }
243
244 int reset_mem_on_reboot = 1;
245
246 /*
247 * Halt the system or reboot.
248 */
249 void
250 halt_all_cpus(boolean_t reboot)
251 {
252 if (reboot) {
253 /*
254 * Tell the BIOS not to clear and test memory.
255 */
256 #if 0 /* XXX fixme */
257 if (!reset_mem_on_reboot)
258 *(unsigned short *)phystokv(0x472) = 0x1234;
259 #endif
260
261 printf("MACH Reboot\n");
262 PEHaltRestart( kPERestartCPU );
263 } else {
264 printf("CPU halted\n");
265 PEHaltRestart( kPEHaltCPU );
266 }
267 while(1);
268 }
269
270 /*XXX*/
271 void fc_get(mach_timespec_t *ts);
272 #include <kern/clock.h>
273 extern kern_return_t sysclk_gettime(
274 mach_timespec_t *cur_time);
275 void fc_get(mach_timespec_t *ts) {
276 (void )sysclk_gettime(ts);
277 }
278
279 void
280 Debugger(
281 const char *message)
282 {
283
284 if (!panic_is_inited) {
285 postcode(PANIC_HLT);
286 asm("hlt");
287 }
288
289 printf("Debugger called: <%s>\n", message);
290 kprintf("Debugger called: <%s>\n", message);
291
292 draw_panic_dialog();
293
294 __asm__("int3");
295 }
296
297 void
298 enable_bluebox(void)
299 {
300 }
301 void
302 disable_bluebox(void)
303 {
304 }
305
306 char *
307 machine_boot_info(char *buf, __unused vm_size_t size)
308 {
309 *buf ='\0';
310 return buf;
311 }
312