machdep.c revision 1.5       1  1.5  gdamore /* $NetBSD: machdep.c,v 1.5 2006/09/26 06:37:32 gdamore Exp $ */
      2  1.1  gdamore 
      3  1.1  gdamore /*
      4  1.1  gdamore  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      5  1.1  gdamore  * Copyright (c) 2006 Garrett D'Amore.
      6  1.1  gdamore  * All rights reserved.
      7  1.1  gdamore  *
      8  1.1  gdamore  * Portions of this code were written by Garrett D'Amore for the
      9  1.1  gdamore  * Champaign-Urbana Community Wireless Network Project.
     10  1.1  gdamore  *
     11  1.1  gdamore  * Redistribution and use in source and binary forms, with or
     12  1.1  gdamore  * without modification, are permitted provided that the following
     13  1.1  gdamore  * conditions are met:
     14  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     15  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     16  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above
     17  1.1  gdamore  *    copyright notice, this list of conditions and the following
     18  1.1  gdamore  *    disclaimer in the documentation and/or other materials provided
     19  1.1  gdamore  *    with the distribution.
     20  1.1  gdamore  * 3. All advertising materials mentioning features or use of this
     21  1.1  gdamore  *    software must display the following acknowledgements:
     22  1.1  gdamore  *      This product includes software developed by the Urbana-Champaign
     23  1.1  gdamore  *      Independent Media Center.
     24  1.1  gdamore  *	This product includes software developed by Garrett D'Amore.
     25  1.1  gdamore  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     26  1.1  gdamore  *    D'Amore's name may not be used to endorse or promote products
     27  1.1  gdamore  *    derived from this software without specific prior written permission.
     28  1.1  gdamore  *
     29  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     30  1.1  gdamore  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     31  1.1  gdamore  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     32  1.1  gdamore  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33  1.1  gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     34  1.1  gdamore  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     35  1.1  gdamore  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     36  1.1  gdamore  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     37  1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     38  1.1  gdamore  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1  gdamore  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     40  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     41  1.1  gdamore  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     42  1.1  gdamore  */
     43  1.1  gdamore /*-
     44  1.1  gdamore  * Copyright (c) 2006 Itronix Inc.
     45  1.1  gdamore  * All rights reserved.
     46  1.1  gdamore  *
     47  1.1  gdamore  * Portions written by Garrett D'Amore for Itronix Inc.
     48  1.1  gdamore  *
     49  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
     50  1.1  gdamore  * modification, are permitted provided that the following conditions
     51  1.1  gdamore  * are met:
     52  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     53  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     54  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     55  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     56  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     57  1.1  gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     58  1.1  gdamore  *    or promote products derived from this software without specific
     59  1.1  gdamore  *    prior written permission.
     60  1.1  gdamore  *
     61  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     62  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     63  1.1  gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     64  1.1  gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     65  1.1  gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     66  1.1  gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     67  1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     68  1.1  gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     69  1.1  gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     70  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     71  1.1  gdamore  * POSSIBILITY OF SUCH DAMAGE.
     72  1.1  gdamore  */
     73  1.1  gdamore /*
     74  1.1  gdamore  * Copyright (c) 1992, 1993
     75  1.1  gdamore  *	The Regents of the University of California.  All rights reserved.
     76  1.1  gdamore  *
     77  1.1  gdamore  * This code is derived from software contributed to Berkeley by
     78  1.1  gdamore  * the Systems Programming Group of the University of Utah Computer
     79  1.1  gdamore  * Science Department, The Mach Operating System project at
     80  1.1  gdamore  * Carnegie-Mellon University and Ralph Campbell.
     81  1.1  gdamore  *
     82  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
     83  1.1  gdamore  * modification, are permitted provided that the following conditions
     84  1.1  gdamore  * are met:
     85  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     86  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     87  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     89  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     90  1.1  gdamore  * 3. Neither the name of the University nor the names of its contributors
     91  1.1  gdamore  *    may be used to endorse or promote products derived from this software
     92  1.1  gdamore  *    without specific prior written permission.
     93  1.1  gdamore  *
     94  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     95  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     96  1.1  gdamore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     97  1.1  gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     98  1.1  gdamore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     99  1.1  gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    100  1.1  gdamore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    101  1.1  gdamore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    102  1.1  gdamore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    103  1.1  gdamore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    104  1.1  gdamore  * SUCH DAMAGE.
    105  1.1  gdamore  *
    106  1.1  gdamore  *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
    107  1.1  gdamore  * 	from: Utah Hdr: machdep.c 1.63 91/04/24
    108  1.1  gdamore  */
    109  1.1  gdamore /*
    110  1.1  gdamore  * Copyright (c) 1988 University of Utah.
    111  1.1  gdamore  *
    112  1.1  gdamore  * This code is derived from software contributed to Berkeley by
    113  1.1  gdamore  * the Systems Programming Group of the University of Utah Computer
    114  1.1  gdamore  * Science Department, The Mach Operating System project at
    115  1.1  gdamore  * Carnegie-Mellon University and Ralph Campbell.
    116  1.1  gdamore  *
    117  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
    118  1.1  gdamore  * modification, are permitted provided that the following conditions
    119  1.1  gdamore  * are met:
    120  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
    121  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
    122  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
    123  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
    124  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
    125  1.1  gdamore  * 3. All advertising materials mentioning features or use of this software
    126  1.1  gdamore  *    must display the following acknowledgement:
    127  1.1  gdamore  *	This product includes software developed by the University of
    128  1.1  gdamore  *	California, Berkeley and its contributors.
    129  1.1  gdamore  * 4. Neither the name of the University nor the names of its contributors
    130  1.1  gdamore  *    may be used to endorse or promote products derived from this software
    131  1.1  gdamore  *    without specific prior written permission.
    132  1.1  gdamore  *
    133  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    134  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    135  1.1  gdamore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    136  1.1  gdamore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    137  1.1  gdamore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    138  1.1  gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    139  1.1  gdamore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    140  1.1  gdamore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    141  1.1  gdamore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    142  1.1  gdamore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    143  1.1  gdamore  * SUCH DAMAGE.
    144  1.1  gdamore  *
    145  1.1  gdamore  *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
    146  1.1  gdamore  * 	from: Utah Hdr: machdep.c 1.63 91/04/24
    147  1.1  gdamore  */
    148  1.1  gdamore 
    149  1.1  gdamore #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
    150  1.5  gdamore __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.5 2006/09/26 06:37:32 gdamore Exp $");
    151  1.1  gdamore 
    152  1.1  gdamore #include "opt_ddb.h"
    153  1.1  gdamore #include "opt_kgdb.h"
    154  1.1  gdamore 
    155  1.1  gdamore #include <sys/param.h>
    156  1.1  gdamore #include <sys/systm.h>
    157  1.1  gdamore #include <sys/kernel.h>
    158  1.1  gdamore #include <sys/buf.h>
    159  1.1  gdamore #include <sys/reboot.h>
    160  1.1  gdamore #include <sys/user.h>
    161  1.1  gdamore #include <sys/mount.h>
    162  1.1  gdamore #include <sys/kcore.h>
    163  1.1  gdamore #include <sys/boot_flag.h>
    164  1.1  gdamore #include <sys/termios.h>
    165  1.1  gdamore #include <sys/ksyms.h>
    166  1.1  gdamore 
    167  1.1  gdamore #include <uvm/uvm_extern.h>
    168  1.1  gdamore 
    169  1.1  gdamore #include <dev/cons.h>
    170  1.1  gdamore 
    171  1.1  gdamore #include "ksyms.h"
    172  1.1  gdamore 
    173  1.1  gdamore #if NKSYMS || defined(DDB) || defined(LKM)
    174  1.1  gdamore #include <machine/db_machdep.h>
    175  1.1  gdamore #include <ddb/db_extern.h>
    176  1.1  gdamore #endif
    177  1.1  gdamore 
    178  1.1  gdamore #include <mips/cache.h>
    179  1.1  gdamore #include <mips/locore.h>
    180  1.1  gdamore #include <mips/cpuregs.h>
    181  1.1  gdamore 
    182  1.1  gdamore #include <mips/atheros/include/ar531xvar.h>
    183  1.1  gdamore #include <mips/atheros/include/arbusvar.h>
    184  1.1  gdamore 
    185  1.1  gdamore struct	user *proc0paddr;
    186  1.1  gdamore 
    187  1.1  gdamore /* Our exported CPU info; we can have only one. */
    188  1.1  gdamore struct cpu_info cpu_info_store;
    189  1.1  gdamore 
    190  1.1  gdamore /* Maps for VM objects. */
    191  1.1  gdamore struct vm_map *exec_map = NULL;
    192  1.1  gdamore struct vm_map *mb_map = NULL;
    193  1.1  gdamore struct vm_map *phys_map = NULL;
    194  1.1  gdamore 
    195  1.1  gdamore int physmem;		/* # pages of physical memory */
    196  1.1  gdamore int maxmem;			/* max memory per process */
    197  1.1  gdamore 
    198  1.1  gdamore int mem_cluster_cnt;
    199  1.1  gdamore phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
    200  1.1  gdamore 
    201  1.1  gdamore void	mach_init(void); /* XXX */
    202  1.1  gdamore 
    203  1.4  gdamore static void
    204  1.4  gdamore cal_timer(void)
    205  1.4  gdamore {
    206  1.4  gdamore 	uint32_t	cntfreq;
    207  1.1  gdamore 
    208  1.4  gdamore 	cntfreq = curcpu()->ci_cpu_freq = ar531x_cpu_freq();
    209  1.4  gdamore 
    210  1.4  gdamore 	/* MIPS 4Kc CP0 counts every other clock */
    211  1.4  gdamore 	if (mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
    212  1.4  gdamore 		cntfreq /= 2;
    213  1.4  gdamore 
    214  1.4  gdamore 	curcpu()->ci_cycles_per_hz = (cntfreq + hz / 2) / hz;
    215  1.4  gdamore 
    216  1.4  gdamore 	/* XXX: i don't understand this logic, it was borrowed from Malta */
    217  1.4  gdamore 	curcpu()->ci_divisor_delay = ((cntfreq + 500000) / 1000000);
    218  1.4  gdamore 	MIPS_SET_CI_RECIPRICAL(curcpu());
    219  1.4  gdamore }
    220  1.1  gdamore 
    221  1.1  gdamore void
    222  1.1  gdamore mach_init(void)
    223  1.1  gdamore {
    224  1.1  gdamore 	caddr_t kernend;
    225  1.1  gdamore 	u_long first, last;
    226  1.1  gdamore 	caddr_t				v;
    227  1.1  gdamore 	uint32_t			memsize;
    228  1.1  gdamore 
    229  1.1  gdamore 	extern char edata[], end[];	/* XXX */
    230  1.1  gdamore 
    231  1.1  gdamore 	/* clear the BSS segment */
    232  1.1  gdamore 	kernend = (caddr_t)mips_round_page(end);
    233  1.1  gdamore 
    234  1.1  gdamore 	memset(edata, 0, kernend - (caddr_t)edata);
    235  1.1  gdamore 
    236  1.5  gdamore 	/* setup early console */
    237  1.5  gdamore 	ar531x_early_console();
    238  1.5  gdamore 
    239  1.1  gdamore 	/* set CPU model info for sysctl_hw */
    240  1.4  gdamore 	snprintf(cpu_model, 64, "%s", ar531x_cpuname());
    241  1.1  gdamore 
    242  1.1  gdamore 	/*
    243  1.1  gdamore 	 * Set up the exception vectors and CPU-specific function
    244  1.1  gdamore 	 * vectors early on.  We need the wbflush() vector set up
    245  1.1  gdamore 	 * before comcnattach() is called (or at least before the
    246  1.1  gdamore 	 * first printf() after that is called).
    247  1.1  gdamore 	 * Sets up mips_cpu_flags that may be queried by other
    248  1.1  gdamore 	 * functions called during startup.
    249  1.1  gdamore 	 * Also clears the I+D caches.
    250  1.1  gdamore 	 */
    251  1.1  gdamore 	mips_vector_init();
    252  1.1  gdamore 
    253  1.1  gdamore 	/*
    254  1.1  gdamore 	 * Calibrate timers.
    255  1.1  gdamore 	 */
    256  1.4  gdamore 	cal_timer();
    257  1.1  gdamore 
    258  1.1  gdamore 	/*
    259  1.1  gdamore 	 * Set the VM page size.
    260  1.1  gdamore 	 */
    261  1.1  gdamore 	uvm_setpagesize();
    262  1.1  gdamore 
    263  1.1  gdamore 	/*
    264  1.1  gdamore 	 * Look at arguments passed to us and compute boothowto.
    265  1.1  gdamore 	 */
    266  1.1  gdamore 	boothowto = RB_AUTOBOOT;
    267  1.1  gdamore #ifdef KADB
    268  1.1  gdamore 	boothowto |= RB_KDB;
    269  1.1  gdamore #endif
    270  1.1  gdamore 
    271  1.1  gdamore 	/*
    272  1.1  gdamore 	 * This would be a good place to parse a boot command line, bif
    273  1.1  gdamore 	 * we got one from the bootloader.  Right now we have no way to
    274  1.1  gdamore 	 * get one from e.g. vxworks.
    275  1.1  gdamore 	 */
    276  1.1  gdamore 
    277  1.1  gdamore 	/*
    278  1.4  gdamore 	 * Determine the memory size.
    279  1.1  gdamore 	 *
    280  1.1  gdamore 	 * Note: Reserve the first page!  That's where the trap
    281  1.1  gdamore 	 * vectors are located.
    282  1.1  gdamore 	 */
    283  1.4  gdamore 	memsize = ar531x_memsize();
    284  1.1  gdamore 
    285  1.1  gdamore 	printf("Memory size: 0x%08x\n", memsize);
    286  1.1  gdamore 	physmem = btoc(memsize);
    287  1.1  gdamore 
    288  1.1  gdamore 	mem_clusters[mem_cluster_cnt].start = PAGE_SIZE;
    289  1.1  gdamore 	mem_clusters[mem_cluster_cnt].size =
    290  1.1  gdamore 	    memsize - mem_clusters[mem_cluster_cnt].start;
    291  1.1  gdamore 	mem_cluster_cnt++;
    292  1.1  gdamore 
    293  1.1  gdamore 	/*
    294  1.1  gdamore 	 * Load the rest of the available pages into the VM system.
    295  1.1  gdamore 	 */
    296  1.1  gdamore 	first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
    297  1.1  gdamore 	last = mem_clusters[0].start + mem_clusters[0].size;
    298  1.1  gdamore 	uvm_page_physload(atop(first), atop(last), atop(first), atop(last),
    299  1.1  gdamore 	    VM_FREELIST_DEFAULT);
    300  1.1  gdamore 
    301  1.1  gdamore 	/*
    302  1.1  gdamore 	 * Initialize message buffer (at end of core).
    303  1.1  gdamore 	 */
    304  1.1  gdamore 	mips_init_msgbuf();
    305  1.1  gdamore 
    306  1.1  gdamore 	/*
    307  1.1  gdamore 	 * Initialize the virtual memory system.
    308  1.1  gdamore 	 */
    309  1.1  gdamore 	pmap_bootstrap();
    310  1.1  gdamore 
    311  1.1  gdamore 	/*
    312  1.1  gdamore 	 * Init mapping for u page(s) for proc0.
    313  1.1  gdamore 	 */
    314  1.1  gdamore 	v = (caddr_t) uvm_pageboot_alloc(USPACE);
    315  1.1  gdamore 	lwp0.l_addr = proc0paddr = (struct user *)v;
    316  1.1  gdamore 	lwp0.l_md.md_regs = (struct frame *)(v + USPACE) - 1;
    317  1.1  gdamore 	curpcb = &lwp0.l_addr->u_pcb;
    318  1.1  gdamore 	curpcb->pcb_context[11] = MIPS_INT_MASK | MIPS_SR_INT_IE; /* SR */
    319  1.1  gdamore 
    320  1.1  gdamore 	/*
    321  1.4  gdamore 	 * Initialize busses.
    322  1.1  gdamore 	 */
    323  1.4  gdamore 	ar531x_businit();
    324  1.1  gdamore 
    325  1.1  gdamore 	/*
    326  1.1  gdamore 	 * Turn off (ignore) the hardware watchdog.  If we got this
    327  1.1  gdamore 	 * far, then we shouldn't need it anymore.
    328  1.1  gdamore 	 */
    329  1.4  gdamore 	ar531x_wdog(0);
    330  1.1  gdamore 
    331  1.1  gdamore 	/*
    332  1.1  gdamore 	 * Turn off watchpoint that may have been enabled by the
    333  1.1  gdamore 	 * PROM.  VxWorks bootloader seems to leave one set.
    334  1.1  gdamore 	 */
    335  1.1  gdamore 	__asm volatile (
    336  1.1  gdamore 		"mtc0	$0, $" ___STRING(MIPS_COP_0_WATCH_LO) " \n\t"
    337  1.1  gdamore 		"nop\n\t"
    338  1.1  gdamore 		"nop\n\t");
    339  1.1  gdamore 
    340  1.1  gdamore 	/*
    341  1.1  gdamore 	 * Initialize debuggers, and break into them, if appropriate.
    342  1.1  gdamore 	 */
    343  1.1  gdamore #if NKSYMS || defined(DDB) || defined(LKM)
    344  1.1  gdamore 	ksyms_init(0, 0, 0);
    345  1.1  gdamore #endif
    346  1.1  gdamore 
    347  1.1  gdamore #ifdef DDB
    348  1.1  gdamore 	if (boothowto & RB_KDB)
    349  1.1  gdamore 		Debugger();
    350  1.1  gdamore #endif
    351  1.1  gdamore }
    352  1.1  gdamore 
    353  1.1  gdamore void
    354  1.1  gdamore consinit(void)
    355  1.1  gdamore {
    356  1.1  gdamore 
    357  1.1  gdamore 	/*
    358  1.1  gdamore 	 * Everything related to console initialization is done
    359  1.1  gdamore 	 * in mach_init().
    360  1.1  gdamore 	 */
    361  1.4  gdamore 	ar531x_consinit();
    362  1.1  gdamore }
    363  1.1  gdamore 
    364  1.1  gdamore void
    365  1.1  gdamore cpu_startup(void)
    366  1.1  gdamore {
    367  1.1  gdamore 	char pbuf[9];
    368  1.1  gdamore 	vaddr_t minaddr, maxaddr;
    369  1.1  gdamore #ifdef DEBUG
    370  1.1  gdamore 	extern int pmapdebug;		/* XXX */
    371  1.1  gdamore 	int opmapdebug = pmapdebug;
    372  1.1  gdamore 
    373  1.1  gdamore 	pmapdebug = 0;		/* Shut up pmap debug during bootstrap */
    374  1.1  gdamore #endif
    375  1.1  gdamore 
    376  1.1  gdamore 	/*
    377  1.1  gdamore 	 * Good {morning,afternoon,evening,night}.
    378  1.1  gdamore 	 */
    379  1.1  gdamore 	printf("%s%s", copyright, version);
    380  1.1  gdamore 	printf("%s\n", cpu_model);
    381  1.1  gdamore 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    382  1.1  gdamore 	printf("total memory = %s\n", pbuf);
    383  1.1  gdamore 
    384  1.1  gdamore 	minaddr = 0;
    385  1.1  gdamore 	/*
    386  1.1  gdamore 	 * Allocate a submap for exec arguments.  This map effectively
    387  1.1  gdamore 	 * limits the number of processes exec'ing at any time.
    388  1.1  gdamore 	 */
    389  1.1  gdamore 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    390  1.1  gdamore 	    16 * NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    391  1.1  gdamore 
    392  1.1  gdamore 	/*
    393  1.1  gdamore 	 * Allocate a submap for physio
    394  1.1  gdamore 	 */
    395  1.1  gdamore 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    396  1.1  gdamore 	    VM_PHYS_SIZE, 0, FALSE, NULL);
    397  1.1  gdamore 
    398  1.1  gdamore 	/*
    399  1.1  gdamore 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    400  1.1  gdamore 	 * are allocated via the pool allocator, and we use KSEG to
    401  1.1  gdamore 	 * map those pages.
    402  1.1  gdamore 	 */
    403  1.1  gdamore 
    404  1.1  gdamore #ifdef DEBUG
    405  1.1  gdamore 	pmapdebug = opmapdebug;
    406  1.1  gdamore #endif
    407  1.1  gdamore 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    408  1.1  gdamore 	printf("avail memory = %s\n", pbuf);
    409  1.1  gdamore }
    410  1.1  gdamore 
    411  1.1  gdamore void
    412  1.1  gdamore cpu_reboot(int howto, char *bootstr)
    413  1.1  gdamore {
    414  1.1  gdamore 	static int waittime = -1;
    415  1.1  gdamore 
    416  1.1  gdamore 	/* Take a snapshot before clobbering any registers. */
    417  1.1  gdamore 	if (curproc)
    418  1.1  gdamore 		savectx((struct user *)curpcb);
    419  1.1  gdamore 
    420  1.1  gdamore 	/* If "always halt" was specified as a boot flag, obey. */
    421  1.1  gdamore 	if (boothowto & RB_HALT)
    422  1.1  gdamore 		howto |= RB_HALT;
    423  1.1  gdamore 
    424  1.1  gdamore 	boothowto = howto;
    425  1.1  gdamore 
    426  1.1  gdamore 	/* If system is cold, just halt. */
    427  1.1  gdamore 	if (cold) {
    428  1.1  gdamore 		boothowto |= RB_HALT;
    429  1.1  gdamore 		goto haltsys;
    430  1.1  gdamore 	}
    431  1.1  gdamore 
    432  1.1  gdamore 	if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) {
    433  1.1  gdamore 		waittime = 0;
    434  1.1  gdamore 
    435  1.1  gdamore 		/*
    436  1.1  gdamore 		 * Synchronize the disks....
    437  1.1  gdamore 		 */
    438  1.1  gdamore 		vfs_shutdown();
    439  1.1  gdamore 
    440  1.1  gdamore 		/*
    441  1.1  gdamore 		 * If we've been adjusting the clock, the todr
    442  1.1  gdamore 		 * will be out of synch; adjust it now.
    443  1.1  gdamore 		 */
    444  1.1  gdamore 		resettodr();
    445  1.1  gdamore 	}
    446  1.1  gdamore 
    447  1.1  gdamore 	/* Disable interrupts. */
    448  1.1  gdamore 	splhigh();
    449  1.1  gdamore 
    450  1.1  gdamore 	if (boothowto & RB_DUMP)
    451  1.1  gdamore 		dumpsys();
    452  1.1  gdamore 
    453  1.1  gdamore  haltsys:
    454  1.1  gdamore 	/* Run any shutdown hooks. */
    455  1.1  gdamore 	doshutdownhooks();
    456  1.1  gdamore 
    457  1.1  gdamore #if 0
    458  1.1  gdamore 	if ((boothowto & RB_POWERDOWN) == RB_POWERDOWN)
    459  1.1  gdamore 		if (board && board->ab_poweroff)
    460  1.1  gdamore 			board->ab_poweroff();
    461  1.1  gdamore #endif
    462  1.1  gdamore 
    463  1.1  gdamore 	/*
    464  1.1  gdamore 	 * Firmware may autoboot (depending on settings), and we cannot pass
    465  1.1  gdamore 	 * flags to it (at least I haven't figured out how to yet), so
    466  1.1  gdamore 	 * we "pseudo-halt" now.
    467  1.1  gdamore 	 */
    468  1.1  gdamore 	if (boothowto & RB_HALT) {
    469  1.1  gdamore 		printf("\n");
    470  1.1  gdamore 		printf("The operating system has halted.\n");
    471  1.1  gdamore 		printf("Please press any key to reboot.\n\n");
    472  1.1  gdamore 		cnpollc(1);	/* For proper keyboard command handling */
    473  1.1  gdamore 		cngetc();
    474  1.1  gdamore 		cnpollc(0);
    475  1.1  gdamore 	}
    476  1.1  gdamore 
    477  1.1  gdamore 	printf("reseting board...\n\n");
    478  1.1  gdamore 	mips_icache_sync_all();
    479  1.1  gdamore 	mips_dcache_wbinv_all();
    480  1.1  gdamore 	__asm volatile("jr	%0" :: "r"(MIPS_RESET_EXC_VEC));
    481  1.1  gdamore 	printf("Oops, back from reset\n\nSpinning...");
    482  1.1  gdamore 	for (;;)
    483  1.1  gdamore 		/* spin forever */ ;	/* XXX */
    484  1.1  gdamore 	/*NOTREACHED*/
    485  1.1  gdamore }
    486