Home | History | Annotate | Line # | Download | only in sun3x
machdep.c revision 1.40
      1  1.40    scottr /*	$NetBSD: machdep.c,v 1.40 1999/02/27 06:39:37 scottr 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.40    scottr #include "opt_bufcache.h"
     45  1.35  jonathan #include "opt_ddb.h"
     46  1.34       gwr #include "opt_uvm.h"
     47  1.36      tron #include "opt_sysv.h"
     48  1.34       gwr 
     49   1.1       gwr #include <sys/param.h>
     50   1.1       gwr #include <sys/systm.h>
     51   1.1       gwr #include <sys/kernel.h>
     52   1.1       gwr #include <sys/map.h>
     53   1.1       gwr #include <sys/proc.h>
     54   1.1       gwr #include <sys/buf.h>
     55   1.1       gwr #include <sys/reboot.h>
     56   1.1       gwr #include <sys/conf.h>
     57   1.1       gwr #include <sys/file.h>
     58   1.1       gwr #include <sys/clist.h>
     59   1.1       gwr #include <sys/callout.h>
     60  1.37    kleink #include <sys/device.h>
     61   1.1       gwr #include <sys/malloc.h>
     62   1.1       gwr #include <sys/mbuf.h>
     63   1.1       gwr #include <sys/msgbuf.h>
     64   1.1       gwr #include <sys/ioctl.h>
     65   1.1       gwr #include <sys/tty.h>
     66   1.1       gwr #include <sys/mount.h>
     67   1.1       gwr #include <sys/user.h>
     68   1.1       gwr #include <sys/exec.h>
     69   1.1       gwr #include <sys/core.h>
     70   1.1       gwr #include <sys/kcore.h>
     71   1.1       gwr #include <sys/vnode.h>
     72   1.1       gwr #include <sys/syscallargs.h>
     73   1.1       gwr #ifdef SYSVMSG
     74   1.1       gwr #include <sys/msg.h>
     75   1.1       gwr #endif
     76   1.1       gwr #ifdef SYSVSEM
     77   1.1       gwr #include <sys/sem.h>
     78   1.1       gwr #endif
     79   1.1       gwr #ifdef SYSVSHM
     80   1.1       gwr #include <sys/shm.h>
     81   1.1       gwr #endif
     82   1.8       gwr #ifdef	KGDB
     83   1.8       gwr #include <sys/kgdb.h>
     84   1.8       gwr #endif
     85   1.1       gwr 
     86   1.1       gwr #include <vm/vm.h>
     87   1.1       gwr #include <vm/vm_map.h>
     88   1.1       gwr #include <vm/vm_kern.h>
     89   1.1       gwr #include <vm/vm_page.h>
     90  1.26   hannken 
     91  1.34       gwr #if defined(UVM)
     92  1.34       gwr #include <uvm/uvm.h> /* XXX: not _extern ... need vm_map_create */
     93  1.34       gwr #endif
     94  1.34       gwr 
     95  1.26   hannken #include <sys/sysctl.h>
     96   1.1       gwr 
     97   1.1       gwr #include <dev/cons.h>
     98   1.1       gwr 
     99   1.1       gwr #include <machine/cpu.h>
    100  1.29       gwr #include <machine/dvma.h>
    101  1.29       gwr #include <machine/idprom.h>
    102  1.29       gwr #include <machine/kcore.h>
    103   1.1       gwr #include <machine/reg.h>
    104   1.1       gwr #include <machine/psl.h>
    105   1.1       gwr #include <machine/pte.h>
    106  1.29       gwr 
    107   1.1       gwr #include <machine/db_machdep.h>
    108  1.33       gwr #include <ddb/db_sym.h>
    109  1.32        tv #include <ddb/db_extern.h>
    110   1.1       gwr 
    111  1.29       gwr #include <sun3/sun3/machdep.h>
    112   1.1       gwr 
    113   1.1       gwr /* Defined in locore.s */
    114   1.1       gwr extern char kernel_text[];
    115   1.1       gwr /* Defined by the linker */
    116   1.1       gwr extern char etext[];
    117   1.1       gwr 
    118  1.34       gwr #if defined(UVM)
    119  1.34       gwr /* XXX - Gratuitous name changes... */
    120  1.34       gwr #define kmem_alloc uvm_km_alloc
    121  1.34       gwr vm_map_t exec_map = NULL;
    122  1.34       gwr vm_map_t mb_map = NULL;
    123  1.34       gwr vm_map_t phys_map = NULL;
    124  1.34       gwr #else
    125  1.34       gwr vm_map_t buffer_map;
    126  1.34       gwr #endif
    127  1.34       gwr 
    128   1.1       gwr int	physmem;
    129   1.9       gwr int	fputype;
    130  1.22       leo caddr_t	msgbufaddr;
    131   1.1       gwr 
    132  1.29       gwr /* Virtual page frame for /dev/mem (see mem.c) */
    133   1.1       gwr vm_offset_t vmmap;
    134   1.1       gwr 
    135   1.1       gwr /*
    136   1.1       gwr  * safepri is a safe priority for sleep to set for a spin-wait
    137   1.1       gwr  * during autoconfiguration or after a panic.
    138   1.1       gwr  */
    139   1.1       gwr int	safepri = PSL_LOWIPL;
    140   1.1       gwr 
    141   1.1       gwr /*
    142   1.1       gwr  * Declare these as initialized data so we can patch them.
    143   1.1       gwr  */
    144   1.1       gwr int	nswbuf = 0;
    145   1.1       gwr #ifdef	NBUF
    146   1.1       gwr int	nbuf = NBUF;
    147   1.1       gwr #else
    148   1.1       gwr int	nbuf = 0;
    149   1.1       gwr #endif
    150   1.1       gwr #ifdef	BUFPAGES
    151   1.1       gwr int	bufpages = BUFPAGES;
    152   1.1       gwr #else
    153   1.1       gwr int	bufpages = 0;
    154   1.1       gwr #endif
    155   1.1       gwr 
    156  1.29       gwr u_char cpu_machine_id = 0;
    157  1.15       gwr char *cpu_string = NULL;
    158  1.15       gwr int cpu_has_vme = 0;
    159  1.15       gwr int has_iocache = 0;
    160  1.15       gwr 
    161   1.1       gwr static void identifycpu __P((void));
    162   1.1       gwr static void initcpu __P((void));
    163   1.1       gwr 
    164   1.1       gwr /*
    165   1.1       gwr  * Console initialization: called early on from main,
    166  1.15       gwr  * before vm init or cpu_startup.  This system is able
    167  1.29       gwr  * to use the console for output immediately (via PROM)
    168  1.29       gwr  * but can not use it for input until after this point.
    169   1.1       gwr  */
    170   1.8       gwr void
    171   1.8       gwr consinit()
    172   1.1       gwr {
    173  1.29       gwr 
    174  1.29       gwr 	/*
    175  1.29       gwr 	 * Switch from the PROM console (output only)
    176  1.29       gwr 	 * to our own console driver.
    177  1.29       gwr 	 */
    178  1.29       gwr 	cninit();
    179   1.1       gwr 
    180   1.1       gwr #ifdef DDB
    181   1.1       gwr 	db_machine_init();
    182  1.32        tv 	{
    183  1.33       gwr 		extern int end[];
    184  1.33       gwr 		extern char *esym;
    185  1.32        tv 
    186  1.34       gwr 		/* symsize, symstart, symend */
    187  1.33       gwr 		ddb_init(end[0], end + 1, (int*)esym);
    188  1.32        tv 	}
    189  1.31       gwr #endif DDB
    190  1.31       gwr 
    191  1.31       gwr 	/*
    192  1.31       gwr 	 * Now that the console can do input as well as
    193  1.31       gwr 	 * output, consider stopping for a debugger.
    194  1.31       gwr 	 */
    195  1.31       gwr 	if (boothowto & RB_KDB) {
    196  1.31       gwr #ifdef KGDB
    197  1.31       gwr 		/* XXX - Ask on console for kgdb_dev? */
    198  1.31       gwr 		/* Note: this will just return if kgdb_dev==NODEV */
    199  1.31       gwr 		kgdb_connect(1);
    200  1.31       gwr #else	/* KGDB */
    201  1.31       gwr 		/* Either DDB or no debugger (just PROM). */
    202   1.1       gwr 		Debugger();
    203  1.31       gwr #endif	/* KGDB */
    204  1.31       gwr 	}
    205   1.1       gwr }
    206   1.1       gwr 
    207   1.1       gwr /*
    208   1.1       gwr  * allocsys() - Private routine used by cpu_startup() below.
    209   1.1       gwr  *
    210   1.1       gwr  * Allocate space for system data structures.  We are given
    211   1.1       gwr  * a starting virtual address and we return a final virtual
    212   1.1       gwr  * address; along the way we set each data structure pointer.
    213   1.1       gwr  *
    214   1.1       gwr  * We call allocsys() with 0 to find out how much space we want,
    215   1.1       gwr  * allocate that much and fill it with zeroes, and then call
    216   1.1       gwr  * allocsys() again with the correct base virtual address.
    217   1.1       gwr  */
    218   1.1       gwr #define	valloc(name, type, num) \
    219   1.1       gwr 	v = (caddr_t)(((name) = (type *)v) + (num))
    220   1.1       gwr static caddr_t allocsys __P((caddr_t));
    221   1.1       gwr static caddr_t
    222   1.1       gwr allocsys(v)
    223   1.1       gwr 	register caddr_t v;
    224   1.1       gwr {
    225   1.1       gwr 
    226   1.1       gwr #ifdef REAL_CLISTS
    227   1.1       gwr 	valloc(cfree, struct cblock, nclist);
    228   1.1       gwr #endif
    229   1.1       gwr 	valloc(callout, struct callout, ncallout);
    230   1.1       gwr #ifdef SYSVSHM
    231   1.1       gwr 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    232   1.1       gwr #endif
    233   1.1       gwr #ifdef SYSVSEM
    234   1.1       gwr 	valloc(sema, struct semid_ds, seminfo.semmni);
    235   1.1       gwr 	valloc(sem, struct sem, seminfo.semmns);
    236   1.1       gwr 	/* This is pretty disgusting! */
    237   1.1       gwr 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    238   1.1       gwr #endif
    239   1.1       gwr #ifdef SYSVMSG
    240   1.1       gwr 	valloc(msgpool, char, msginfo.msgmax);
    241   1.1       gwr 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    242   1.1       gwr 	valloc(msghdrs, struct msg, msginfo.msgtql);
    243   1.1       gwr 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    244   1.1       gwr #endif
    245   1.1       gwr 
    246   1.1       gwr 	/*
    247   1.1       gwr 	 * Determine how many buffers to allocate. We allocate
    248   1.1       gwr 	 * the BSD standard of use 10% of memory for the first 2 Meg,
    249   1.1       gwr 	 * 5% of remaining. Insure a minimum of 16 buffers.
    250   1.1       gwr 	 * Allocate 1/2 as many swap buffer headers as file i/o buffers.
    251   1.1       gwr 	 */
    252   1.1       gwr 	if (bufpages == 0) {
    253   1.1       gwr 		/* We always have more than 2MB of memory. */
    254   1.1       gwr 		bufpages = ((btoc(2 * 1024 * 1024) + physmem) /
    255   1.1       gwr 		            (20 * CLSIZE));
    256   1.1       gwr 	}
    257   1.1       gwr 	if (nbuf == 0) {
    258   1.1       gwr 		nbuf = bufpages;
    259   1.1       gwr 		if (nbuf < 16)
    260   1.1       gwr 			nbuf = 16;
    261   1.1       gwr 	}
    262   1.1       gwr 	if (nswbuf == 0) {
    263   1.1       gwr 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
    264   1.1       gwr 		if (nswbuf > 256)
    265   1.1       gwr 			nswbuf = 256;		/* sanity */
    266   1.1       gwr 	}
    267  1.34       gwr #if !defined(UVM)
    268   1.1       gwr 	valloc(swbuf, struct buf, nswbuf);
    269  1.34       gwr #endif
    270   1.1       gwr 	valloc(buf, struct buf, nbuf);
    271   1.1       gwr 	return v;
    272   1.1       gwr }
    273   1.1       gwr #undef	valloc
    274   1.1       gwr 
    275   1.1       gwr /*
    276   1.1       gwr  * cpu_startup: allocate memory for variable-sized tables,
    277   1.1       gwr  * initialize cpu, and do autoconfiguration.
    278   1.1       gwr  *
    279   1.1       gwr  * This is called early in init_main.c:main(), after the
    280   1.1       gwr  * kernel memory allocator is ready for use, but before
    281   1.1       gwr  * the creation of processes 1,2, and mountroot, etc.
    282   1.1       gwr  */
    283   1.1       gwr void
    284   1.1       gwr cpu_startup()
    285   1.1       gwr {
    286   1.1       gwr 	caddr_t v;
    287   1.1       gwr 	int sz, i;
    288   1.1       gwr 	vm_size_t size;
    289   1.1       gwr 	int base, residual;
    290   1.1       gwr 	vm_offset_t minaddr, maxaddr;
    291   1.1       gwr 
    292   1.1       gwr 	/*
    293   1.1       gwr 	 * Initialize message buffer (for kernel printf).
    294   1.1       gwr 	 * This is put in physical page zero so it will
    295   1.1       gwr 	 * always be in the same place after a reboot.
    296   1.1       gwr 	 * Its mapping was prepared in pmap_bootstrap().
    297   1.1       gwr 	 * Also, offset some to avoid PROM scribbles.
    298   1.1       gwr 	 */
    299   1.1       gwr 	v = (caddr_t) KERNBASE;
    300  1.23       gwr 	msgbufaddr = (caddr_t)(v + MSGBUFOFF);
    301  1.23       gwr 	initmsgbuf(msgbufaddr, MSGBUFSIZE);
    302   1.1       gwr 
    303   1.1       gwr 	/*
    304   1.1       gwr 	 * Good {morning,afternoon,evening,night}.
    305   1.1       gwr 	 */
    306   1.1       gwr 	printf(version);
    307   1.1       gwr 	identifycpu();
    308   1.1       gwr 	initfpu();	/* also prints FPU type */
    309   1.1       gwr 
    310  1.29       gwr 	size = ptoa(physmem);
    311  1.38    kleink 	printf("real  mem = %ldK (0x%lx)\n", (size >> 10), size);
    312   1.1       gwr 
    313   1.1       gwr 	/*
    314   1.1       gwr 	 * Find out how much space we need, allocate it,
    315   1.1       gwr 	 * and then give everything true virtual addresses.
    316   1.1       gwr 	 */
    317   1.1       gwr 	sz = (int)allocsys((caddr_t)0);
    318   1.1       gwr 	if ((v = (caddr_t)kmem_alloc(kernel_map, round_page(sz))) == 0)
    319   1.1       gwr 		panic("startup: no room for tables");
    320   1.1       gwr 	if (allocsys(v) - v != sz)
    321   1.1       gwr 		panic("startup: table size inconsistency");
    322   1.1       gwr 
    323   1.1       gwr 	/*
    324   1.1       gwr 	 * Now allocate buffers proper.  They are different than the above
    325   1.1       gwr 	 * in that they usually occupy more virtual memory than physical.
    326   1.1       gwr 	 */
    327   1.1       gwr 	size = MAXBSIZE * nbuf;
    328  1.34       gwr #if defined(UVM)
    329  1.34       gwr 	if (uvm_map(kernel_map, (vm_offset_t *) &buffers, round_page(size),
    330  1.34       gwr 		    NULL, UVM_UNKNOWN_OFFSET,
    331  1.34       gwr 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    332  1.34       gwr 				UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
    333  1.34       gwr 		panic("startup: cannot allocate VM for buffers");
    334  1.34       gwr 	minaddr = (vm_offset_t)buffers;
    335  1.34       gwr #else
    336   1.1       gwr 	buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
    337   1.1       gwr 				   &maxaddr, size, TRUE);
    338   1.1       gwr 	minaddr = (vm_offset_t)buffers;
    339   1.1       gwr 	if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
    340   1.1       gwr 			&minaddr, size, FALSE) != KERN_SUCCESS)
    341   1.1       gwr 		panic("startup: cannot allocate buffers");
    342  1.34       gwr #endif /* UVM */
    343   1.1       gwr 	if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
    344   1.1       gwr 		/* don't want to alloc more physical mem than needed */
    345   1.1       gwr 		bufpages = btoc(MAXBSIZE) * nbuf;
    346   1.1       gwr 	}
    347   1.1       gwr 	base = bufpages / nbuf;
    348   1.1       gwr 	residual = bufpages % nbuf;
    349   1.1       gwr 	for (i = 0; i < nbuf; i++) {
    350  1.34       gwr #if defined(UVM)
    351  1.34       gwr 		vm_size_t curbufsize;
    352  1.34       gwr 		vm_offset_t curbuf;
    353  1.34       gwr 		struct vm_page *pg;
    354  1.34       gwr 
    355  1.34       gwr 		/*
    356  1.34       gwr 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    357  1.34       gwr 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    358  1.34       gwr 		 * for the first "residual" buffers, and then we allocate
    359  1.34       gwr 		 * "base" pages for the rest.
    360  1.34       gwr 		 */
    361  1.34       gwr 		curbuf = (vm_offset_t) buffers + (i * MAXBSIZE);
    362  1.34       gwr 		curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
    363  1.34       gwr 
    364  1.34       gwr 		while (curbufsize) {
    365  1.34       gwr 			pg = uvm_pagealloc(NULL, 0, NULL);
    366  1.34       gwr 			if (pg == NULL)
    367  1.34       gwr 				panic("cpu_startup: not enough memory for "
    368  1.34       gwr 				    "buffer cache");
    369  1.34       gwr #if defined(PMAP_NEW)
    370  1.34       gwr 			pmap_kenter_pgs(curbuf, &pg, 1);
    371  1.34       gwr #else
    372  1.34       gwr 			pmap_enter(kernel_map->pmap, curbuf,
    373  1.34       gwr 				   VM_PAGE_TO_PHYS(pg), VM_PROT_ALL, TRUE);
    374  1.34       gwr #endif
    375  1.34       gwr 			curbuf += PAGE_SIZE;
    376  1.34       gwr 			curbufsize -= PAGE_SIZE;
    377  1.34       gwr 		}
    378  1.34       gwr #else /* ! UVM */
    379   1.1       gwr 		vm_size_t curbufsize;
    380   1.1       gwr 		vm_offset_t curbuf;
    381   1.1       gwr 
    382   1.1       gwr 		/*
    383   1.1       gwr 		 * First <residual> buffers get (base+1) physical pages
    384   1.1       gwr 		 * allocated for them.  The rest get (base) physical pages.
    385   1.1       gwr 		 *
    386   1.1       gwr 		 * The rest of each buffer occupies virtual space,
    387   1.1       gwr 		 * but has no physical memory allocated for it.
    388   1.1       gwr 		 */
    389   1.1       gwr 		curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
    390   1.1       gwr 		curbufsize = CLBYTES * (i < residual ? base+1 : base);
    391   1.1       gwr 		vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
    392   1.1       gwr 		vm_map_simplify(buffer_map, curbuf);
    393  1.34       gwr #endif /* UVM */
    394   1.1       gwr 	}
    395   1.1       gwr 
    396   1.1       gwr 	/*
    397   1.1       gwr 	 * Allocate a submap for exec arguments.  This map effectively
    398   1.1       gwr 	 * limits the number of processes exec'ing at any time.
    399   1.1       gwr 	 */
    400  1.34       gwr #if defined(UVM)
    401  1.34       gwr 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    402  1.34       gwr 				   16*NCARGS, TRUE, FALSE, NULL);
    403  1.34       gwr #else
    404   1.1       gwr 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    405   1.1       gwr 				 16*NCARGS, TRUE);
    406  1.34       gwr #endif
    407   1.1       gwr 
    408   1.1       gwr 	/*
    409   1.1       gwr 	 * We don't use a submap for physio, and use a separate map
    410   1.1       gwr 	 * for DVMA allocations.  Our vmapbuf just maps pages into
    411   1.1       gwr 	 * the kernel map (any kernel mapping is OK) and then the
    412   1.1       gwr 	 * device drivers clone the kernel mappings into DVMA space.
    413   1.1       gwr 	 */
    414   1.1       gwr 
    415   1.1       gwr 	/*
    416  1.12   thorpej 	 * Finally, allocate mbuf cluster submap.
    417   1.1       gwr 	 */
    418  1.34       gwr #if defined(UVM)
    419  1.39   thorpej 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    420  1.34       gwr 				 VM_MBUF_SIZE, FALSE, FALSE, NULL);
    421  1.34       gwr #else
    422  1.39   thorpej 	mb_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    423   1.1       gwr 			       VM_MBUF_SIZE, FALSE);
    424  1.34       gwr #endif
    425   1.1       gwr 
    426   1.1       gwr 	/*
    427   1.1       gwr 	 * Initialize callouts
    428   1.1       gwr 	 */
    429   1.1       gwr 	callfree = callout;
    430   1.1       gwr 	for (i = 1; i < ncallout; i++)
    431   1.1       gwr 		callout[i-1].c_next = &callout[i];
    432   1.1       gwr 	callout[i-1].c_next = NULL;
    433   1.1       gwr 
    434  1.34       gwr #if defined(UVM)
    435  1.34       gwr 	size = ptoa(uvmexp.free);
    436  1.34       gwr #else
    437  1.29       gwr 	size = ptoa(cnt.v_free_count);
    438  1.34       gwr #endif
    439  1.38    kleink 	printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
    440   1.1       gwr 	printf("using %d buffers containing %d bytes of memory\n",
    441   1.1       gwr 		   nbuf, bufpages * CLBYTES);
    442   1.1       gwr 
    443   1.1       gwr 	/*
    444   1.1       gwr 	 * Tell the VM system that writing to kernel text isn't allowed.
    445   1.1       gwr 	 * If we don't, we might end up COW'ing the text segment!
    446   1.1       gwr 	 */
    447  1.34       gwr #if defined(UVM)
    448  1.34       gwr 	if (uvm_map_protect(kernel_map, (vm_offset_t) kernel_text,
    449  1.34       gwr 	    m68k_trunc_page((vm_offset_t) etext),
    450  1.34       gwr 	    UVM_PROT_READ|UVM_PROT_EXEC, TRUE) != KERN_SUCCESS)
    451  1.34       gwr 		panic("can't protect kernel text");
    452  1.34       gwr #else
    453   1.1       gwr 	if (vm_map_protect(kernel_map, (vm_offset_t) kernel_text,
    454  1.34       gwr 	    m68k_trunc_page((vm_offset_t) etext),
    455  1.34       gwr 	    VM_PROT_READ|VM_PROT_EXECUTE, TRUE) != KERN_SUCCESS)
    456   1.1       gwr 		panic("can't protect kernel text");
    457  1.34       gwr #endif
    458   1.1       gwr 
    459   1.1       gwr 	/*
    460   1.1       gwr 	 * Allocate a virtual page (for use by /dev/mem)
    461   1.1       gwr 	 * This page is handed to pmap_enter() therefore
    462   1.1       gwr 	 * it has to be in the normal kernel VA range.
    463   1.1       gwr 	 */
    464  1.34       gwr #if defined(UVM)
    465  1.34       gwr 	vmmap = uvm_km_valloc_wait(kernel_map, NBPG);
    466  1.34       gwr #else
    467   1.1       gwr 	vmmap = kmem_alloc_wait(kernel_map, NBPG);
    468  1.34       gwr #endif
    469   1.1       gwr 
    470   1.1       gwr 	/*
    471   1.1       gwr 	 * Create the DVMA maps.
    472   1.1       gwr 	 */
    473   1.1       gwr 	dvma_init();
    474   1.1       gwr 
    475   1.1       gwr 	/*
    476   1.1       gwr 	 * Set up CPU-specific registers, cache, etc.
    477   1.1       gwr 	 */
    478   1.1       gwr 	initcpu();
    479   1.1       gwr 
    480   1.1       gwr 	/*
    481   1.1       gwr 	 * Set up buffers, so they can be used to read disk labels.
    482   1.1       gwr 	 */
    483   1.1       gwr 	bufinit();
    484   1.1       gwr 
    485   1.1       gwr 	/*
    486   1.1       gwr 	 * Configure the system.
    487   1.1       gwr 	 */
    488   1.1       gwr 	configure();
    489   1.1       gwr }
    490   1.1       gwr 
    491   1.1       gwr /*
    492   1.1       gwr  * Set registers on exec.
    493   1.1       gwr  */
    494   1.1       gwr void
    495  1.19   mycroft setregs(p, pack, stack)
    496  1.34       gwr 	struct proc *p;
    497   1.1       gwr 	struct exec_package *pack;
    498   1.1       gwr 	u_long stack;
    499   1.1       gwr {
    500   1.5       gwr 	struct trapframe *tf = (struct trapframe *)p->p_md.md_regs;
    501   1.1       gwr 
    502  1.21   mycroft 	tf->tf_sr = PSL_USERSET;
    503   1.5       gwr 	tf->tf_pc = pack->ep_entry & ~1;
    504  1.20   mycroft 	tf->tf_regs[D0] = 0;
    505  1.20   mycroft 	tf->tf_regs[D1] = 0;
    506  1.20   mycroft 	tf->tf_regs[D2] = 0;
    507  1.20   mycroft 	tf->tf_regs[D3] = 0;
    508  1.20   mycroft 	tf->tf_regs[D4] = 0;
    509  1.20   mycroft 	tf->tf_regs[D5] = 0;
    510  1.20   mycroft 	tf->tf_regs[D6] = 0;
    511  1.20   mycroft 	tf->tf_regs[D7] = 0;
    512  1.20   mycroft 	tf->tf_regs[A0] = 0;
    513  1.20   mycroft 	tf->tf_regs[A1] = 0;
    514  1.20   mycroft 	tf->tf_regs[A2] = (int)PS_STRINGS;
    515  1.20   mycroft 	tf->tf_regs[A3] = 0;
    516  1.20   mycroft 	tf->tf_regs[A4] = 0;
    517  1.20   mycroft 	tf->tf_regs[A5] = 0;
    518  1.20   mycroft 	tf->tf_regs[A6] = 0;
    519   1.5       gwr 	tf->tf_regs[SP] = stack;
    520   1.1       gwr 
    521   1.1       gwr 	/* restore a null state frame */
    522   1.1       gwr 	p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
    523  1.19   mycroft 	if (fputype)
    524   1.1       gwr 		m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
    525  1.19   mycroft 
    526   1.1       gwr 	p->p_md.md_flags = 0;
    527   1.1       gwr }
    528   1.1       gwr 
    529   1.1       gwr /*
    530   1.1       gwr  * Info for CTL_HW
    531   1.1       gwr  */
    532  1.25       gwr char	machine[16] = MACHINE;	/* from <machine/param.h> */
    533   1.1       gwr char	cpu_model[120];
    534  1.15       gwr 
    535  1.15       gwr /*
    536  1.15       gwr  * XXX - Should empirically estimate the divisor...
    537  1.15       gwr  * Note that the value of delay_divisor is roughly
    538  1.15       gwr  * 2048 / cpuclock	(where cpuclock is in MHz).
    539  1.15       gwr  */
    540  1.16       gwr int delay_divisor = 62;		/* assume the fastest (33 MHz) */
    541   1.1       gwr 
    542   1.1       gwr void
    543   1.1       gwr identifycpu()
    544   1.1       gwr {
    545  1.29       gwr 	u_char machtype;
    546   1.1       gwr 
    547  1.15       gwr 	machtype = identity_prom.idp_machtype;
    548  1.29       gwr 	if ((machtype & IDM_ARCH_MASK) != IDM_ARCH_SUN3X) {
    549  1.29       gwr 		printf("Bad IDPROM arch!\n");
    550  1.15       gwr 		sunmon_abort();
    551  1.15       gwr 	}
    552  1.15       gwr 
    553  1.29       gwr 	cpu_machine_id = machtype;
    554  1.15       gwr 	switch (cpu_machine_id) {
    555  1.15       gwr 
    556  1.15       gwr 	case SUN3X_MACH_80:
    557  1.15       gwr 		cpu_string = "80";  	/* Hydra */
    558  1.16       gwr 		delay_divisor = 102;	/* 20 MHz */
    559  1.15       gwr 		cpu_has_vme = FALSE;
    560  1.15       gwr 		break;
    561  1.15       gwr 
    562  1.15       gwr 	case SUN3X_MACH_470:
    563  1.15       gwr 		cpu_string = "470"; 	/* Pegasus */
    564  1.15       gwr 		delay_divisor = 62; 	/* 33 MHz */
    565  1.15       gwr 		cpu_has_vme = TRUE;
    566  1.15       gwr 		break;
    567  1.15       gwr 
    568  1.15       gwr 	default:
    569  1.15       gwr 		printf("unknown sun3x model\n");
    570  1.15       gwr 		sunmon_abort();
    571  1.15       gwr 	}
    572  1.15       gwr 
    573  1.15       gwr 	/* Other stuff? (VAC, mc6888x version, etc.) */
    574  1.29       gwr 	sprintf(cpu_model, "Sun-3X (3/%s)", cpu_string);
    575   1.1       gwr 
    576  1.29       gwr 	printf("Model: %s\n", cpu_model);
    577   1.1       gwr }
    578   1.1       gwr 
    579   1.1       gwr /*
    580   1.1       gwr  * machine dependent system variables.
    581   1.1       gwr  */
    582   1.1       gwr int
    583   1.1       gwr cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    584   1.1       gwr 	int *name;
    585   1.1       gwr 	u_int namelen;
    586   1.1       gwr 	void *oldp;
    587   1.1       gwr 	size_t *oldlenp;
    588   1.1       gwr 	void *newp;
    589   1.1       gwr 	size_t newlen;
    590   1.1       gwr 	struct proc *p;
    591   1.1       gwr {
    592   1.1       gwr 	int error;
    593   1.1       gwr 	dev_t consdev;
    594   1.1       gwr 
    595   1.1       gwr 	/* all sysctl names at this level are terminal */
    596   1.1       gwr 	if (namelen != 1)
    597   1.1       gwr 		return (ENOTDIR);		/* overloaded */
    598   1.1       gwr 
    599   1.1       gwr 	switch (name[0]) {
    600   1.1       gwr 	case CPU_CONSDEV:
    601   1.1       gwr 		if (cn_tab != NULL)
    602   1.1       gwr 			consdev = cn_tab->cn_dev;
    603   1.1       gwr 		else
    604   1.1       gwr 			consdev = NODEV;
    605   1.1       gwr 		error = sysctl_rdstruct(oldp, oldlenp, newp,
    606   1.1       gwr 		    &consdev, sizeof consdev);
    607   1.1       gwr 		break;
    608   1.1       gwr 
    609   1.1       gwr #if 0	/* XXX - Not yet... */
    610   1.1       gwr 	case CPU_ROOT_DEVICE:
    611   1.1       gwr 		error = sysctl_rdstring(oldp, oldlenp, newp, root_device);
    612   1.1       gwr 		break;
    613   1.1       gwr 
    614   1.1       gwr 	case CPU_BOOTED_KERNEL:
    615   1.1       gwr 		error = sysctl_rdstring(oldp, oldlenp, newp, booted_kernel);
    616   1.1       gwr 		break;
    617   1.1       gwr #endif
    618   1.1       gwr 
    619   1.1       gwr 	default:
    620   1.1       gwr 		error = EOPNOTSUPP;
    621   1.1       gwr 	}
    622   1.1       gwr 	return (error);
    623   1.1       gwr }
    624   1.1       gwr 
    625   1.7       gwr /* See: sig_machdep.c */
    626   1.1       gwr 
    627   1.1       gwr /*
    628   1.1       gwr  * Do a sync in preparation for a reboot.
    629   1.1       gwr  * XXX - This could probably be common code.
    630   1.1       gwr  * XXX - And now, most of it is in vfs_shutdown()
    631   1.1       gwr  * XXX - Put waittime checks in there too?
    632   1.1       gwr  */
    633   1.1       gwr int waittime = -1;	/* XXX - Who else looks at this? -gwr */
    634   1.1       gwr static void
    635   1.1       gwr reboot_sync __P((void))
    636   1.1       gwr {
    637   1.1       gwr 
    638   1.1       gwr 	/* Check waittime here to localize its use to this function. */
    639   1.1       gwr 	if (waittime >= 0)
    640   1.1       gwr 		return;
    641   1.1       gwr 	waittime = 0;
    642   1.1       gwr 	vfs_shutdown();
    643   1.1       gwr }
    644   1.1       gwr 
    645   1.1       gwr /*
    646   1.1       gwr  * Common part of the BSD and SunOS reboot system calls.
    647   1.1       gwr  */
    648   1.1       gwr __dead void
    649  1.11       gwr cpu_reboot(howto, user_boot_string)
    650   1.1       gwr 	int howto;
    651   1.1       gwr 	char *user_boot_string;
    652   1.1       gwr {
    653   1.2       gwr 	/* Note: this string MUST be static! */
    654   1.2       gwr 	static char bootstr[128];
    655   1.2       gwr 	char *p;
    656   1.1       gwr 
    657   1.1       gwr 	/* If system is cold, just halt. (early panic?) */
    658   1.1       gwr 	if (cold)
    659   1.1       gwr 		goto haltsys;
    660   1.1       gwr 
    661  1.24       gwr 	/* Un-blank the screen if appropriate. */
    662  1.24       gwr 	cnpollc(1);
    663  1.24       gwr 
    664   1.1       gwr 	if ((howto & RB_NOSYNC) == 0) {
    665   1.1       gwr 		reboot_sync();
    666   1.1       gwr 		/*
    667   1.1       gwr 		 * If we've been adjusting the clock, the todr
    668   1.1       gwr 		 * will be out of synch; adjust it now.
    669   1.1       gwr 		 *
    670   1.1       gwr 		 * XXX - However, if the kernel has been sitting in ddb,
    671   1.1       gwr 		 * the time will be way off, so don't set the HW clock!
    672   1.1       gwr 		 * XXX - Should do sanity check against HW clock. -gwr
    673   1.1       gwr 		 */
    674   1.1       gwr 		/* resettodr(); */
    675   1.1       gwr 	}
    676   1.1       gwr 
    677   1.1       gwr 	/* Disable interrupts. */
    678   1.1       gwr 	splhigh();
    679   1.1       gwr 
    680   1.1       gwr 	/* Write out a crash dump if asked. */
    681   1.1       gwr 	if (howto & RB_DUMP)
    682   1.1       gwr 		dumpsys();
    683   1.1       gwr 
    684   1.1       gwr 	/* run any shutdown hooks */
    685   1.1       gwr 	doshutdownhooks();
    686   1.1       gwr 
    687   1.1       gwr 	if (howto & RB_HALT) {
    688   1.1       gwr 	haltsys:
    689   1.1       gwr 		printf("Kernel halted.\n");
    690  1.15       gwr #if 0
    691  1.15       gwr 		/*
    692  1.15       gwr 		 * This calls the PROM monitor "exit_to_mon" function
    693  1.15       gwr 		 * which appears to have problems...  SunOS uses the
    694  1.15       gwr 		 * "abort" function when you halt (bug work-around?)
    695  1.15       gwr 		 * so we might as well do the same.
    696  1.15       gwr 		 */
    697  1.15       gwr 		sunmon_halt(); /* provokes PROM monitor bug */
    698  1.15       gwr #else
    699  1.15       gwr 		sunmon_abort();
    700  1.15       gwr #endif
    701   1.1       gwr 	}
    702   1.1       gwr 
    703   1.1       gwr 	/*
    704   1.1       gwr 	 * Automatic reboot.
    705   1.1       gwr 	 */
    706   1.2       gwr 	if (user_boot_string)
    707   1.2       gwr 		strncpy(bootstr, user_boot_string, sizeof(bootstr));
    708   1.2       gwr 	else {
    709   1.1       gwr 		/*
    710   1.1       gwr 		 * Build our own boot string with an empty
    711   1.1       gwr 		 * boot device/file and (maybe) some flags.
    712   1.1       gwr 		 * The PROM will supply the device/file name.
    713   1.1       gwr 		 */
    714   1.2       gwr 		p = bootstr;
    715   1.2       gwr 		*p = '\0';
    716   1.1       gwr 		if (howto & (RB_KDB|RB_ASKNAME|RB_SINGLE)) {
    717   1.1       gwr 			/* Append the boot flags. */
    718   1.1       gwr 			*p++ = ' ';
    719   1.1       gwr 			*p++ = '-';
    720   1.1       gwr 			if (howto & RB_KDB)
    721   1.1       gwr 				*p++ = 'd';
    722   1.1       gwr 			if (howto & RB_ASKNAME)
    723   1.1       gwr 				*p++ = 'a';
    724   1.1       gwr 			if (howto & RB_SINGLE)
    725   1.1       gwr 				*p++ = 's';
    726   1.1       gwr 			*p = '\0';
    727   1.1       gwr 		}
    728   1.1       gwr 	}
    729   1.1       gwr 	printf("Kernel rebooting...\n");
    730   1.3       gwr 	sunmon_reboot(bootstr);
    731   1.1       gwr 	for (;;) ;
    732   1.1       gwr 	/*NOTREACHED*/
    733   1.1       gwr }
    734   1.1       gwr 
    735   1.1       gwr /*
    736   1.1       gwr  * These variables are needed by /sbin/savecore
    737   1.1       gwr  */
    738   1.1       gwr u_long	dumpmag = 0x8fca0101;	/* magic number */
    739   1.1       gwr int 	dumpsize = 0;		/* pages */
    740   1.1       gwr long	dumplo = 0; 		/* blocks */
    741   1.1       gwr 
    742   1.1       gwr /*
    743  1.11       gwr  * This is called by main to set dumplo, dumpsize.
    744   1.1       gwr  * Dumps always skip the first CLBYTES of disk space
    745   1.1       gwr  * in case there might be a disk label stored there.
    746   1.1       gwr  * If there is extra space, put dump at the end to
    747   1.1       gwr  * reduce the chance that swapping trashes it.
    748   1.1       gwr  */
    749   1.1       gwr void
    750  1.11       gwr cpu_dumpconf()
    751   1.1       gwr {
    752   1.1       gwr 	int nblks;	/* size of dump area */
    753   1.1       gwr 	int maj;
    754   1.1       gwr 	int (*getsize)__P((dev_t));
    755  1.24       gwr 
    756  1.24       gwr 	/* Validate space in page zero for the kcore header. */
    757  1.24       gwr 	if (MSGBUFOFF < (sizeof(kcore_seg_t) + sizeof(cpu_kcore_hdr_t)))
    758  1.24       gwr 		panic("cpu_dumpconf: MSGBUFOFF too small");
    759   1.1       gwr 
    760   1.1       gwr 	if (dumpdev == NODEV)
    761   1.1       gwr 		return;
    762   1.1       gwr 
    763   1.1       gwr 	maj = major(dumpdev);
    764   1.1       gwr 	if (maj < 0 || maj >= nblkdev)
    765   1.1       gwr 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
    766   1.1       gwr 	getsize = bdevsw[maj].d_psize;
    767   1.1       gwr 	if (getsize == NULL)
    768   1.1       gwr 		return;
    769   1.1       gwr 	nblks = (*getsize)(dumpdev);
    770   1.1       gwr 	if (nblks <= ctod(1))
    771   1.1       gwr 		return;
    772   1.1       gwr 
    773   1.1       gwr 	/* Position dump image near end of space, page aligned. */
    774   1.1       gwr 	dumpsize = physmem; 	/* pages */
    775   1.1       gwr 	dumplo = nblks - ctod(dumpsize);
    776   1.1       gwr 	dumplo &= ~(ctod(1)-1);
    777   1.1       gwr 
    778   1.1       gwr 	/* If it does not fit, truncate it by moving dumplo. */
    779   1.1       gwr 	/* Note: Must force signed comparison. */
    780   1.1       gwr 	if (dumplo < ((long)ctod(1))) {
    781   1.1       gwr 		dumplo = ctod(1);
    782   1.1       gwr 		dumpsize = dtoc(nblks - dumplo);
    783   1.1       gwr 	}
    784   1.1       gwr }
    785   1.1       gwr 
    786  1.13       gwr /* Note: gdb looks for "dumppcb" in a kernel crash dump. */
    787   1.1       gwr struct pcb dumppcb;
    788   1.1       gwr 
    789   1.1       gwr /*
    790   1.1       gwr  * Write a crash dump.  The format while in swap is:
    791   1.1       gwr  *   kcore_seg_t cpu_hdr;
    792   1.1       gwr  *   cpu_kcore_hdr_t cpu_data;
    793   1.1       gwr  *   padding (NBPG-sizeof(kcore_seg_t))
    794   1.1       gwr  *   pagemap (2*NBPG)
    795   1.1       gwr  *   physical memory...
    796   1.1       gwr  */
    797   1.1       gwr void
    798   1.1       gwr dumpsys()
    799   1.1       gwr {
    800   1.1       gwr 	struct bdevsw *dsw;
    801  1.10       gwr 	kcore_seg_t	*kseg_p;
    802  1.10       gwr 	cpu_kcore_hdr_t *chdr_p;
    803  1.14   thorpej 	struct sun3x_kcore_hdr *sh;
    804  1.14   thorpej 	phys_ram_seg_t *crs_p;
    805   1.1       gwr 	char *vaddr;
    806   1.1       gwr 	vm_offset_t paddr;
    807  1.10       gwr 	int psize, todo, seg, segsz;
    808   1.1       gwr 	daddr_t blkno;
    809   1.1       gwr 	int error = 0;
    810   1.1       gwr 
    811  1.30   thorpej 	msgbufenabled = 0;
    812   1.1       gwr 	if (dumpdev == NODEV)
    813   1.1       gwr 		return;
    814   1.1       gwr 
    815   1.1       gwr 	/*
    816   1.1       gwr 	 * For dumps during autoconfiguration,
    817   1.1       gwr 	 * if dump device has already configured...
    818   1.1       gwr 	 */
    819   1.1       gwr 	if (dumpsize == 0)
    820  1.11       gwr 		cpu_dumpconf();
    821  1.28   mycroft 	if (dumplo <= 0) {
    822  1.28   mycroft 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    823  1.28   mycroft 		    minor(dumpdev));
    824   1.1       gwr 		return;
    825  1.28   mycroft 	}
    826   1.1       gwr 	savectx(&dumppcb);
    827   1.1       gwr 
    828   1.1       gwr 	dsw = &bdevsw[major(dumpdev)];
    829   1.1       gwr 	psize = (*(dsw->d_psize))(dumpdev);
    830   1.1       gwr 	if (psize == -1) {
    831   1.1       gwr 		printf("dump area unavailable\n");
    832   1.1       gwr 		return;
    833   1.1       gwr 	}
    834   1.1       gwr 
    835  1.28   mycroft 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    836  1.28   mycroft 	    minor(dumpdev), dumplo);
    837   1.1       gwr 
    838   1.1       gwr 	/*
    839  1.10       gwr 	 * We put the dump header is in physical page zero,
    840  1.10       gwr 	 * so there is no extra work here to write it out.
    841  1.25       gwr 	 * All we do is initialize the header.
    842   1.1       gwr 	 */
    843  1.25       gwr 
    844  1.25       gwr 	/* Set pointers to all three parts. */
    845  1.10       gwr 	kseg_p = (kcore_seg_t *)KERNBASE;
    846  1.10       gwr 	chdr_p = (cpu_kcore_hdr_t *) (kseg_p + 1);
    847  1.14   thorpej 	sh = &chdr_p->un._sun3x;
    848  1.25       gwr 
    849  1.25       gwr 	/* Fill in kcore_seg_t part. */
    850  1.10       gwr 	CORE_SETMAGIC(*kseg_p, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    851  1.10       gwr 	kseg_p->c_size = sizeof(*chdr_p);
    852  1.25       gwr 
    853  1.25       gwr 	/* Fill in cpu_kcore_hdr_t part. */
    854  1.29       gwr 	/* Can NOT use machine[] as the name! */
    855  1.29       gwr 	strncpy(chdr_p->name, "sun3x", sizeof(chdr_p->name));
    856  1.25       gwr 	chdr_p->page_size = NBPG;
    857  1.25       gwr 	chdr_p->kernbase = KERNBASE;
    858  1.25       gwr 
    859  1.25       gwr 	/* Fill in the sun3x_kcore_hdr part. */
    860  1.25       gwr 	pmap_kcore_hdr(sh);
    861  1.10       gwr 
    862  1.10       gwr 	/*
    863  1.10       gwr 	 * Now dump physical memory.  Note that physical memory
    864  1.10       gwr 	 * might NOT be congiguous, so do it by segments.
    865  1.10       gwr 	 */
    866  1.10       gwr 
    867   1.1       gwr 	blkno = dumplo;
    868   1.1       gwr 	todo = dumpsize;	/* pages */
    869  1.10       gwr 	vaddr = (char*)vmmap;	/* Borrow /dev/mem VA */
    870   1.1       gwr 
    871  1.14   thorpej 	for (seg = 0; seg < SUN3X_NPHYS_RAM_SEGS; seg++) {
    872  1.14   thorpej 		crs_p = &sh->ram_segs[seg];
    873  1.10       gwr 		paddr = crs_p->start;
    874  1.10       gwr 		segsz = crs_p->size;
    875  1.10       gwr 		/*
    876  1.10       gwr 		 * Our header lives in the first little bit of
    877  1.10       gwr 		 * physical memory (not written separately), so
    878  1.10       gwr 		 * we have to adjust the first ram segment size
    879  1.10       gwr 		 * and start address to reflect the stolen RAM.
    880  1.10       gwr 		 * (Nothing interesing in that RAM anyway 8^).
    881  1.10       gwr 		 */
    882  1.10       gwr 		if (seg == 0) {
    883  1.10       gwr 			int adj = sizeof(*kseg_p) + sizeof(*chdr_p);
    884  1.10       gwr 			crs_p->start += adj;
    885  1.10       gwr 			crs_p->size  -= adj;
    886  1.10       gwr 		}
    887   1.1       gwr 
    888  1.10       gwr 		while (todo && (segsz > 0)) {
    889   1.1       gwr 
    890  1.10       gwr 			/* Print pages left after every 16. */
    891  1.10       gwr 			if ((todo & 0xf) == 0)
    892  1.10       gwr 				printf("\r%4d", todo);
    893  1.10       gwr 
    894  1.10       gwr 			/* Make a temporary mapping for the page. */
    895  1.10       gwr 			pmap_enter(pmap_kernel(), vmmap, paddr | PMAP_NC,
    896  1.10       gwr 					   VM_PROT_READ, FALSE);
    897  1.10       gwr 			error = (*dsw->d_dump)(dumpdev, blkno, vaddr, NBPG);
    898  1.10       gwr 			pmap_remove(pmap_kernel(), vmmap, vmmap + NBPG);
    899  1.10       gwr 			if (error)
    900  1.10       gwr 				goto fail;
    901  1.10       gwr 			paddr += NBPG;
    902  1.10       gwr 			segsz -= NBPG;
    903  1.10       gwr 			blkno += btodb(NBPG);
    904  1.10       gwr 			todo--;
    905  1.10       gwr 		}
    906  1.10       gwr 	}
    907   1.1       gwr 	printf("\rdump succeeded\n");
    908   1.1       gwr 	return;
    909   1.1       gwr fail:
    910   1.1       gwr 	printf(" dump error=%d\n", error);
    911   1.1       gwr }
    912   1.1       gwr 
    913   1.1       gwr static void
    914   1.1       gwr initcpu()
    915   1.1       gwr {
    916   1.1       gwr 	/* XXX: Enable RAM parity/ECC checking? */
    917   1.1       gwr 	/* XXX: parityenable(); */
    918   1.1       gwr 
    919   1.1       gwr #ifdef	HAVECACHE
    920   1.1       gwr 	cache_enable();
    921   1.1       gwr #endif
    922   1.1       gwr }
    923   1.1       gwr 
    924   1.8       gwr /* straptrap() in trap.c */
    925   1.1       gwr 
    926   1.1       gwr /* from hp300: badaddr() */
    927  1.15       gwr /* peek_byte(), peek_word() moved to bus_subr.c */
    928   1.1       gwr 
    929   1.1       gwr /* XXX: parityenable() ? */
    930   1.7       gwr /* regdump() moved to regdump.c */
    931   1.1       gwr 
    932   1.1       gwr /*
    933   1.1       gwr  * cpu_exec_aout_makecmds():
    934   1.1       gwr  *	cpu-dependent a.out format hook for execve().
    935   1.1       gwr  *
    936   1.1       gwr  * Determine if the given exec package refers to something which we
    937   1.1       gwr  * understand and, if so, set up the vmcmds for it.
    938   1.1       gwr  */
    939   1.1       gwr int
    940   1.1       gwr cpu_exec_aout_makecmds(p, epp)
    941   1.1       gwr 	struct proc *p;
    942   1.1       gwr 	struct exec_package *epp;
    943   1.1       gwr {
    944  1.27        tv 	return ENOEXEC;
    945   1.1       gwr }
    946