Home | History | Annotate | Line # | Download | only in sun3x
machdep.c revision 1.96
      1  1.96    atatat /*	$NetBSD: machdep.c,v 1.96 2004/03/24 15:34:51 atatat Exp $	*/
      2   1.1       gwr 
      3   1.1       gwr /*
      4   1.1       gwr  * Copyright (c) 1982, 1986, 1990, 1993
      5   1.1       gwr  *	The Regents of the University of California.  All rights reserved.
      6   1.1       gwr  *
      7   1.1       gwr  * This code is derived from software contributed to Berkeley by
      8   1.1       gwr  * the Systems Programming Group of the University of Utah Computer
      9   1.1       gwr  * Science Department.
     10   1.1       gwr  *
     11   1.1       gwr  * Redistribution and use in source and binary forms, with or without
     12   1.1       gwr  * modification, are permitted provided that the following conditions
     13   1.1       gwr  * are met:
     14   1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     15   1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     16   1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     18   1.1       gwr  *    documentation and/or other materials provided with the distribution.
     19  1.91       agc  * 3. Neither the name of the University nor the names of its contributors
     20  1.91       agc  *    may be used to endorse or promote products derived from this software
     21  1.91       agc  *    without specific prior written permission.
     22  1.91       agc  *
     23  1.91       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.91       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.91       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.91       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.91       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.91       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.91       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.91       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.91       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.91       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.91       agc  * SUCH DAMAGE.
     34  1.91       agc  *
     35  1.91       agc  *	from: Utah Hdr: machdep.c 1.74 92/12/20
     36  1.91       agc  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
     37  1.91       agc  */
     38  1.91       agc /*
     39  1.91       agc  * Copyright (c) 1988 University of Utah.
     40  1.91       agc  *
     41  1.91       agc  * This code is derived from software contributed to Berkeley by
     42  1.91       agc  * the Systems Programming Group of the University of Utah Computer
     43  1.91       agc  * Science Department.
     44  1.91       agc  *
     45  1.91       agc  * Redistribution and use in source and binary forms, with or without
     46  1.91       agc  * modification, are permitted provided that the following conditions
     47  1.91       agc  * are met:
     48  1.91       agc  * 1. Redistributions of source code must retain the above copyright
     49  1.91       agc  *    notice, this list of conditions and the following disclaimer.
     50  1.91       agc  * 2. Redistributions in binary form must reproduce the above copyright
     51  1.91       agc  *    notice, this list of conditions and the following disclaimer in the
     52  1.91       agc  *    documentation and/or other materials provided with the distribution.
     53   1.1       gwr  * 3. All advertising materials mentioning features or use of this software
     54   1.1       gwr  *    must display the following acknowledgement:
     55   1.1       gwr  *	This product includes software developed by the University of
     56   1.1       gwr  *	California, Berkeley and its contributors.
     57   1.1       gwr  * 4. Neither the name of the University nor the names of its contributors
     58   1.1       gwr  *    may be used to endorse or promote products derived from this software
     59   1.1       gwr  *    without specific prior written permission.
     60   1.1       gwr  *
     61   1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62   1.1       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63   1.1       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64   1.1       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65   1.1       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66   1.1       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67   1.1       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68   1.1       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69   1.1       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70   1.1       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71   1.1       gwr  * SUCH DAMAGE.
     72   1.1       gwr  *
     73   1.1       gwr  *	from: Utah Hdr: machdep.c 1.74 92/12/20
     74   1.1       gwr  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
     75   1.1       gwr  */
     76  1.90     lukem 
     77  1.90     lukem #include <sys/cdefs.h>
     78  1.96    atatat __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.96 2004/03/24 15:34:51 atatat Exp $");
     79   1.1       gwr 
     80  1.35  jonathan #include "opt_ddb.h"
     81  1.69     lukem #include "opt_kgdb.h"
     82  1.34       gwr 
     83   1.1       gwr #include <sys/param.h>
     84   1.1       gwr #include <sys/systm.h>
     85   1.1       gwr #include <sys/kernel.h>
     86   1.1       gwr #include <sys/proc.h>
     87   1.1       gwr #include <sys/buf.h>
     88   1.1       gwr #include <sys/reboot.h>
     89   1.1       gwr #include <sys/conf.h>
     90   1.1       gwr #include <sys/file.h>
     91  1.37    kleink #include <sys/device.h>
     92   1.1       gwr #include <sys/malloc.h>
     93   1.1       gwr #include <sys/mbuf.h>
     94   1.1       gwr #include <sys/msgbuf.h>
     95   1.1       gwr #include <sys/ioctl.h>
     96   1.1       gwr #include <sys/tty.h>
     97   1.1       gwr #include <sys/mount.h>
     98   1.1       gwr #include <sys/user.h>
     99   1.1       gwr #include <sys/exec.h>
    100   1.1       gwr #include <sys/core.h>
    101   1.1       gwr #include <sys/kcore.h>
    102   1.1       gwr #include <sys/vnode.h>
    103  1.85   thorpej #include <sys/sa.h>
    104   1.1       gwr #include <sys/syscallargs.h>
    105  1.87     ragge #include <sys/ksyms.h>
    106   1.8       gwr #ifdef	KGDB
    107   1.8       gwr #include <sys/kgdb.h>
    108   1.8       gwr #endif
    109  1.26   hannken 
    110  1.42       mrg #include <uvm/uvm_extern.h>
    111  1.34       gwr 
    112  1.26   hannken #include <sys/sysctl.h>
    113   1.1       gwr 
    114   1.1       gwr #include <dev/cons.h>
    115   1.1       gwr 
    116   1.1       gwr #include <machine/cpu.h>
    117  1.29       gwr #include <machine/dvma.h>
    118  1.29       gwr #include <machine/idprom.h>
    119  1.29       gwr #include <machine/kcore.h>
    120   1.1       gwr #include <machine/reg.h>
    121   1.1       gwr #include <machine/psl.h>
    122   1.1       gwr #include <machine/pte.h>
    123  1.29       gwr 
    124  1.41    kleink #if defined(DDB)
    125   1.1       gwr #include <machine/db_machdep.h>
    126  1.33       gwr #include <ddb/db_sym.h>
    127  1.32        tv #include <ddb/db_extern.h>
    128  1.41    kleink #endif
    129   1.1       gwr 
    130  1.29       gwr #include <sun3/sun3/machdep.h>
    131   1.1       gwr 
    132  1.87     ragge #include "ksyms.h"
    133  1.87     ragge 
    134   1.1       gwr /* Defined in locore.s */
    135   1.1       gwr extern char kernel_text[];
    136   1.1       gwr /* Defined by the linker */
    137   1.1       gwr extern char etext[];
    138  1.56   thorpej 
    139  1.56   thorpej /* Our exported CPU info; we can have only one. */
    140  1.56   thorpej struct cpu_info cpu_info_store;
    141   1.1       gwr 
    142  1.70       chs struct vm_map *exec_map = NULL;
    143  1.70       chs struct vm_map *mb_map = NULL;
    144  1.70       chs struct vm_map *phys_map = NULL;
    145  1.34       gwr 
    146   1.1       gwr int	physmem;
    147   1.9       gwr int	fputype;
    148  1.22       leo caddr_t	msgbufaddr;
    149   1.1       gwr 
    150  1.29       gwr /* Virtual page frame for /dev/mem (see mem.c) */
    151  1.73   tsutsui vaddr_t vmmap;
    152  1.79     lukem 
    153  1.79     lukem union sun3sir sun3sir;
    154   1.1       gwr 
    155   1.1       gwr /*
    156   1.1       gwr  * safepri is a safe priority for sleep to set for a spin-wait
    157   1.1       gwr  * during autoconfiguration or after a panic.
    158   1.1       gwr  */
    159   1.1       gwr int	safepri = PSL_LOWIPL;
    160   1.1       gwr 
    161  1.29       gwr u_char cpu_machine_id = 0;
    162  1.15       gwr char *cpu_string = NULL;
    163  1.15       gwr int cpu_has_vme = 0;
    164  1.15       gwr int has_iocache = 0;
    165  1.15       gwr 
    166  1.66       chs vaddr_t dumppage;
    167  1.66       chs 
    168   1.1       gwr static void identifycpu __P((void));
    169   1.1       gwr static void initcpu __P((void));
    170   1.1       gwr 
    171   1.1       gwr /*
    172   1.1       gwr  * Console initialization: called early on from main,
    173  1.15       gwr  * before vm init or cpu_startup.  This system is able
    174  1.29       gwr  * to use the console for output immediately (via PROM)
    175  1.29       gwr  * but can not use it for input until after this point.
    176   1.1       gwr  */
    177   1.8       gwr void
    178   1.8       gwr consinit()
    179   1.1       gwr {
    180  1.29       gwr 
    181  1.29       gwr 	/*
    182  1.29       gwr 	 * Switch from the PROM console (output only)
    183  1.29       gwr 	 * to our own console driver.
    184  1.29       gwr 	 */
    185  1.29       gwr 	cninit();
    186   1.1       gwr 
    187  1.87     ragge #if NKSYMS || defined(DDB) || defined(LKM)
    188  1.32        tv 	{
    189  1.63       chs 		extern int nsym;
    190  1.63       chs 		extern char *ssym, *esym;
    191  1.32        tv 
    192  1.87     ragge 		ksyms_init(nsym, ssym, esym);
    193  1.32        tv 	}
    194  1.72    simonb #endif	/* DDB */
    195  1.31       gwr 
    196  1.31       gwr 	/*
    197  1.31       gwr 	 * Now that the console can do input as well as
    198  1.31       gwr 	 * output, consider stopping for a debugger.
    199  1.31       gwr 	 */
    200  1.31       gwr 	if (boothowto & RB_KDB) {
    201  1.31       gwr #ifdef KGDB
    202  1.31       gwr 		/* XXX - Ask on console for kgdb_dev? */
    203  1.31       gwr 		/* Note: this will just return if kgdb_dev==NODEV */
    204  1.31       gwr 		kgdb_connect(1);
    205  1.31       gwr #else	/* KGDB */
    206  1.31       gwr 		/* Either DDB or no debugger (just PROM). */
    207   1.1       gwr 		Debugger();
    208  1.31       gwr #endif	/* KGDB */
    209  1.31       gwr 	}
    210   1.1       gwr }
    211   1.1       gwr 
    212   1.1       gwr /*
    213   1.1       gwr  * cpu_startup: allocate memory for variable-sized tables,
    214  1.95       wiz  * initialize CPU, and do autoconfiguration.
    215   1.1       gwr  *
    216   1.1       gwr  * This is called early in init_main.c:main(), after the
    217   1.1       gwr  * kernel memory allocator is ready for use, but before
    218   1.1       gwr  * the creation of processes 1,2, and mountroot, etc.
    219   1.1       gwr  */
    220   1.1       gwr void
    221   1.1       gwr cpu_startup()
    222   1.1       gwr {
    223   1.1       gwr 	caddr_t v;
    224  1.73   tsutsui 	vaddr_t minaddr, maxaddr;
    225  1.50     lukem 	char pbuf[9];
    226   1.1       gwr 
    227  1.85   thorpej 	if (fputype != FPU_NONE)
    228  1.85   thorpej 		m68k_make_fpu_idle_frame();
    229  1.85   thorpej 
    230   1.1       gwr 	/*
    231   1.1       gwr 	 * Initialize message buffer (for kernel printf).
    232   1.1       gwr 	 * This is put in physical page zero so it will
    233   1.1       gwr 	 * always be in the same place after a reboot.
    234   1.1       gwr 	 * Its mapping was prepared in pmap_bootstrap().
    235   1.1       gwr 	 * Also, offset some to avoid PROM scribbles.
    236   1.1       gwr 	 */
    237   1.1       gwr 	v = (caddr_t) KERNBASE;
    238  1.23       gwr 	msgbufaddr = (caddr_t)(v + MSGBUFOFF);
    239  1.23       gwr 	initmsgbuf(msgbufaddr, MSGBUFSIZE);
    240   1.1       gwr 
    241   1.1       gwr 	/*
    242   1.1       gwr 	 * Good {morning,afternoon,evening,night}.
    243   1.1       gwr 	 */
    244   1.1       gwr 	printf(version);
    245   1.1       gwr 	identifycpu();
    246   1.1       gwr 	initfpu();	/* also prints FPU type */
    247   1.1       gwr 
    248  1.50     lukem 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    249  1.50     lukem 	printf("total memory = %s\n", pbuf);
    250   1.1       gwr 
    251   1.1       gwr 	/*
    252  1.66       chs 	 * Get scratch page for dumpsys().
    253  1.66       chs 	 */
    254  1.86   thorpej 	if ((dumppage = uvm_km_alloc(kernel_map, PAGE_SIZE)) == 0)
    255  1.66       chs 		panic("startup: alloc dumppage");
    256  1.66       chs 
    257  1.94        pk 	minaddr = 0;
    258   1.1       gwr 	/*
    259   1.1       gwr 	 * Allocate a submap for exec arguments.  This map effectively
    260   1.1       gwr 	 * limits the number of processes exec'ing at any time.
    261   1.1       gwr 	 */
    262  1.34       gwr 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    263  1.51   thorpej 				   16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    264   1.1       gwr 
    265   1.1       gwr 	/*
    266  1.84       chs 	 * Allocate a submap for physio
    267   1.1       gwr 	 */
    268  1.84       chs 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    269  1.84       chs 				   VM_PHYS_SIZE, 0, FALSE, NULL);
    270   1.1       gwr 
    271   1.1       gwr 	/*
    272  1.12   thorpej 	 * Finally, allocate mbuf cluster submap.
    273   1.1       gwr 	 */
    274  1.39   thorpej 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    275  1.51   thorpej 				 nmbclusters * mclbytes, VM_MAP_INTRSAFE,
    276  1.51   thorpej 				 FALSE, NULL);
    277   1.1       gwr 
    278  1.50     lukem 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    279  1.50     lukem 	printf("avail memory = %s\n", pbuf);
    280   1.1       gwr 
    281   1.1       gwr 	/*
    282   1.1       gwr 	 * Allocate a virtual page (for use by /dev/mem)
    283   1.1       gwr 	 * This page is handed to pmap_enter() therefore
    284   1.1       gwr 	 * it has to be in the normal kernel VA range.
    285   1.1       gwr 	 */
    286  1.86   thorpej 	vmmap = uvm_km_valloc_wait(kernel_map, PAGE_SIZE);
    287   1.1       gwr 
    288   1.1       gwr 	/*
    289   1.1       gwr 	 * Create the DVMA maps.
    290   1.1       gwr 	 */
    291   1.1       gwr 	dvma_init();
    292   1.1       gwr 
    293   1.1       gwr 	/*
    294   1.1       gwr 	 * Set up CPU-specific registers, cache, etc.
    295   1.1       gwr 	 */
    296   1.1       gwr 	initcpu();
    297   1.1       gwr }
    298   1.1       gwr 
    299   1.1       gwr /*
    300   1.1       gwr  * Set registers on exec.
    301   1.1       gwr  */
    302   1.1       gwr void
    303  1.85   thorpej setregs(l, pack, stack)
    304  1.85   thorpej 	struct lwp *l;
    305   1.1       gwr 	struct exec_package *pack;
    306   1.1       gwr 	u_long stack;
    307   1.1       gwr {
    308  1.85   thorpej 	struct trapframe *tf = (struct trapframe *)l->l_md.md_regs;
    309   1.1       gwr 
    310  1.21   mycroft 	tf->tf_sr = PSL_USERSET;
    311   1.5       gwr 	tf->tf_pc = pack->ep_entry & ~1;
    312  1.20   mycroft 	tf->tf_regs[D0] = 0;
    313  1.20   mycroft 	tf->tf_regs[D1] = 0;
    314  1.20   mycroft 	tf->tf_regs[D2] = 0;
    315  1.20   mycroft 	tf->tf_regs[D3] = 0;
    316  1.20   mycroft 	tf->tf_regs[D4] = 0;
    317  1.20   mycroft 	tf->tf_regs[D5] = 0;
    318  1.20   mycroft 	tf->tf_regs[D6] = 0;
    319  1.20   mycroft 	tf->tf_regs[D7] = 0;
    320  1.20   mycroft 	tf->tf_regs[A0] = 0;
    321  1.20   mycroft 	tf->tf_regs[A1] = 0;
    322  1.85   thorpej 	tf->tf_regs[A2] = (int)l->l_proc->p_psstr;
    323  1.20   mycroft 	tf->tf_regs[A3] = 0;
    324  1.20   mycroft 	tf->tf_regs[A4] = 0;
    325  1.20   mycroft 	tf->tf_regs[A5] = 0;
    326  1.20   mycroft 	tf->tf_regs[A6] = 0;
    327   1.5       gwr 	tf->tf_regs[SP] = stack;
    328   1.1       gwr 
    329   1.1       gwr 	/* restore a null state frame */
    330  1.85   thorpej 	l->l_addr->u_pcb.pcb_fpregs.fpf_null = 0;
    331  1.19   mycroft 	if (fputype)
    332  1.85   thorpej 		m68881_restore(&l->l_addr->u_pcb.pcb_fpregs);
    333  1.19   mycroft 
    334  1.85   thorpej 	l->l_md.md_flags = 0;
    335   1.1       gwr }
    336   1.1       gwr 
    337   1.1       gwr /*
    338   1.1       gwr  * Info for CTL_HW
    339   1.1       gwr  */
    340  1.46       gwr char	machine[16] = MACHINE;		/* from <machine/param.h> */
    341  1.46       gwr char	kernel_arch[16] = "sun3x";	/* XXX needs a sysctl node */
    342   1.1       gwr char	cpu_model[120];
    343  1.15       gwr 
    344  1.15       gwr /*
    345  1.15       gwr  * XXX - Should empirically estimate the divisor...
    346  1.15       gwr  * Note that the value of delay_divisor is roughly
    347  1.15       gwr  * 2048 / cpuclock	(where cpuclock is in MHz).
    348  1.15       gwr  */
    349  1.16       gwr int delay_divisor = 62;		/* assume the fastest (33 MHz) */
    350   1.1       gwr 
    351   1.1       gwr void
    352   1.1       gwr identifycpu()
    353   1.1       gwr {
    354  1.29       gwr 	u_char machtype;
    355   1.1       gwr 
    356  1.15       gwr 	machtype = identity_prom.idp_machtype;
    357  1.29       gwr 	if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
    358  1.29       gwr 		printf("Bad IDPROM arch!\n");
    359  1.15       gwr 		sunmon_abort();
    360  1.15       gwr 	}
    361  1.15       gwr 
    362  1.29       gwr 	cpu_machine_id = machtype;
    363  1.15       gwr 	switch (cpu_machine_id) {
    364  1.15       gwr 
    365  1.15       gwr 	case SUN3X_MACH_80:
    366  1.15       gwr 		cpu_string = "80";  	/* Hydra */
    367  1.16       gwr 		delay_divisor = 102;	/* 20 MHz */
    368  1.15       gwr 		cpu_has_vme = FALSE;
    369  1.15       gwr 		break;
    370  1.15       gwr 
    371  1.15       gwr 	case SUN3X_MACH_470:
    372  1.15       gwr 		cpu_string = "470"; 	/* Pegasus */
    373  1.15       gwr 		delay_divisor = 62; 	/* 33 MHz */
    374  1.15       gwr 		cpu_has_vme = TRUE;
    375  1.15       gwr 		break;
    376  1.15       gwr 
    377  1.15       gwr 	default:
    378  1.15       gwr 		printf("unknown sun3x model\n");
    379  1.15       gwr 		sunmon_abort();
    380  1.15       gwr 	}
    381  1.15       gwr 
    382  1.15       gwr 	/* Other stuff? (VAC, mc6888x version, etc.) */
    383  1.46       gwr 	/* Note: miniroot cares about the kernel_arch part. */
    384  1.46       gwr 	sprintf(cpu_model, "%s %s", kernel_arch, cpu_string);
    385   1.1       gwr 
    386  1.29       gwr 	printf("Model: %s\n", cpu_model);
    387   1.1       gwr }
    388   1.1       gwr 
    389   1.1       gwr /*
    390   1.1       gwr  * machine dependent system variables.
    391   1.1       gwr  */
    392  1.93    atatat #if 0   /* XXX - Not yet... */
    393  1.93    atatat static int
    394  1.93    atatat sysctl_machdep_root_device(SYSCTLFN_ARGS)
    395   1.1       gwr {
    396  1.93    atatat 	struct sysctlnode node = *rnode;
    397   1.1       gwr 
    398  1.93    atatat 	node.sysctl_data = some permutation on root_device;
    399  1.93    atatat 	node.sysctl_size = strlen(root_device) + 1;
    400  1.93    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    401  1.93    atatat }
    402   1.1       gwr 
    403  1.93    atatat static int
    404  1.93    atatat sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
    405  1.93    atatat {
    406  1.93    atatat 	struct sysctlnode node = *rnode;
    407   1.1       gwr 
    408  1.93    atatat 	node.sysctl_data = some permutation on booted_kernel;
    409  1.93    atatat 	node.sysctl_size = strlen(booted_kernel) + 1;
    410  1.93    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    411  1.93    atatat }
    412   1.1       gwr #endif
    413   1.1       gwr 
    414  1.93    atatat SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
    415  1.93    atatat {
    416  1.93    atatat 
    417  1.96    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    418  1.96    atatat 		       CTLFLAG_PERMANENT,
    419  1.93    atatat 		       CTLTYPE_NODE, "machdep", NULL,
    420  1.93    atatat 		       NULL, 0, NULL, 0,
    421  1.93    atatat 		       CTL_MACHDEP, CTL_EOL);
    422  1.93    atatat 
    423  1.96    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    424  1.96    atatat 		       CTLFLAG_PERMANENT,
    425  1.93    atatat 		       CTLTYPE_STRUCT, "console_device", NULL,
    426  1.93    atatat 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    427  1.93    atatat 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
    428  1.93    atatat #if 0 /* XXX - Not yet... */
    429  1.96    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    430  1.96    atatat 		       CTLFLAG_PERMANENT,
    431  1.93    atatat 		       CTLTYPE_STRING, "root_device", NULL,
    432  1.93    atatat 		       sysctl_machdep_root_device, 0, NULL, 0,
    433  1.93    atatat 		       CTL_MACHDEP, CPU_ROOT_DEVICE, CTL_EOL);
    434  1.96    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    435  1.96    atatat 		       CTLFLAG_PERMANENT,
    436  1.93    atatat 		       CTLTYPE_STRING, "booted_kernel", NULL,
    437  1.93    atatat 		       sysctl_machdep_booted_kernel, 0, NULL, 0,
    438  1.93    atatat 		       CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
    439  1.93    atatat #endif
    440   1.1       gwr }
    441   1.1       gwr 
    442   1.7       gwr /* See: sig_machdep.c */
    443   1.1       gwr 
    444   1.1       gwr /*
    445   1.1       gwr  * Do a sync in preparation for a reboot.
    446   1.1       gwr  * XXX - This could probably be common code.
    447   1.1       gwr  * XXX - And now, most of it is in vfs_shutdown()
    448   1.1       gwr  * XXX - Put waittime checks in there too?
    449   1.1       gwr  */
    450   1.1       gwr int waittime = -1;	/* XXX - Who else looks at this? -gwr */
    451   1.1       gwr static void
    452   1.1       gwr reboot_sync __P((void))
    453   1.1       gwr {
    454   1.1       gwr 
    455   1.1       gwr 	/* Check waittime here to localize its use to this function. */
    456   1.1       gwr 	if (waittime >= 0)
    457   1.1       gwr 		return;
    458   1.1       gwr 	waittime = 0;
    459   1.1       gwr 	vfs_shutdown();
    460   1.1       gwr }
    461   1.1       gwr 
    462   1.1       gwr /*
    463   1.1       gwr  * Common part of the BSD and SunOS reboot system calls.
    464   1.1       gwr  */
    465   1.1       gwr __dead void
    466  1.11       gwr cpu_reboot(howto, user_boot_string)
    467   1.1       gwr 	int howto;
    468   1.1       gwr 	char *user_boot_string;
    469   1.1       gwr {
    470   1.2       gwr 	/* Note: this string MUST be static! */
    471   1.2       gwr 	static char bootstr[128];
    472   1.2       gwr 	char *p;
    473   1.1       gwr 
    474   1.1       gwr 	/* If system is cold, just halt. (early panic?) */
    475   1.1       gwr 	if (cold)
    476   1.1       gwr 		goto haltsys;
    477   1.1       gwr 
    478  1.24       gwr 	/* Un-blank the screen if appropriate. */
    479  1.24       gwr 	cnpollc(1);
    480  1.24       gwr 
    481   1.1       gwr 	if ((howto & RB_NOSYNC) == 0) {
    482   1.1       gwr 		reboot_sync();
    483   1.1       gwr 		/*
    484   1.1       gwr 		 * If we've been adjusting the clock, the todr
    485   1.1       gwr 		 * will be out of synch; adjust it now.
    486   1.1       gwr 		 *
    487   1.1       gwr 		 * XXX - However, if the kernel has been sitting in ddb,
    488   1.1       gwr 		 * the time will be way off, so don't set the HW clock!
    489   1.1       gwr 		 * XXX - Should do sanity check against HW clock. -gwr
    490   1.1       gwr 		 */
    491   1.1       gwr 		/* resettodr(); */
    492   1.1       gwr 	}
    493   1.1       gwr 
    494   1.1       gwr 	/* Disable interrupts. */
    495   1.1       gwr 	splhigh();
    496   1.1       gwr 
    497   1.1       gwr 	/* Write out a crash dump if asked. */
    498   1.1       gwr 	if (howto & RB_DUMP)
    499   1.1       gwr 		dumpsys();
    500   1.1       gwr 
    501   1.1       gwr 	/* run any shutdown hooks */
    502   1.1       gwr 	doshutdownhooks();
    503   1.1       gwr 
    504   1.1       gwr 	if (howto & RB_HALT) {
    505   1.1       gwr 	haltsys:
    506  1.63       chs 		printf("halted.\n");
    507  1.61   tsutsui 		sunmon_halt();
    508   1.1       gwr 	}
    509   1.1       gwr 
    510   1.1       gwr 	/*
    511   1.1       gwr 	 * Automatic reboot.
    512   1.1       gwr 	 */
    513   1.2       gwr 	if (user_boot_string)
    514   1.2       gwr 		strncpy(bootstr, user_boot_string, sizeof(bootstr));
    515   1.2       gwr 	else {
    516   1.1       gwr 		/*
    517   1.1       gwr 		 * Build our own boot string with an empty
    518   1.1       gwr 		 * boot device/file and (maybe) some flags.
    519   1.1       gwr 		 * The PROM will supply the device/file name.
    520   1.1       gwr 		 */
    521   1.2       gwr 		p = bootstr;
    522   1.2       gwr 		*p = '\0';
    523   1.1       gwr 		if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
    524   1.1       gwr 			/* Append the boot flags. */
    525   1.1       gwr 			*p++ = ' ';
    526   1.1       gwr 			*p++ = '-';
    527   1.1       gwr 			if (howto & RB_KDB)
    528   1.1       gwr 				*p++ = 'd';
    529   1.1       gwr 			if (howto & RB_ASKNAME)
    530   1.1       gwr 				*p++ = 'a';
    531   1.1       gwr 			if (howto & RB_SINGLE)
    532   1.1       gwr 				*p++ = 's';
    533   1.1       gwr 			*p = '\0';
    534   1.1       gwr 		}
    535   1.1       gwr 	}
    536  1.63       chs 	printf("rebooting...\n");
    537   1.3       gwr 	sunmon_reboot(bootstr);
    538   1.1       gwr 	for (;;) ;
    539   1.1       gwr 	/*NOTREACHED*/
    540   1.1       gwr }
    541   1.1       gwr 
    542   1.1       gwr /*
    543   1.1       gwr  * These variables are needed by /sbin/savecore
    544   1.1       gwr  */
    545  1.77   tsutsui u_int32_t dumpmag = 0x8fca0101;	/* magic number */
    546   1.1       gwr int 	dumpsize = 0;		/* pages */
    547   1.1       gwr long	dumplo = 0; 		/* blocks */
    548   1.1       gwr 
    549  1.71   tsutsui #define DUMP_EXTRA	1	/* CPU-dependent extra pages */
    550  1.71   tsutsui 
    551   1.1       gwr /*
    552  1.11       gwr  * This is called by main to set dumplo, dumpsize.
    553  1.86   thorpej  * Dumps always skip the first PAGE_SIZE of disk space
    554   1.1       gwr  * in case there might be a disk label stored there.
    555   1.1       gwr  * If there is extra space, put dump at the end to
    556   1.1       gwr  * reduce the chance that swapping trashes it.
    557   1.1       gwr  */
    558   1.1       gwr void
    559  1.11       gwr cpu_dumpconf()
    560   1.1       gwr {
    561  1.81   gehenna 	const struct bdevsw *bdev;
    562  1.71   tsutsui 	int devblks;	/* size of dump device in blocks */
    563  1.71   tsutsui 	int dumpblks;	/* size of dump image in blocks */
    564   1.1       gwr 	int (*getsize)__P((dev_t));
    565   1.1       gwr 
    566   1.1       gwr 	if (dumpdev == NODEV)
    567   1.1       gwr 		return;
    568   1.1       gwr 
    569  1.81   gehenna 	bdev = bdevsw_lookup(dumpdev);
    570  1.81   gehenna 	if (bdev == NULL)
    571   1.1       gwr 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
    572  1.81   gehenna 	getsize = bdev->d_psize;
    573   1.1       gwr 	if (getsize == NULL)
    574   1.1       gwr 		return;
    575  1.71   tsutsui 	devblks = (*getsize)(dumpdev);
    576  1.71   tsutsui 	if (devblks <= ctod(1))
    577   1.1       gwr 		return;
    578  1.71   tsutsui 	devblks &= ~(ctod(1) - 1);
    579  1.71   tsutsui 
    580  1.71   tsutsui 	/*
    581  1.71   tsutsui 	 * Note: savecore expects dumpsize to be the
    582  1.71   tsutsui 	 * number of pages AFTER the dump header.
    583  1.71   tsutsui 	 */
    584  1.71   tsutsui 	dumpsize = physmem; 	/* pages */
    585   1.1       gwr 
    586   1.1       gwr 	/* Position dump image near end of space, page aligned. */
    587  1.71   tsutsui 	dumpblks = ctod(physmem + DUMP_EXTRA);
    588  1.71   tsutsui 	dumplo = devblks - dumpblks;
    589   1.1       gwr 
    590   1.1       gwr 	/* If it does not fit, truncate it by moving dumplo. */
    591   1.1       gwr 	/* Note: Must force signed comparison. */
    592   1.1       gwr 	if (dumplo < ((long)ctod(1))) {
    593   1.1       gwr 		dumplo = ctod(1);
    594  1.71   tsutsui 		dumpsize = dtoc(devblks - dumplo) - DUMP_EXTRA;
    595   1.1       gwr 	}
    596   1.1       gwr }
    597   1.1       gwr 
    598  1.13       gwr /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
    599   1.1       gwr struct pcb dumppcb;
    600   1.1       gwr 
    601   1.1       gwr /*
    602   1.1       gwr  * Write a crash dump.  The format while in swap is:
    603   1.1       gwr  *   kcore_seg_t cpu_hdr;
    604   1.1       gwr  *   cpu_kcore_hdr_t cpu_data;
    605  1.86   thorpej  *   padding (PAGE_SIZE-sizeof(kcore_seg_t))
    606  1.86   thorpej  *   pagemap (2*PAGE_SIZE)
    607   1.1       gwr  *   physical memory...
    608   1.1       gwr  */
    609   1.1       gwr void
    610   1.1       gwr dumpsys()
    611   1.1       gwr {
    612  1.81   gehenna 	const struct bdevsw *dsw;
    613  1.66       chs 	kcore_seg_t *kseg_p;
    614  1.10       gwr 	cpu_kcore_hdr_t *chdr_p;
    615  1.14   thorpej 	struct sun3x_kcore_hdr *sh;
    616  1.14   thorpej 	phys_ram_seg_t *crs_p;
    617   1.1       gwr 	char *vaddr;
    618  1.73   tsutsui 	paddr_t paddr;
    619  1.10       gwr 	int psize, todo, seg, segsz;
    620   1.1       gwr 	daddr_t blkno;
    621   1.1       gwr 	int error = 0;
    622   1.1       gwr 
    623   1.1       gwr 	if (dumpdev == NODEV)
    624   1.1       gwr 		return;
    625  1.81   gehenna 	dsw = bdevsw_lookup(dumpdev);
    626  1.81   gehenna 	if (dsw == NULL || dsw->d_psize == NULL)
    627  1.81   gehenna 		return;
    628   1.1       gwr 
    629   1.1       gwr 	/*
    630   1.1       gwr 	 * For dumps during autoconfiguration,
    631   1.1       gwr 	 * if dump device has already configured...
    632   1.1       gwr 	 */
    633   1.1       gwr 	if (dumpsize == 0)
    634  1.11       gwr 		cpu_dumpconf();
    635  1.28   mycroft 	if (dumplo <= 0) {
    636  1.28   mycroft 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    637  1.28   mycroft 		    minor(dumpdev));
    638   1.1       gwr 		return;
    639  1.28   mycroft 	}
    640   1.1       gwr 	savectx(&dumppcb);
    641   1.1       gwr 
    642   1.1       gwr 	psize = (*(dsw->d_psize))(dumpdev);
    643   1.1       gwr 	if (psize == -1) {
    644   1.1       gwr 		printf("dump area unavailable\n");
    645   1.1       gwr 		return;
    646   1.1       gwr 	}
    647   1.1       gwr 
    648  1.28   mycroft 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    649  1.28   mycroft 	    minor(dumpdev), dumplo);
    650   1.1       gwr 
    651   1.1       gwr 	/*
    652  1.71   tsutsui 	 * Prepare the dump header
    653   1.1       gwr 	 */
    654  1.71   tsutsui 	blkno = dumplo;
    655  1.71   tsutsui 	todo = dumpsize;	/* pages */
    656  1.71   tsutsui 	vaddr = (char *)dumppage;
    657  1.86   thorpej 	memset(vaddr, 0, PAGE_SIZE);
    658  1.25       gwr 
    659  1.25       gwr 	/* Set pointers to all three parts. */
    660  1.71   tsutsui 	kseg_p = (kcore_seg_t *)vaddr;
    661  1.66       chs 	chdr_p = (cpu_kcore_hdr_t *)(kseg_p + 1);
    662  1.14   thorpej 	sh = &chdr_p->un._sun3x;
    663  1.25       gwr 
    664  1.25       gwr 	/* Fill in kcore_seg_t part. */
    665  1.10       gwr 	CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    666  1.71   tsutsui 	kseg_p->c_size = (ctob(DUMP_EXTRA) - sizeof(*kseg_p));
    667  1.25       gwr 
    668  1.25       gwr 	/* Fill in cpu_kcore_hdr_t part. */
    669  1.46       gwr 	strncpy(chdr_p->name, kernel_arch, sizeof(chdr_p->name));
    670  1.86   thorpej 	chdr_p->page_size = PAGE_SIZE;
    671  1.25       gwr 	chdr_p->kernbase = KERNBASE;
    672  1.25       gwr 
    673  1.25       gwr 	/* Fill in the sun3x_kcore_hdr part. */
    674  1.25       gwr 	pmap_kcore_hdr(sh);
    675  1.10       gwr 
    676  1.71   tsutsui 	/* Write out the dump header. */
    677  1.86   thorpej 	error = (*dsw->d_dump)(dumpdev, blkno, vaddr, PAGE_SIZE);
    678  1.71   tsutsui 	if (error)
    679  1.71   tsutsui 		goto fail;
    680  1.86   thorpej 	blkno += btodb(PAGE_SIZE);
    681  1.71   tsutsui 
    682  1.10       gwr 	/*
    683  1.10       gwr 	 * Now dump physical memory.  Note that physical memory
    684  1.10       gwr 	 * might NOT be congiguous, so do it by segments.
    685  1.10       gwr 	 */
    686  1.10       gwr 
    687  1.66       chs 	vaddr = (char *)vmmap;	/* Borrow /dev/mem VA */
    688   1.1       gwr 
    689  1.14   thorpej 	for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
    690  1.14   thorpej 		crs_p = &sh->ram_segs[seg];
    691  1.10       gwr 		paddr = crs_p->start;
    692  1.10       gwr 		segsz = crs_p->size;
    693   1.1       gwr 
    694  1.10       gwr 		while (todo && (segsz > 0)) {
    695   1.1       gwr 
    696  1.10       gwr 			/* Print pages left after every 16. */
    697  1.10       gwr 			if ((todo & 0xf) == 0)
    698  1.10       gwr 				printf("\r%4d", todo);
    699  1.10       gwr 
    700  1.10       gwr 			/* Make a temporary mapping for the page. */
    701  1.76       chs 			pmap_kenter_pa(vmmap, paddr | PMAP_NC, VM_PROT_READ);
    702  1.75     chris 			pmap_update(pmap_kernel());
    703  1.86   thorpej 			error = (*dsw->d_dump)(dumpdev, blkno, vaddr,
    704  1.86   thorpej 					       PAGE_SIZE);
    705  1.86   thorpej 			pmap_kremove(vmmap, PAGE_SIZE);
    706  1.75     chris 			pmap_update(pmap_kernel());
    707  1.10       gwr 			if (error)
    708  1.10       gwr 				goto fail;
    709  1.86   thorpej 			paddr += PAGE_SIZE;
    710  1.86   thorpej 			segsz -= PAGE_SIZE;
    711  1.86   thorpej 			blkno += btodb(PAGE_SIZE);
    712  1.10       gwr 			todo--;
    713  1.10       gwr 		}
    714  1.10       gwr 	}
    715   1.1       gwr 	printf("\rdump succeeded\n");
    716   1.1       gwr 	return;
    717   1.1       gwr fail:
    718   1.1       gwr 	printf(" dump error=%d\n", error);
    719   1.1       gwr }
    720   1.1       gwr 
    721   1.1       gwr static void
    722   1.1       gwr initcpu()
    723   1.1       gwr {
    724   1.1       gwr 	/* XXX: Enable RAM parity/ECC checking? */
    725   1.1       gwr 	/* XXX: parityenable(); */
    726   1.1       gwr 
    727   1.1       gwr #ifdef	HAVECACHE
    728   1.1       gwr 	cache_enable();
    729   1.1       gwr #endif
    730   1.1       gwr }
    731   1.1       gwr 
    732   1.8       gwr /* straptrap() in trap.c */
    733   1.1       gwr 
    734   1.1       gwr /* from hp300: badaddr() */
    735  1.15       gwr /* peek_byte(), peek_word() moved to bus_subr.c */
    736   1.1       gwr 
    737   1.1       gwr /* XXX: parityenable() ? */
    738   1.7       gwr /* regdump() moved to regdump.c */
    739   1.1       gwr 
    740   1.1       gwr /*
    741   1.1       gwr  * cpu_exec_aout_makecmds():
    742  1.95       wiz  *	CPU-dependent a.out format hook for execve().
    743   1.1       gwr  *
    744   1.1       gwr  * Determine if the given exec package refers to something which we
    745   1.1       gwr  * understand and, if so, set up the vmcmds for it.
    746   1.1       gwr  */
    747   1.1       gwr int
    748  1.89      fvdl cpu_exec_aout_makecmds(p, epp)
    749  1.89      fvdl 	struct proc *p;
    750   1.1       gwr 	struct exec_package *epp;
    751   1.1       gwr {
    752  1.27        tv 	return ENOEXEC;
    753   1.1       gwr }
    754