Home | History | Annotate | Line # | Download | only in iyonix
iyonix_machdep.c revision 1.1
      1  1.1  macallan /*	$NetBSD: iyonix_machdep.c,v 1.1 2019/02/14 21:47:52 macallan Exp $	*/
      2  1.1  macallan 
      3  1.1  macallan /*
      4  1.1  macallan  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      5  1.1  macallan  * All rights reserved.
      6  1.1  macallan  *
      7  1.1  macallan  * Based on code written by Jason R. Thorpe and Steve C. Woodford for
      8  1.1  macallan  * Wasabi Systems, Inc.
      9  1.1  macallan  *
     10  1.1  macallan  * Redistribution and use in source and binary forms, with or without
     11  1.1  macallan  * modification, are permitted provided that the following conditions
     12  1.1  macallan  * are met:
     13  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     14  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     15  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     18  1.1  macallan  * 3. All advertising materials mentioning features or use of this software
     19  1.1  macallan  *    must display the following acknowledgement:
     20  1.1  macallan  *	This product includes software developed for the NetBSD Project by
     21  1.1  macallan  *	Wasabi Systems, Inc.
     22  1.1  macallan  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23  1.1  macallan  *    or promote products derived from this software without specific prior
     24  1.1  macallan  *    written permission.
     25  1.1  macallan  *
     26  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27  1.1  macallan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30  1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  macallan  */
     38  1.1  macallan 
     39  1.1  macallan /*
     40  1.1  macallan  * Copyright (c) 1997,1998 Mark Brinicombe.
     41  1.1  macallan  * Copyright (c) 1997,1998 Causality Limited.
     42  1.1  macallan  * All rights reserved.
     43  1.1  macallan  *
     44  1.1  macallan  * Redistribution and use in source and binary forms, with or without
     45  1.1  macallan  * modification, are permitted provided that the following conditions
     46  1.1  macallan  * are met:
     47  1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     48  1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     49  1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     51  1.1  macallan  *    documentation and/or other materials provided with the distribution.
     52  1.1  macallan  * 3. All advertising materials mentioning features or use of this software
     53  1.1  macallan  *    must display the following acknowledgement:
     54  1.1  macallan  *	This product includes software developed by Mark Brinicombe
     55  1.1  macallan  *	for the NetBSD Project.
     56  1.1  macallan  * 4. The name of the company nor the name of the author may be used to
     57  1.1  macallan  *    endorse or promote products derived from this software without specific
     58  1.1  macallan  *    prior written permission.
     59  1.1  macallan  *
     60  1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     61  1.1  macallan  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     62  1.1  macallan  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     63  1.1  macallan  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     64  1.1  macallan  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     65  1.1  macallan  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     66  1.1  macallan  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  1.1  macallan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  1.1  macallan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  1.1  macallan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  1.1  macallan  * SUCH DAMAGE.
     71  1.1  macallan  *
     72  1.1  macallan  * Machine dependent functions for kernel setup for Iyonix.
     73  1.1  macallan  */
     74  1.1  macallan 
     75  1.1  macallan #include <sys/cdefs.h>
     76  1.1  macallan __KERNEL_RCSID(0, "$NetBSD: iyonix_machdep.c,v 1.1 2019/02/14 21:47:52 macallan Exp $");
     77  1.1  macallan 
     78  1.1  macallan #include "opt_ddb.h"
     79  1.1  macallan #include "opt_kgdb.h"
     80  1.1  macallan #include "opt_pmap_debug.h"
     81  1.1  macallan 
     82  1.1  macallan #include <sys/param.h>
     83  1.1  macallan #include <sys/device.h>
     84  1.1  macallan #include <sys/systm.h>
     85  1.1  macallan #include <sys/kernel.h>
     86  1.1  macallan #include <sys/exec.h>
     87  1.1  macallan #include <sys/proc.h>
     88  1.1  macallan #include <sys/msgbuf.h>
     89  1.1  macallan #include <sys/reboot.h>
     90  1.1  macallan #include <sys/termios.h>
     91  1.1  macallan #include <sys/ksyms.h>
     92  1.1  macallan #include <sys/bus.h>
     93  1.1  macallan #include <sys/cpu.h>
     94  1.1  macallan 
     95  1.1  macallan #include <uvm/uvm_extern.h>
     96  1.1  macallan 
     97  1.1  macallan #include <dev/cons.h>
     98  1.1  macallan 
     99  1.1  macallan #include <dev/pci/ppbreg.h>
    100  1.1  macallan #include <dev/ic/i8259reg.h>
    101  1.1  macallan 
    102  1.1  macallan #include <net/if.h>
    103  1.1  macallan #include <net/if_ether.h>
    104  1.1  macallan 
    105  1.1  macallan #include <machine/db_machdep.h>
    106  1.1  macallan #include <ddb/db_sym.h>
    107  1.1  macallan #include <ddb/db_extern.h>
    108  1.1  macallan 
    109  1.1  macallan #include <acorn32/include/bootconfig.h>
    110  1.1  macallan #include <arm/locore.h>
    111  1.1  macallan #include <arm/undefined.h>
    112  1.1  macallan 
    113  1.1  macallan #include <arm/arm32/machdep.h>
    114  1.1  macallan 
    115  1.1  macallan #include <arm/xscale/i80321reg.h>
    116  1.1  macallan #include <arm/xscale/i80321var.h>
    117  1.1  macallan 
    118  1.1  macallan #include <evbarm/iyonix/iyonixreg.h>
    119  1.1  macallan #include <evbarm/iyonix/obiovar.h>
    120  1.1  macallan 
    121  1.1  macallan #include <dev/wscons/wsconsio.h>
    122  1.1  macallan #include <dev/wscons/wsdisplayvar.h>
    123  1.1  macallan #include <dev/rasops/rasops.h>
    124  1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
    125  1.1  macallan #include <dev/wsfont/wsfont.h>
    126  1.1  macallan 
    127  1.1  macallan #include "ksyms.h"
    128  1.1  macallan 
    129  1.1  macallan #define	KERNEL_TEXT_BASE	KERNEL_BASE
    130  1.1  macallan #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    131  1.1  macallan 
    132  1.1  macallan struct vcons_screen rascons_console_screen;
    133  1.1  macallan 
    134  1.1  macallan struct wsscreen_descr rascons_stdscreen = {
    135  1.1  macallan 	"std",
    136  1.1  macallan 	0, 0,	/* will be filled in -- XXX shouldn't, it's global */
    137  1.1  macallan 	0,
    138  1.1  macallan 	0, 0,
    139  1.1  macallan 	WSSCREEN_REVERSE
    140  1.1  macallan };
    141  1.1  macallan 
    142  1.1  macallan /*
    143  1.1  macallan  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    144  1.1  macallan  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    145  1.1  macallan  */
    146  1.1  macallan #define KERNEL_VM_SIZE		0x0C000000
    147  1.1  macallan 
    148  1.1  macallan struct bootconfig bootconfig;		/* Boot config storage */
    149  1.1  macallan 
    150  1.1  macallan char *boot_args;
    151  1.1  macallan 
    152  1.1  macallan vaddr_t physical_start;
    153  1.1  macallan vaddr_t physical_freestart;
    154  1.1  macallan vaddr_t physical_freeend;
    155  1.1  macallan vaddr_t physical_end;
    156  1.1  macallan u_int free_pages;
    157  1.1  macallan vaddr_t pagetables_start;
    158  1.1  macallan 
    159  1.1  macallan /*int debug_flags;*/
    160  1.1  macallan #ifndef PMAP_STATIC_L1S
    161  1.1  macallan int max_processes = 64;			/* Default number */
    162  1.1  macallan #endif	/* !PMAP_STATIC_L1S */
    163  1.1  macallan 
    164  1.1  macallan /* Physical and virtual addresses for some global pages */
    165  1.1  macallan pv_addr_t minidataclean;
    166  1.1  macallan 
    167  1.1  macallan paddr_t msgbufphys;
    168  1.1  macallan 
    169  1.1  macallan #ifdef PMAP_DEBUG
    170  1.1  macallan extern int pmap_debug_level;
    171  1.1  macallan #endif
    172  1.1  macallan 
    173  1.1  macallan #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    174  1.1  macallan 
    175  1.1  macallan #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    176  1.1  macallan #define	KERNEL_PT_KERNEL_NUM	4
    177  1.1  macallan 
    178  1.1  macallan 					/* L2 table for mapping i80321 */
    179  1.1  macallan #define	KERNEL_PT_IOPXS		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    180  1.1  macallan 
    181  1.1  macallan 					/* L2 tables for mapping kernel VM */
    182  1.1  macallan #define KERNEL_PT_VMDATA	(KERNEL_PT_IOPXS + 1)
    183  1.1  macallan #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    184  1.1  macallan #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    185  1.1  macallan 
    186  1.1  macallan pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    187  1.1  macallan 
    188  1.1  macallan char iyonix_macaddr[ETHER_ADDR_LEN];
    189  1.1  macallan 
    190  1.1  macallan char boot_consdev[16];
    191  1.1  macallan 
    192  1.1  macallan /* Prototypes */
    193  1.1  macallan 
    194  1.1  macallan void	iyonix_pic_init(void);
    195  1.1  macallan void	iyonix_read_machineid(void);
    196  1.1  macallan 
    197  1.1  macallan void	consinit(void);
    198  1.1  macallan 
    199  1.1  macallan static void consinit_com(const char *consdev);
    200  1.1  macallan static void consinit_genfb(const char *consdev);
    201  1.1  macallan static void process_kernel_args(void);
    202  1.1  macallan static void parse_iyonix_bootargs(char *args);
    203  1.1  macallan 
    204  1.1  macallan #include "com.h"
    205  1.1  macallan #if NCOM > 0
    206  1.1  macallan #include <dev/ic/comreg.h>
    207  1.1  macallan #include <dev/ic/comvar.h>
    208  1.1  macallan #endif
    209  1.1  macallan 
    210  1.1  macallan #include "genfb.h"
    211  1.1  macallan 
    212  1.1  macallan #if (NGENFB == 0) && (NCOM == 0)
    213  1.1  macallan # error "No valid console device (com or genfb)"
    214  1.1  macallan #elif defined(COMCONSOLE) || (NGENFB == 0)
    215  1.1  macallan # define DEFAULT_CONSDEV "com"
    216  1.1  macallan #else
    217  1.1  macallan # define DEFAULT_CONSDEV "genfb"
    218  1.1  macallan #endif
    219  1.1  macallan 
    220  1.1  macallan /*
    221  1.1  macallan  * Define the default console speed for the machine.
    222  1.1  macallan  */
    223  1.1  macallan #ifndef CONSPEED
    224  1.1  macallan #define CONSPEED B9600
    225  1.1  macallan #endif /* ! CONSPEED */
    226  1.1  macallan 
    227  1.1  macallan #ifndef CONUNIT
    228  1.1  macallan #define	CONUNIT	0
    229  1.1  macallan #endif
    230  1.1  macallan 
    231  1.1  macallan #ifndef CONMODE
    232  1.1  macallan #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    233  1.1  macallan #endif
    234  1.1  macallan 
    235  1.1  macallan int comcnspeed = CONSPEED;
    236  1.1  macallan int comcnmode = CONMODE;
    237  1.1  macallan int comcnunit = CONUNIT;
    238  1.1  macallan 
    239  1.1  macallan #if KGDB
    240  1.1  macallan #ifndef KGDB_DEVNAME
    241  1.1  macallan #error Must define KGDB_DEVNAME
    242  1.1  macallan #endif
    243  1.1  macallan const char kgdb_devname[] = KGDB_DEVNAME;
    244  1.1  macallan 
    245  1.1  macallan #ifndef KGDB_DEVADDR
    246  1.1  macallan #error Must define KGDB_DEVADDR
    247  1.1  macallan #endif
    248  1.1  macallan unsigned long kgdb_devaddr = KGDB_DEVADDR;
    249  1.1  macallan 
    250  1.1  macallan #ifndef KGDB_DEVRATE
    251  1.1  macallan #define KGDB_DEVRATE	CONSPEED
    252  1.1  macallan #endif
    253  1.1  macallan int kgdb_devrate = KGDB_DEVRATE;
    254  1.1  macallan 
    255  1.1  macallan #ifndef KGDB_DEVMODE
    256  1.1  macallan #define KGDB_DEVMODE	CONMODE
    257  1.1  macallan #endif
    258  1.1  macallan int kgdb_devmode = KGDB_DEVMODE;
    259  1.1  macallan #endif /* KGDB */
    260  1.1  macallan 
    261  1.1  macallan /*
    262  1.1  macallan  * void cpu_reboot(int howto, char *bootstr)
    263  1.1  macallan  *
    264  1.1  macallan  * Reboots the system
    265  1.1  macallan  *
    266  1.1  macallan  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    267  1.1  macallan  * then reset the CPU.
    268  1.1  macallan  */
    269  1.1  macallan void
    270  1.1  macallan cpu_reboot(int howto, char *bootstr)
    271  1.1  macallan {
    272  1.1  macallan 
    273  1.1  macallan 	/*
    274  1.1  macallan 	 * If we are still cold then hit the air brakes
    275  1.1  macallan 	 * and crash to earth fast
    276  1.1  macallan 	 */
    277  1.1  macallan 	if (cold) {
    278  1.1  macallan 		doshutdownhooks();
    279  1.1  macallan 		pmf_system_shutdown(boothowto);
    280  1.1  macallan 		printf("The operating system has halted.\n");
    281  1.1  macallan 		printf("Please press any key to reboot.\n\n");
    282  1.1  macallan 		cngetc();
    283  1.1  macallan 		printf("rebooting...\n");
    284  1.1  macallan 		goto reset;
    285  1.1  macallan 	}
    286  1.1  macallan 
    287  1.1  macallan 	/* Disable console buffering */
    288  1.1  macallan 
    289  1.1  macallan 	/*
    290  1.1  macallan 	 * If RB_NOSYNC was not specified sync the discs.
    291  1.1  macallan 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    292  1.1  macallan 	 * unmount.  It looks like syslogd is getting woken up only to find
    293  1.1  macallan 	 * that it cannot page part of the binary in as the filesystem has
    294  1.1  macallan 	 * been unmounted.
    295  1.1  macallan 	 */
    296  1.1  macallan 	if (!(howto & RB_NOSYNC))
    297  1.1  macallan 		bootsync();
    298  1.1  macallan 
    299  1.1  macallan 	/* Say NO to interrupts */
    300  1.1  macallan 	splhigh();
    301  1.1  macallan 
    302  1.1  macallan 	/* Do a dump if requested. */
    303  1.1  macallan 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    304  1.1  macallan 		dumpsys();
    305  1.1  macallan 
    306  1.1  macallan 	/* Run any shutdown hooks */
    307  1.1  macallan 	doshutdownhooks();
    308  1.1  macallan 
    309  1.1  macallan 	pmf_system_shutdown(boothowto);
    310  1.1  macallan 
    311  1.1  macallan 	/* Make sure IRQ's are disabled */
    312  1.1  macallan 	IRQdisable;
    313  1.1  macallan 
    314  1.1  macallan 	if (howto & RB_HALT) {
    315  1.1  macallan 		printf("The operating system has halted.\n");
    316  1.1  macallan 		printf("Please press any key to reboot.\n\n");
    317  1.1  macallan 		cngetc();
    318  1.1  macallan 	}
    319  1.1  macallan 
    320  1.1  macallan 	printf("rebooting...\n\r");
    321  1.1  macallan  reset:
    322  1.1  macallan 	/*
    323  1.1  macallan 	 * Make really really sure that all interrupts are disabled,
    324  1.1  macallan 	 * and poke the Internal Bus and Peripheral Bus reset lines.
    325  1.1  macallan 	 */
    326  1.1  macallan 	(void) disable_interrupts(I32_bit|F32_bit);
    327  1.1  macallan 	*(volatile uint32_t *)(IYONIX_80321_VBASE + VERDE_ATU_BASE +
    328  1.1  macallan 	    ATU_PCSR) = PCSR_RIB | PCSR_RPB;
    329  1.1  macallan 
    330  1.1  macallan 	/* ...and if that didn't work, just croak. */
    331  1.1  macallan 	printf("RESET FAILED!\n");
    332  1.1  macallan 	for (;;);
    333  1.1  macallan }
    334  1.1  macallan 
    335  1.1  macallan /* Static device mappings. */
    336  1.1  macallan static const struct pmap_devmap iyonix_devmap[] = {
    337  1.1  macallan     /*
    338  1.1  macallan      * Map the on-board devices VA == PA so that we can access them
    339  1.1  macallan      * with the MMU on or off.
    340  1.1  macallan      */
    341  1.1  macallan     {
    342  1.1  macallan 	IYONIX_OBIO_BASE,
    343  1.1  macallan 	IYONIX_OBIO_BASE,
    344  1.1  macallan 	IYONIX_OBIO_SIZE,
    345  1.1  macallan 	VM_PROT_READ|VM_PROT_WRITE,
    346  1.1  macallan 	PTE_NOCACHE,
    347  1.1  macallan     },
    348  1.1  macallan 
    349  1.1  macallan     {
    350  1.1  macallan 	IYONIX_IOW_VBASE,
    351  1.1  macallan 	VERDE_OUT_XLATE_IO_WIN0_BASE,
    352  1.1  macallan 	VERDE_OUT_XLATE_IO_WIN_SIZE,
    353  1.1  macallan 	VM_PROT_READ|VM_PROT_WRITE,
    354  1.1  macallan 	PTE_NOCACHE,
    355  1.1  macallan    },
    356  1.1  macallan 
    357  1.1  macallan    {
    358  1.1  macallan 	IYONIX_80321_VBASE,
    359  1.1  macallan 	VERDE_PMMR_BASE,
    360  1.1  macallan 	VERDE_PMMR_SIZE,
    361  1.1  macallan 	VM_PROT_READ|VM_PROT_WRITE,
    362  1.1  macallan 	PTE_NOCACHE,
    363  1.1  macallan    },
    364  1.1  macallan 
    365  1.1  macallan    {
    366  1.1  macallan 	IYONIX_FLASH_BASE,
    367  1.1  macallan 	IYONIX_FLASH_BASE,
    368  1.1  macallan 	IYONIX_FLASH_SIZE,
    369  1.1  macallan 	VM_PROT_READ|VM_PROT_WRITE,
    370  1.1  macallan 	PTE_NOCACHE,
    371  1.1  macallan    },
    372  1.1  macallan 
    373  1.1  macallan    {
    374  1.1  macallan 	0,
    375  1.1  macallan 	0,
    376  1.1  macallan 	0,
    377  1.1  macallan 	0,
    378  1.1  macallan 	0,
    379  1.1  macallan     }
    380  1.1  macallan };
    381  1.1  macallan 
    382  1.1  macallan /* Read out the Machine ID from the flash, and stash it away for later use. */
    383  1.1  macallan 
    384  1.1  macallan void
    385  1.1  macallan iyonix_read_machineid(void)
    386  1.1  macallan {
    387  1.1  macallan 	volatile uint32_t *flashbase = (uint32_t *)IYONIX_FLASH_BASE;
    388  1.1  macallan 	volatile uint16_t *flashword = (uint16_t *)IYONIX_FLASH_BASE;
    389  1.1  macallan 	union {
    390  1.1  macallan 		uint32_t w[2];
    391  1.1  macallan 		uint8_t  b[8];
    392  1.1  macallan 	} machid;
    393  1.1  macallan 
    394  1.1  macallan 	/* Enter SecSi Sector Region */
    395  1.1  macallan 	flashword[0x555] = 0xAA;
    396  1.1  macallan 	flashword[0x2AA] = 0x55;
    397  1.1  macallan 	flashword[0x555] = 0x88;
    398  1.1  macallan 
    399  1.1  macallan 	machid.w[0] = flashbase[0];
    400  1.1  macallan 	machid.w[1] = flashbase[1];
    401  1.1  macallan 
    402  1.1  macallan 	iyonix_macaddr[0] = machid.b[6];
    403  1.1  macallan 	iyonix_macaddr[1] = machid.b[5];
    404  1.1  macallan 	iyonix_macaddr[2] = machid.b[4];
    405  1.1  macallan 	iyonix_macaddr[3] = machid.b[3];
    406  1.1  macallan 	iyonix_macaddr[4] = machid.b[2];
    407  1.1  macallan 	iyonix_macaddr[5] = machid.b[1];
    408  1.1  macallan 
    409  1.1  macallan 	/* Exit SecSi Sector Region */
    410  1.1  macallan 	flashword[0x555] = 0xAA;
    411  1.1  macallan 	flashword[0x2AA] = 0x55;
    412  1.1  macallan 	flashword[0x555] = 0x90;
    413  1.1  macallan 	flashword[0x555] = 0x00;
    414  1.1  macallan }
    415  1.1  macallan 
    416  1.1  macallan #define IYONIX_PIC_WRITE(a,v) (*((char *)IYONIX_OBIO_BASE + (a)) = (v))
    417  1.1  macallan 
    418  1.1  macallan void
    419  1.1  macallan iyonix_pic_init(void)
    420  1.1  macallan {
    421  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_MASTER_PIC + PIC_ICW1, ICW1_IC4|ICW1_SELECT);
    422  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_MASTER_PIC + PIC_ICW2, ICW2_IRL(0));
    423  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_MASTER_PIC + PIC_ICW3, ICW3_CASCADE(2));
    424  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_MASTER_PIC + PIC_ICW4, ICW4_8086);
    425  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_MASTER_PIC + PIC_OCW1, 0x0); /* Unmask */
    426  1.1  macallan 
    427  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_SLAVE_PIC + PIC_ICW1, ICW1_IC4|ICW1_SELECT);
    428  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_SLAVE_PIC + PIC_ICW2, ICW2_IRL(0));
    429  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_SLAVE_PIC + PIC_ICW3, ICW3_CASCADE(1));
    430  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_SLAVE_PIC + PIC_ICW4, ICW4_8086);
    431  1.1  macallan 	IYONIX_PIC_WRITE(IYONIX_SLAVE_PIC + PIC_OCW1, 0x0); /* Unmask */
    432  1.1  macallan 
    433  1.1  macallan }
    434  1.1  macallan 
    435  1.1  macallan /*
    436  1.1  macallan  * u_int initarm(...)
    437  1.1  macallan  *
    438  1.1  macallan  * Initial entry point on startup. This gets called before main() is
    439  1.1  macallan  * entered.
    440  1.1  macallan  * It should be responsible for setting up everything that must be
    441  1.1  macallan  * in place when main is called.
    442  1.1  macallan  * This includes
    443  1.1  macallan  *   Taking a copy of the boot configuration structure.
    444  1.1  macallan  *   Initialising the physical console so characters can be printed.
    445  1.1  macallan  *   Setting up page tables for the kernel
    446  1.1  macallan  *   Initialising interrupt controllers to a sane default state
    447  1.1  macallan  */
    448  1.1  macallan u_int
    449  1.1  macallan initarm(void *arg)
    450  1.1  macallan {
    451  1.1  macallan 	struct bootconfig *passed_bootconfig = arg;
    452  1.1  macallan 	extern vaddr_t xscale_cache_clean_addr;
    453  1.1  macallan #ifdef DIAGNOSTIC
    454  1.1  macallan 	extern vsize_t xscale_minidata_clean_size;
    455  1.1  macallan #endif
    456  1.1  macallan 	extern char _end[];
    457  1.1  macallan 	int loop;
    458  1.1  macallan 	int loop1;
    459  1.1  macallan 	u_int l1pagetable;
    460  1.1  macallan 	paddr_t memstart = 0;
    461  1.1  macallan 	psize_t memsize = 0;
    462  1.1  macallan 
    463  1.1  macallan 	/* Calibrate the delay loop. */
    464  1.1  macallan 	i80321_calibrate_delay();
    465  1.1  macallan 
    466  1.1  macallan 	/* Ensure bootconfig has valid magic */
    467  1.1  macallan 	if (passed_bootconfig->magic != BOOTCONFIG_MAGIC)
    468  1.1  macallan 		printf("Bad bootconfig magic: %x\n", bootconfig.magic);
    469  1.1  macallan 
    470  1.1  macallan 	bootconfig = *passed_bootconfig;
    471  1.1  macallan 
    472  1.1  macallan 	/* Fake bootconfig structure for anything that still needs it */
    473  1.1  macallan 	/* XXX must make the memory description h/w independent */
    474  1.1  macallan 	bootconfig.dram[0].address = memstart;
    475  1.1  macallan 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    476  1.1  macallan 	bootconfig.dramblocks = 1;
    477  1.1  macallan 
    478  1.1  macallan 	/* process arguments - can update boothowto */
    479  1.1  macallan 	process_kernel_args();
    480  1.1  macallan 
    481  1.1  macallan 	/*
    482  1.1  macallan 	 * Since we map the on-board devices VA==PA, and the kernel
    483  1.1  macallan 	 * is running VA==PA, it's possible for us to initialize
    484  1.1  macallan 	 * the console now.
    485  1.1  macallan 	 */
    486  1.1  macallan 	consinit();
    487  1.1  macallan 
    488  1.1  macallan #ifdef VERBOSE_INIT_ARM
    489  1.1  macallan 	/* Talk to the user */
    490  1.1  macallan 	printf("\nNetBSD/iyonix booting ...\n");
    491  1.1  macallan #endif
    492  1.1  macallan 
    493  1.1  macallan 	/*
    494  1.1  macallan 	 * Heads up ... Setup the CPU / MMU / TLB functions
    495  1.1  macallan 	 */
    496  1.1  macallan 	if (set_cpufuncs())
    497  1.1  macallan 		panic("cpu not recognized!");
    498  1.1  macallan 
    499  1.1  macallan 	/*
    500  1.1  macallan 	 * We are currently running with the MMU enabled and the
    501  1.1  macallan 	 * entire address space mapped VA==PA.
    502  1.1  macallan 	 */
    503  1.1  macallan 
    504  1.1  macallan 	/*
    505  1.1  macallan 	 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
    506  1.1  macallan 	 * registers.
    507  1.1  macallan 	 */
    508  1.1  macallan 	i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
    509  1.1  macallan 	    &memstart, &memsize);
    510  1.1  macallan 
    511  1.1  macallan #ifdef VERBOSE_INIT_ARM
    512  1.1  macallan 	printf("initarm: Configuring system ...\n");
    513  1.1  macallan #endif
    514  1.1  macallan 
    515  1.1  macallan 	/*
    516  1.1  macallan 	 * Set up the variables that define the availability of
    517  1.1  macallan 	 * physical memory.
    518  1.1  macallan 	 */
    519  1.1  macallan 	physical_start = memstart;
    520  1.1  macallan 	physical_end = physical_start + memsize;
    521  1.1  macallan 
    522  1.1  macallan 	physical_freestart = physical_start +
    523  1.1  macallan 	    (((uintptr_t) _end - KERNEL_TEXT_BASE + PGOFSET) & ~PGOFSET);
    524  1.1  macallan 	physical_freeend = physical_end;
    525  1.1  macallan 
    526  1.1  macallan 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    527  1.1  macallan 
    528  1.1  macallan #ifdef VERBOSE_INIT_ARM
    529  1.1  macallan 	/* Tell the user about the memory */
    530  1.1  macallan 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    531  1.1  macallan 	    physical_start, physical_end - 1);
    532  1.1  macallan #endif
    533  1.1  macallan 
    534  1.1  macallan 	/*
    535  1.1  macallan 	 * The kernel is loaded at the base of physical memory. We allocate
    536  1.1  macallan 	 * pages upwards from the top of the kernel.
    537  1.1  macallan 	 *
    538  1.1  macallan 	 * We need to allocate some fixed page tables to get the kernel
    539  1.1  macallan 	 * going.  We allocate one page directory and a number of page
    540  1.1  macallan 	 * tables and store the physical addresses in the kernel_pt_table
    541  1.1  macallan 	 * array.
    542  1.1  macallan 	 *
    543  1.1  macallan 	 * The kernel page directory must be on a 16K boundary.  The page
    544  1.1  macallan 	 * tables must be on 4K boundaries.  What we do is allocate the
    545  1.1  macallan 	 * page directory on the first 16K boundary that we encounter, and
    546  1.1  macallan 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    547  1.1  macallan 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    548  1.1  macallan 	 * least one 16K aligned region.
    549  1.1  macallan 	 */
    550  1.1  macallan 
    551  1.1  macallan #ifdef VERBOSE_INIT_ARM
    552  1.1  macallan 	printf("Allocating page tables\n");
    553  1.1  macallan #endif
    554  1.1  macallan 
    555  1.1  macallan 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    556  1.1  macallan 
    557  1.1  macallan #ifdef VERBOSE_INIT_ARM
    558  1.1  macallan 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    559  1.1  macallan 	       physical_freestart, free_pages, free_pages);
    560  1.1  macallan #endif
    561  1.1  macallan 
    562  1.1  macallan 	/* Define a macro to simplify memory allocation */
    563  1.1  macallan #define	valloc_pages(var, np)				\
    564  1.1  macallan 	alloc_pages((var).pv_pa, (np));			\
    565  1.1  macallan 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    566  1.1  macallan 
    567  1.1  macallan #define alloc_pages(var, np)				\
    568  1.1  macallan 	(var) = physical_freestart;			\
    569  1.1  macallan 	physical_freestart += ((np) * PAGE_SIZE);	\
    570  1.1  macallan 	if (physical_freeend < physical_freestart)	\
    571  1.1  macallan 		panic("initarm: out of memory");	\
    572  1.1  macallan 	free_pages -= (np);				\
    573  1.1  macallan 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    574  1.1  macallan 
    575  1.1  macallan 	loop1 = 0;
    576  1.1  macallan 	kernel_l1pt.pv_pa = kernel_l1pt.pv_va = 0;
    577  1.1  macallan 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    578  1.1  macallan 		/* Are we 16KB aligned for an L1 ? */
    579  1.1  macallan 		if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
    580  1.1  macallan 		    && kernel_l1pt.pv_pa == 0) {
    581  1.1  macallan 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    582  1.1  macallan 		} else {
    583  1.1  macallan 			valloc_pages(kernel_pt_table[loop1],
    584  1.1  macallan 			    L2_TABLE_SIZE / PAGE_SIZE);
    585  1.1  macallan 			++loop1;
    586  1.1  macallan 		}
    587  1.1  macallan 	}
    588  1.1  macallan 
    589  1.1  macallan 	/* This should never be able to happen but better confirm that. */
    590  1.1  macallan 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    591  1.1  macallan 		panic("initarm: Failed to align the kernel page directory");
    592  1.1  macallan 
    593  1.1  macallan 	/*
    594  1.1  macallan 	 * Allocate a page for the system page mapped to V0x00000000
    595  1.1  macallan 	 * This page will just contain the system vectors and can be
    596  1.1  macallan 	 * shared by all processes.
    597  1.1  macallan 	 */
    598  1.1  macallan 	alloc_pages(systempage.pv_pa, 1);
    599  1.1  macallan 
    600  1.1  macallan 	/* Allocate stacks for all modes */
    601  1.1  macallan 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    602  1.1  macallan 	valloc_pages(abtstack, ABT_STACK_SIZE);
    603  1.1  macallan 	valloc_pages(undstack, UND_STACK_SIZE);
    604  1.1  macallan 	valloc_pages(kernelstack, UPAGES);
    605  1.1  macallan 
    606  1.1  macallan 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    607  1.1  macallan 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    608  1.1  macallan 	valloc_pages(minidataclean, 1);
    609  1.1  macallan 
    610  1.1  macallan #ifdef VERBOSE_INIT_ARM
    611  1.1  macallan 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    612  1.1  macallan 	    irqstack.pv_va);
    613  1.1  macallan 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    614  1.1  macallan 	    abtstack.pv_va);
    615  1.1  macallan 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    616  1.1  macallan 	    undstack.pv_va);
    617  1.1  macallan 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    618  1.1  macallan 	    kernelstack.pv_va);
    619  1.1  macallan #endif
    620  1.1  macallan 
    621  1.1  macallan 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    622  1.1  macallan 
    623  1.1  macallan 	/*
    624  1.1  macallan 	 * Ok we have allocated physical pages for the primary kernel
    625  1.1  macallan 	 * page tables
    626  1.1  macallan 	 */
    627  1.1  macallan 
    628  1.1  macallan #ifdef VERBOSE_INIT_ARM
    629  1.1  macallan 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    630  1.1  macallan #endif
    631  1.1  macallan 
    632  1.1  macallan 	/*
    633  1.1  macallan 	 * Now we start construction of the L1 page table
    634  1.1  macallan 	 * We start by mapping the L2 page tables into the L1.
    635  1.1  macallan 	 * This means that we can replace L1 mappings later on if necessary
    636  1.1  macallan 	 */
    637  1.1  macallan 	l1pagetable = kernel_l1pt.pv_pa;
    638  1.1  macallan 
    639  1.1  macallan 	/* Map the L2 pages tables in the L1 page table */
    640  1.1  macallan 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    641  1.1  macallan 	    &kernel_pt_table[KERNEL_PT_SYS]);
    642  1.1  macallan 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    643  1.1  macallan 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    644  1.1  macallan 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    645  1.1  macallan 	pmap_link_l2pt(l1pagetable, IYONIX_IOPXS_VBASE,
    646  1.1  macallan 	    &kernel_pt_table[KERNEL_PT_IOPXS]);
    647  1.1  macallan 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    648  1.1  macallan 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    649  1.1  macallan 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    650  1.1  macallan 
    651  1.1  macallan 	/* update the top of the kernel VM */
    652  1.1  macallan 	pmap_curmaxkvaddr =
    653  1.1  macallan 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    654  1.1  macallan 
    655  1.1  macallan #ifdef VERBOSE_INIT_ARM
    656  1.1  macallan 	printf("Mapping kernel\n");
    657  1.1  macallan #endif
    658  1.1  macallan 
    659  1.1  macallan 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    660  1.1  macallan 	{
    661  1.1  macallan 		extern char etext[], _end[];
    662  1.1  macallan 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    663  1.1  macallan 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    664  1.1  macallan 		u_int logical;
    665  1.1  macallan 
    666  1.1  macallan 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    667  1.1  macallan 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    668  1.1  macallan 
    669  1.1  macallan 		logical = 0;	/* offset of kernel in RAM */
    670  1.1  macallan 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    671  1.1  macallan 		    physical_start + logical, textsize,
    672  1.1  macallan 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    673  1.1  macallan 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    674  1.1  macallan 		    physical_start + logical, totalsize - textsize,
    675  1.1  macallan 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    676  1.1  macallan 	}
    677  1.1  macallan 
    678  1.1  macallan #ifdef VERBOSE_INIT_ARM
    679  1.1  macallan 	printf("Constructing L2 page tables\n");
    680  1.1  macallan #endif
    681  1.1  macallan 
    682  1.1  macallan 	/* Map the stack pages */
    683  1.1  macallan 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    684  1.1  macallan 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    685  1.1  macallan 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    686  1.1  macallan 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    687  1.1  macallan 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    688  1.1  macallan 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    689  1.1  macallan 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    690  1.1  macallan 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    691  1.1  macallan 
    692  1.1  macallan 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    693  1.1  macallan 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    694  1.1  macallan 
    695  1.1  macallan 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    696  1.1  macallan 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    697  1.1  macallan 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    698  1.1  macallan 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    699  1.1  macallan 	}
    700  1.1  macallan 
    701  1.1  macallan 	/* Map the Mini-Data cache clean area. */
    702  1.1  macallan 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    703  1.1  macallan 	    minidataclean.pv_pa);
    704  1.1  macallan 
    705  1.1  macallan 	/* Map the vector page. */
    706  1.1  macallan 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    707  1.1  macallan 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    708  1.1  macallan 
    709  1.1  macallan 	/* Map the statically mapped devices. */
    710  1.1  macallan 	pmap_devmap_bootstrap(l1pagetable, iyonix_devmap);
    711  1.1  macallan 
    712  1.1  macallan 	/*
    713  1.1  macallan 	 * Give the XScale global cache clean code an appropriately
    714  1.1  macallan 	 * sized chunk of unmapped VA space starting at 0xff000000
    715  1.1  macallan 	 * (our device mappings end before this address).
    716  1.1  macallan 	 */
    717  1.1  macallan 	xscale_cache_clean_addr = 0xff000000U;
    718  1.1  macallan 
    719  1.1  macallan 	/*
    720  1.1  macallan 	 * Now we have the real page tables in place so we can switch to them.
    721  1.1  macallan 	 * Once this is done we will be running with the REAL kernel page
    722  1.1  macallan 	 * tables.
    723  1.1  macallan 	 */
    724  1.1  macallan 
    725  1.1  macallan 	/* Switch tables */
    726  1.1  macallan #ifdef VERBOSE_INIT_ARM
    727  1.1  macallan 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    728  1.1  macallan 	       physical_freestart, free_pages, free_pages);
    729  1.1  macallan 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    730  1.1  macallan #endif
    731  1.1  macallan 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    732  1.1  macallan 	cpu_setttb(kernel_l1pt.pv_pa, true);
    733  1.1  macallan 	cpu_tlb_flushID();
    734  1.1  macallan 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    735  1.1  macallan 
    736  1.1  macallan 	iyonix_read_machineid();
    737  1.1  macallan 
    738  1.1  macallan 	/*
    739  1.1  macallan 	 * Moved from cpu_startup() as data_abort_handler() references
    740  1.1  macallan 	 * this during uvm init
    741  1.1  macallan 	 */
    742  1.1  macallan 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    743  1.1  macallan 
    744  1.1  macallan #ifdef VERBOSE_INIT_ARM
    745  1.1  macallan 	printf("done!\n");
    746  1.1  macallan #endif
    747  1.1  macallan 
    748  1.1  macallan #ifdef VERBOSE_INIT_ARM
    749  1.1  macallan 	printf("bootstrap done.\n");
    750  1.1  macallan #endif
    751  1.1  macallan 
    752  1.1  macallan 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    753  1.1  macallan 
    754  1.1  macallan 	/*
    755  1.1  macallan 	 * Pages were allocated during the secondary bootstrap for the
    756  1.1  macallan 	 * stacks for different CPU modes.
    757  1.1  macallan 	 * We must now set the r13 registers in the different CPU modes to
    758  1.1  macallan 	 * point to these stacks.
    759  1.1  macallan 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    760  1.1  macallan 	 * of the stack memory.
    761  1.1  macallan 	 */
    762  1.1  macallan #ifdef VERBOSE_INIT_ARM
    763  1.1  macallan 	printf("init subsystems: stacks ");
    764  1.1  macallan #endif
    765  1.1  macallan 
    766  1.1  macallan 	set_stackptr(PSR_IRQ32_MODE,
    767  1.1  macallan 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    768  1.1  macallan 	set_stackptr(PSR_ABT32_MODE,
    769  1.1  macallan 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    770  1.1  macallan 	set_stackptr(PSR_UND32_MODE,
    771  1.1  macallan 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    772  1.1  macallan 
    773  1.1  macallan 	/*
    774  1.1  macallan 	 * Well we should set a data abort handler.
    775  1.1  macallan 	 * Once things get going this will change as we will need a proper
    776  1.1  macallan 	 * handler.
    777  1.1  macallan 	 * Until then we will use a handler that just panics but tells us
    778  1.1  macallan 	 * why.
    779  1.1  macallan 	 * Initialisation of the vectors will just panic on a data abort.
    780  1.1  macallan 	 * This just fills in a slightly better one.
    781  1.1  macallan 	 */
    782  1.1  macallan #ifdef VERBOSE_INIT_ARM
    783  1.1  macallan 	printf("vectors ");
    784  1.1  macallan #endif
    785  1.1  macallan 	data_abort_handler_address = (u_int)data_abort_handler;
    786  1.1  macallan 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    787  1.1  macallan 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    788  1.1  macallan 
    789  1.1  macallan 	/* Initialise the undefined instruction handlers */
    790  1.1  macallan #ifdef VERBOSE_INIT_ARM
    791  1.1  macallan 	printf("undefined ");
    792  1.1  macallan #endif
    793  1.1  macallan 	undefined_init();
    794  1.1  macallan 
    795  1.1  macallan 	/* Load memory into UVM. */
    796  1.1  macallan #ifdef VERBOSE_INIT_ARM
    797  1.1  macallan 	printf("page ");
    798  1.1  macallan #endif
    799  1.1  macallan 	uvm_md_init();
    800  1.1  macallan 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    801  1.1  macallan 	    atop(physical_freestart), atop(physical_freeend),
    802  1.1  macallan 	    VM_FREELIST_DEFAULT);
    803  1.1  macallan 
    804  1.1  macallan 	/* Boot strap pmap telling it where managed kernel virtual memory is */
    805  1.1  macallan #ifdef VERBOSE_INIT_ARM
    806  1.1  macallan 	printf("pmap ");
    807  1.1  macallan #endif
    808  1.1  macallan 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    809  1.1  macallan 
    810  1.1  macallan 	/* Setup the IRQ system */
    811  1.1  macallan #ifdef VERBOSE_INIT_ARM
    812  1.1  macallan 	printf("irq ");
    813  1.1  macallan #endif
    814  1.1  macallan 	i80321_intr_init();
    815  1.1  macallan 
    816  1.1  macallan #ifdef VERBOSE_INIT_ARM
    817  1.1  macallan 	printf("done.\n");
    818  1.1  macallan #endif
    819  1.1  macallan 
    820  1.1  macallan #ifdef DDB
    821  1.1  macallan 	db_machine_init();
    822  1.1  macallan 	if (boothowto & RB_KDB)
    823  1.1  macallan 		Debugger();
    824  1.1  macallan #endif
    825  1.1  macallan 
    826  1.1  macallan 	iyonix_pic_init();
    827  1.1  macallan 
    828  1.1  macallan 	printf("args: %s\n", bootconfig.args);
    829  1.1  macallan 	printf("howto: %x\n", boothowto);
    830  1.1  macallan 
    831  1.1  macallan 	/* We return the new stack pointer address */
    832  1.1  macallan 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    833  1.1  macallan }
    834  1.1  macallan 
    835  1.1  macallan void
    836  1.1  macallan consinit(void)
    837  1.1  macallan {
    838  1.1  macallan 	static int consinit_called;
    839  1.1  macallan 
    840  1.1  macallan 	if (consinit_called != 0)
    841  1.1  macallan 		return;
    842  1.1  macallan 
    843  1.1  macallan 	consinit_called = 1;
    844  1.1  macallan 
    845  1.1  macallan 	/* We let consinit_<foo> worry about device numbers */
    846  1.1  macallan 	if (strncmp(boot_consdev, "genfb", 5) &&
    847  1.1  macallan 	    strncmp(boot_consdev, "com", 3))
    848  1.1  macallan 	        strcpy(boot_consdev, DEFAULT_CONSDEV);
    849  1.1  macallan 
    850  1.1  macallan 	if (!strncmp(boot_consdev, "com", 3))
    851  1.1  macallan 		consinit_com(boot_consdev);
    852  1.1  macallan 	else
    853  1.1  macallan 		consinit_genfb(boot_consdev);
    854  1.1  macallan }
    855  1.1  macallan 
    856  1.1  macallan static void
    857  1.1  macallan consinit_com(const char *consdev)
    858  1.1  macallan {
    859  1.1  macallan 	static const bus_addr_t comcnaddrs[] = {
    860  1.1  macallan 		IYONIX_UART1,		/* com0 */
    861  1.1  macallan 	};
    862  1.1  macallan 	/*
    863  1.1  macallan 	 * Console devices are mapped VA==PA.  Our devmap reflects
    864  1.1  macallan 	 * this, so register it now so drivers can map the console
    865  1.1  macallan 	 * device.
    866  1.1  macallan 	 */
    867  1.1  macallan 	pmap_devmap_register(iyonix_devmap);
    868  1.1  macallan 
    869  1.1  macallan 	/* When we support more than the first serial port as console,
    870  1.1  macallan 	 * we should check consdev for a number.
    871  1.1  macallan 	 */
    872  1.1  macallan #if NCOM > 0
    873  1.1  macallan 	if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
    874  1.1  macallan 	    COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    875  1.1  macallan 	{
    876  1.1  macallan 		panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
    877  1.1  macallan 	}
    878  1.1  macallan #else
    879  1.1  macallan 	panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
    880  1.1  macallan #endif
    881  1.1  macallan 
    882  1.1  macallan #if KGDB
    883  1.1  macallan #if NCOM > 0
    884  1.1  macallan 	if (strcmp(kgdb_devname, "com") == 0) {
    885  1.1  macallan 		com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
    886  1.1  macallan 		    COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
    887  1.1  macallan 	}
    888  1.1  macallan #endif	/* NCOM > 0 */
    889  1.1  macallan #endif	/* KGDB */
    890  1.1  macallan }
    891  1.1  macallan 
    892  1.1  macallan static void
    893  1.1  macallan consinit_genfb(const char *consdev)
    894  1.1  macallan {
    895  1.1  macallan 	/* NOTYET */
    896  1.1  macallan }
    897  1.1  macallan 
    898  1.1  macallan static void
    899  1.1  macallan process_kernel_args(void)
    900  1.1  macallan {
    901  1.1  macallan 	char *args;
    902  1.1  macallan 
    903  1.1  macallan 	/* Ok now we will check the arguments for interesting parameters. */
    904  1.1  macallan 	args = bootconfig.args;
    905  1.1  macallan 
    906  1.1  macallan #ifdef BOOTHOWTO
    907  1.1  macallan 	boothowto = BOOTHOWTO;
    908  1.1  macallan #else
    909  1.1  macallan 	boothowto = 0;
    910  1.1  macallan #endif
    911  1.1  macallan 
    912  1.1  macallan 	/* Only arguments itself are passed from the bootloader */
    913  1.1  macallan 	while (*args == ' ')
    914  1.1  macallan 		++args;
    915  1.1  macallan 
    916  1.1  macallan 	boot_args = args;
    917  1.1  macallan 	parse_mi_bootargs(boot_args);
    918  1.1  macallan 	parse_iyonix_bootargs(boot_args);
    919  1.1  macallan }
    920  1.1  macallan 
    921  1.1  macallan static void
    922  1.1  macallan parse_iyonix_bootargs(char *args)
    923  1.1  macallan {
    924  1.1  macallan 	char *ptr;
    925  1.1  macallan 
    926  1.1  macallan 	if (get_bootconf_option(args, "consdev", BOOTOPT_TYPE_STRING, &ptr))
    927  1.1  macallan 	{
    928  1.1  macallan 		/* ptr may have trailing clutter */
    929  1.1  macallan 		strlcpy(boot_consdev, ptr, sizeof(boot_consdev));
    930  1.1  macallan 		if ( (ptr = strchr(boot_consdev, ' ')) )
    931  1.1  macallan 			*ptr = 0;
    932  1.1  macallan 	}
    933  1.1  macallan }
    934