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