iq80310_machdep.c revision 1.2 1 /* $NetBSD: iq80310_machdep.c,v 1.2 2001/11/07 00:33:24 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997,1998 Mark Brinicombe.
5 * Copyright (c) 1997,1998 Causality Limited.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe
19 * for the NetBSD Project.
20 * 4. The name of the company nor the name of the author may be used to
21 * endorse or promote products derived from this software without specific
22 * prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
37 * boards using RedBoot firmware.
38 */
39
40 #include "opt_ddb.h"
41 #include "opt_pmap_debug.h"
42
43 #include <sys/param.h>
44 #include <sys/device.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/exec.h>
48 #include <sys/proc.h>
49 #include <sys/msgbuf.h>
50 #include <sys/reboot.h>
51 #include <sys/termios.h>
52
53 #include <dev/cons.h>
54
55 #include <machine/db_machdep.h>
56 #include <ddb/db_sym.h>
57 #include <ddb/db_extern.h>
58
59 #include <machine/bootconfig.h>
60 #include <machine/bus.h>
61 #include <machine/cpu.h>
62 #include <machine/frame.h>
63 #include <machine/irqhandler.h>
64 #include <machine/pte.h>
65 #include <machine/undefined.h>
66
67 #include <arm/xscale/i80312reg.h>
68 #include <arm/xscale/i80312var.h>
69
70 #include <evbarm/iq80310/iq80310reg.h>
71 #include <evbarm/iq80310/iq80310var.h>
72 #include <evbarm/iq80310/obiovar.h>
73
74 #include "opt_ipkdb.h"
75
76 /*
77 * Address to call from cpu_reset() to reset the machine.
78 * This is machine architecture dependant as it varies depending
79 * on where the ROM appears when you turn the MMU off.
80 */
81
82 u_int cpu_reset_address = 0;
83
84 /* Define various stack sizes in pages */
85 #define IRQ_STACK_SIZE 1
86 #define ABT_STACK_SIZE 1
87 #ifdef IPKDB
88 #define UND_STACK_SIZE 2
89 #else
90 #define UND_STACK_SIZE 1
91 #endif
92
93 BootConfig bootconfig; /* Boot config storage */
94 static char bootargs[MAX_BOOT_STRING + 1];
95 char *boot_args = NULL;
96 char *boot_file = NULL;
97
98 vm_offset_t physical_start;
99 vm_offset_t physical_freestart;
100 vm_offset_t physical_freeend;
101 vm_offset_t physical_end;
102 u_int free_pages;
103 vm_offset_t pagetables_start;
104 int physmem = 0;
105
106 /*int debug_flags;*/
107 #ifndef PMAP_STATIC_L1S
108 int max_processes = 64; /* Default number */
109 #endif /* !PMAP_STATIC_L1S */
110
111 /* Physical and virtual addresses for some global pages */
112 pv_addr_t systempage;
113 pv_addr_t irqstack;
114 pv_addr_t undstack;
115 pv_addr_t abtstack;
116 pv_addr_t kernelstack;
117
118 vm_offset_t msgbufphys;
119
120 extern u_int data_abort_handler_address;
121 extern u_int prefetch_abort_handler_address;
122 extern u_int undefined_handler_address;
123
124 #ifdef PMAP_DEBUG
125 extern int pmap_debug_level;
126 #endif
127
128 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
129 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
130 #define KERNEL_PT_VMDATA 2 /* Page tables for mapping kernel VM */
131 #define KERNEL_PT_VMDATA_NUM (KERNEL_VM_SIZE >> (PDSHIFT + 2))
132 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
133
134 pt_entry_t kernel_pt_table[NUM_KERNEL_PTS];
135
136 struct user *proc0paddr;
137
138 /* Prototypes */
139
140 void consinit(void);
141
142 void map_section(vm_offset_t pt, vm_offset_t va, vm_offset_t pa,
143 int cacheable);
144 void map_pagetable(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
145 void map_entry(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
146 void map_entry_nc(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
147 void map_entry_ro(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
148 vm_size_t map_chunk(vm_offset_t pd, vm_offset_t pt, vm_offset_t va,
149 vm_offset_t pa, vm_size_t size, u_int acc, u_int flg);
150
151 void process_kernel_args(char *);
152 void data_abort_handler(trapframe_t *frame);
153 void prefetch_abort_handler(trapframe_t *frame);
154 void undefinedinstruction_bounce(trapframe_t *frame);
155 void zero_page_readonly(void);
156 void zero_page_readwrite(void);
157
158 extern void db_machine_init(void);
159 extern void parse_mi_bootargs(char *args);
160 extern void dumpsys(void);
161
162 #include "com.h"
163 #if NCOM > 0
164 #include <dev/ic/comreg.h>
165 #include <dev/ic/comvar.h>
166 #endif
167
168 #ifndef CONSPEED
169 #define CONSPEED B115200 /* What RedBoot uses */
170 #endif
171 #ifndef CONMODE
172 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
173 #endif
174
175 int comcnspeed = CONSPEED;
176 int comcnmode = CONMODE;
177
178 /*
179 * void cpu_reboot(int howto, char *bootstr)
180 *
181 * Reboots the system
182 *
183 * Deal with any syncing, unmounting, dumping and shutdown hooks,
184 * then reset the CPU.
185 */
186 void
187 cpu_reboot(int howto, char *bootstr)
188 {
189 #ifdef DIAGNOSTIC
190 /* info */
191 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
192 #endif
193
194 /*
195 * If we are still cold then hit the air brakes
196 * and crash to earth fast
197 */
198 if (cold) {
199 doshutdownhooks();
200 printf("The operating system has halted.\n");
201 printf("Please press any key to reboot.\n\n");
202 cngetc();
203 printf("rebooting...\n");
204 cpu_reset();
205 /*NOTREACHED*/
206 }
207
208 /* Disable console buffering */
209 /* cnpollc(1);*/
210
211 /*
212 * If RB_NOSYNC was not specified sync the discs.
213 * Note: Unless cold is set to 1 here, syslogd will die during the
214 * unmount. It looks like syslogd is getting woken up only to find
215 * that it cannot page part of the binary in as the filesystem has
216 * been unmounted.
217 */
218 if (!(howto & RB_NOSYNC))
219 bootsync();
220
221 /* Say NO to interrupts */
222 splhigh();
223
224 /* Do a dump if requested. */
225 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
226 dumpsys();
227
228 /* Run any shutdown hooks */
229 doshutdownhooks();
230
231 /* Make sure IRQ's are disabled */
232 IRQdisable;
233
234 if (howto & RB_HALT) {
235 printf("The operating system has halted.\n");
236 printf("Please press any key to reboot.\n\n");
237 cngetc();
238 }
239
240 printf("rebooting...\n");
241 cpu_reset();
242 /*NOTREACHED*/
243 }
244
245 /*
246 * Mapping table for core kernel memory. This memory is mapped at init
247 * time with section mappings.
248 */
249 struct l1_sec_map {
250 vaddr_t va;
251 vaddr_t pa;
252 vsize_t size;
253 int flags;
254 } l1_sec_table[] = {
255 /*
256 * Map the on-board devices VA == PA so that we can access them
257 * with the MMU on or off.
258 */
259 {
260 IQ80310_OBIO_BASE,
261 IQ80310_OBIO_BASE,
262 IQ80310_OBIO_SIZE,
263 0,
264 },
265
266 {
267 0,
268 0,
269 0,
270 0,
271 }
272 };
273
274 /*
275 * u_int initarm(...)
276 *
277 * Initial entry point on startup. This gets called before main() is
278 * entered.
279 * It should be responsible for setting up everything that must be
280 * in place when main is called.
281 * This includes
282 * Taking a copy of the boot configuration structure.
283 * Initialising the physical console so characters can be printed.
284 * Setting up page tables for the kernel
285 * Relocating the kernel to the bottom of physical memory
286 */
287 u_int
288 initarm(void)
289 {
290 int loop;
291 int loop1;
292 u_int l1pagetable;
293 u_int l2pagetable;
294 extern char page0[], page0_end[];
295 pv_addr_t kernel_l1pt;
296 pv_addr_t kernel_ptpt;
297 paddr_t memstart;
298 psize_t memsize;
299
300 /*
301 * Clear out the 7-segment display. Whee, the first visual
302 * indication that we're running kernel code.
303 */
304 iq80310_7seg(' ', ' ');
305
306 /*
307 * Heads up ... Setup the CPU / MMU / TLB functions
308 */
309 if (set_cpufuncs())
310 panic("cpu not recognized!");
311
312 /* Calibrate the delay loop. */
313 iq80310_calibrate_delay();
314
315 /*
316 * Since we map the on-board devices VA==PA, and the kernel
317 * is running VA==PA, it's possible for us to initialize
318 * the console now.
319 */
320 consinit();
321
322 /* Talk to the user */
323 printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
324
325 /*
326 * Okay, RedBoot has provided us with the following memory map:
327 *
328 *
329 * Physical Address Range Description
330 * ----------------------- ----------------------------------
331 * 0x00000000 - 0x00000fff flash Memory
332 * 0x00001000 - 0x00001fff 80312 Internal Registers
333 * 0x00002000 - 0x007fffff flash Memory
334 * 0x00800000 - 0x7fffffff PCI ATU Outbound Direct Window
335 * 0x80000000 - 0x83ffffff Primary PCI 32-bit Memory
336 * 0x84000000 - 0x87ffffff Primary PCI 64-bit Memory
337 * 0x88000000 - 0x8bffffff Secondary PCI 32-bit Memory
338 * 0x8c000000 - 0x8fffffff Secondary PCI 64-bit Memory
339 * 0x90000000 - 0x9000ffff Primary PCI IO Space
340 * 0x90010000 - 0x9001ffff Secondary PCI IO Space
341 * 0x90020000 - 0x9fffffff Unused
342 * 0xa0000000 - 0xbfffffff SDRAM
343 * 0xc0000000 - 0xefffffff Unused
344 * 0xf0000000 - 0xffffffff 80200 Internal Registers
345 *
346 *
347 * Virtual Address Range C B Description
348 * ----------------------- - - ----------------------------------
349 * 0x00000000 - 0x00000fff Y Y SDRAM
350 * 0x00001000 - 0x00001fff N N 80312 Internal Registers
351 * 0x00002000 - 0x007fffff Y N flash Memory
352 * 0x00800000 - 0x7fffffff N N PCI ATU Outbound Direct Window
353 * 0x80000000 - 0x83ffffff N N Primary PCI 32-bit Memory
354 * 0x84000000 - 0x87ffffff N N Primary PCI 64-bit Memory
355 * 0x88000000 - 0x8bffffff N N Secondary PCI 32-bit Memory
356 * 0x8c000000 - 0x8fffffff N N Secondary PCI 64-bit Memory
357 * 0x90000000 - 0x9000ffff N N Primary PCI IO Space
358 * 0x90010000 - 0x9001ffff N N Secondary PCI IO Space
359 * 0xa0000000 - 0xa0000fff Y N flash
360 * 0xa0001000 - 0xbfffffff Y Y SDRAM
361 * 0xc0000000 - 0xcfffffff Y Y Cache Flush Region
362 * 0xf0000000 - 0xffffffff N N 80200 Internal Registers
363 *
364 * The first level page table is at 0xa0004000. There are also
365 * 2 second-level tables at 0xa0008000 and 0xa0008400.
366 *
367 * This corresponds roughly to the physical memory map, i.e.
368 * we are quite nearly running VA==PA.
369 */
370
371 /*
372 * Examine the boot args string for options we need to know about
373 * now.
374 */
375 #if 0
376 process_kernel_args((char *)nwbootinfo.bt_args);
377 #endif
378
379 /*
380 * Fetch the SDRAM start/size from the i80312 SDRAM configration
381 * registers.
382 */
383 i80312_sdram_bounds(&obio_bs_tag, I80312_MEM_BASE, &memstart,
384 &memsize);
385
386 printf("initarm: Configuring system ...\n");
387
388 /* Fake bootconfig structure for the benefit of pmap.c */
389 /* XXX must make the memory description h/w independant */
390 bootconfig.dramblocks = 1;
391 bootconfig.dram[0].address = memstart;
392 bootconfig.dram[0].pages = memsize / NBPG;
393
394 /*
395 * Set up the variables that define the availablilty of
396 * physical memory. For now, we're going to set
397 * physical_freestart to 0xa0200000 (where the kernel
398 * was loaded), and allocate the memory we need downwards.
399 * If we get too close to the page tables that RedBoot
400 * set up, we will panic. We will update physical_freestart
401 * and physical_freeend later to reflect what pmap_bootstrap()
402 * wants to see.
403 *
404 * XXX pmap_bootstrap() needs an enema.
405 */
406 physical_start = bootconfig.dram[0].address;
407 physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
408
409 physical_freestart = 0xa0009000UL;
410 physical_freeend = 0xa0200000UL;
411
412 physmem = (physical_end - physical_start) / NBPG;
413
414 /* Tell the user about the memory */
415 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
416 physical_start, physical_end - 1);
417
418 /*
419 * Okay, the kernel starts 2MB in from the bottom of physical
420 * memory. We are going to allocate our bootstrap pages downwards
421 * from there.
422 *
423 * We need to allocate some fixed page tables to get the kernel
424 * going. We allocate one page directory and a number of page
425 * tables and store the physical addresses in the kernel_pt_table
426 * array.
427 *
428 * The kernel page directory must be on a 16K boundary. The page
429 * tables must be on 4K bounaries. What we do is allocate the
430 * page directory on the first 16K boundary that we encounter, and
431 * the page tables on 4K boundaries otherwise. Since we allocate
432 * at least 3 L2 page tables, we are guaranteed to encounter at
433 * least one 16K aligned region.
434 */
435
436 #ifdef VERBOSE_INIT_ARM
437 printf("Allocating page tables\n");
438 #endif
439
440 free_pages = (physical_freeend - physical_freestart) / NBPG;
441
442 #ifdef VERBOSE_INIT_ARM
443 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
444 physical_freestart, free_pages, free_pages);
445 #endif
446
447 /* Define a macro to simplify memory allocation */
448 #define valloc_pages(var, np) \
449 alloc_pages((var).pv_pa, (np)); \
450 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
451
452 #define alloc_pages(var, np) \
453 physical_freeend -= ((np) * NBPG); \
454 if (physical_freeend < physical_freestart) \
455 panic("initarm: out of memory"); \
456 (var) = physical_freeend; \
457 free_pages -= (np); \
458 memset((char *)(var), 0, ((np) * NBPG));
459
460 loop1 = 0;
461 kernel_l1pt.pv_pa = 0;
462 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
463 /* Are we 16KB aligned for an L1 ? */
464 if (((physical_freeend - PD_SIZE) & (PD_SIZE - 1)) == 0
465 && kernel_l1pt.pv_pa == 0) {
466 valloc_pages(kernel_l1pt, PD_SIZE / NBPG);
467 } else {
468 alloc_pages(kernel_pt_table[loop1], PT_SIZE / NBPG);
469 ++loop1;
470 }
471 }
472
473 /* This should never be able to happen but better confirm that. */
474 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (PD_SIZE-1)) != 0)
475 panic("initarm: Failed to align the kernel page directory\n");
476
477 /*
478 * Allocate a page for the system page mapped to V0x00000000
479 * This page will just contain the system vectors and can be
480 * shared by all processes.
481 */
482 alloc_pages(systempage.pv_pa, 1);
483
484 /* Allocate a page for the page table to map kernel page tables. */
485 valloc_pages(kernel_ptpt, PT_SIZE / NBPG);
486
487 /* Allocate stacks for all modes */
488 valloc_pages(irqstack, IRQ_STACK_SIZE);
489 valloc_pages(abtstack, ABT_STACK_SIZE);
490 valloc_pages(undstack, UND_STACK_SIZE);
491 valloc_pages(kernelstack, UPAGES);
492
493 #ifdef VERBOSE_INIT_ARM
494 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
495 irqstack.pv_va);
496 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
497 abtstack.pv_va);
498 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
499 undstack.pv_va);
500 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
501 kernelstack.pv_va);
502 #endif
503
504 /*
505 * XXX Defer this to later so that we can reclaim the memory
506 * XXX used by the RedBoot page tables.
507 */
508 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
509
510 /*
511 * Ok we have allocated physical pages for the primary kernel
512 * page tables
513 */
514
515 #ifdef VERBOSE_INIT_ARM
516 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
517 #endif
518
519 /*
520 * Now we start consturction of the L1 page table
521 * We start by mapping the L2 page tables into the L1.
522 * This means that we can replace L1 mappings later on if necessary
523 */
524 l1pagetable = kernel_l1pt.pv_pa;
525
526 /* Map the L2 pages tables in the L1 page table */
527 map_pagetable(l1pagetable, 0x00000000,
528 kernel_pt_table[KERNEL_PT_SYS]);
529 map_pagetable(l1pagetable, KERNEL_BASE,
530 kernel_pt_table[KERNEL_PT_KERNEL]);
531 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
532 map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
533 kernel_pt_table[KERNEL_PT_VMDATA + loop]);
534 map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE,
535 kernel_ptpt.pv_pa);
536
537 #ifdef VERBOSE_INIT_ARM
538 printf("Mapping kernel\n");
539 #endif
540
541 /* Now we fill in the L2 pagetable for the kernel static code/data */
542 l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL];
543
544 {
545 extern char etext[], _end[];
546 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
547 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
548 u_int logical;
549
550 /* Round down text size and round up total size. */
551 textsize = textsize & ~PGOFSET;
552 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
553
554 logical = 0x00200000; /* offset of kernel in RAM */
555
556 /*
557 * This maps the kernel text/data/bss VA==PA.
558 */
559 logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
560 physical_start + logical, textsize,
561 AP_KRW, PT_CACHEABLE);
562 logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
563 physical_start + logical, totalsize - textsize,
564 AP_KRW, PT_CACHEABLE);
565
566 #if 0 /* XXX No symbols yet. */
567 logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
568 physical_start + logical, kernexec->a_syms + sizeof(int)
569 + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
570 AP_KRW, PT_CACHEABLE);
571 #endif
572 }
573
574 #ifdef VERBOSE_INIT_ARM
575 printf("Constructing L2 page tables\n");
576 #endif
577
578 /* Map the stack pages */
579 map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa,
580 IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
581 map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa,
582 ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
583 map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa,
584 UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
585 map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa,
586 UPAGES * NBPG, AP_KRW, PT_CACHEABLE);
587 map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
588 PD_SIZE, AP_KRW, 0);
589
590 /* Map the page table that maps the kernel pages */
591 map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa);
592
593 /*
594 * Map entries in the page table used to map PTE's
595 * Basically every kernel page table gets mapped here
596 */
597 /* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
598 l2pagetable = kernel_ptpt.pv_pa;
599 map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)),
600 kernel_pt_table[KERNEL_PT_KERNEL]);
601 map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)),
602 kernel_ptpt.pv_pa);
603 map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)),
604 kernel_pt_table[KERNEL_PT_SYS]);
605 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
606 map_entry_nc(l2pagetable, ((KERNEL_VM_BASE +
607 (loop * 0x00400000)) >> (PGSHIFT-2)),
608 kernel_pt_table[KERNEL_PT_VMDATA + loop]);
609
610 /*
611 * Map the system page in the kernel page table for the bottom 1Meg
612 * of the virtual memory map.
613 */
614 l2pagetable = kernel_pt_table[KERNEL_PT_SYS];
615 map_entry(l2pagetable, 0x00000000, systempage.pv_pa);
616
617 /* Map the core memory needed before autoconfig */
618 loop = 0;
619 while (l1_sec_table[loop].size) {
620 vm_size_t sz;
621
622 #ifdef VERBOSE_INIT_ARM
623 printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
624 l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
625 l1_sec_table[loop].va);
626 #endif
627 for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_SEC_SIZE)
628 map_section(l1pagetable, l1_sec_table[loop].va + sz,
629 l1_sec_table[loop].pa + sz,
630 l1_sec_table[loop].flags);
631 ++loop;
632 }
633
634 /*
635 * Now we have the real page tables in place so we can switch to them.
636 * Once this is done we will be running with the REAL kernel page
637 * tables.
638 */
639
640 /*
641 * Update the physical_freestart/physical_freeend/free_pages
642 * variables.
643 */
644 {
645 extern char _end[];
646
647 physical_freestart = (((uintptr_t) _end) + PGOFSET) & ~PGOFSET;
648 physical_freeend = physical_end;
649 free_pages = (physical_freeend - physical_freestart) / NBPG;
650 }
651
652 /* Switch tables */
653 #ifdef VERBOSE_INIT_ARM
654 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
655 physical_freestart, free_pages, free_pages);
656 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
657 #endif
658 setttb(kernel_l1pt.pv_pa);
659
660 #ifdef VERBOSE_INIT_ARM
661 printf("done!\n");
662 #endif
663
664 #ifdef VERBOSE_INIT_ARM
665 printf("bootstrap done.\n");
666 #endif
667
668 /* Right, set up the vectors at the bottom of page 0 */
669 memcpy((char *)0x00000000, page0, page0_end - page0);
670
671 /* We have modified a text page so sync the icache */
672 cpu_cache_syncI();
673
674 /*
675 * Pages were allocated during the secondary bootstrap for the
676 * stacks for different CPU modes.
677 * We must now set the r13 registers in the different CPU modes to
678 * point to these stacks.
679 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
680 * of the stack memory.
681 */
682 printf("init subsystems: stacks ");
683
684 set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
685 set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
686 set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
687
688 /*
689 * Well we should set a data abort handler.
690 * Once things get going this will change as we will need a proper
691 * handler.
692 * Until then we will use a handler that just panics but tells us
693 * why.
694 * Initialisation of the vectors will just panic on a data abort.
695 * This just fills in a slighly better one.
696 */
697 printf("vectors ");
698 data_abort_handler_address = (u_int)data_abort_handler;
699 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
700 undefined_handler_address = (u_int)undefinedinstruction_bounce;
701
702 /* At last !
703 * We now have the kernel in physical memory from the bottom upwards.
704 * Kernel page tables are physically above this.
705 * The kernel is mapped to KERNEL_TEXT_BASE
706 * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
707 * The page tables are mapped to 0xefc00000
708 */
709
710 /* Initialise the undefined instruction handlers */
711 printf("undefined ");
712 undefined_init();
713
714 /* Boot strap pmap telling it where the kernel page table is */
715 printf("pmap ");
716 pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
717
718 /* Setup the IRQ system */
719 printf("irq ");
720 irq_init();
721 printf("done.\n");
722
723 #ifdef IPKDB
724 /* Initialise ipkdb */
725 ipkdb_init();
726 if (boothowto & RB_KDB)
727 ipkdb_connect(0);
728 #endif
729
730 #ifdef DDB
731 printf("ddb: ");
732 db_machine_init();
733 #if 0
734 ddb_init(end[0], end + 1, esym);
735 #endif
736
737 if (boothowto & RB_KDB)
738 Debugger();
739 #endif
740
741 /* We return the new stack pointer address */
742 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
743 }
744
745 void
746 process_kernel_args(char *args)
747 {
748
749 boothowto = 0;
750
751 /* Make a local copy of the bootargs */
752 strncpy(bootargs, args, MAX_BOOT_STRING);
753
754 args = bootargs;
755 boot_file = bootargs;
756
757 /* Skip the kernel image filename */
758 while (*args != ' ' && *args != 0)
759 ++args;
760
761 if (*args != 0)
762 *args++ = 0;
763
764 while (*args == ' ')
765 ++args;
766
767 boot_args = args;
768
769 printf("bootfile: %s\n", boot_file);
770 printf("bootargs: %s\n", boot_args);
771
772 parse_mi_bootargs(boot_args);
773 }
774
775 void
776 consinit(void)
777 {
778 static int consinit_called;
779
780 if (consinit_called != 0)
781 return;
782
783 consinit_called = 1;
784
785 #if NCOM > 0
786 if (comcnattach(&obio_bs_tag, IQ80310_UART2, comcnspeed,
787 COM_FREQ, comcnmode))
788 panic("can't init serial console @%lx", IQ80310_UART1);
789 #else
790 panic("serial console @%lx not configured", IQ80310_UART1);
791 #endif
792 }
793