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