1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989, 1988 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 /*
28 * HISTORY
29 * $Log: model_dep.c,v $
30 * Revision 2.11 93/08/10 15:57:58 mrt
31 * Look for the rconsole serial line FIRST.
32 * [93/06/17 22:43:15 rvb]
33 *
34 * Added extern (patchable) use_all_mem variable. It defaults to
35 * 0 which limits memory use to 16M. If set to 1 all memory will
36 * be used, but DMA from higher memory does not work.
37 * [93/06/08 rvb]
38 *
39 * Revision 2.10 93/05/15 19:33:02 mrt
40 * machparam.h -> machspl.h
41 *
42 * Revision 2.9 93/01/14 17:31:41 danner
43 * Proper spl typing.
44 * [92/11/30 af]
45 *
46 * Revision 2.8 92/07/09 22:54:52 rvb
47 * GROSS temporary (?) hack to limit memory to 16Meg to not freak
48 * out ISA machines doing dma.
49 * [92/06/18 rvb]
50 *
51 * Revision 2.7 92/01/03 20:11:49 dbg
52 * Fixed so that mem_size can be patched to limit physical memory
53 * use.
54 * [91/09/29 dbg]
55 *
56 * Rename kdb_init to ddb_init. Remove esym.
57 * [91/09/11 dbg]
58 *
59 * Revision 2.6 91/07/31 17:42:41 dbg
60 * Remove call to pcb_module_init (in machine-independent code).
61 * [91/07/26 dbg]
62 *
63 * Revision 2.5 91/06/19 11:55:48 rvb
64 * cputypes.h->platforms.h
65 * [91/06/12 13:45:37 rvb]
66 *
67 * Revision 2.4 91/05/18 14:30:38 rpd
68 * Changed pmap_bootstrap arguments.
69 * Moved pmap_free_pages and pmap_next_page here.
70 * [91/05/15 rpd]
71 *
72 * Revision 2.3 91/05/14 16:29:13 mrt
73 * Correcting copyright
74 *
75 * Revision 2.2 91/05/08 12:44:52 dbg
76 * Initialization for i386 AT bus machines only.
77 * Combine code that was in i386/init.c and i386/i386_init.c.
78 * [91/04/26 14:40:43 dbg]
79 *
80 * Revision 2.3 90/09/23 17:45:10 jsb
81 * Added support for iPSC2.
82 * [90/09/21 16:39:41 jsb]
83 *
84 * Revision 2.2 90/05/03 15:27:39 dbg
85 * Alter for pure kernel.
86 * [90/02/15 dbg]
87 *
88 * Revision 1.5.1.4 90/02/01 13:36:37 rvb
89 * esym must always be defined. This is as good a place as any.
90 * [90/01/31 rvb]
91 *
92 * Revision 1.5.1.3 89/12/28 12:43:10 rvb
93 * Fix av_start & esym initialization, esp for MACH_KDB.
94 * [89/12/26 rvb]
95 *
96 * Revision 1.5.1.2 89/12/21 17:59:49 rvb
97 * enable esym processing.
98 *
99 *
100 * Revision 1.5.1.1 89/10/22 11:30:41 rvb
101 * Setup of rootdevice should not be here. And it was wrong.
102 * [89/10/17 rvb]
103 *
104 * Scary! We've changed sbss to edata. AND the coff loader
105 * following the vuifile spec was actually aligning the bss
106 * on 4k boundaries.
107 * [89/10/16 rvb]
108 *
109 * Revision 1.5 89/04/05 12:57:39 rvb
110 * Move extern out of function scope for gcc.
111 * [89/03/04 rvb]
112 *
113 * Revision 1.4 89/02/26 12:31:25 gm0w
114 * Changes for cleanup.
115 *
116 * 31-Dec-88 Robert Baron (rvb) at Carnegie-Mellon University
117 * Derived from MACH2.0 vax release.
118 *
119 */
120
121 /*
122 * File: model_dep.c
123 * Author: Avadis Tevanian, Jr., Michael Wayne Young
124 *
125 * Copyright (C) 1986, Avadis Tevanian, Jr., Michael Wayne Young
126 *
127 * Basic initialization for I386 - ISA bus machines.
128 */
129
130 #include <platforms.h>
131 #include <mach_kdb.h>
132
133 #include <mach/i386/vm_param.h>
134
135 #include <mach/vm_param.h>
136 #include <mach/vm_prot.h>
137 #include <mach/machine.h>
138 #include <kern/time_out.h>
139 #include <sys/time.h>
140 #include <vm/vm_page.h>
141 #include <i386/machspl.h>
142
143 #if MACH_KDB
144 #include <sys/reboot.h>
145 #endif MACH_KDB
146
147 int loadpt;
148
149 vm_size_t mem_size = 0;
150 vm_size_t rawmem_size;
151 vm_offset_t first_addr = 0; /* set by start.s - keep out of bss */
152 vm_offset_t first_avail = 0;/* first after page tables */
153 vm_offset_t last_addr;
154
155 vm_offset_t avail_start, avail_end;
156 vm_offset_t virtual_avail, virtual_end;
157 vm_offset_t hole_start, hole_end;
158 vm_offset_t avail_next;
159 unsigned int avail_remaining;
160
161 /* parameters passed from bootstrap loader */
162 int cnvmem = 0; /* must be in .data section */
163 int extmem = 0;
164 int boottype = 0;
165
166 extern char edata, end;
167
168 extern char version[];
169
170 extern void setup_main();
171
172 void inittodr(); /* forward */
173
174 int rebootflag = 0; /* exported to kdintr */
175
176 /*
177 * Cpu initialization. Running virtual, but without MACH VM
178 * set up. First C routine called.
179 */
180 void machine_startup()
181 {
182 /*
183 * Do basic VM initialization
184 */
185 i386_init();
186
187 /*
188 * Initialize the console so we can print.
189 */
190 cninit();
191 proberc();
192 #if MACH_KDB
193
194 /*
195 * Initialize the kernel debugger.
196 */
197 ddb_init();
198
199 /*
200 * Cause a breakpoint trap to the debugger before proceeding
201 * any further if the proper option bit was specified in
202 * the boot flags.
203 *
204 * XXX use -a switch to invoke kdb, since there's no
205 * boot-program switch to turn on RB_HALT!
206 */
207 if (boothowto & RB_ASKNAME)
208 Debugger();
209 #endif MACH_KDB
210
211 printf(version);
212
213 machine_slot[0].is_cpu = TRUE;
214 machine_slot[0].running = TRUE;
215 machine_slot[0].cpu_type = CPU_TYPE_I386;
216 machine_slot[0].cpu_subtype = CPU_SUBTYPE_AT386;
217
218 /*
219 * Start the system.
220 */
221 setup_main();
222 }
223
224 /*
225 * Find devices. The system is alive.
226 */
227 void machine_init()
228 {
229 /*
230 * Set up to use floating point.
231 */
232 init_fpu();
233
234 /*
235 * Find the devices
236 */
237 probeio();
238
239 /*
240 * Find the root device
241 */
242 get_root_device();
243
244 /*
245 * Get the time
246 */
247 inittodr();
248 }
249
250 /*
251 * Halt a cpu.
252 */
253 halt_cpu()
254 {
255 }
256
257 /*
258 * Halt the system or reboot.
259 */
260 halt_all_cpus(reboot)
261 boolean_t reboot;
262 {
263 if (reboot) {
264 /*
265 * Tell the BIOS not to clear and test memory.
266 */
267 *(unsigned short *)phystokv(0x472) = 0x1234;
268
269 kdreboot();
270 }
271 else {
272 rebootflag = 1;
273 printf("In tight loop: hit ctl-alt-del to reboot\n");
274 (void) spl0();
275 }
276 for (;;)
277 continue;
278 }
279
280 /*
281 * Basic VM initialization.
282 */
283 int use_all_mem = 0;
284 i386_init()
285 {
286 /*
287 * Zero the BSS.
288 */
289 bzero((char *)&edata,(unsigned)(&end - &edata));
290
291 /*
292 * Initialize the pic prior to any possible call to an spl.
293 */
294 picinit();
295
296 vm_set_page_size();
297
298 /*
299 * Compute the memory size.
300 */
301 first_addr = 0x1000;
302 /* BIOS leaves data in low memory */
303 last_addr = 1024*1024 + extmem*1024;
304 /* extended memory starts at 1MB */
305 if (mem_size != 0) {
306 if (mem_size < last_addr - loadpt)
307 last_addr = loadpt + mem_size;
308 }
309 if ((!use_all_mem) && last_addr - loadpt > 16 * 1024*1024) {
310 printf("************ i386at/model_dep.c: i386_init(); ");
311 printf("Limiting useable memory to 16 Meg to avoid DMA problems.\n");
312 last_addr = loadpt + 16 * 1024*1024; /* XXX */
313 }
314
315 mem_size = last_addr - loadpt;
316
317 first_addr = round_page(first_addr);
318 last_addr = trunc_page(last_addr);
319
320 /*
321 * Initialize kernel physical map, mapping the
322 * region from loadpt to avail_start.
323 * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS.
324 */
325
326 avail_start = first_addr;
327 avail_end = last_addr;
328 printf("AT386 boot: memory from 0x%x to 0x%x\n", avail_start,
329 avail_end);
330
331 pmap_bootstrap(loadpt);
332
333 /*
334 * Initialize for pmap_free_pages and pmap_next_page.
335 * These guys should be page-aligned.
336 */
337
338 hole_start = trunc_page((vm_offset_t)(1024 * cnvmem));
339 hole_end = round_page((vm_offset_t)first_avail);
340
341 avail_remaining = atop((avail_end - avail_start) -
342 (hole_end - hole_start));
343 avail_next = avail_start;
344
345 printf("i386_init: virtual_avail = %x, virtual_end = %x\n",
346 virtual_avail, virtual_end);
347 }
348
349 #include <mach/vm_prot.h>
350 #include <vm/pmap.h>
351 #include <mach/time_value.h>
352
353 timemmap(dev,off,prot)
354 vm_prot_t prot;
355 {
356 extern time_value_t *mtime;
357
358 #ifdef lint
359 dev++; off++;
360 #endif lint
361
362 if (prot & VM_PROT_WRITE) return (-1);
363
364 return (i386_btop(pmap_extract(pmap_kernel(), (vm_offset_t) mtime)));
365 }
366
367 startrtclock()
368 {
369 clkstart();
370 }
371
372 void
373 inittodr()
374 {
375 time_value_t new_time;
376
377 new_time.seconds = 0;
378 new_time.microseconds = 0;
379
380 (void) readtodc(&new_time.seconds);
381
382 {
383 spl_t s = splhigh();
384 time = new_time;
385 splx(s);
386 }
387 }
388
389 void
390 resettodr()
391 {
392 writetodc();
393 }
394
395 unsigned int pmap_free_pages()
396 {
397 return avail_remaining;
398 }
399
400 boolean_t pmap_next_page(addrp)
401 vm_offset_t *addrp;
402 {
403 if (avail_next == avail_end)
404 return FALSE;
405
406 /* skip the hole */
407
408 if (avail_next == hole_start)
409 avail_next = hole_end;
410
411 *addrp = avail_next;
412 avail_next += PAGE_SIZE;
413 avail_remaining--;
414 return TRUE;
415 }
416
417 boolean_t pmap_valid_page(x)
418 vm_offset_t x;
419 {
420 return (((avail_start <= x) && (x < avail_end)) &&
421 !((hole_start <= x) && (x < hole_end)));
422 }
Cache object: dfc5a4c7fda1d9385d515974ae92ed31
|