Home | History | Annotate | Line # | Download | only in gemini
gemini_machdep.c revision 1.8
      1 /*	$NetBSD: gemini_machdep.c,v 1.8 2008/11/13 01:32:48 cliff Exp $	*/
      2 
      3 /* adapted from:
      4  *	NetBSD: sdp24xx_machdep.c,v 1.4 2008/08/27 11:03:10 matt Exp
      5  */
      6 
      7 /*
      8  * Machine dependent functions for kernel setup for TI OSK5912 board.
      9  * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c
     10  *
     11  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
     12  * Written by Hiroyuki Bessho for Genetec Corporation.
     13  *
     14  * Redistribution and use in source and binary forms, with or without
     15  * modification, are permitted provided that the following conditions
     16  * are met:
     17  * 1. Redistributions of source code must retain the above copyright
     18  *    notice, this list of conditions and the following disclaimer.
     19  * 2. Redistributions in binary form must reproduce the above copyright
     20  *    notice, this list of conditions and the following disclaimer in the
     21  *    documentation and/or other materials provided with the distribution.
     22  * 3. The name of Genetec Corporation may not be used to endorse or
     23  *    promote products derived from this software without specific prior
     24  *    written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  *
     38  * Copyright (c) 2001 Wasabi Systems, Inc.
     39  * All rights reserved.
     40  *
     41  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     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 for the NetBSD Project by
     54  *	Wasabi Systems, Inc.
     55  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     56  *    or promote products derived from this software without specific prior
     57  *    written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     61  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     62  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     63  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     64  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     65  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     66  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     67  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     68  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69  * POSSIBILITY OF SUCH DAMAGE.
     70  *
     71  * Copyright (c) 1997,1998 Mark Brinicombe.
     72  * Copyright (c) 1997,1998 Causality Limited.
     73  * All rights reserved.
     74  *
     75  * Redistribution and use in source and binary forms, with or without
     76  * modification, are permitted provided that the following conditions
     77  * are met:
     78  * 1. Redistributions of source code must retain the above copyright
     79  *    notice, this list of conditions and the following disclaimer.
     80  * 2. Redistributions in binary form must reproduce the above copyright
     81  *    notice, this list of conditions and the following disclaimer in the
     82  *    documentation and/or other materials provided with the distribution.
     83  * 3. All advertising materials mentioning features or use of this software
     84  *    must display the following acknowledgement:
     85  *	This product includes software developed by Mark Brinicombe
     86  *	for the NetBSD Project.
     87  * 4. The name of the company nor the name of the author may be used to
     88  *    endorse or promote products derived from this software without specific
     89  *    prior written permission.
     90  *
     91  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     92  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     93  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     94  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     95  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     96  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     97  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     98  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     99  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    100  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    101  * SUCH DAMAGE.
    102  *
    103  * Copyright (c) 2007 Microsoft
    104  * All rights reserved.
    105  *
    106  * Redistribution and use in source and binary forms, with or without
    107  * modification, are permitted provided that the following conditions
    108  * are met:
    109  * 1. Redistributions of source code must retain the above copyright
    110  *    notice, this list of conditions and the following disclaimer.
    111  * 2. Redistributions in binary form must reproduce the above copyright
    112  *    notice, this list of conditions and the following disclaimer in the
    113  *    documentation and/or other materials provided with the distribution.
    114  * 3. All advertising materials mentioning features or use of this software
    115  *    must display the following acknowledgement:
    116  *	This product includes software developed by Microsoft
    117  *
    118  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    119  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    120  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    121  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
    122  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    123  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    124  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    125  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    126  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    127  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    128  * SUCH DAMAGE.
    129  */
    130 
    131 #include <sys/cdefs.h>
    132 __KERNEL_RCSID(0, "$NetBSD: gemini_machdep.c,v 1.8 2008/11/13 01:32:48 cliff Exp $");
    133 
    134 #include "opt_machdep.h"
    135 #include "opt_ddb.h"
    136 #include "opt_kgdb.h"
    137 #include "opt_ipkdb.h"
    138 #include "opt_md.h"
    139 #include "opt_com.h"
    140 #include "opt_gemini.h"
    141 #include "geminiwdt.h"
    142 #include "md.h"
    143 
    144 #include <sys/param.h>
    145 #include <sys/device.h>
    146 #include <sys/systm.h>
    147 #include <sys/kernel.h>
    148 #include <sys/exec.h>
    149 #include <sys/proc.h>
    150 #include <sys/msgbuf.h>
    151 #include <sys/reboot.h>
    152 #include <sys/termios.h>
    153 #include <sys/ksyms.h>
    154 
    155 #include <uvm/uvm_extern.h>
    156 
    157 #include <sys/conf.h>
    158 #include <dev/cons.h>
    159 #include <dev/md.h>
    160 
    161 #include <machine/db_machdep.h>
    162 #include <ddb/db_sym.h>
    163 #include <ddb/db_extern.h>
    164 #ifdef KGDB
    165 #include <sys/kgdb.h>
    166 #endif
    167 
    168 #include <machine/bootconfig.h>
    169 #include <machine/bus.h>
    170 #include <machine/cpu.h>
    171 #include <machine/frame.h>
    172 #include <arm/armreg.h>
    173 #include <arm/undefined.h>
    174 
    175 #include <arm/arm32/machdep.h>
    176 
    177 #include <arm/gemini/gemini_reg.h>
    178 #include <arm/gemini/gemini_var.h>
    179 #include <arm/gemini/gemini_wdtvar.h>
    180 #include <arm/gemini/gemini_com.h>
    181 #include <arm/gemini/lpc_com.h>
    182 
    183 #include <evbarm/gemini/gemini.h>
    184 
    185 #if defined(VERBOSE_INIT_ARM)
    186 # define GEMINI_PUTCHAR(c)	gemini_putchar(c)
    187 # define GEMINI_PUTHEX(n)	gemini_puthex(n)
    188 #else	/* VERBOSE_INIT_ARM */
    189 # define GEMINI_PUTCHAR(c)
    190 # define GEMINI_PUTHEX(n)
    191 #endif	/* VERBOSE_INIT_ARM */
    192 
    193 /*
    194  * Address to call from cpu_reset() to reset the machine.
    195  * This is machine architecture dependant as it varies depending
    196  * on where the ROM appears when you turn the MMU off.
    197  */
    198 
    199 u_int cpu_reset_address = 0;
    200 
    201 /* Define various stack sizes in pages */
    202 #define IRQ_STACK_SIZE	1
    203 #define FIQ_STACK_SIZE	1
    204 #define ABT_STACK_SIZE	1
    205 #ifdef IPKDB
    206 #define UND_STACK_SIZE	2
    207 #else
    208 #define UND_STACK_SIZE	1
    209 #endif
    210 
    211 BootConfig bootconfig;		/* Boot config storage */
    212 char *boot_args = NULL;
    213 char *boot_file = NULL;
    214 
    215 /* Physical address of the beginning of SDRAM. */
    216 paddr_t physical_start;
    217 /* Physical address of the first byte after the end of SDRAM. */
    218 paddr_t physical_end;
    219 /* Number of pages of memory. */
    220 int physmem = 0;
    221 
    222 /* Same things, but for the free (unused by the kernel) memory. */
    223 static paddr_t physical_freestart, physical_freeend;
    224 static u_int free_pages;
    225 
    226 /* Physical and virtual addresses for some global pages */
    227 pv_addr_t fiqstack;
    228 pv_addr_t irqstack;
    229 pv_addr_t undstack;
    230 pv_addr_t abtstack;
    231 pv_addr_t kernelstack;	/* stack for SVC mode */
    232 
    233 /* Physical address of the message buffer. */
    234 paddr_t msgbufphys;
    235 
    236 extern u_int data_abort_handler_address;
    237 extern u_int prefetch_abort_handler_address;
    238 extern u_int undefined_handler_address;
    239 extern char KERNEL_BASE_phys[];
    240 extern char KERNEL_BASE_virt[];
    241 extern char etext[], __data_start[], _edata[], __bss_start[], __bss_end__[];
    242 extern char _end[];
    243 
    244 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    245 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    246 #define	KERNEL_PT_KERNEL_NUM	4
    247 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    248 				        /* Page tables for mapping kernel VM */
    249 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    250 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    251 
    252 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    253 
    254 extern struct user *proc0paddr;
    255 
    256 /*
    257  * Macros to translate between physical and virtual for a subset of the
    258  * kernel address space.  *Not* for general use.
    259  */
    260 #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
    261 
    262 #define KERN_VTOPHYS(va) \
    263 	((paddr_t)((vaddr_t)va - KERNEL_BASE + GEMINI_DRAM_BASE))
    264 #define KERN_PHYSTOV(pa) \
    265 	((vaddr_t)((paddr_t)pa - GEMINI_DRAM_BASE + KERNEL_BASE))
    266 
    267 /* Prototypes */
    268 
    269 void gemini_intr_init(bus_space_tag_t);
    270 void consinit(void);
    271 #ifdef KGDB
    272 static void kgdb_port_init(void);
    273 #endif
    274 
    275 static void setup_real_page_tables(void);
    276 static void init_clocks(void);
    277 
    278 bs_protos(bs_notimpl);
    279 
    280 #include "com.h"
    281 #if NCOM > 0
    282 #include <dev/ic/comreg.h>
    283 #include <dev/ic/comvar.h>
    284 #endif
    285 
    286 
    287 static void gemini_global_reset(void) __attribute__ ((noreturn));
    288 static void gemini_cpu1_start(void);
    289 
    290 static void
    291 gemini_global_reset(void)
    292 {
    293 #if defined(GEMINI_MASTER) || defined(GEMINI_SINGLE)
    294 	volatile uint32_t *rp;
    295 	uint32_t r;
    296 
    297 	rp = (volatile uint32_t *)
    298 		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
    299 	r = *rp;
    300 	r |= GLOBAL_RESET_GLOBAL;
    301 	*rp = r;
    302 #endif
    303 	for(;;);
    304 	/* NOTREACHED */
    305 }
    306 
    307 static void
    308 gemini_cpu1_start(void)
    309 {
    310 #ifdef GEMINI_MASTER
    311 	volatile uint32_t *rp;
    312 	uint32_t r;
    313 
    314 	rp = (volatile uint32_t *)
    315 		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
    316 	r = *rp;
    317 	r &= ~GLOBAL_RESET_CPU1;
    318 	*rp = r;
    319 #endif
    320 }
    321 
    322 /*
    323  * void cpu_reboot(int howto, char *bootstr)
    324  *
    325  * Reboots the system
    326  *
    327  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    328  * then reset the CPU.
    329  */
    330 void
    331 cpu_reboot(int howto, char *bootstr)
    332 {
    333 	extern struct geminitmr_softc *ref_sc;
    334 
    335 #ifdef DIAGNOSTIC
    336 	/* info */
    337 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    338 #endif
    339 
    340 	/*
    341 	 * If we are still cold then hit the air brakes
    342 	 * and crash to earth fast
    343 	 */
    344 	if (cold) {
    345 		doshutdownhooks();
    346 		pmf_system_shutdown(boothowto);
    347 		printf("The operating system has halted.\n");
    348 		printf("Please press any key to reboot.\n\n");
    349 		cngetc();
    350 		printf("rebooting...\n");
    351 		if (ref_sc != NULL)
    352 			delay(2000);			/* cnflush(); */
    353 		gemini_global_reset();
    354 		/*NOTREACHED*/
    355 	}
    356 
    357 	/* Disable console buffering */
    358 	cnpollc(1);
    359 
    360 	/*
    361 	 * If RB_NOSYNC was not specified sync the discs.
    362 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    363 	 * unmount.  It looks like syslogd is getting woken up only to find
    364 	 * that it cannot page part of the binary in as the filesystem has
    365 	 * been unmounted.
    366 	 */
    367 	if (!(howto & RB_NOSYNC))
    368 		bootsync();
    369 
    370 	/* Say NO to interrupts */
    371 	splhigh();
    372 
    373 	/* Do a dump if requested. */
    374 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    375 		dumpsys();
    376 
    377 	/* Run any shutdown hooks */
    378 	doshutdownhooks();
    379 
    380 	pmf_system_shutdown(boothowto);
    381 
    382 	/* Make sure IRQ's are disabled */
    383 	IRQdisable;
    384 
    385 	if (howto & RB_HALT) {
    386 		printf("The operating system has halted.\n");
    387 		printf("Please press any key to reboot.\n\n");
    388 		cngetc();
    389 	}
    390 
    391 	printf("rebooting...\n");
    392 	if (ref_sc != NULL)
    393 		delay(2000);			/* cnflush(); */
    394 	gemini_global_reset();
    395 	/*NOTREACHED*/
    396 }
    397 
    398 /*
    399  * Static device mappings. These peripheral registers are mapped at
    400  * fixed virtual addresses very early in initarm() so that we can use
    401  * them while booting the kernel, and stay at the same address
    402  * throughout whole kernel's life time.
    403  *
    404  * We use this table twice; once with bootstrap page table, and once
    405  * with kernel's page table which we build up in initarm().
    406  *
    407  * Since we map these registers into the bootstrap page table using
    408  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    409  * registers segment-aligned and segment-rounded in order to avoid
    410  * using the 2nd page tables.
    411  */
    412 
    413 #define	_A(a)	((a) & ~L1_S_OFFSET)
    414 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    415 
    416 static const struct pmap_devmap devmap[] = {
    417 	/* Global regs */
    418 	{
    419 		.pd_va = _A(GEMINI_GLOBAL_VBASE),
    420 		.pd_pa = _A(GEMINI_GLOBAL_BASE),
    421 		.pd_size = _S(L1_S_SIZE),
    422 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    423 		.pd_cache = PTE_NOCACHE
    424 	},
    425 
    426 	/* Watchdog */
    427 	{
    428 		.pd_va = _A(GEMINI_WATCHDOG_VBASE),
    429 		.pd_pa = _A(GEMINI_WATCHDOG_BASE),
    430 		.pd_size = _S(L1_S_SIZE),
    431 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    432 		.pd_cache = PTE_NOCACHE
    433 	},
    434 
    435 	/* UART */
    436 	{
    437 		.pd_va = _A(GEMINI_UART_VBASE),
    438 		.pd_pa = _A(GEMINI_UART_BASE),
    439 		.pd_size = _S(L1_S_SIZE),
    440 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    441 		.pd_cache = PTE_NOCACHE
    442 	},
    443 
    444 	/* LPCHC */
    445 	{
    446 		.pd_va = _A(GEMINI_LPCHC_VBASE),
    447 		.pd_pa = _A(GEMINI_LPCHC_BASE),
    448 		.pd_size = _S(L1_S_SIZE),
    449 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    450 		.pd_cache = PTE_NOCACHE
    451 	},
    452 
    453 	/* LPCIO */
    454 	{
    455 		.pd_va = _A(GEMINI_LPCIO_VBASE),
    456 		.pd_pa = _A(GEMINI_LPCIO_BASE),
    457 		.pd_size = _S(L1_S_SIZE),
    458 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    459 		.pd_cache = PTE_NOCACHE
    460 	},
    461 
    462 	/* Timers */
    463 	{
    464 		.pd_va = _A(GEMINI_TIMER_VBASE),
    465 		.pd_pa = _A(GEMINI_TIMER_BASE),
    466 		.pd_size = _S(L1_S_SIZE),
    467 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    468 		.pd_cache = PTE_NOCACHE
    469 	},
    470 
    471 #if defined(MEMORY_DISK_DYNAMIC)
    472 	/* Ramdisk */
    473 	{
    474 		.pd_va = _A(GEMINI_RAMDISK_VBASE),
    475 		.pd_pa = _A(GEMINI_RAMDISK_PBASE),
    476 		.pd_size = _S(GEMINI_RAMDISK_SIZE),
    477 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    478 		.pd_cache = PTE_NOCACHE
    479 	},
    480 #endif
    481 
    482 	{0}	/* list terminator */
    483 };
    484 
    485 #undef	_A
    486 #undef	_S
    487 
    488 #ifdef DDB
    489 static void gemini_db_trap(int where)
    490 {
    491 #if  NGEMINIWDT > 0
    492 	static int oldwatchdogstate;
    493 
    494 	if (where) {
    495 		oldwatchdogstate = geminiwdt_enable(0);
    496 	} else {
    497 		geminiwdt_enable(oldwatchdogstate);
    498 	}
    499 #endif
    500 }
    501 #endif
    502 
    503 #if defined(VERBOSE_INIT_ARM) || 1
    504 void gemini_putchar(char c);
    505 void
    506 gemini_putchar(char c)
    507 {
    508 	unsigned char *com0addr = (unsigned char *)GEMINI_UART_VBASE;
    509 	int timo = 150000;
    510 
    511 	while ((com0addr[COM_REG_LSR * 4] & LSR_TXRDY) == 0)
    512 		if (--timo == 0)
    513 			break;
    514 
    515 	com0addr[COM_REG_TXDATA] = c;
    516 
    517 	while ((com0addr[COM_REG_LSR * 4] & LSR_TSRE) == 0)
    518 		if (--timo == 0)
    519 			break;
    520 }
    521 
    522 void gemini_puthex(unsigned int);
    523 void
    524 gemini_puthex(unsigned int val)
    525 {
    526 	char hexc[] = "0123456789abcdef";
    527 
    528 	gemini_putchar('0');
    529 	gemini_putchar('x');
    530 	gemini_putchar(hexc[(val >> 28) & 0xf]);
    531 	gemini_putchar(hexc[(val >> 24) & 0xf]);
    532 	gemini_putchar(hexc[(val >> 20) & 0xf]);
    533 	gemini_putchar(hexc[(val >> 16) & 0xf]);
    534 	gemini_putchar(hexc[(val >> 12) & 0xf]);
    535 	gemini_putchar(hexc[(val >> 8) & 0xf]);
    536 	gemini_putchar(hexc[(val >> 4) & 0xf]);
    537 	gemini_putchar(hexc[(val >> 0) & 0xf]);
    538 }
    539 #endif	/* VERBOSE_INIT_ARM */
    540 
    541 /*
    542  * u_int initarm(...)
    543  *
    544  * Initial entry point on startup. This gets called before main() is
    545  * entered.
    546  * It should be responsible for setting up everything that must be
    547  * in place when main is called.
    548  * This includes
    549  *   Taking a copy of the boot configuration structure.
    550  *   Initialising the physical console so characters can be printed.
    551  *   Setting up page tables for the kernel
    552  *   Relocating the kernel to the bottom of physical memory
    553  */
    554 u_int
    555 initarm(void *arg)
    556 {
    557 	GEMINI_PUTCHAR('0');
    558 
    559 	/*
    560 	 * start cpu#1 now
    561 	 */
    562 	gemini_cpu1_start();
    563 
    564 	/*
    565 	 * When we enter here, we are using a temporary first level
    566 	 * translation table with section entries in it to cover the OBIO
    567 	 * peripherals and SDRAM.  The temporary first level translation table
    568 	 * is at the end of SDRAM.
    569 	 */
    570 
    571 	/* Heads up ... Setup the CPU / MMU / TLB functions. */
    572 	GEMINI_PUTCHAR('1');
    573 	if (set_cpufuncs())
    574 		panic("cpu not recognized!");
    575 
    576 	GEMINI_PUTCHAR('2');
    577 	init_clocks();
    578 	GEMINI_PUTCHAR('3');
    579 
    580 	/* The console is going to try to map things.  Give pmap a devmap. */
    581 	pmap_devmap_register(devmap);
    582 	GEMINI_PUTCHAR('4');
    583 	consinit();
    584 	GEMINI_PUTCHAR('5');
    585 #ifdef KGDB
    586 	kgdb_port_init();
    587 #endif
    588 
    589 #ifdef VERBOSE_INIT_ARM
    590 	/* Talk to the user */
    591 	printf("\nNetBSD/evbarm (gemini) booting ...\n");
    592 #endif
    593 
    594 #ifdef BOOT_ARGS
    595 	char mi_bootargs[] = BOOT_ARGS;
    596 	parse_mi_bootargs(mi_bootargs);
    597 #endif
    598 
    599 #ifdef VERBOSE_INIT_ARM
    600 	printf("initarm: Configuring system ...\n");
    601 #endif
    602 
    603 	/*
    604 	 * Set up the variables that define the availability of physical
    605 	 * memory.
    606 	 */
    607 	physical_start = GEMINI_DRAM_BASE;
    608 #define	MEMSIZE_BYTES 	(MEMSIZE * 1024 * 1024)
    609 	physical_end = (physical_start & ~(0x400000-1)) + MEMSIZE_BYTES;
    610 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    611 
    612 	/* Fake bootconfig structure for the benefit of pmap.c. */
    613 	bootconfig.dramblocks = 1;
    614 	bootconfig.dram[0].address = physical_start;
    615 	bootconfig.dram[0].pages = physmem;
    616 
    617 	/*
    618 	 * Our kernel is at the beginning of memory, so set our free space to
    619 	 * all the memory after the kernel.
    620 	 */
    621 	physical_freestart = KERN_VTOPHYS(round_page((vaddr_t) _end));
    622 	physical_freeend = physical_end;
    623 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    624 
    625 	/*
    626 	 * This is going to do all the hard work of setting up the first and
    627 	 * and second level page tables.  Pages of memory will be allocated
    628 	 * and mapped for other structures that are required for system
    629 	 * operation.  When it returns, physical_freestart and free_pages will
    630 	 * have been updated to reflect the allocations that were made.  In
    631 	 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
    632 	 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
    633 	 * the memory that was allocated for them.
    634 	 */
    635 	setup_real_page_tables();
    636 
    637 	/*
    638 	 * Moved from cpu_startup() as data_abort_handler() references
    639 	 * this during uvm init.
    640 	 */
    641 	proc0paddr = (struct user *)kernelstack.pv_va;
    642 	lwp0.l_addr = proc0paddr;
    643 
    644 #ifdef VERBOSE_INIT_ARM
    645 	printf("bootstrap done.\n");
    646 #endif
    647 
    648 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    649 
    650 	/*
    651 	 * Pages were allocated during the secondary bootstrap for the
    652 	 * stacks for different CPU modes.
    653 	 * We must now set the r13 registers in the different CPU modes to
    654 	 * point to these stacks.
    655 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    656 	 * of the stack memory.
    657 	 */
    658 #ifdef VERBOSE_INIT_ARM
    659 	printf("init subsystems: stacks ");
    660 #endif
    661 
    662 	set_stackptr(PSR_FIQ32_MODE, fiqstack.pv_va + FIQ_STACK_SIZE * PAGE_SIZE);
    663 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    664 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    665 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    666 
    667 	/*
    668 	 * Well we should set a data abort handler.
    669 	 * Once things get going this will change as we will need a proper
    670 	 * handler.
    671 	 * Until then we will use a handler that just panics but tells us
    672 	 * why.
    673 	 * Initialisation of the vectors will just panic on a data abort.
    674 	 * This just fills in a slightly better one.
    675 	 */
    676 #ifdef VERBOSE_INIT_ARM
    677 	printf("vectors ");
    678 #endif
    679 	data_abort_handler_address = (u_int)data_abort_handler;
    680 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    681 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    682 
    683 	/* Initialise the undefined instruction handlers */
    684 #ifdef VERBOSE_INIT_ARM
    685 	printf("undefined ");
    686 #endif
    687 	undefined_init();
    688 
    689 	/* Load memory into UVM. */
    690 #ifdef VERBOSE_INIT_ARM
    691 	printf("page ");
    692 #endif
    693 	uvm_setpagesize();        /* initialize PAGE_SIZE-dependent variables */
    694 
    695 #if defined(MEMORY_DISK_DYNAMIC)
    696 	uvm_page_physload(atop(physical_freestart), atop(GEMINI_RAMDISK_PBASE),
    697 	    atop(physical_freestart), atop(GEMINI_RAMDISK_PBASE),
    698 	    VM_FREELIST_DEFAULT);
    699 	uvm_page_physload(atop(GEMINI_RAMDISK_PEND), atop(physical_freeend),
    700 	    atop(GEMINI_RAMDISK_PEND), atop(physical_freeend),
    701 	    VM_FREELIST_DEFAULT);
    702 #else
    703 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    704 	    atop(physical_freestart), atop(physical_freeend),
    705 	    VM_FREELIST_DEFAULT);
    706 #endif
    707 	uvm_page_physload(atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
    708 	    atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
    709 	    VM_FREELIST_DEFAULT);
    710 
    711 	/* Boot strap pmap telling it where the kernel page table is */
    712 #ifdef VERBOSE_INIT_ARM
    713 	printf("pmap ");
    714 #endif
    715 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    716 
    717 #ifdef VERBOSE_INIT_ARM
    718 	printf("done.\n");
    719 #endif
    720 
    721 #ifdef IPKDB
    722 	/* Initialise ipkdb */
    723 	ipkdb_init();
    724 	if (boothowto & RB_KDB)
    725 		ipkdb_connect(0);
    726 #endif
    727 
    728 #if defined(MEMORY_DISK_DYNAMIC)
    729 	md_root_setconf((char *)GEMINI_RAMDISK_VBASE, GEMINI_RAMDISK_SIZE);
    730 #endif
    731 
    732 #ifdef KGDB
    733 	if (boothowto & RB_KDB) {
    734 		kgdb_debug_init = 1;
    735 		kgdb_connect(1);
    736 	}
    737 #endif
    738 
    739 #ifdef DDB
    740 	db_trap_callback = gemini_db_trap;
    741 	db_machine_init();
    742 
    743 	/* Firmware doesn't load symbols. */
    744 	ddb_init(0, NULL, NULL);
    745 
    746 	if (boothowto & RB_KDB)
    747 		Debugger();
    748 #endif
    749 	printf("initarm done.\n");
    750 
    751 	/* We return the new stack pointer address */
    752 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    753 }
    754 
    755 static void
    756 init_clocks(void)
    757 {
    758 }
    759 
    760 #ifndef CONSADDR
    761 #error Specify the address of the console UART with the CONSADDR option.
    762 #endif
    763 #ifndef CONSPEED
    764 #define CONSPEED 19200
    765 #endif
    766 #ifndef CONMODE
    767 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    768 #endif
    769 
    770 static const bus_addr_t consaddr = CONSADDR;
    771 static const int conspeed = CONSPEED;
    772 static const int conmode = CONMODE;
    773 
    774 #if CONSADDR==0x42000000
    775 /*
    776  * console initialization for obio com console
    777  */
    778 void
    779 consinit(void)
    780 {
    781 	static int consinit_called = 0;
    782 
    783 	if (consinit_called != 0)
    784 		return;
    785 	consinit_called = 1;
    786 
    787 	if (comcnattach(&gemini_a4x_bs_tag, consaddr, conspeed,
    788 		GEMINI_COM_FREQ, COM_TYPE_16550_NOERS, conmode))
    789 			panic("Serial console can not be initialized.");
    790 }
    791 
    792 #elif CONSADDR==0x478003f8
    793 # include <arm/gemini/gemini_lpcvar.h>
    794 /*
    795  * console initialization for lpc com console
    796  */
    797 void
    798 consinit(void)
    799 {
    800 	static int consinit_called = 0;
    801 	bus_space_tag_t iot = &gemini_bs_tag;
    802 	bus_space_handle_t lpchc_ioh;
    803 	bus_space_handle_t lpcio_ioh;
    804 	bus_size_t sz = L1_S_SIZE;
    805 	gemini_lpc_softc_t lpcsoftc;
    806 	gemini_lpc_bus_ops_t *ops;
    807 	void *lpctag = &lpcsoftc;
    808 	uint32_t r;
    809 	extern gemini_lpc_bus_ops_t gemini_lpc_bus_ops;
    810 
    811 	ops = &gemini_lpc_bus_ops;
    812 
    813 	if (consinit_called != 0)
    814 		return;
    815 	consinit_called = 1;
    816 
    817 	if (bus_space_map(iot, GEMINI_LPCHC_BASE, sz, 0, &lpchc_ioh))
    818 		panic("consinit: LPCHC can not be mapped.");
    819 
    820 	if (bus_space_map(iot, GEMINI_LPCIO_BASE, sz, 0, &lpcio_ioh))
    821 		panic("consinit: LPCIO can not be mapped.");
    822 
    823 	/* enable the LPC bus */
    824 	r = bus_space_read_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR);
    825 	r |= LPCHC_CSR_BEN;
    826 	bus_space_write_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR, r);
    827 
    828 	memset(&lpcsoftc, 0, sizeof(lpcsoftc));
    829 	lpcsoftc.sc_iot = iot;
    830 	lpcsoftc.sc_ioh = lpcio_ioh;
    831 
    832 	/* activate Serial Port 1 */
    833 	(*ops->lpc_pnp_enter)(lpctag);
    834 	(*ops->lpc_pnp_write)(lpctag, 1, 0x30, 0x01);
    835 	(*ops->lpc_pnp_exit)(lpctag);
    836 
    837 	if (comcnattach(iot, consaddr, conspeed,
    838 		IT8712F_COM_FREQ, COM_TYPE_NORMAL, conmode)) {
    839 			panic("Serial console can not be initialized.");
    840 	}
    841 
    842 	bus_space_unmap(iot, lpcio_ioh, sz);
    843 	bus_space_unmap(iot, lpchc_ioh, sz);
    844 }
    845 #else
    846 # error unknown console
    847 #endif
    848 
    849 #ifdef KGDB
    850 #ifndef KGDB_DEVADDR
    851 #error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
    852 #endif
    853 #ifndef KGDB_DEVRATE
    854 #define KGDB_DEVRATE 19200
    855 #endif
    856 
    857 #ifndef KGDB_DEVMODE
    858 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    859 #endif
    860 static const vaddr_t comkgdbaddr = KGDB_DEVADDR;
    861 static const int comkgdbspeed = KGDB_DEVRATE;
    862 static const int comkgdbmode = KGDB_DEVMODE;
    863 
    864 void
    865 static kgdb_port_init(void)
    866 {
    867 	static int kgdbsinit_called = 0;
    868 
    869 	if (kgdbsinit_called != 0)
    870 		return;
    871 
    872 	kgdbsinit_called = 1;
    873 
    874 	bus_space_handle_t bh;
    875 	if (bus_space_map(&gemini_a4x_bs_tag, comkgdbaddr,
    876 		GEMINI_UART_SIZE, 0, &bh))
    877 			panic("kgdb port can not be mapped.");
    878 
    879 	if (com_kgdb_attach(&gemini_a4x_bs_tag, comkgdbaddr, comkgdbspeed,
    880 		GEMINI_UART_SIZE, COM_TYPE_16550_NOERS, comkgdbmode))
    881 			panic("KGDB uart can not be initialized.");
    882 
    883 	bus_space_unmap(&gemini_a4x_bs_tag, bh, GEMINI_UART_SIZE);
    884 }
    885 #endif
    886 
    887 static void
    888 setup_real_page_tables(void)
    889 {
    890 	/*
    891 	 * We need to allocate some fixed page tables to get the kernel going.
    892 	 *
    893 	 * We are going to allocate our bootstrap pages from the beginning of
    894 	 * the free space that we just calculated.  We allocate one page
    895 	 * directory and a number of page tables and store the physical
    896 	 * addresses in the kernel_pt_table array.
    897 	 *
    898 	 * The kernel page directory must be on a 16K boundary.  The page
    899 	 * tables must be on 4K boundaries.  What we do is allocate the
    900 	 * page directory on the first 16K boundary that we encounter, and
    901 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    902 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    903 	 * least one 16K aligned region.
    904 	 */
    905 
    906 #ifdef VERBOSE_INIT_ARM
    907 	printf("Allocating page tables\n");
    908 #endif
    909 
    910 	/*
    911 	 * Define a macro to simplify memory allocation.  As we allocate the
    912 	 * memory, make sure that we don't walk over our temporary first level
    913 	 * translation table.
    914 	 */
    915 #define valloc_pages(var, np)						\
    916 	(var).pv_pa = physical_freestart;				\
    917 	physical_freestart += ((np) * PAGE_SIZE);			\
    918 	if (physical_freestart > (physical_freeend - L1_TABLE_SIZE))	\
    919 		panic("initarm: out of memory");			\
    920 	free_pages -= (np);						\
    921 	(var).pv_va = KERN_PHYSTOV((var).pv_pa);			\
    922 	memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
    923 
    924 	int loop, pt_index;
    925 
    926 	pt_index = 0;
    927 	kernel_l1pt.pv_pa = 0;
    928 	kernel_l1pt.pv_va = 0;
    929 #ifdef VERBOSE_INIT_ARM
    930 	printf("%s: physical_freestart %#lx\n", __func__, physical_freestart);
    931 #endif
    932 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    933 		/* Are we 16KB aligned for an L1 ? */
    934 		if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
    935 		    && kernel_l1pt.pv_pa == 0) {
    936 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    937 		} else {
    938 			valloc_pages(kernel_pt_table[pt_index],
    939 			    L2_TABLE_SIZE / PAGE_SIZE);
    940 			++pt_index;
    941 		}
    942 	}
    943 
    944 #ifdef VERBOSE_INIT_ARM
    945 	pt_index=0;
    946 	printf("%s: kernel_l1pt: %#lx:%#lx\n",
    947 		__func__, kernel_l1pt.pv_va, kernel_l1pt.pv_pa);
    948 	printf("%s: kernel_pt_table:\n", __func__);
    949 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    950 		printf("\t%#lx:%#lx\n", kernel_pt_table[pt_index].pv_va,
    951 			kernel_pt_table[pt_index].pv_pa);
    952 		++pt_index;
    953 	}
    954 #endif
    955 
    956 	/* This should never be able to happen but better confirm that. */
    957 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    958 		panic("initarm: Failed to align the kernel page directory");
    959 
    960 	/*
    961 	 * Allocate a page for the system page mapped to V0x00000000
    962 	 * This page will just contain the system vectors and can be
    963 	 * shared by all processes.
    964 	 */
    965 	valloc_pages(systempage, 1);
    966 	systempage.pv_va = ARM_VECTORS_HIGH;
    967 
    968 	/* Allocate stacks for all modes */
    969 	valloc_pages(fiqstack, FIQ_STACK_SIZE);
    970 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    971 	valloc_pages(abtstack, ABT_STACK_SIZE);
    972 	valloc_pages(undstack, UND_STACK_SIZE);
    973 	valloc_pages(kernelstack, UPAGES);
    974 
    975 	/* Allocate the message buffer. */
    976 	pv_addr_t msgbuf;
    977 	int msgbuf_pgs = round_page(MSGBUFSIZE) / PAGE_SIZE;
    978 	valloc_pages(msgbuf, msgbuf_pgs);
    979 	msgbufphys = msgbuf.pv_pa;
    980 
    981 	/*
    982 	 * Ok we have allocated physical pages for the primary kernel
    983 	 * page tables
    984 	 */
    985 
    986 #ifdef VERBOSE_INIT_ARM
    987 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    988 #endif
    989 
    990 	/*
    991 	 * Now we start construction of the L1 page table
    992 	 * We start by mapping the L2 page tables into the L1.
    993 	 * This means that we can replace L1 mappings later on if necessary
    994 	 */
    995 	vaddr_t l1_va = kernel_l1pt.pv_va;
    996 	paddr_t l1_pa = kernel_l1pt.pv_pa;
    997 
    998 	/* Map the L2 pages tables in the L1 page table */
    999 	pmap_link_l2pt(l1_va, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
   1000 		       &kernel_pt_table[KERNEL_PT_SYS]);
   1001 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
   1002 		pmap_link_l2pt(l1_va, KERNEL_BASE + loop * 0x00400000,
   1003 			       &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
   1004 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
   1005 		pmap_link_l2pt(l1_va, KERNEL_VM_BASE + loop * 0x00400000,
   1006 			       &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
   1007 
   1008 	/* update the top of the kernel VM */
   1009 	pmap_curmaxkvaddr =
   1010 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
   1011 
   1012 #ifdef VERBOSE_INIT_ARM
   1013 	printf("Mapping kernel\n");
   1014 #endif
   1015 
   1016 	/* Now we fill in the L2 pagetable for the kernel static code/data */
   1017 #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
   1018 	size_t textsize = round_L_page(etext - KERNEL_BASE_virt);
   1019 	size_t totalsize = round_L_page(_end - KERNEL_BASE_virt);
   1020 	/* offset of kernel in RAM */
   1021 	u_int offset = (u_int)KERNEL_BASE_virt - KERNEL_BASE;
   1022 
   1023 	/* Map text section read-only. */
   1024 	offset += pmap_map_chunk(l1_va,
   1025 				(vaddr_t)KERNEL_BASE + offset,
   1026 				 physical_start + offset, textsize,
   1027 				 VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE);
   1028 	/* Map data and bss sections read-write. */
   1029 	offset += pmap_map_chunk(l1_va,
   1030 				(vaddr_t)KERNEL_BASE + offset,
   1031 				 physical_start + offset, totalsize - textsize,
   1032 				 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1033 
   1034 #ifdef VERBOSE_INIT_ARM
   1035 	printf("Constructing L2 page tables\n");
   1036 #endif
   1037 
   1038 	/* Map the stack pages */
   1039 	pmap_map_chunk(l1_va, fiqstack.pv_va, fiqstack.pv_pa,
   1040 	    FIQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1041 	pmap_map_chunk(l1_va, irqstack.pv_va, irqstack.pv_pa,
   1042 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1043 	pmap_map_chunk(l1_va, abtstack.pv_va, abtstack.pv_pa,
   1044 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1045 	pmap_map_chunk(l1_va, undstack.pv_va, undstack.pv_pa,
   1046 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1047 	pmap_map_chunk(l1_va, kernelstack.pv_va, kernelstack.pv_pa,
   1048 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
   1049 
   1050 	pmap_map_chunk(l1_va, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
   1051 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
   1052 
   1053 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
   1054 		pmap_map_chunk(l1_va, kernel_pt_table[loop].pv_va,
   1055 			       kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
   1056 			       VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
   1057 	}
   1058 
   1059 	/* Map the vector page. */
   1060 	pmap_map_entry(l1_va, ARM_VECTORS_HIGH, systempage.pv_pa,
   1061 		       VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1062 
   1063 	/*
   1064 	 * Map integrated peripherals at same address in first level page
   1065 	 * table so that we can continue to use console.
   1066 	 */
   1067 	pmap_devmap_bootstrap(l1_va, devmap);
   1068 
   1069 
   1070 #ifdef VERBOSE_INIT_ARM
   1071 	/* Tell the user about where all the bits and pieces live. */
   1072 	printf("%22s       Physical              Virtual        Num\n", " ");
   1073 	printf("%22s Starting    Ending    Starting    Ending   Pages\n", " ");
   1074 
   1075 	static const char mem_fmt[] =
   1076 	    "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
   1077 	static const char mem_fmt_nov[] =
   1078 	    "%20s: 0x%08lx 0x%08lx                       %d\n";
   1079 
   1080 	printf(mem_fmt, "SDRAM", physical_start, physical_end-1,
   1081 	    KERN_PHYSTOV(physical_start), KERN_PHYSTOV(physical_end-1),
   1082 	    physmem);
   1083 	printf(mem_fmt, "text section",
   1084 	       KERN_VTOPHYS(KERNEL_BASE_virt), KERN_VTOPHYS(etext-1),
   1085 	       (vaddr_t)KERNEL_BASE_virt, (vaddr_t)etext-1,
   1086 	       (int)(textsize / PAGE_SIZE));
   1087 	printf(mem_fmt, "data section",
   1088 	       KERN_VTOPHYS(__data_start), KERN_VTOPHYS(_edata),
   1089 	       (vaddr_t)__data_start, (vaddr_t)_edata,
   1090 	       (int)((round_page((vaddr_t)_edata)
   1091 		      - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
   1092 	printf(mem_fmt, "bss section",
   1093 	       KERN_VTOPHYS(__bss_start), KERN_VTOPHYS(__bss_end__),
   1094 	       (vaddr_t)__bss_start, (vaddr_t)__bss_end__,
   1095 	       (int)((round_page((vaddr_t)__bss_end__)
   1096 		      - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
   1097 	printf(mem_fmt, "L1 page directory",
   1098 	    kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1,
   1099 	    kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1,
   1100 	    L1_TABLE_SIZE / PAGE_SIZE);
   1101 	printf(mem_fmt, "Exception Vectors",
   1102 	    systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1,
   1103 	    (vaddr_t)ARM_VECTORS_HIGH, (vaddr_t)ARM_VECTORS_HIGH + PAGE_SIZE - 1,
   1104 	    1);
   1105 	printf(mem_fmt, "FIQ stack",
   1106 	    fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
   1107 	    fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
   1108 	    FIQ_STACK_SIZE);
   1109 	printf(mem_fmt, "IRQ stack",
   1110 	    irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
   1111 	    irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
   1112 	    IRQ_STACK_SIZE);
   1113 	printf(mem_fmt, "ABT stack",
   1114 	    abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
   1115 	    abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
   1116 	    ABT_STACK_SIZE);
   1117 	printf(mem_fmt, "UND stack",
   1118 	    undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1,
   1119 	    undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1,
   1120 	    UND_STACK_SIZE);
   1121 	printf(mem_fmt, "SVC stack",
   1122 	    kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
   1123 	    kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1,
   1124 	    UPAGES);
   1125 	printf(mem_fmt_nov, "Message Buffer",
   1126 	    msgbufphys, msgbufphys + msgbuf_pgs * PAGE_SIZE - 1, msgbuf_pgs);
   1127 	printf(mem_fmt, "Free Memory", physical_freestart, physical_freeend-1,
   1128 	    KERN_PHYSTOV(physical_freestart), KERN_PHYSTOV(physical_freeend-1),
   1129 	    free_pages);
   1130 #endif
   1131 
   1132 	/*
   1133 	 * Now we have the real page tables in place so we can switch to them.
   1134 	 * Once this is done we will be running with the REAL kernel page
   1135 	 * tables.
   1136 	 */
   1137 
   1138 	/* Switch tables */
   1139 #ifdef VERBOSE_INIT_ARM
   1140 	printf("switching to new L1 page table  @%#lx...", l1_pa);
   1141 #endif
   1142 
   1143 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
   1144 	setttb(l1_pa);
   1145 	cpu_tlb_flushID();
   1146 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
   1147 
   1148 #ifdef VERBOSE_INIT_ARM
   1149 	printf("OK.\n");
   1150 #endif
   1151 }
   1152