Home | History | Annotate | Line # | Download | only in ixdp425
ixdp425_machdep.c revision 1.1
      1 /*	$NetBSD: ixdp425_machdep.c,v 1.1 2003/05/23 00:57:27 ichiro Exp $ */
      2 #define VERBOSE_INIT_ARM
      3 /*
      4  * Copyright (c) 2003
      5  *	Ichiro FUKUHARA <ichiro (at) ichiro.org>.
      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 Ichiro FUKUHARA.
     19  * 4. The name of the company nor the name of the author may be used to
     20  *    endorse or promote products derived from this software without specific
     21  *    prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 /*
     36  * Copyright (c) 1997,1998 Mark Brinicombe.
     37  * Copyright (c) 1997,1998 Causality Limited.
     38  * All rights reserved.
     39  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  * 3. All advertising materials mentioning features or use of this software
     49  *    must display the following acknowledgement:
     50  *	This product includes software developed by Mark Brinicombe
     51  *	for the NetBSD Project.
     52  * 4. The name of the company nor the name of the author may be used to
     53  *    endorse or promote products derived from this software without specific
     54  *    prior written permission.
     55  *
     56  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     57  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     58  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     60  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     61  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     62  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     64  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     65  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     66  * SUCH DAMAGE.
     67  */
     68 
     69 /* Machine dependant functions for kernel setup for Intel IXP425 evaluation
     70  * boards using RedBoot firmware.
     71  */
     72 
     73 #include "opt_ddb.h"
     74 #include "opt_kgdb.h"
     75 #include "opt_pmap_debug.h"
     76 
     77 #include <sys/param.h>
     78 #include <sys/device.h>
     79 #include <sys/systm.h>
     80 #include <sys/kernel.h>
     81 #include <sys/exec.h>
     82 #include <sys/proc.h>
     83 #include <sys/msgbuf.h>
     84 #include <sys/reboot.h>
     85 #include <sys/termios.h>
     86 #include <sys/ksyms.h>
     87 
     88 #include <uvm/uvm_extern.h>
     89 
     90 #include <dev/cons.h>
     91 
     92 #include <machine/db_machdep.h>
     93 #include <ddb/db_sym.h>
     94 #include <ddb/db_extern.h>
     95 
     96 #include <machine/bootconfig.h>
     97 #include <machine/bus.h>
     98 #include <machine/cpu.h>
     99 #include <machine/frame.h>
    100 #include <arm/undefined.h>
    101 
    102 #include <arm/arm32/machdep.h>
    103 
    104 #include <arm/xscale/ixp425reg.h>
    105 #include <arm/xscale/ixp425var.h>
    106 
    107 #include <arm/xscale/ixp425_sipvar.h>
    108 #include <arm/xscale/ixp425_comvar.h>
    109 
    110 #include "opt_ipkdb.h"
    111 #include "ksyms.h"
    112 
    113 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    114 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    115 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    116 
    117 /*
    118  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    119  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    120  */
    121 #define	KERNEL_VM_SIZE		0x0C000000
    122 
    123 
    124 /*
    125  * Address to call from cpu_reset() to reset the machine.
    126  * This is machine architecture dependant as it varies depending
    127  * on where the ROM appears when you turn the MMU off.
    128  */
    129 
    130 u_int cpu_reset_address = 0x00000000;
    131 
    132 /* Define various stack sizes in pages */
    133 #define IRQ_STACK_SIZE	1
    134 #define ABT_STACK_SIZE	1
    135 #ifdef IPKDB
    136 #define UND_STACK_SIZE	2
    137 #else
    138 #define UND_STACK_SIZE	1
    139 #endif
    140 
    141 BootConfig bootconfig;		/* Boot config storage */
    142 char *boot_args = NULL;
    143 char *boot_file = NULL;
    144 
    145 vm_offset_t physical_start;
    146 vm_offset_t physical_freestart;
    147 vm_offset_t physical_freeend;
    148 vm_offset_t physical_end;
    149 u_int free_pages;
    150 vm_offset_t pagetables_start;
    151 int physmem = 0;
    152 
    153 /*int debug_flags;*/
    154 #ifndef PMAP_STATIC_L1S
    155 int max_processes = 64;			/* Default number */
    156 #endif	/* !PMAP_STATIC_L1S */
    157 
    158 /* Physical and virtual addresses for some global pages */
    159 pv_addr_t systempage;
    160 pv_addr_t irqstack;
    161 pv_addr_t undstack;
    162 pv_addr_t abtstack;
    163 pv_addr_t kernelstack;
    164 pv_addr_t minidataclean;
    165 
    166 vm_offset_t msgbufphys;
    167 
    168 extern u_int data_abort_handler_address;
    169 extern u_int prefetch_abort_handler_address;
    170 extern u_int undefined_handler_address;
    171 extern int end;
    172 
    173 #ifdef PMAP_DEBUG
    174 extern int pmap_debug_level;
    175 #endif
    176 
    177 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    178 
    179 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    180 #define	KERNEL_PT_KERNEL_NUM	4
    181 #define	KERNEL_PT_IO		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    182 					/* L2 tables for mapping kernel VM */
    183 #define KERNEL_PT_VMDATA	(KERNEL_PT_IO + 1)
    184 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    185 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    186 
    187 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    188 
    189 struct user *proc0paddr;
    190 
    191 /* Prototypes */
    192 
    193 void	consinit(void);
    194 u_int	cpu_get_control   __P((void));
    195 
    196 /*
    197  * Define the default console speed for the board.  This is generally
    198  * what the firmware provided with the board defaults to.
    199  */
    200 #ifndef CONSPEED
    201 #define CONSPEED B115200
    202 #endif /* ! CONSPEED */
    203 
    204 #ifndef CONUNIT
    205 #define	CONUNIT	0
    206 #endif
    207 
    208 #ifndef CONMODE
    209 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
    210 #endif
    211 
    212 int comcnspeed = CONSPEED;
    213 int comcnmode = CONMODE;
    214 int comcnunit = CONUNIT;
    215 
    216 #if KGDB
    217 #ifndef KGDB_DEVNAME
    218 #error Must define KGDB_DEVNAME
    219 #endif
    220 const char kgdb_devname[] = KGDB_DEVNAME;
    221 
    222 #ifndef KGDB_DEVADDR
    223 #error Must define KGDB_DEVADDR
    224 #endif
    225 unsigned long kgdb_devaddr = KGDB_DEVADDR;
    226 
    227 #ifndef KGDB_DEVRATE
    228 #define KGDB_DEVRATE	CONSPEED
    229 #endif
    230 int kgdb_devrate = KGDB_DEVRATE;
    231 
    232 #ifndef KGDB_DEVMODE
    233 #define KGDB_DEVMODE	CONMODE
    234 #endif
    235 int kgdb_devmode = KGDB_DEVMODE;
    236 #endif /* KGDB */
    237 
    238 /*
    239  * void cpu_reboot(int howto, char *bootstr)
    240  *
    241  * Reboots the system
    242  *
    243  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    244  * then reset the CPU.
    245  */
    246 void
    247 cpu_reboot(int howto, char *bootstr)
    248 {
    249 #ifdef DIAGNOSTIC
    250 	/* info */
    251 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    252 #endif
    253 
    254 	/*
    255 	 * If we are still cold then hit the air brakes
    256 	 * and crash to earth fast
    257 	 */
    258 	if (cold) {
    259 		doshutdownhooks();
    260 		printf("The operating system has halted.\n");
    261 		printf("Please press any key to reboot.\n\n");
    262 		cngetc();
    263 		printf("rebooting...\n");
    264 		goto reset;
    265 	}
    266 
    267 	/* Disable console buffering */
    268 
    269 	/*
    270 	 * If RB_NOSYNC was not specified sync the discs.
    271 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    272 	 * unmount.  It looks like syslogd is getting woken up only to find
    273 	 * that it cannot page part of the binary in as the filesystem has
    274 	 * been unmounted.
    275 	 */
    276 	if (!(howto & RB_NOSYNC))
    277 		bootsync();
    278 
    279 	/* Say NO to interrupts */
    280 	splhigh();
    281 
    282 	/* Do a dump if requested. */
    283 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    284 		dumpsys();
    285 
    286 	/* Run any shutdown hooks */
    287 	doshutdownhooks();
    288 
    289 	/* Make sure IRQ's are disabled */
    290 	IRQdisable;
    291 
    292 	if (howto & RB_HALT) {
    293 		printf("The operating system has halted.\n");
    294 		printf("Please press any key to reboot.\n\n");
    295 		cngetc();
    296 	}
    297 
    298 	printf("rebooting...\n\r");
    299  reset:
    300 	/*
    301 	 * Make really really sure that all interrupts are disabled,
    302 	 */
    303 	(void) disable_interrupts(I32_bit|F32_bit);
    304 /*
    305  * XXX system reset routine
    306  */
    307 	(void) disable_interrupts(I32_bit|F32_bit);
    308 	/* ...and if that didn't work, just croak. */
    309 	printf("RESET FAILED!\n");
    310 	for (;;);
    311 }
    312 
    313 /*
    314  * Mapping table for core kernel memory. This memory is mapped at init
    315  * time with section mappings.
    316  */
    317 struct l1_sec_map {
    318 	vaddr_t	va;
    319 	vaddr_t	pa;
    320 	vsize_t	size;
    321 	vm_prot_t prot;
    322 	int cache;
    323 } l1_sec_table[] = {
    324     /*
    325      * Map the on-board devices VA == PA so that we can access them
    326      * with the MMU on or off.
    327      */
    328     {
    329 	IXP425_UART0_HWBASE,
    330 	IXP425_UART0_HWBASE,
    331 	IXP425_REG_SIZE * 2,
    332 	VM_PROT_READ|VM_PROT_WRITE,
    333 	PTE_NOCACHE,
    334     },
    335     {
    336 	0,
    337 	0,
    338 	0,
    339 	0,
    340 	0,
    341     }
    342 };
    343 
    344 /*
    345  * u_int initarm(...)
    346  *
    347  * Initial entry point on startup. This gets called before main() is
    348  * entered.
    349  * It should be responsible for setting up everything that must be
    350  * in place when main is called.
    351  * This includes
    352  *   Taking a copy of the boot configuration structure.
    353  *   Initialising the physical console so characters can be printed.
    354  *   Setting up page tables for the kernel
    355  *   Relocating the kernel to the bottom of physical memory
    356  */
    357 u_int
    358 initarm(void *arg)
    359 {
    360 	extern vaddr_t xscale_cache_clean_addr;
    361 #ifdef DIAGNOSTIC
    362 	extern vsize_t xscale_minidata_clean_size;
    363 #endif
    364 	int loop;
    365 	int loop1;
    366 	u_int kerneldatasize, symbolsize;
    367 	u_int l1pagetable;
    368 	u_int freemempos;
    369 	pv_addr_t kernel_l1pt;
    370 #if 0
    371 	paddr_t memstart;
    372 	psize_t memsize;
    373 #endif
    374 
    375 	/*
    376 	 * Since we map v0xf0000000 == p0xc8000000, it's possible for
    377 	 * us to initialize the console now.
    378 	 */
    379 	consinit();
    380 
    381 #ifdef VERBOSE_INIT_ARM
    382 	/* Talk to the user */
    383 	printf("\nNetBSD/evbarm (IXP425) booting ...\n");
    384 #endif
    385 
    386 	/*
    387 	 * Heads up ... Setup the CPU / MMU / TLB functions
    388 	 */
    389 	if (set_cpufuncs())
    390 		panic("cpu not recognized!");
    391 
    392 	/* XXX overwrite bootconfig to hardcoded values */
    393 	bootconfig.dramblocks = 1;
    394 	bootconfig.dram[0].address = 0x10000000;
    395 	bootconfig.dram[0].pages = 0x04000000 / PAGE_SIZE; /* SDRAM 64MB */
    396 
    397 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    398 
    399 #ifdef VERBOSE_INIT_ARM
    400         printf("kernsize=0x%x\n", kerneldatasize);
    401 #endif
    402         kerneldatasize += symbolsize;
    403         kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
    404 
    405 	/*
    406 	 * Set up the variables that define the availablilty of
    407 	 * physical memory.  For now, we're going to set
    408 	 * physical_freestart to 0x10200000 (where the kernel
    409 	 * was loaded), and allocate the memory we need downwards.
    410 	 * If we get too close to the L1 table that we set up, we
    411 	 * will panic.  We will update physical_freestart and
    412 	 * physical_freeend later to reflect what pmap_bootstrap()
    413 	 * wants to see.
    414 	 *
    415 	 * XXX pmap_bootstrap() needs an enema.
    416 	 */
    417 	physical_start = bootconfig.dram[0].address;
    418 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    419 
    420 	physical_freestart = physical_start
    421                 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    422         physical_freeend = physical_end;
    423 
    424 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    425 
    426 	/* Tell the user about the memory */
    427 #ifdef VERBOSE_INIT_ARM
    428 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    429 	    physical_start, physical_end - 1);
    430 
    431 	printf("Allocating page tables\n");
    432 #endif
    433 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    434 
    435 	freemempos = 0x10000000;
    436 
    437 #ifdef VERBOSE_INIT_ARM
    438         printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
    439         printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    440                 physical_start, physical_end);
    441 #endif
    442 
    443 	/* Define a macro to simplify memory allocation */
    444 #define	valloc_pages(var, np)				\
    445 	alloc_pages((var).pv_pa, (np));			\
    446 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    447 
    448 #if 0
    449 #define alloc_pages(var, np)				\
    450 	physical_freeend -= ((np) * PAGE_SIZE);		\
    451 	if (physical_freeend < physical_freestart)	\
    452 		panic("initarm: out of memory");	\
    453 	(var) = physical_freeend;			\
    454 	free_pages -= (np);				\
    455 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    456 #else
    457 #define alloc_pages(var, np)				\
    458         (var) = freemempos;                             \
    459         memset((char *)(var), 0, ((np) * PAGE_SIZE));   \
    460         freemempos += (np) * PAGE_SIZE;
    461 #endif
    462 
    463 	loop1 = 0;
    464 	kernel_l1pt.pv_pa = 0;
    465 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    466 		/* Are we 16KB aligned for an L1 ? */
    467 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    468 		    && kernel_l1pt.pv_pa == 0) {
    469 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    470 		} else {
    471 			valloc_pages(kernel_pt_table[loop1],
    472 			    L2_TABLE_SIZE / PAGE_SIZE);
    473 			++loop1;
    474 		}
    475 	}
    476 
    477 	/* This should never be able to happen but better confirm that. */
    478 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    479 		panic("initarm: Failed to align the kernel page directory");
    480 
    481 	/*
    482 	 * Allocate a page for the system page mapped to V0x00000000
    483 	 * This page will just contain the system vectors and can be
    484 	 * shared by all processes.
    485 	 */
    486 	alloc_pages(systempage.pv_pa, 1);
    487 
    488 	/* Allocate stacks for all modes */
    489 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    490 	valloc_pages(abtstack, ABT_STACK_SIZE);
    491 	valloc_pages(undstack, UND_STACK_SIZE);
    492 	valloc_pages(kernelstack, UPAGES);
    493 
    494 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    495 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    496 	valloc_pages(minidataclean, 1);
    497 
    498 #ifdef VERBOSE_INIT_ARM
    499 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    500 	    irqstack.pv_va);
    501 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    502 	    abtstack.pv_va);
    503 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    504 	    undstack.pv_va);
    505 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    506 	    kernelstack.pv_va);
    507 #endif
    508 
    509 	/*
    510 	 * XXX Defer this to later so that we can reclaim the memory
    511 	 * XXX used by the RedBoot page tables.
    512 	 */
    513 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    514 
    515 	/*
    516 	 * Ok we have allocated physical pages for the primary kernel
    517 	 * page tables
    518 	 */
    519 
    520 #ifdef VERBOSE_INIT_ARM
    521 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    522 #endif
    523 
    524 	/*
    525 	 * Now we start construction of the L1 page table
    526 	 * We start by mapping the L2 page tables into the L1.
    527 	 * This means that we can replace L1 mappings later on if necessary
    528 	 */
    529 	l1pagetable = kernel_l1pt.pv_pa;
    530 
    531 	/* Map the L2 pages tables in the L1 page table */
    532 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    533 	    &kernel_pt_table[KERNEL_PT_SYS]);
    534 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    535 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    536 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    537 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    538 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    539 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    540 
    541 	/* update the top of the kernel VM */
    542 	pmap_curmaxkvaddr =
    543 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    544 
    545 	pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
    546 	    &kernel_pt_table[KERNEL_PT_IO]);
    547 
    548 #ifdef VERBOSE_INIT_ARM
    549 	printf("Mapping kernel\n");
    550 #endif
    551 
    552 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    553 	{
    554 		extern char etext[], _end[];
    555 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    556 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    557 		u_int logical;
    558 
    559 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    560 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    561 
    562 		logical = 0x00200000;	/* offset of kernel in RAM */
    563 
    564 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    565 		    physical_start + logical, textsize,
    566 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    567 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    568 		    physical_start + logical, totalsize - textsize,
    569 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    570 	}
    571 
    572 #ifdef VERBOSE_INIT_ARM
    573 	printf("Constructing L2 page tables\n");
    574 #endif
    575 
    576 	/* Map the stack pages */
    577 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    578 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    579 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    580 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    581 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    582 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    583 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    584 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    585 
    586 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    587 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    588 
    589 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    590 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    591 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    592 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    593 	}
    594 
    595 	/* Map the Mini-Data cache clean area. */
    596 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    597 	    minidataclean.pv_pa);
    598 
    599 	/* Map the vector page. */
    600 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    601 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    602 
    603         /*
    604          * Map the IXP425 registers
    605          */
    606 
    607 	ixp425_pmap_io_reg(l1pagetable);
    608 
    609 	/*
    610 	 * Map devices we can map w/ section mappings.
    611 	 */
    612 	loop = 0;
    613 	while (l1_sec_table[loop].size) {
    614 		vm_size_t sz;
    615 
    616 #ifdef VERBOSE_INIT_ARM
    617 		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
    618 		    l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
    619 		    l1_sec_table[loop].va);
    620 #endif
    621 		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
    622 			pmap_map_section(l1pagetable,
    623 			    l1_sec_table[loop].va + sz,
    624 			    l1_sec_table[loop].pa + sz,
    625 			    l1_sec_table[loop].prot,
    626 			    l1_sec_table[loop].cache);
    627 		++loop;
    628 	}
    629 
    630 
    631 	/*
    632 	 * Give the XScale global cache clean code an appropriately
    633 	 * sized chunk of unmapped VA space starting at 0xff000000
    634 	 * (our device mappings end before this address).
    635 	 */
    636 	xscale_cache_clean_addr = 0xff000000U;
    637 
    638 	/*
    639 	 * Now we have the real page tables in place so we can switch to them.
    640 	 * Once this is done we will be running with the REAL kernel page
    641 	 * tables.
    642 	 */
    643 
    644 	/*
    645 	 * Update the physical_freestart/physical_freeend/free_pages
    646 	 * variables.
    647 	 */
    648 	{
    649 		extern char _end[];
    650 
    651 		physical_freestart = physical_start +
    652 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    653 		     KERNEL_BASE);
    654 		physical_freeend = physical_end;
    655 		free_pages =
    656 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    657 	}
    658 
    659 	/* Switch tables */
    660 #ifdef VERBOSE_INIT_ARM
    661 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    662 	       physical_freestart, free_pages, free_pages);
    663 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    664 #endif
    665 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    666 	setttb(kernel_l1pt.pv_pa);
    667 	cpu_tlb_flushID();
    668 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    669 
    670 	/*
    671 	 * Moved from cpu_startup() as data_abort_handler() references
    672 	 * this during uvm init
    673 	 */
    674 	proc0paddr = (struct user *)kernelstack.pv_va;
    675 	lwp0.l_addr = proc0paddr;
    676 
    677 #ifdef VERBOSE_INIT_ARM
    678 	printf("bootstrap done.\n");
    679 #endif
    680 
    681 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    682 
    683 	/*
    684 	 * Pages were allocated during the secondary bootstrap for the
    685 	 * stacks for different CPU modes.
    686 	 * We must now set the r13 registers in the different CPU modes to
    687 	 * point to these stacks.
    688 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    689 	 * of the stack memory.
    690 	 */
    691 #ifdef VERBOSE_INIT_ARM
    692 	printf("init subsystems: stacks ");
    693 #endif
    694 
    695 	set_stackptr(PSR_IRQ32_MODE,
    696 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    697 	set_stackptr(PSR_ABT32_MODE,
    698 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    699 	set_stackptr(PSR_UND32_MODE,
    700 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    701 
    702 	/*
    703 	 * Well we should set a data abort handler.
    704 	 * Once things get going this will change as we will need a proper
    705 	 * handler.
    706 	 * Until then we will use a handler that just panics but tells us
    707 	 * why.
    708 	 * Initialisation of the vectors will just panic on a data abort.
    709 	 * This just fills in a slighly better one.
    710 	 */
    711 #ifdef VERBOSE_INIT_ARM
    712 	printf("vectors ");
    713 #endif
    714 	data_abort_handler_address = (u_int)data_abort_handler;
    715 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    716 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    717 
    718 	/* Initialise the undefined instruction handlers */
    719 #ifdef VERBOSE_INIT_ARM
    720 	printf("undefined ");
    721 #endif
    722 	undefined_init();
    723 
    724 	/* Load memory into UVM. */
    725 #ifdef VERBOSE_INIT_ARM
    726 	printf("page ");
    727 #endif
    728 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    729 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    730 	    atop(physical_freestart), atop(physical_freeend),
    731 	    VM_FREELIST_DEFAULT);
    732 
    733 	/* Boot strap pmap telling it where the kernel page table is */
    734 #ifdef VERBOSE_INIT_ARM
    735 	printf("pmap ");
    736 #endif
    737 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
    738 	    KERNEL_VM_BASE + KERNEL_VM_SIZE);
    739 
    740 	/* Setup the IRQ system */
    741 #ifdef VERBOSE_INIT_ARM
    742 	printf("irq ");
    743 #endif
    744 	ixp425_intr_init();
    745 #ifdef VERBOSE_INIT_ARM
    746 	printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
    747 #endif
    748 
    749 #ifdef BOOTHOWTO
    750 	boothowto = BOOTHOWTO;
    751 #endif
    752 
    753 #ifdef IPKDB
    754 	/* Initialise ipkdb */
    755 	ipkdb_init();
    756 	if (boothowto & RB_KDB)
    757 		ipkdb_connect(0);
    758 #endif
    759 
    760 #if NKSYMS || defined(DDB) || defined(LKM)
    761 	/* Firmware doesn't load symbols. */
    762 	ksyms_init(0, NULL, NULL);
    763 #endif
    764 
    765 #ifdef DDB
    766 	db_machine_init();
    767 	if (boothowto & RB_KDB)
    768 		Debugger();
    769 #endif
    770 
    771 	/* We return the new stack pointer address */
    772 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    773 }
    774 
    775 /*
    776  * consinit
    777  */
    778 static const struct uart_info {
    779         const char      *name;
    780         u_int32_t       hw_addr;
    781         u_int32_t       v_addr;
    782 } comcn_config[] = {
    783 	{ "HighSpeed Serial (UART0)",
    784 	  IXP425_UART0_HWBASE,
    785 	  IXP425_UART0_VBASE,
    786 	},
    787 	{ "Console (UART1)",
    788 	  IXP425_UART1_HWBASE,
    789 	  IXP425_UART1_VBASE,
    790 	},
    791 };
    792 
    793 void
    794 consinit(void)
    795 {
    796 	extern struct bus_space ixpsip_bs_tag;
    797 	static int consinit_called;
    798 
    799 	if (consinit_called != 0)
    800 		return;
    801 
    802 	consinit_called = 1;
    803 
    804 	if (ixp4xx_comcnattach(&ixpsip_bs_tag, comcn_config[comcnunit].hw_addr,
    805 		comcn_config[comcnunit].v_addr, comcnspeed, FREQ, comcnmode))
    806 		panic("can't init serial console (%s)", comcn_config[comcnunit].name);
    807 }
    808