Home | History | Annotate | Line # | Download | only in gdium
machdep.c revision 1.6
      1  1.6  cliff /*	$NetBSD: machdep.c,v 1.6 2009/08/11 03:56:34 cliff Exp $	*/
      2  1.1   matt 
      3  1.1   matt /*
      4  1.1   matt  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5  1.1   matt  * All rights reserved.
      6  1.1   matt  *
      7  1.1   matt  * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
      8  1.1   matt  *
      9  1.1   matt  * Redistribution and use in source and binary forms, with or without
     10  1.1   matt  * modification, are permitted provided that the following conditions
     11  1.1   matt  * are met:
     12  1.1   matt  * 1. Redistributions of source code must retain the above copyright
     13  1.1   matt  *    notice, this list of conditions and the following disclaimer.
     14  1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   matt  *    documentation and/or other materials provided with the distribution.
     17  1.1   matt  * 3. All advertising materials mentioning features or use of this software
     18  1.1   matt  *    must display the following acknowledgement:
     19  1.1   matt  *      This product includes software developed for the NetBSD Project by
     20  1.1   matt  *      Wasabi Systems, Inc.
     21  1.1   matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1   matt  *    or promote products derived from this software without specific prior
     23  1.1   matt  *    written permission.
     24  1.1   matt  *
     25  1.1   matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1   matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1   matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1   matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1   matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1   matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1   matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1   matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1   matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1   matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1   matt  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1   matt  */
     37  1.1   matt 
     38  1.1   matt /*
     39  1.1   matt  * Copyright (c) 1992, 1993
     40  1.1   matt  *	The Regents of the University of California.  All rights reserved.
     41  1.1   matt  *
     42  1.1   matt  * This code is derived from software contributed to Berkeley by
     43  1.1   matt  * the Systems Programming Group of the University of Utah Computer
     44  1.1   matt  * Science Department, The Mach Operating System project at
     45  1.1   matt  * Carnegie-Mellon University and Ralph Campbell.
     46  1.1   matt  *
     47  1.1   matt  * Redistribution and use in source and binary forms, with or without
     48  1.1   matt  * modification, are permitted provided that the following conditions
     49  1.1   matt  * are met:
     50  1.1   matt  * 1. Redistributions of source code must retain the above copyright
     51  1.1   matt  *    notice, this list of conditions and the following disclaimer.
     52  1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     54  1.1   matt  *    documentation and/or other materials provided with the distribution.
     55  1.1   matt  * 3. Neither the name of the University nor the names of its contributors
     56  1.1   matt  *    may be used to endorse or promote products derived from this software
     57  1.1   matt  *    without specific prior written permission.
     58  1.1   matt  *
     59  1.1   matt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1   matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1   matt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1   matt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1   matt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1   matt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1   matt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1   matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1   matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1   matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1   matt  * SUCH DAMAGE.
     70  1.1   matt  *
     71  1.1   matt  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
     72  1.1   matt  *	from: Utah Hdr: machdep.c 1.63 91/04/24
     73  1.1   matt  */
     74  1.1   matt /*
     75  1.1   matt  * Copyright (c) 1988 University of Utah.
     76  1.1   matt  *
     77  1.1   matt  * This code is derived from software contributed to Berkeley by
     78  1.1   matt  * the Systems Programming Group of the University of Utah Computer
     79  1.1   matt  * Science Department, The Mach Operating System project at
     80  1.1   matt  * Carnegie-Mellon University and Ralph Campbell.
     81  1.1   matt  *
     82  1.1   matt  * Redistribution and use in source and binary forms, with or without
     83  1.1   matt  * modification, are permitted provided that the following conditions
     84  1.1   matt  * are met:
     85  1.1   matt  * 1. Redistributions of source code must retain the above copyright
     86  1.1   matt  *    notice, this list of conditions and the following disclaimer.
     87  1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     89  1.1   matt  *    documentation and/or other materials provided with the distribution.
     90  1.1   matt  * 3. All advertising materials mentioning features or use of this software
     91  1.1   matt  *    must display the following acknowledgement:
     92  1.1   matt  *	This product includes software developed by the University of
     93  1.1   matt  *	California, Berkeley and its contributors.
     94  1.1   matt  * 4. Neither the name of the University nor the names of its contributors
     95  1.1   matt  *    may be used to endorse or promote products derived from this software
     96  1.1   matt  *    without specific prior written permission.
     97  1.1   matt  *
     98  1.1   matt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     99  1.1   matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    100  1.1   matt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    101  1.1   matt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    102  1.1   matt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    103  1.1   matt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    104  1.1   matt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  1.1   matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  1.1   matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  1.1   matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  1.1   matt  * SUCH DAMAGE.
    109  1.1   matt  *
    110  1.1   matt  *	@(#)machdep.c   8.3 (Berkeley) 1/12/94
    111  1.1   matt  *	from: Utah Hdr: machdep.c 1.63 91/04/24
    112  1.1   matt  */
    113  1.1   matt 
    114  1.1   matt #include <sys/cdefs.h>
    115  1.6  cliff __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.6 2009/08/11 03:56:34 cliff Exp $");
    116  1.1   matt 
    117  1.1   matt #include "opt_ddb.h"
    118  1.1   matt #include "opt_execfmt.h"
    119  1.1   matt #include "opt_modular.h"
    120  1.1   matt 
    121  1.1   matt #include <sys/param.h>
    122  1.1   matt #include <sys/systm.h>
    123  1.1   matt #include <sys/kernel.h>
    124  1.1   matt #include <sys/buf.h>
    125  1.1   matt #include <sys/reboot.h>
    126  1.1   matt #include <sys/user.h>
    127  1.1   matt #include <sys/mount.h>
    128  1.1   matt #include <sys/kcore.h>
    129  1.1   matt #include <sys/boot_flag.h>
    130  1.1   matt #include <sys/termios.h>
    131  1.1   matt #include <sys/ksyms.h>
    132  1.1   matt #include <sys/device.h>
    133  1.1   matt 
    134  1.1   matt #include <uvm/uvm_extern.h>
    135  1.1   matt 
    136  1.1   matt #include <dev/cons.h>
    137  1.1   matt 
    138  1.1   matt #include "ksyms.h"
    139  1.1   matt 
    140  1.1   matt #if NKSYMS || defined(DDB) || defined(MODULAR)
    141  1.1   matt #include <machine/db_machdep.h>
    142  1.1   matt #include <ddb/db_extern.h>
    143  1.1   matt #endif
    144  1.1   matt 
    145  1.1   matt #include <machine/cpu.h>
    146  1.1   matt #include <machine/psl.h>
    147  1.1   matt 
    148  1.1   matt #include <mips/bonito/bonitoreg.h>
    149  1.1   matt #include <evbmips/gdium/gdiumvar.h>
    150  1.1   matt 
    151  1.1   matt #include "com.h"
    152  1.1   matt #if NCOM > 0
    153  1.1   matt #include <dev/ic/comreg.h>
    154  1.1   matt #include <dev/ic/comvar.h>
    155  1.1   matt 
    156  1.1   matt int	comcnrate = 38400;	/* XXX should be config option */
    157  1.1   matt #endif /* NCOM > 0 */
    158  1.1   matt 
    159  1.1   matt struct gdium_config gdium_configuration = {
    160  1.1   matt 	.gc_bonito = {
    161  1.1   matt 		.bc_adbase = 11,	/* magic */
    162  1.1   matt 	},
    163  1.1   matt };
    164  1.1   matt 
    165  1.1   matt /* For sysctl_hw. */
    166  1.1   matt extern char cpu_model[];
    167  1.1   matt 
    168  1.1   matt /* Our exported CPU info; we can have only one. */
    169  1.1   matt struct cpu_info cpu_info_store;
    170  1.1   matt 
    171  1.1   matt /* Maps for VM objects. */
    172  1.1   matt struct vm_map *mb_map = NULL;
    173  1.1   matt struct vm_map *phys_map = NULL;
    174  1.1   matt 
    175  1.1   matt int	physmem;		/* Total physical memory */
    176  1.1   matt int	netboot;		/* Are we netbooting? */
    177  1.1   matt 
    178  1.1   matt phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    179  1.1   matt int mem_cluster_cnt;
    180  1.1   matt 
    181  1.1   matt void	configure(void);
    182  1.2   matt void	mach_init(int, char **, char **, void *);
    183  1.1   matt 
    184  1.1   matt /*
    185  1.1   matt  * safepri is a safe priority for sleep to set for a spin-wait during
    186  1.1   matt  * autoconfiguration or after a panic.  Used as an argument to splx().
    187  1.1   matt  */
    188  1.1   matt int	safepri = MIPS1_PSL_LOWIPL;
    189  1.1   matt 
    190  1.1   matt extern struct user *proc0paddr;
    191  1.1   matt 
    192  1.1   matt /*
    193  1.4   matt  * For some reason, PMON doesn't assign a real address to the Ralink's BAR.
    194  1.4   matt  * So we have to do it.
    195  1.4   matt  */
    196  1.4   matt static void
    197  1.4   matt gdium_pci_attach_hook(device_t parent, device_t self,
    198  1.4   matt     struct pcibus_attach_args *pba)
    199  1.4   matt {
    200  1.4   matt 	const pcitag_t high_dev = pci_make_tag(pba->pba_pc, 0, 17, 1);
    201  1.4   matt 	const pcitag_t ralink_dev = pci_make_tag(pba->pba_pc, 0, 13, 0);
    202  1.4   matt 	bus_size_t high_size, ralink_size;
    203  1.4   matt 	pcireg_t v;
    204  1.4   matt 
    205  1.4   matt 	/*
    206  1.4   matt 	 * Get the highest PCI addr used from the last PCI dev.
    207  1.4   matt 	 */
    208  1.4   matt 	v = pci_conf_read(pba->pba_pc, high_dev, PCI_MAPREG_START);
    209  1.4   matt 	v &= PCI_MAPREG_MEM_ADDR_MASK;
    210  1.4   matt 
    211  1.4   matt 	/*
    212  1.4   matt 	 * Get the sizes of the map registers.
    213  1.4   matt 	 */
    214  1.4   matt 	pci_mapreg_info(pba->pba_pc, high_dev, PCI_MAPREG_START,
    215  1.4   matt 	    PCI_MAPREG_MEM_TYPE_32BIT, NULL, &high_size, NULL);
    216  1.4   matt 	pci_mapreg_info(pba->pba_pc, ralink_dev, PCI_MAPREG_START,
    217  1.4   matt 	    PCI_MAPREG_MEM_TYPE_32BIT, NULL, &ralink_size, NULL);
    218  1.4   matt 
    219  1.4   matt 	/*
    220  1.4   matt 	 * Position the ralink register space after the last device.
    221  1.4   matt 	 */
    222  1.4   matt 	v = (v + high_size + ralink_size - 1) & ~(ralink_size - 1);
    223  1.4   matt 
    224  1.4   matt 	/*
    225  1.4   matt 	 * Set the mapreg.
    226  1.4   matt 	 */
    227  1.4   matt 	pci_conf_write(pba->pba_pc, ralink_dev, PCI_MAPREG_START, v);
    228  1.5   matt 
    229  1.5   matt #if 0
    230  1.5   matt 	/*
    231  1.5   matt 	 * Why does linux do this?
    232  1.5   matt 	 */
    233  1.5   matt 	for (int dev = 15; dev <= 17; dev +=2) {
    234  1.5   matt 		for (int func = 0; func <= 1; func++) {
    235  1.5   matt 			pcitag_t usb_dev = pci_make_tag(pba->pba_pc, 0, dev, func);
    236  1.5   matt 			v = pci_conf_read(pba->pba_pc, usb_dev, 0xe0);
    237  1.5   matt 			v |= 3;
    238  1.5   matt 			pci_conf_write(pba->pba_pc, usb_dev, 0xe0, v);
    239  1.5   matt 		}
    240  1.5   matt 	}
    241  1.5   matt #endif
    242  1.4   matt }
    243  1.4   matt 
    244  1.4   matt /*
    245  1.1   matt  * Do all the stuff that locore normally does before calling main().
    246  1.1   matt  */
    247  1.1   matt void
    248  1.3   matt mach_init(int argc, char **argv, char **envp, void *callvec)
    249  1.1   matt {
    250  1.1   matt 	struct gdium_config *gc = &gdium_configuration;
    251  1.1   matt 	void *kernend, *v;
    252  1.1   matt         u_long first, last;
    253  1.6  cliff #ifdef NOTYET
    254  1.1   matt 	char *cp;
    255  1.6  cliff 	int howto;
    256  1.6  cliff #endif
    257  1.6  cliff 	int i;
    258  1.1   matt 	psize_t memsize;
    259  1.1   matt 
    260  1.1   matt 	extern char edata[], end[];
    261  1.1   matt 
    262  1.1   matt 	/*
    263  1.1   matt 	 * Clear the BSS segment.
    264  1.1   matt 	 */
    265  1.1   matt 	kernend = (void *)mips_round_page(end);
    266  1.1   matt 	memset(edata, 0, (char *)kernend - edata);
    267  1.1   matt 
    268  1.1   matt 	/*
    269  1.1   matt 	 * Set up the exception vectors and CPU-specific function
    270  1.1   matt 	 * vectors early on.  We need the wbflush() vector set up
    271  1.1   matt 	 * before comcnattach() is called (or at least before the
    272  1.1   matt 	 * first printf() after that is called).
    273  1.1   matt 	 * Also clears the I+D caches.
    274  1.1   matt 	 */
    275  1.1   matt 	mips_vector_init();
    276  1.1   matt 
    277  1.1   matt 	/* set the VM page size */
    278  1.1   matt 	uvm_setpagesize();
    279  1.1   matt 
    280  1.1   matt 	memsize = 256*1024*1024;
    281  1.1   matt 	physmem = btoc(memsize);
    282  1.1   matt 
    283  1.1   matt 	bonito_pci_init(&gc->gc_pc, &gc->gc_bonito);
    284  1.4   matt 	/*
    285  1.4   matt 	 * Override the null bonito_pci_attach_hook with our own to we can
    286  1.4   matt 	 * fix the ralink (device 13).
    287  1.4   matt 	 */
    288  1.4   matt 	gc->gc_pc.pc_attach_hook = gdium_pci_attach_hook;
    289  1.1   matt 	gdium_bus_io_init(&gc->gc_iot, gc);
    290  1.1   matt 	gdium_bus_mem_init(&gc->gc_memt, gc);
    291  1.2   matt 	gdium_dma_init(gc);
    292  1.1   matt 	gdium_cnattach(gc);
    293  1.1   matt 
    294  1.1   matt 	/*
    295  1.5   matt 	 * Disable the 2nd PCI window since we don't need it.
    296  1.5   matt 	 */
    297  1.5   matt 	REGVAL(BONITO_REGBASE + 0x158) = 0xe;
    298  1.5   matt 	REGVAL(BONITO_REGBASE + 0x15c) = 0;
    299  1.5   matt 	pci_conf_write(&gc->gc_pc, pci_make_tag(&gc->gc_pc, 0, 0, 0), 18, 0);
    300  1.5   matt 
    301  1.5   matt 	/*
    302  1.3   matt 	 * Get the timer from PMON.
    303  1.1   matt 	 */
    304  1.3   matt 	for (i = 0; envp[i] != NULL; i++) {
    305  1.3   matt 		if (!strncmp(envp[i], "cpuclock=", 9)) {
    306  1.3   matt 			curcpu()->ci_cpu_freq =
    307  1.3   matt 			    strtoul(&envp[i][9], NULL, 10);
    308  1.3   matt 			break;
    309  1.3   matt 		}
    310  1.3   matt 	}
    311  1.3   matt 
    312  1.3   matt 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    313  1.3   matt 		curcpu()->ci_cpu_freq /= 2;
    314  1.3   matt 
    315  1.3   matt 	/* Compute the number of ticks for hz. */
    316  1.3   matt 	curcpu()->ci_cycles_per_hz = (curcpu()->ci_cpu_freq + hz / 2) / hz;
    317  1.3   matt 
    318  1.3   matt 	/* Compute the delay divisor. */
    319  1.3   matt 	curcpu()->ci_divisor_delay =
    320  1.3   matt 	    ((curcpu()->ci_cpu_freq + 500000) / 1000000);
    321  1.3   matt 
    322  1.3   matt 	/*
    323  1.3   matt 	 * Get correct cpu frequency if the CPU runs at twice the
    324  1.3   matt 	 * external/cp0-count frequency.
    325  1.3   matt 	 */
    326  1.3   matt 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    327  1.3   matt 		curcpu()->ci_cpu_freq *= 2;
    328  1.3   matt 
    329  1.3   matt #ifdef DEBUG
    330  1.3   matt 	printf("Timer calibration: %lu cycles/sec\n",
    331  1.3   matt 	    curcpu()->ci_cpu_freq);
    332  1.1   matt #endif
    333  1.1   matt 
    334  1.1   matt #if NCOM > 0
    335  1.1   matt 	/*
    336  1.1   matt 	 * Delay to allow firmware putchars to complete.
    337  1.1   matt 	 * FIFO depth * character time.
    338  1.1   matt 	 * character time = (1000000 / (defaultrate / 10))
    339  1.1   matt 	 */
    340  1.1   matt 	delay(160000000 / comcnrate);
    341  1.1   matt 	if (comcnattach(&gc->gc_iot, MALTA_UART0ADR, comcnrate,
    342  1.1   matt 	    COM_FREQ, COM_TYPE_NORMAL,
    343  1.1   matt 	    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8) != 0)
    344  1.1   matt 		panic("malta: unable to initialize serial console");
    345  1.1   matt #endif /* NCOM > 0 */
    346  1.1   matt 
    347  1.1   matt 	mem_clusters[0].start = 0;
    348  1.1   matt 	mem_clusters[0].size = ctob(physmem);
    349  1.1   matt 	mem_cluster_cnt = 1;
    350  1.1   matt 
    351  1.1   matt 	strcpy(cpu_model, "Gdium Liberty 1000");
    352  1.1   matt 
    353  1.1   matt 	/*
    354  1.1   matt 	 * XXX: check argv[0] - do something if "gdb"???
    355  1.1   matt 	 */
    356  1.1   matt 
    357  1.1   matt 	/*
    358  1.1   matt 	 * Look at arguments passed to us and compute boothowto.
    359  1.1   matt 	 */
    360  1.1   matt 	boothowto = RB_AUTOBOOT;
    361  1.6  cliff #ifdef NOTYET
    362  1.1   matt 	for (i = 1; i < argc; i++) {
    363  1.1   matt 		for (cp = argv[i]; *cp; cp++) {
    364  1.1   matt 			/* Ignore superfluous '-', if there is one */
    365  1.1   matt 			if (*cp == '-')
    366  1.1   matt 				continue;
    367  1.1   matt 
    368  1.1   matt 			howto = 0;
    369  1.1   matt 			BOOT_FLAG(*cp, howto);
    370  1.1   matt 			if (! howto)
    371  1.1   matt 				printf("bootflag '%c' not recognised\n", *cp);
    372  1.1   matt 			else
    373  1.1   matt 				boothowto |= howto;
    374  1.1   matt 		}
    375  1.1   matt 	}
    376  1.6  cliff #endif
    377  1.1   matt 
    378  1.1   matt 	/*
    379  1.1   matt 	 * Load the rest of the available pages into the VM system.
    380  1.1   matt 	 */
    381  1.1   matt 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    382  1.1   matt 	last = mem_clusters[0].start + mem_clusters[0].size;
    383  1.1   matt 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    384  1.1   matt 		VM_FREELIST_DEFAULT);
    385  1.1   matt 
    386  1.1   matt 	/*
    387  1.1   matt 	 * Initialize error message buffer (at end of core).
    388  1.1   matt 	 */
    389  1.1   matt 	mips_init_msgbuf();
    390  1.1   matt 
    391  1.1   matt 	pmap_bootstrap();
    392  1.1   matt 
    393  1.1   matt 	/*
    394  1.1   matt 	 * Allocate space for proc0's USPACE.
    395  1.1   matt 	 */
    396  1.1   matt 	v = (void *)uvm_pageboot_alloc(USPACE);
    397  1.1   matt 	lwp0.l_addr = proc0paddr = (struct user *)v;
    398  1.1   matt 	lwp0.l_md.md_regs = (struct frame *)((char *)v + USPACE) - 1;
    399  1.1   matt 	proc0paddr->u_pcb.pcb_context[11] =
    400  1.1   matt 	    MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
    401  1.1   matt 
    402  1.1   matt 	/*
    403  1.1   matt 	 * Initialize debuggers, and break into them, if appropriate.
    404  1.1   matt 	 */
    405  1.1   matt #if defined(DDB)
    406  1.1   matt 	if (boothowto & RB_KDB)
    407  1.1   matt 		Debugger();
    408  1.1   matt #endif
    409  1.1   matt }
    410  1.1   matt 
    411  1.1   matt void
    412  1.1   matt consinit(void)
    413  1.1   matt {
    414  1.1   matt 
    415  1.1   matt 	/*
    416  1.1   matt 	 * Everything related to console initialization is done
    417  1.1   matt 	 * in mach_init().
    418  1.1   matt 	 */
    419  1.1   matt }
    420  1.1   matt 
    421  1.1   matt /*
    422  1.1   matt  * Allocate memory for variable-sized tables,
    423  1.1   matt  */
    424  1.1   matt void
    425  1.1   matt cpu_startup(void)
    426  1.1   matt {
    427  1.1   matt 	vaddr_t minaddr, maxaddr;
    428  1.1   matt 	char pbuf[9];
    429  1.1   matt 
    430  1.1   matt 	/*
    431  1.1   matt 	 * Good {morning,afternoon,evening,night}.
    432  1.1   matt 	 */
    433  1.1   matt 	printf("%s%s", copyright, version);
    434  1.1   matt 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    435  1.1   matt 	printf("total memory = %s\n", pbuf);
    436  1.1   matt 
    437  1.1   matt 	/*
    438  1.1   matt 	 * Virtual memory is bootstrapped -- notify the bus spaces
    439  1.1   matt 	 * that memory allocation is now safe.
    440  1.1   matt 	 */
    441  1.1   matt 	gdium_configuration.gc_mallocsafe = 1;
    442  1.1   matt 
    443  1.1   matt 	minaddr = 0;
    444  1.1   matt 	/*
    445  1.1   matt 	 * Allocate a submap for physio.
    446  1.1   matt 	 */
    447  1.1   matt 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    448  1.1   matt 				    VM_PHYS_SIZE, 0, FALSE, NULL);
    449  1.1   matt 
    450  1.1   matt 	/*
    451  1.1   matt 	 * (No need to allocate an mbuf cluster submap.  Mbuf clusters
    452  1.1   matt 	 * are allocated via the pool allocator, and we use KSEG to
    453  1.1   matt 	 * map those pages.)
    454  1.1   matt 	 */
    455  1.1   matt 
    456  1.1   matt 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    457  1.1   matt 	printf("avail memory = %s\n", pbuf);
    458  1.1   matt }
    459  1.1   matt 
    460  1.1   matt int	waittime = -1;
    461  1.1   matt 
    462  1.1   matt void
    463  1.1   matt cpu_reboot(int howto, char *bootstr)
    464  1.1   matt {
    465  1.1   matt 
    466  1.1   matt 	/* Take a snapshot before clobbering any registers. */
    467  1.1   matt 	if (curproc)
    468  1.1   matt 		savectx((struct user *)curpcb);
    469  1.1   matt 
    470  1.1   matt 	if (cold) {
    471  1.1   matt 		howto |= RB_HALT;
    472  1.1   matt 		goto haltsys;
    473  1.1   matt 	}
    474  1.1   matt 
    475  1.1   matt 	/* If "always halt" was specified as a boot flag, obey. */
    476  1.1   matt 	if (boothowto & RB_HALT)
    477  1.1   matt 		howto |= RB_HALT;
    478  1.1   matt 
    479  1.1   matt 	boothowto = howto;
    480  1.1   matt 	if ((howto & RB_NOSYNC) == 0 && (waittime < 0)) {
    481  1.1   matt 		waittime = 0;
    482  1.1   matt 		vfs_shutdown();
    483  1.1   matt 
    484  1.1   matt 		/*
    485  1.1   matt 		 * If we've been adjusting the clock, the todr
    486  1.1   matt 		 * will be out of synch; adjust it now.
    487  1.1   matt 		 */
    488  1.1   matt 		resettodr();
    489  1.1   matt 	}
    490  1.1   matt 
    491  1.1   matt 	splhigh();
    492  1.1   matt 
    493  1.1   matt 	if (howto & RB_DUMP)
    494  1.1   matt 		dumpsys();
    495  1.1   matt 
    496  1.1   matt haltsys:
    497  1.1   matt 	doshutdownhooks();
    498  1.1   matt 
    499  1.1   matt 	pmf_system_shutdown(boothowto);
    500  1.1   matt 
    501  1.1   matt 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    502  1.1   matt 		/*
    503  1.1   matt 		 * Turning on GPIO1 as output will cause a powerdown.
    504  1.1   matt 		 */
    505  1.1   matt 		REGVAL(BONITO_GPIODATA) |= 2;
    506  1.1   matt 		REGVAL(BONITO_GPIOIE) &= ~2;
    507  1.1   matt 	}
    508  1.1   matt 
    509  1.1   matt 	if (howto & RB_HALT) {
    510  1.1   matt 		printf("\n");
    511  1.1   matt 		printf("The operating system has halted.\n");
    512  1.1   matt 		printf("Please press any key to reboot.\n\n");
    513  1.1   matt 		cnpollc(1);	/* For proper keyboard command handling */
    514  1.1   matt 		cngetc();
    515  1.1   matt 		cnpollc(0);
    516  1.1   matt 	}
    517  1.1   matt 
    518  1.1   matt 	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");
    519  1.1   matt 
    520  1.1   matt 	/*
    521  1.1   matt 	 * Turning off GPIO2 as output will cause a reset.
    522  1.1   matt 	 */
    523  1.1   matt 	REGVAL(BONITO_GPIODATA) &= ~4;
    524  1.1   matt 	REGVAL(BONITO_GPIOIE) &= ~4;
    525  1.1   matt 
    526  1.1   matt 	__asm__ __volatile__ (
    527  1.1   matt 		"\t.long 0x3c02bfc0\n"
    528  1.1   matt 		"\t.long 0x00400008\n"
    529  1.1   matt 	    ::: "v0");
    530  1.1   matt }
    531