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