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