Home | History | Annotate | Line # | Download | only in ixm1200
ixm1200_machdep.c revision 1.10
      1 /*	$NetBSD: ixm1200_machdep.c,v 1.10 2002/12/02 14:25:38 ichiro Exp $ */
      2 #undef DEBUG_BEFOREMMU
      3 /*
      4  * Copyright (c) 2002
      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 #include "opt_ddb.h"
     70 #include "opt_pmap_debug.h"
     71 
     72 #include <sys/param.h>
     73 #include <sys/device.h>
     74 #include <sys/systm.h>
     75 #include <sys/kernel.h>
     76 #include <sys/exec.h>
     77 #include <sys/proc.h>
     78 #include <sys/msgbuf.h>
     79 #include <sys/reboot.h>
     80 #include <sys/termios.h>
     81 
     82 #include <dev/cons.h>
     83 
     84 #ifdef DDB
     85 #include <machine/db_machdep.h>
     86 #include <ddb/db_sym.h>
     87 #include <ddb/db_extern.h>
     88 #ifndef DB_ELFSIZE
     89 #error Must define DB_ELFSIZE!
     90 #endif
     91 #define ELFSIZE	DB_ELFSIZE
     92 #include <sys/exec_elf.h>
     93 #endif
     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/ixp12x0/ixp12x0reg.h>
    104 #include <arm/ixp12x0/ixp12x0var.h>
    105 #include <arm/ixp12x0/ixp12x0_comreg.h>
    106 #include <arm/ixp12x0/ixp12x0_comvar.h>
    107 #include <arm/ixp12x0/ixp12x0_pcireg.h>
    108 
    109 #include <evbarm/ixm1200/ixm1200reg.h>
    110 #include <evbarm/ixm1200/ixm1200var.h>
    111 
    112 #include "opt_ipkdb.h"
    113 
    114 /* XXX for consinit related hacks */
    115 #include <sys/conf.h>
    116 
    117 void ixp12x0_reset(void) __attribute__((noreturn));
    118 
    119 /*
    120  * Address to call from cpu_reset() to reset the machine.
    121  * This is machine architecture dependant as it varies depending
    122  * on where the ROM appears when you turn the MMU off.
    123  */
    124 
    125 u_int cpu_reset_address = (u_int) ixp12x0_reset;
    126 
    127 /*
    128  * Define the default console speed for the board.
    129  */
    130 #ifndef CONMODE
    131 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
    132 #endif
    133 #ifndef CONSPEED
    134 #define CONSPEED B38400
    135 #endif
    136 #ifndef CONADDR
    137 #define CONADDR IXPCOM_UART_BASE
    138 #endif
    139 
    140 cons_decl(com);
    141 cons_decl(ixpcom);
    142 
    143 struct consdev constab[] = {
    144 #if (NIXPCOM > 0)
    145 	cons_init(ixpcom),
    146 #endif
    147 	{ 0 },
    148 };
    149 
    150 /* Define various stack sizes in pages */
    151 #define IRQ_STACK_SIZE  1
    152 #define ABT_STACK_SIZE  1
    153 #ifdef IPKDB
    154 #define UND_STACK_SIZE  2
    155 #else
    156 #define UND_STACK_SIZE  1
    157 #endif
    158 
    159 BootConfig bootconfig;          /* Boot config storage */
    160 char *boot_args = NULL;
    161 char *boot_file = NULL;
    162 
    163 vm_offset_t physical_start;
    164 vm_offset_t physical_freestart;
    165 vm_offset_t physical_freeend;
    166 vm_offset_t physical_end;
    167 u_int free_pages;
    168 vm_offset_t pagetables_start;
    169 int physmem = 0;
    170 
    171 /*int debug_flags;*/
    172 #ifndef PMAP_STATIC_L1S
    173 int max_processes = 64;                 /* Default number */
    174 #endif  /* !PMAP_STATIC_L1S */
    175 
    176 /* Physical and virtual addresses for some global pages */
    177 pv_addr_t systempage;
    178 pv_addr_t irqstack;
    179 pv_addr_t undstack;
    180 pv_addr_t abtstack;
    181 pv_addr_t kernelstack;
    182 
    183 vm_offset_t msgbufphys;
    184 
    185 extern u_int data_abort_handler_address;
    186 extern u_int prefetch_abort_handler_address;
    187 extern u_int undefined_handler_address;
    188 extern int end;
    189 
    190 #ifdef PMAP_DEBUG
    191 extern int pmap_debug_level;
    192 #endif  /* PMAP_DEBUG */
    193 
    194 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    195 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    196 #define KERNEL_PT_KERNEL_NUM	2
    197 #define KERNEL_PT_IO		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    198 					/* Page table for mapping IO */
    199 #define KERNEL_PT_VMDATA	(KERNEL_PT_IO + 1)
    200 					/* Page tables for mapping kernel VM */
    201 #define KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    202 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    203 
    204 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    205 
    206 struct user *proc0paddr;
    207 
    208 #ifdef CPU_IXP12X0
    209 #define CPU_IXP12X0_CACHE_CLEAN_SIZE (0x4000 * 2)
    210 extern unsigned int ixp12x0_cache_clean_addr;
    211 extern unsigned int ixp12x0_cache_clean_size;
    212 static vaddr_t ixp12x0_cc_base;
    213 #endif  /* CPU_IXP12X0 */
    214 
    215 /* Prototypes */
    216 
    217 void consinit		__P((void));
    218 u_int cpu_get_control	__P((void));
    219 
    220 void ixdp_ixp12x0_cc_setup(void);
    221 
    222 #ifdef DEBUG_BEFOREMMU
    223 static void fakecninit();
    224 #endif
    225 
    226 extern int db_trapper(u_int, u_int, trapframe_t *, int);
    227 
    228 /*
    229  * void cpu_reboot(int howto, char *bootstr)
    230  *
    231  * Reboots the system
    232  *
    233  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    234  * then reset the CPU.
    235  */
    236 
    237 void
    238 cpu_reboot(howto, bootstr)
    239 	int howto;
    240 	char *bootstr;
    241 {
    242 	/*
    243 	 * If we are still cold then hit the air brakes
    244 	 * and crash to earth fast
    245 	 */
    246 	if (cold) {
    247 		doshutdownhooks();
    248 		printf("Halted while still in the ICE age.\n");
    249 		printf("The operating system has halted.\n");
    250 		printf("Please press any key to reboot.\n\n");
    251 		cngetc();
    252 		printf("rebooting...\n");
    253 		ixp12x0_reset();
    254 	}
    255 
    256 	/* Disable console buffering */
    257 	cnpollc(1);
    258 
    259 	/*
    260 	 * If RB_NOSYNC was not specified sync the discs.
    261 	 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
    262 	 * It looks like syslogd is getting woken up only to find that it cannot
    263 	 * page part of the binary in as the filesystem has been unmounted.
    264 	 */
    265 	if (!(howto & RB_NOSYNC))
    266 		bootsync();
    267 
    268 	/* Say NO to interrupts */
    269 	splhigh();
    270 
    271 	/* Do a dump if requested. */
    272 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    273 		dumpsys();
    274 
    275 	/* Run any shutdown hooks */
    276 	doshutdownhooks();
    277 
    278 	/* Make sure IRQ's are disabled */
    279 	IRQdisable;
    280 
    281 	if (howto & RB_HALT) {
    282 		printf("The operating system has halted.\n");
    283 		printf("Please press any key to reboot.\n\n");
    284 		cngetc();
    285 	}
    286 
    287 	printf("rebooting...\n");
    288 
    289 	/* all interrupts are disabled */
    290 	disable_interrupts(I32_bit);
    291 
    292 	ixp12x0_reset();
    293 
    294 	/* ...and if that didn't work, just croak. */
    295 	printf("RESET FAILED!\n");
    296 	for (;;);
    297 }
    298 
    299 /*
    300  * pmap table
    301  */
    302 /*
    303  * IXM1200 specific I/O registers mapping table
    304  */
    305 static struct pmap_ent	map_tbl_ixm1200[] = {
    306 	{ "IXM1200 SlowPort I/O Registers",
    307 	  IXM1200_LED_VADDR, IXM1200_LED_ADDR,
    308 	  IXM1200_LED_ADDR_SIZE,
    309 	  VM_PROT_READ|VM_PROT_WRITE,
    310 	  PTE_NOCACHE, },
    311 
    312 	{ NULL,
    313 	  0,
    314 	  0,
    315 	  0,
    316 	  0,
    317 	  0,
    318 	}
    319 };
    320 
    321 /*
    322  * Initial entry point on startup. This gets called before main() is
    323  * entered.
    324  * It should be responsible for setting up everything that must be
    325  * in place when main is called.
    326  * This includes
    327  *   Taking a copy of the boot configuration structure.
    328  *   Initialising the physical console so characters can be printed.
    329  *   Setting up page tables for the kernel
    330  *   Relocating the kernel to the bottom of physical memory
    331  */
    332 u_int
    333 initarm(void *arg)
    334 {
    335         int loop;
    336 	int loop1;
    337 	u_int kerneldatasize, symbolsize;
    338 	vaddr_t l1pagetable;
    339 	vaddr_t freemempos;
    340 	pv_addr_t kernel_l1pt;
    341 	pv_addr_t kernel_ptpt;
    342 #ifdef DDB
    343         Elf_Shdr *sh;
    344 #endif
    345 
    346 #ifdef DEBUG_BEFOREMMU
    347 	/*
    348 	 * At this point, we cannot call real consinit().
    349 	 * Just call a faked up version of consinit(), which does the thing
    350 	 * with MMU disabled.
    351 	 */
    352 	fakecninit();
    353 #endif
    354         /*
    355          * Since we map v0xf0000000 == p0x90000000, it's possible for
    356          * us to initialize the console now.
    357          */
    358 	consinit();
    359 
    360 	/* Talk to the user */
    361 	printf("\nNetBSD/evbarm (IXM1200) booting ...\n");
    362 
    363 	/*
    364 	 * Heads up ... Setup the CPU / MMU / TLB functions
    365 	 */
    366 	if (set_cpufuncs())
    367 		panic("cpu not recognized!");
    368 
    369 	/* XXX overwrite bootconfig to hardcoded values */
    370 	bootconfig.dram[0].address = 0xc0000000;
    371 	bootconfig.dram[0].pages   = 0x10000000 / NBPG;	/* SDRAM 256MB */
    372 	bootconfig.dramblocks = 1;
    373 
    374 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    375 
    376 	symbolsize = 0;
    377 
    378 #ifdef PMAP_DEBUG
    379 	pmap_debug(-1);
    380 #endif
    381 
    382 #ifdef DDB
    383         if (! memcmp(&end, "\177ELF", 4)) {
    384                 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff);
    385                 loop = ((Elf_Ehdr *)&end)->e_shnum;
    386                 for(; loop; loop--, sh++)
    387                         if (sh->sh_offset > 0 &&
    388                             (sh->sh_offset + sh->sh_size) > symbolsize)
    389                                 symbolsize = sh->sh_offset + sh->sh_size;
    390         }
    391 #endif
    392 	printf("kernsize=0x%x\n", kerneldatasize);
    393 	kerneldatasize += symbolsize;
    394 	kerneldatasize = ((kerneldatasize - 1) & ~(NBPG * 4 - 1)) + NBPG * 8;
    395 
    396 	/*
    397 	 * Set up the variables that define the availablilty of physcial
    398 	 * memory
    399 	 */
    400 	physical_start = bootconfig.dram[0].address;
    401 	physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
    402 
    403 	physical_freestart = physical_start
    404 		+ (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    405 	physical_freeend = physical_end;
    406 
    407 	physmem = (physical_end - physical_start) / NBPG;
    408 
    409 	freemempos = 0xc0000000;
    410 
    411 #ifdef VERBOSE_INIT_ARM
    412 	printf("Allocating page tables\n");
    413 #endif
    414 	free_pages = (physical_freeend - physical_freestart) / NBPG;
    415 
    416 #ifdef VERBOSE_INIT_ARM
    417 	printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
    418 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    419 		physical_freestart, free_pages, free_pages);
    420 	printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    421 		physical_start, physical_end);
    422 #endif
    423 
    424 	/* Define a macro to simplify memory allocation */
    425 #define valloc_pages(var, np)			\
    426 	alloc_pages((var).pv_pa, (np));		\
    427 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    428 #define alloc_pages(var, np)				\
    429 	(var) = freemempos;				\
    430 	memset((char *)(var), 0, ((np) * NBPG));	\
    431 	freemempos += (np) * NBPG;
    432 
    433 	loop1 = 0;
    434 	kernel_l1pt.pv_pa = 0;
    435 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    436 		/* Are we 16KB aligned for an L1 ? */
    437 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    438 		    && kernel_l1pt.pv_pa == 0) {
    439 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / NBPG);
    440 		} else {
    441 			alloc_pages(kernel_pt_table[loop1].pv_pa,
    442 			    L2_TABLE_SIZE / NBPG);
    443 			kernel_pt_table[loop1].pv_va =
    444 			    kernel_pt_table[loop1].pv_pa;
    445 			++loop1;
    446 		}
    447 	}
    448 
    449 #ifdef DIAGNOSTIC
    450 	/* This should never be able to happen but better confirm that. */
    451 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    452 		panic("initarm: Failed to align the kernel page directory");
    453 #endif
    454 
    455 	/*
    456 	 * Allocate a page for the system page mapped to V0x00000000
    457 	 * This page will just contain the system vectors and can be
    458 	 * shared by all processes.
    459 	 */
    460 	alloc_pages(systempage.pv_pa, 1);
    461 
    462 	/* Allocate a page for the page table to map kernel page tables. */
    463 	valloc_pages(kernel_ptpt, L2_TABLE_SIZE / NBPG);
    464 
    465 	/* Allocate stacks for all modes */
    466 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    467 	valloc_pages(abtstack, ABT_STACK_SIZE);
    468 	valloc_pages(undstack, UND_STACK_SIZE);
    469 	valloc_pages(kernelstack, UPAGES);
    470 
    471 #ifdef VERBOSE_INIT_ARM
    472 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
    473 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
    474 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
    475 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
    476 #endif
    477 
    478 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
    479 
    480 #ifdef CPU_IXP12X0
    481         /*
    482          * XXX totally stuffed hack to work round problems introduced
    483          * in recent versions of the pmap code. Due to the calls used there
    484          * we cannot allocate virtual memory during bootstrap.
    485          */
    486 	for(;;) {
    487 		alloc_pages(ixp12x0_cc_base, 1);
    488 		if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1)))
    489 			break;
    490 	}
    491 	{
    492 		vaddr_t dummy;
    493 		alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / NBPG - 1);
    494 	}
    495 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    496 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    497 #endif /* CPU_IXP12X0 */
    498 
    499 #ifdef VERBOSE_INIT_ARM
    500 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    501 #endif
    502 
    503 	/*
    504 	 * Now we start construction of the L1 page table
    505 	 * We start by mapping the L2 page tables into the L1.
    506 	 * This means that we can replace L1 mappings later on if necessary
    507 	 */
    508 	l1pagetable = kernel_l1pt.pv_pa;
    509 
    510 	/* Map the L2 pages tables in the L1 page table */
    511 	pmap_link_l2pt(l1pagetable, 0x00000000,
    512 	    &kernel_pt_table[KERNEL_PT_SYS]);
    513 
    514 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    515 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    516 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    517 
    518 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    519 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    520 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    521 	pmap_link_l2pt(l1pagetable, PTE_BASE, &kernel_ptpt);
    522 
    523 	/* update the top of the kernel VM */
    524 	pmap_curmaxkvaddr =
    525 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    526 
    527 	pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE,
    528 	    &kernel_pt_table[KERNEL_PT_IO]);
    529 
    530 #ifdef VERBOSE_INIT_ARM
    531 	printf("Mapping kernel\n");
    532 #endif
    533 
    534 #if XXX
    535 	/* Now we fill in the L2 pagetable for the kernel code/data */
    536 	{
    537 		extern char etext[], _end[];
    538 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    539 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    540 		u_int logical;
    541 
    542 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    543 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    544 
    545 		logical = 0x00200000;   /* offset of kernel in RAM */
    546 
    547 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    548 		    physical_start + logical, textsize,
    549 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    550 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    551 		    physical_start + logical, totalsize - textsize,
    552 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    553 	}
    554 #else
    555 	{
    556 		pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    557                     KERNEL_TEXT_BASE, kerneldatasize,
    558                     VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    559 	}
    560 #endif
    561 
    562 #ifdef VERBOSE_INIT_ARM
    563         printf("Constructing L2 page tables\n");
    564 #endif
    565 
    566 	/* Map the stack pages */
    567 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    568 	    IRQ_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    569 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    570 	    ABT_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    571 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    572 	    UND_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    573 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    574 	    UPAGES * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    575 
    576 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    577 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    578 
    579 	/* Map the page table that maps the kernel pages */
    580 	pmap_map_entry(l1pagetable, kernel_ptpt.pv_va, kernel_ptpt.pv_pa,
    581 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    582 
    583 	/*
    584 	 * Map entries in the page table used to map PTE's
    585 	 * Basically every kernel page table gets mapped here
    586 	 */
    587 	/* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
    588 	pmap_map_entry(l1pagetable,
    589 	    PTE_BASE + (0x00000000 >> (PGSHIFT-2)),
    590 	    kernel_pt_table[KERNEL_PT_SYS].pv_pa,
    591 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    592 
    593 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    594 		pmap_map_entry(l1pagetable,
    595 		    PTE_BASE + ((KERNEL_BASE +
    596 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    597 		    kernel_pt_table[KERNEL_PT_KERNEL + loop].pv_pa,
    598 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    599 
    600 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    601 		pmap_map_entry(l1pagetable,
    602 		    PTE_BASE + ((KERNEL_VM_BASE +
    603 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    604 		    kernel_pt_table[KERNEL_PT_VMDATA + loop].pv_pa,
    605 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    606 
    607 	pmap_map_entry(l1pagetable,
    608 	    PTE_BASE + (PTE_BASE >> (PGSHIFT-2)),
    609 	    kernel_ptpt.pv_pa, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    610 
    611 	/* Map the vector page. */
    612 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    613 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    614 
    615 #ifdef VERBOSE_INIT_ARM
    616 	printf("systempage (vector page): p0x%08lx v0x%08lx\n",
    617 	       systempage.pv_pa, vector_page);
    618 #endif
    619 
    620 	/*
    621 	 * Map the PCI I/O spaces and IXP12x0 registers
    622 	 */
    623 
    624 	ixp12x0_pmap_io_reg(l1pagetable);
    625 	ixp12x0_pmap_chunk_table(l1pagetable, map_tbl_ixm1200);
    626 
    627 	printf("done.\n");
    628 
    629 	/*
    630 	 * Map the Dcache Flush page.
    631 	 * Hw Ref Manual 3.2.4.5 Software Dcache Flush
    632 	 */
    633 	pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000,
    634 	    CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE);
    635 
    636 	/*
    637 	 * Now we have the real page tables in place so we can switch to them.
    638 	 * Once this is done we will be running with the REAL kernel page
    639 	 * tables.
    640 	 */
    641 
    642 	/* Switch tables */
    643 	setttb(kernel_l1pt.pv_pa);
    644 	cpu_tlb_flushID();
    645 
    646 	/*
    647 	 * We must now clean the cache again....
    648 	 * Cleaning may be done by reading new data to displace any
    649 	 * dirty data in the cache. This will have happened in setttb()
    650 	 * but since we are boot strapping the addresses used for the read
    651 	 * may have just been remapped and thus the cache could be out
    652 	 * of sync. A re-clean after the switch will cure this.
    653 	 * After booting there are no gross reloations of the kernel thus
    654 	 * this problem will not occur after initarm().
    655 	 */
    656 	cpu_idcache_wbinv_all();
    657 
    658 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    659 
    660 	/*
    661 	 * Pages were allocated during the secondary bootstrap for the
    662 	 * stacks for different CPU modes.
    663 	 * We must now set the r13 registers in the different CPU modes to
    664 	 * point to these stacks.
    665 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    666 	 * of the stack memory.
    667 	 */
    668 	printf("init subsystems: stacks ");
    669 
    670 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
    671 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
    672 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
    673 #ifdef PMAP_DEBUG
    674 	if (pmap_debug_level >= 0)
    675 		printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
    676 		    kernelstack.pv_pa);
    677 #endif  /* PMAP_DEBUG */
    678 
    679 	/*
    680 	 * Well we should set a data abort handler.
    681 	 * Once things get going this will change as we will need a proper
    682 	 * handler. Until then we will use a handler that just panics but
    683 	 * tells us why.
    684 	 * Initialisation of the vetcors will just panic on a data abort.
    685 	 * This just fills in a slighly better one.
    686 	 */
    687 	printf("vectors ");
    688 	data_abort_handler_address = (u_int)data_abort_handler;
    689 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    690 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    691 	printf("\ndata_abort_handler_address = %08x\n", data_abort_handler_address);
    692 	printf("prefetch_abort_handler_address = %08x\n", prefetch_abort_handler_address);
    693 	printf("undefined_handler_address = %08x\n", undefined_handler_address);
    694 
    695 	/* Initialise the undefined instruction handlers */
    696 	printf("undefined ");
    697 	undefined_init();
    698 
    699 	/* Load memory into UVM. */
    700 	printf("page ");
    701 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    702 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    703 	    atop(physical_freestart), atop(physical_freeend),
    704 	    VM_FREELIST_DEFAULT);
    705 
    706 	/* Boot strap pmap telling it where the kernel page table is */
    707 	printf("pmap ");
    708 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
    709 
    710 	/* Setup the IRQ system */
    711 	printf("irq ");
    712 	ixp12x0_intr_init();
    713 	printf("done.\n");
    714 
    715 #ifdef VERBOSE_INIT_ARM
    716 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    717 		physical_freestart, free_pages, free_pages);
    718 	printf("freemempos=%08lx\n", freemempos);
    719 	printf("switching to new L1 page table  @%#lx... \n", kernel_l1pt.pv_pa);
    720 #endif
    721 
    722 	consinit();
    723 	printf("consinit \n");
    724 
    725 	ixdp_ixp12x0_cc_setup();
    726 
    727 	printf("bootstrap done.\n");
    728 
    729 #ifdef IPKDB
    730 	/* Initialise ipkdb */
    731 	ipkdb_init();
    732 	if (boothowto & RB_KDB)
    733 		ipkdb_connect(0);
    734 #endif  /* NIPKDB */
    735 
    736 #ifdef DDB
    737 	{
    738 		static struct undefined_handler uh;
    739 
    740 		uh.uh_handler = db_trapper;
    741 		install_coproc_handler_static(0, &uh);
    742 	}
    743 	ddb_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize);
    744 
    745 	if (boothowto & RB_KDB)
    746 		Debugger();
    747 #endif
    748 
    749 	/* We return the new stack pointer address */
    750 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    751 }
    752 
    753 void
    754 consinit(void)
    755 {
    756 	extern struct bus_space ixpsip_bs_tag;
    757 	static int consinit_called = 0;
    758 
    759 	if (consinit_called != 0)
    760 		return;
    761 
    762 	consinit_called = 1;
    763 
    764 	if (ixpcomcnattach(&ixpsip_bs_tag, IXPCOM_UART_BASE,
    765 			   CONSPEED, CONMODE))
    766 		panic("can't init serial console @%lx", IXPCOM_UART_BASE);
    767 }
    768 
    769 #ifdef DEBUG_BEFOREMMU
    770 cons_decl(ixpcom);
    771 void
    772 fakecninit()
    773 {
    774 	static struct consdev fakecntab = cons_init(ixpcom);
    775 	cn_tab = &fakecntab;
    776 
    777 	(*cn_tab->cn_init)(0);
    778 	cn_tab->cn_pri = CN_REMOTE;
    779 }
    780 #endif
    781 
    782 /*
    783  * For optimal cache cleaning we need two 16K banks of
    784  * virtual address space that NOTHING else will access
    785  * and then we alternate the cache cleaning between the
    786  * two banks.
    787  * The cache cleaning code requires requires 2 banks aligned
    788  * on total size boundry so the banks can be alternated by
    789  * eorring the size bit (assumes the bank size is a power of 2)
    790  */
    791 void
    792 ixdp_ixp12x0_cc_setup(void)
    793 {
    794 	int loop;
    795 	paddr_t kaddr;
    796 	pt_entry_t *pte;
    797 
    798 	(void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr);
    799 	for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += NBPG) {
    800                 pte = vtopte(ixp12x0_cc_base + loop);
    801                 *pte = L2_S_PROTO | kaddr |
    802                     L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode;
    803 		PTE_SYNC(pte);
    804         }
    805 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    806 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    807 }
    808