1 /*
2 * Mach Operating System
3 * Copyright (c) 1991 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * Copyright 1988, 1989, 1990, 1991 by Intel Corporation,
28 * Santa Clara, California.
29 *
30 * All Rights Reserved
31 *
32 * Permission to use, copy, modify, and distribute this software and its
33 * documentation for any purpose and without fee is hereby granted,
34 * provided that the above copyright notice appears in all copies and that
35 * both the copyright notice and this permission notice appear in
36 * supporting documentation, and that the name of Intel not be used in
37 * advertising or publicity pertaining to distribution of the software
38 * without specific, written prior permission.
39 *
40 * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
41 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
42 * SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
43 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44 * PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS
45 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
46 * THIS SOFTWARE.
47 */
48 /*
49 * HISTORY
50 * $Log: model_dep.c,v $
51 * Revision 2.13 93/01/14 17:32:12 danner
52 * Proper spl typing.
53 * [92/12/10 17:54:33 af]
54 *
55 * Revision 2.12 92/01/03 20:12:48 dbg
56 * Rename kdb_init to ddb_init.
57 * Use '-d' switch (RB_KDB) for initial debugger breakpoint.
58 * [91/12/18 dbg]
59 *
60 * Revision 2.11 91/12/10 16:30:02 jsb
61 * Fixes from Intel
62 * [91/12/10 15:32:17 jsb]
63 *
64 * Revision 2.10 91/08/03 18:18:07 jsb
65 * Force RB_ASKNAME into boothowto, since we cannot do so at boot time.
66 * [91/07/25 18:40:17 jsb]
67 *
68 * Added node_self(), _node_self.
69 * [91/07/24 23:15:52 jsb]
70 *
71 * Revision 2.9 91/07/31 17:42:57 dbg
72 * Remove call to pcb_module_init (in machine-independent code).
73 * [91/07/26 dbg]
74 *
75 * Revision 2.8 91/07/01 08:24:16 jsb
76 * Temporary hack to prevent kernel text and data from being used
77 * as free memory.
78 * [91/06/29 17:48:16 jsb]
79 *
80 * Revision 2.7 91/06/19 11:55:52 rvb
81 * cputypes.h->platforms.h
82 * [91/06/12 13:45:41 rvb]
83 *
84 * Revision 2.6 91/06/18 20:50:23 jsb
85 * New copyright from Intel.
86 * [91/06/18 20:07:00 jsb]
87 *
88 * Revision 2.5 91/06/17 15:44:12 jsb
89 * Changed intialization printf.
90 * [91/06/17 10:08:20 jsb]
91 *
92 * Revision 2.4 91/06/06 17:04:49 jsb
93 * Changes for new bootstrapper; see asm_startup.h.
94 * [91/05/13 17:08:15 jsb]
95 *
96 * Revision 2.3 91/05/18 14:30:45 rpd
97 * Changed pmap_bootstrap arguments.
98 * Moved pmap_free_pages and pmap_next_page here.
99 * [91/05/15 rpd]
100 *
101 * Revision 2.2 91/05/08 12:46:18 dbg
102 * Initialization for iPSC only.
103 * Add code that was in i386/init.c.
104 * Add pmap_valid_page.
105 * [91/04/26 14:41:16 dbg]
106 *
107 * Revision 2.3 90/09/23 17:45:10 jsb
108 * Added support for iPSC2.
109 * [90/09/21 16:39:41 jsb]
110 *
111 * Revision 2.2 90/05/03 15:27:39 dbg
112 * Alter for pure kernel.
113 * [90/02/15 dbg]
114 *
115 * Revision 1.5.1.4 90/02/01 13:36:37 rvb
116 * esym must always be defined. This is as good a place as any.
117 * [90/01/31 rvb]
118 *
119 * Revision 1.5.1.3 89/12/28 12:43:10 rvb
120 * Fix av_start & esym initialization, esp for MACH_KDB.
121 * [89/12/26 rvb]
122 *
123 * Revision 1.5.1.2 89/12/21 17:59:49 rvb
124 * enable esym processing.
125 *
126 *
127 * Revision 1.5.1.1 89/10/22 11:30:41 rvb
128 * Setup of rootdevice should not be here. And it was wrong.
129 * [89/10/17 rvb]
130 *
131 * Scary! We've changed sbss to edata. AND the coff loader
132 * following the vuifile spec was actually aligning the bss
133 * on 4k boundaries.
134 * [89/10/16 rvb]
135 *
136 * Revision 1.5 89/04/05 12:57:39 rvb
137 * Move extern out of function scope for gcc.
138 * [89/03/04 rvb]
139 *
140 * Revision 1.4 89/02/26 12:31:25 gm0w
141 * Changes for cleanup.
142 *
143 * 31-Dec-88 Robert Baron (rvb) at Carnegie-Mellon University
144 * Derived from MACH2.0 vax release.
145 *
146 */
147
148 /*
149 * File: i386_init.c
150 * Author: Avadis Tevanian, Jr., Michael Wayne Young
151 *
152 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
153 *
154 * Basic initialization for I386
155 */
156
157 #include <platforms.h>
158 #include <mach_kdb.h>
159
160 #include <mach/i386/vm_param.h>
161
162 #include <mach/machine.h>
163 #include <mach/vm_param.h>
164 #include <mach/vm_prot.h>
165 #include <vm/vm_page.h>
166 #include <kern/time_out.h>
167 #include <sys/time.h>
168
169
170 #if MACH_KDB
171 #include <sys/reboot.h>
172 #endif MACH_KDB
173
174 #define HOLE 1
175
176 int loadpt;
177
178 vm_size_t mem_size;
179 vm_size_t rawmem_size;
180 vm_offset_t first_addr = 0; /* set by start.s - keep out of bss */
181 vm_offset_t first_avail = 0;/* first address after page tables */
182 vm_offset_t last_addr;
183 #if HOLE
184 vm_offset_t hole_start, hole_end;
185 #endif HOLE
186
187 vm_offset_t avail_start, avail_end;
188 vm_offset_t virtual_avail, virtual_end;
189 vm_offset_t avail_next;
190 unsigned int avail_remaining;
191
192 int boottype = 0;
193 char *esym = (char *)0;
194
195 /* parameters passed from NX bootstrap loader */
196 int ipsc_basemem = 0; /* must be in .data section */
197 int ipsc_physnode = 0;
198 int ipsc_slot = 0;
199 char *tmp_bootenv = 0; /* must be in .data section */
200 extern char **bootenv, **envcopy();
201 extern int boothowto;
202
203 extern char edata, end;
204
205 extern char version[];
206
207 extern void setup_main();
208
209 void inittodr(); /* forward */
210
211 int rebootflag = 0; /* exported to kdintr */
212
213 int _node_self = -1;
214
215 extern unsigned char *md_address;
216 extern unsigned long md_size;
217
218 /*
219 * Functional form, used by most machine independent code.
220 */
221 node_self()
222 {
223 return _node_self;
224 }
225
226 /*
227 * Cpu initialization. Running virtual, but without MACH VM
228 * set up. First C routine called.
229 */
230 void machine_startup()
231 {
232 /*
233 * Do basic VM initialization
234 */
235 i386_init();
236
237 /*
238 * Initialize the console so we can print.
239 */
240 cninit();
241 #if MACH_KDB
242
243 /*
244 * Initialize the kernel debugger.
245 */
246 ddb_init();
247
248 /*
249 * Cause a breakpoint trap to the debugger before proceeding
250 * any further if RB_KDB (the '-d' switch to the boot program)
251 * was specified in the boot flags.
252 */
253 if (boothowto & RB_KDB) {
254 Debugger();
255 }
256
257 #if 1 /* stan set to 0 [10-14-91] */
258 /*
259 * XXX Until bootcube or something else allows us to dynamically
260 * XXX provide boot options, always ask root and bootstrap names.
261 */
262 boothowto |= RB_ASKNAME;
263 boothowto |= (RB_ASKNAME << RB_SHIFT);
264 #endif
265 #endif MACH_KDB
266
267 printf("EXPERIMENTAL ");
268 printf(version);
269 #if 0
270 {
271 int i;
272
273 db_printf("boot magic:\n");
274 for (i = 0; bootenv[i]; i++) {
275 db_printf("%d %x %s\n", i, bootenv[i], bootenv[i]);
276 }
277 }
278 #endif
279
280 machine_slot[0].is_cpu = TRUE;
281 machine_slot[0].running = TRUE;
282 machine_slot[0].cpu_type = CPU_TYPE_I386;
283 machine_slot[0].cpu_subtype = CPU_SUBTYPE_iPSC386;
284
285 /*
286 * Start the system.
287 */
288 setup_main();
289 }
290
291 /*
292 * Find devices. The system is alive.
293 */
294 void machine_init()
295 {
296 /*
297 * Set up to use floating point.
298 */
299 init_fpu();
300
301 /*
302 * Find the devices
303 */
304 probeio();
305
306 /*
307 * Find the root device
308 */
309 get_root_device();
310
311 /*
312 * Get the time
313 */
314 inittodr();
315 }
316
317 /*
318 * Halt a cpu.
319 */
320 halt_cpu()
321 {
322 }
323
324 /*
325 * Halt the system or reboot.
326 */
327 halt_all_cpus(reboot)
328 boolean_t reboot;
329 {
330 rebootflag = 1;
331 printf("In tight loop: hit ctl-alt-del to reboot\n");
332 (void) spl0();
333 for (;;)
334 continue;
335
336 }
337
338 startrtclock()
339 {
340 clkstart();
341 }
342
343 void
344 inittodr()
345 {
346 time_value_t new_time;
347
348 new_time.seconds = 0;
349 new_time.microseconds = 0;
350
351 (void) readtodc(&new_time.seconds);
352
353 {
354 spl_t s = splhigh();
355 time = new_time;
356 splx(s);
357 }
358 }
359
360 void
361 resettodr()
362 {
363 writetodc();
364 }
365
366 /*
367 * Basic VM initialization.
368 */
369 i386_init()
370 {
371 /*
372 * Clear the BSS.
373 */
374 bzero((char *)&edata,(unsigned)(&end - &edata));
375
376 /*
377 * Set _node_self
378 */
379 _node_self = ipsc_physnode;
380
381 /*
382 * Set ram-disk parameters and fix esym
383 */
384 XXX md_address = (unsigned char *)esym - md_size;
385 XXX esym = (char *)md_address;
386 #if 1
387 bootenv = envcopy(tmp_bootenv); /* bootmagic! */
388 #endif
389
390 /*
391 * Initialize the pic prior to any possible call to an spl.
392 */
393 picinit();
394
395 vm_set_page_size();
396
397 /*
398 * Find the size of memory.
399 */
400 last_addr = ipsc_basemem;
401 mem_size = last_addr - loadpt;
402
403 first_addr = 0;
404 last_addr = trunc_page(last_addr);
405
406 /*
407 * Initialize kernel physical map, mapping the
408 * region from loadpt to avail_start.
409 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
410 */
411
412 avail_start = first_addr;
413 avail_end = last_addr;
414 printf("i386 iPSC boot: ");
415 printf("node %d, slot %d, memory from 0x%x to 0x%x (%d KB)\n",
416 ipsc_physnode, ipsc_slot, avail_start, avail_end,
417 (avail_end - avail_start) / 1024);
418 printf("edata %08X end %08X esym %08X\n",
419 &edata, &end, esym);
420
421 pmap_bootstrap(loadpt);
422
423 /*
424 * Initialize for pmap_free_pages and pmap_next_page.
425 */
426
427 #if HOLE
428
429 hole_start = 0x100000; /* loadpt */
430 hole_end = (vm_offset_t)(((long)md_address + md_size - 0xC0000000 +
431 PAGE_SIZE-1) & ~(PAGE_SIZE-1));
432
433 avail_remaining = atop((avail_end - avail_start) -
434 (hole_end - hole_start));
435 #else HOLE
436
437 avail_remaining = atop(avail_end - avail_start);
438
439 #endif HOLE
440
441 avail_next = avail_start;
442
443 printf("i386_init: virtual_avail = %x, virtual_end = %x\n",
444 virtual_avail, virtual_end);
445
446 /*
447 * XXX I'll fix it when I understand it...
448 */
449 vm_page_free_count -= ((round_page(&esym) & 0x0fffffff) / PAGE_SIZE);
450 }
451
452
453 #include <mach/vm_prot.h>
454 #include <vm/pmap.h>
455 #include <mach/time_value.h>
456
457 timemmap(dev,off,prot)
458 vm_prot_t prot;
459 {
460 extern time_value_t *mtime;
461
462 #ifdef lint
463 dev++; off++;
464 #endif lint
465
466 if (prot & VM_PROT_WRITE) return (-1);
467
468 return (i386_btop(pmap_extract(pmap_kernel(), (vm_offset_t) mtime)));
469 }
470
471 unsigned int pmap_free_pages()
472 {
473
474 printf("Call pmap_free_pages, now %d range %d-%d\n",
475 avail_remaining, avail_next, avail_end);
476 return avail_remaining;
477 }
478
479 boolean_t pmap_next_page(addrp)
480 vm_offset_t *addrp;
481 {
482 if (avail_next == avail_end)
483 return FALSE;
484
485 *addrp = avail_next;
486
487 #if HOLE
488 /* skip the hole */
489
490 if (avail_next == hole_start)
491 avail_next = hole_end;
492 #endif HOLE
493
494 avail_next += PAGE_SIZE;
495 avail_remaining--;
496 pchk(*addrp, pmap_next_page, esym);
497 return TRUE;
498 }
499
500 boolean_t pmap_valid_page(x)
501 vm_offset_t x;
502 {
503 return (avail_start <= x) && (x < avail_end);
504 }
505
506 pchk(a, s, e)
507 unsigned long a, s, e;
508 {
509 #define NSTART 1
510 static n = NSTART;
511
512 s &= ~(PAGE_SIZE-1);
513 if (s >= 0xC0000000)
514 s -= 0xC0000000;
515 e &= ~(PAGE_SIZE-1);
516 if (e >= 0xC0000000)
517 e -= 0xC0000000;
518 if (n == NSTART) {
519 printf("Check at 0x%08X against 0x%08X-0x%08X\n", a, s, e);
520 n--;
521 } else if (a >= s && a < e && n) {
522 printf("Giving away 0x%08X\n", a);
523 n--;
524 } else if (a == s - PAGE_SIZE || a == s ||
525 a == e - PAGE_SIZE || a == e) {
526 printf("Giving away 0x%08X\n", a);
527 }
528 }
Cache object: 8f7abc076b0985e980969b8aa710f048
|