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