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