Home | History | Annotate | Line # | Download | only in alpha
machdep.c revision 1.155
      1 /* $NetBSD: machdep.c,v 1.155 1998/11/19 02:28:56 ross Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center and by Chris G. Demetriou.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
     42  * All rights reserved.
     43  *
     44  * Author: Chris G. Demetriou
     45  *
     46  * Permission to use, copy, modify and distribute this software and
     47  * its documentation is hereby granted, provided that both the copyright
     48  * notice and this permission notice appear in all copies of the
     49  * software, derivative works or modified versions, and any portions
     50  * thereof, and that both notices appear in supporting documentation.
     51  *
     52  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55  *
     56  * Carnegie Mellon requests users of this software to return to
     57  *
     58  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59  *  School of Computer Science
     60  *  Carnegie Mellon University
     61  *  Pittsburgh PA 15213-3890
     62  *
     63  * any improvements or extensions that they make and grant Carnegie the
     64  * rights to redistribute these changes.
     65  */
     66 
     67 #include "opt_ddb.h"
     68 #include "opt_multiprocessor.h"
     69 #include "opt_uvm.h"
     70 #include "opt_pmap_new.h"
     71 #include "opt_dec_3000_300.h"
     72 #include "opt_dec_3000_500.h"
     73 #include "opt_compat_osf1.h"
     74 #include "opt_compat_netbsd.h"
     75 #include "opt_inet.h"
     76 #include "opt_atalk.h"
     77 #include "opt_ccitt.h"
     78 #include "opt_iso.h"
     79 #include "opt_ns.h"
     80 #include "opt_natm.h"
     81 #include "opt_sysv.h"
     82 
     83 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     84 
     85 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.155 1998/11/19 02:28:56 ross Exp $");
     86 
     87 #include <sys/param.h>
     88 #include <sys/systm.h>
     89 #include <sys/signalvar.h>
     90 #include <sys/kernel.h>
     91 #include <sys/map.h>
     92 #include <sys/proc.h>
     93 #include <sys/buf.h>
     94 #include <sys/reboot.h>
     95 #include <sys/device.h>
     96 #include <sys/file.h>
     97 #ifdef REAL_CLISTS
     98 #include <sys/clist.h>
     99 #endif
    100 #include <sys/callout.h>
    101 #include <sys/malloc.h>
    102 #include <sys/mbuf.h>
    103 #include <sys/mman.h>
    104 #include <sys/msgbuf.h>
    105 #include <sys/ioctl.h>
    106 #include <sys/tty.h>
    107 #include <sys/user.h>
    108 #include <sys/exec.h>
    109 #include <sys/exec_ecoff.h>
    110 #include <vm/vm.h>
    111 #include <sys/sysctl.h>
    112 #include <sys/core.h>
    113 #include <sys/kcore.h>
    114 #include <machine/kcore.h>
    115 #ifdef SYSVMSG
    116 #include <sys/msg.h>
    117 #endif
    118 #ifdef SYSVSEM
    119 #include <sys/sem.h>
    120 #endif
    121 #ifdef SYSVSHM
    122 #include <sys/shm.h>
    123 #endif
    124 
    125 #include <sys/mount.h>
    126 #include <sys/syscallargs.h>
    127 
    128 #include <vm/vm_kern.h>
    129 
    130 #if defined(UVM)
    131 #include <uvm/uvm_extern.h>
    132 #endif
    133 
    134 #include <dev/cons.h>
    135 
    136 #include <machine/autoconf.h>
    137 #include <machine/cpu.h>
    138 #include <machine/reg.h>
    139 #include <machine/rpb.h>
    140 #include <machine/prom.h>
    141 #include <machine/conf.h>
    142 
    143 #include <alpha/alpha/cpuvar.h>
    144 
    145 #include <net/netisr.h>
    146 #include <net/if.h>
    147 
    148 #ifdef INET
    149 #include <net/route.h>
    150 #include <netinet/in.h>
    151 #include <netinet/ip_var.h>
    152 #include "arp.h"
    153 #if NARP > 0
    154 #include <netinet/if_inarp.h>
    155 #endif
    156 #endif
    157 #ifdef NS
    158 #include <netns/ns_var.h>
    159 #endif
    160 #ifdef ISO
    161 #include <netiso/iso.h>
    162 #include <netiso/clnp.h>
    163 #endif
    164 #ifdef CCITT
    165 #include <netccitt/x25.h>
    166 #include <netccitt/pk.h>
    167 #include <netccitt/pk_extern.h>
    168 #endif
    169 #ifdef NATM
    170 #include <netnatm/natm.h>
    171 #endif
    172 #ifdef NETATALK
    173 #include <netatalk/at_extern.h>
    174 #endif
    175 #include "ppp.h"
    176 #if NPPP > 0
    177 #include <net/ppp_defs.h>
    178 #include <net/if_ppp.h>
    179 #endif
    180 
    181 #ifdef DDB
    182 #include <machine/db_machdep.h>
    183 #include <ddb/db_access.h>
    184 #include <ddb/db_sym.h>
    185 #include <ddb/db_extern.h>
    186 #include <ddb/db_interface.h>
    187 #endif
    188 
    189 #include <machine/alpha.h>
    190 #include <machine/intrcnt.h>
    191 
    192 #include "com.h"
    193 #if NCOM > 0
    194 extern void comsoft __P((void));
    195 #endif
    196 
    197 #if defined(UVM)
    198 vm_map_t exec_map = NULL;
    199 vm_map_t mb_map = NULL;
    200 vm_map_t phys_map = NULL;
    201 #else
    202 vm_map_t buffer_map;
    203 #endif
    204 
    205 /*
    206  * Declare these as initialized data so we can patch them.
    207  */
    208 int	nswbuf = 0;
    209 #ifdef	NBUF
    210 int	nbuf = NBUF;
    211 #else
    212 int	nbuf = 0;
    213 #endif
    214 
    215 #ifndef	BUFPAGES
    216 #define BUFPAGES 0
    217 #endif
    218 #ifndef BUFCACHE
    219 #define BUFCACHE 10
    220 #endif
    221 
    222 int	bufpages = BUFPAGES;	/* optional hardwired count */
    223 int	bufcache = BUFCACHE;	/* % of RAM to use for buffer cache */
    224 
    225 caddr_t msgbufaddr;
    226 
    227 int	maxmem;			/* max memory per process */
    228 
    229 int	totalphysmem;		/* total amount of physical memory in system */
    230 int	physmem;		/* physical memory used by NetBSD + some rsvd */
    231 int	resvmem;		/* amount of memory reserved for PROM */
    232 int	unusedmem;		/* amount of memory for OS that we don't use */
    233 int	unknownmem;		/* amount of memory with an unknown use */
    234 
    235 int	cputype;		/* system type, from the RPB */
    236 
    237 /*
    238  * XXX We need an address to which we can assign things so that they
    239  * won't be optimized away because we didn't use the value.
    240  */
    241 u_int32_t no_optimize;
    242 
    243 /* the following is used externally (sysctl_hw) */
    244 char	machine[] = MACHINE;		/* from <machine/param.h> */
    245 char	machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    246 char	cpu_model[128];
    247 
    248 struct	user *proc0paddr;
    249 
    250 /* Number of machine cycles per microsecond */
    251 u_int64_t	cycles_per_usec;
    252 
    253 /* number of cpus in the box.  really! */
    254 int		ncpus;
    255 
    256 /* machine check info array, valloc()'ed in allocsys() */
    257 
    258 static struct mchkinfo startup_info,
    259 			*mchkinfo_all_cpus;
    260 
    261 struct bootinfo_kernel bootinfo;
    262 
    263 /* For built-in TCDS */
    264 #if defined(DEC_3000_300) || defined(DEC_3000_500)
    265 u_int8_t	dec_3000_scsiid[2], dec_3000_scsifast[2];
    266 #endif
    267 
    268 struct platform platform;
    269 
    270 u_int32_t vm_mbuf_size = _VM_MBUF_SIZE;
    271 u_int32_t vm_kmem_size = _VM_KMEM_SIZE;
    272 u_int32_t vm_phys_size = _VM_PHYS_SIZE;
    273 
    274 #ifdef DDB
    275 /* start and end of kernel symbol table */
    276 void	*ksym_start, *ksym_end;
    277 #endif
    278 
    279 /* for cpu_sysctl() */
    280 int	alpha_unaligned_print = 1;	/* warn about unaligned accesses */
    281 int	alpha_unaligned_fix = 1;	/* fix up unaligned accesses */
    282 int	alpha_unaligned_sigbus = 0;	/* don't SIGBUS on fixed-up accesses */
    283 
    284 /*
    285  * XXX This should be dynamically sized, but we have the chicken-egg problem!
    286  * XXX it should also be larger than it is, because not all of the mddt
    287  * XXX clusters end up being used for VM.
    288  */
    289 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];	/* low size bits overloaded */
    290 int	mem_cluster_cnt;
    291 
    292 caddr_t	allocsys __P((caddr_t));
    293 int	cpu_dump __P((void));
    294 int	cpu_dumpsize __P((void));
    295 u_long	cpu_dump_mempagecnt __P((void));
    296 void	dumpsys __P((void));
    297 void	identifycpu __P((void));
    298 void	netintr __P((void));
    299 void	printregs __P((struct reg *));
    300 
    301 void
    302 alpha_init(pfn, ptb, bim, bip, biv)
    303 	u_long pfn;		/* first free PFN number */
    304 	u_long ptb;		/* PFN of current level 1 page table */
    305 	u_long bim;		/* bootinfo magic */
    306 	u_long bip;		/* bootinfo pointer */
    307 	u_long biv;		/* bootinfo version */
    308 {
    309 	extern char kernel_text[], _end[];
    310 	struct mddt *mddtp;
    311 	struct mddt_cluster *memc;
    312 	int i, mddtweird;
    313 	struct vm_physseg *vps;
    314 	vaddr_t kernstart, kernend;
    315 	paddr_t kernstartpfn, kernendpfn, pfn0, pfn1;
    316 	vsize_t size;
    317 	char *p;
    318 	caddr_t v;
    319 	char *bootinfo_msg;
    320 
    321 	/* NO OUTPUT ALLOWED UNTIL FURTHER NOTICE */
    322 
    323 	/*
    324 	 * Turn off interrupts (not mchecks) and floating point.
    325 	 * Make sure the instruction and data streams are consistent.
    326 	 */
    327 	(void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
    328 	alpha_pal_wrfen(0);
    329 	ALPHA_TBIA();
    330 	alpha_pal_imb();
    331 
    332 	/*
    333 	 * Get critical system information (if possible, from the
    334 	 * information provided by the boot program).
    335 	 */
    336 	bootinfo_msg = NULL;
    337 	if (bim == BOOTINFO_MAGIC) {
    338 		if (biv == 0) {		/* backward compat */
    339 			biv = *(u_long *)bip;
    340 			bip += 8;
    341 		}
    342 		switch (biv) {
    343 		case 1: {
    344 			struct bootinfo_v1 *v1p = (struct bootinfo_v1 *)bip;
    345 
    346 			bootinfo.ssym = v1p->ssym;
    347 			bootinfo.esym = v1p->esym;
    348 			/* hwrpb may not be provided by boot block in v1 */
    349 			if (v1p->hwrpb != NULL) {
    350 				bootinfo.hwrpb_phys =
    351 				    ((struct rpb *)v1p->hwrpb)->rpb_phys;
    352 				bootinfo.hwrpb_size = v1p->hwrpbsize;
    353 			} else {
    354 				bootinfo.hwrpb_phys =
    355 				    ((struct rpb *)HWRPB_ADDR)->rpb_phys;
    356 				bootinfo.hwrpb_size =
    357 				    ((struct rpb *)HWRPB_ADDR)->rpb_size;
    358 			}
    359 			bcopy(v1p->boot_flags, bootinfo.boot_flags,
    360 			    min(sizeof v1p->boot_flags,
    361 			      sizeof bootinfo.boot_flags));
    362 			bcopy(v1p->booted_kernel, bootinfo.booted_kernel,
    363 			    min(sizeof v1p->booted_kernel,
    364 			      sizeof bootinfo.booted_kernel));
    365 			/* booted dev not provided in bootinfo */
    366 			init_prom_interface((struct rpb *)
    367 			    ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys));
    368                 	prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
    369 			    sizeof bootinfo.booted_dev);
    370 			break;
    371 		}
    372 		default:
    373 			bootinfo_msg = "unknown bootinfo version";
    374 			goto nobootinfo;
    375 		}
    376 	} else {
    377 		bootinfo_msg = "boot program did not pass bootinfo";
    378 nobootinfo:
    379 		bootinfo.ssym = (u_long)_end;
    380 		bootinfo.esym = (u_long)_end;
    381 		bootinfo.hwrpb_phys = ((struct rpb *)HWRPB_ADDR)->rpb_phys;
    382 		bootinfo.hwrpb_size = ((struct rpb *)HWRPB_ADDR)->rpb_size;
    383 		init_prom_interface((struct rpb *)HWRPB_ADDR);
    384 		prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo.boot_flags,
    385 		    sizeof bootinfo.boot_flags);
    386 		prom_getenv(PROM_E_BOOTED_FILE, bootinfo.booted_kernel,
    387 		    sizeof bootinfo.booted_kernel);
    388 		prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
    389 		    sizeof bootinfo.booted_dev);
    390 	}
    391 
    392 	/*
    393 	 * Initialize the kernel's mapping of the RPB.  It's needed for
    394 	 * lots of things.
    395 	 */
    396 	hwrpb = (struct rpb *)ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys);
    397 
    398 #if defined(DEC_3000_300) || defined(DEC_3000_500)
    399 	if (hwrpb->rpb_type == ST_DEC_3000_300 ||
    400 	    hwrpb->rpb_type == ST_DEC_3000_500) {
    401 		prom_getenv(PROM_E_SCSIID, dec_3000_scsiid,
    402 		    sizeof(dec_3000_scsiid));
    403 		prom_getenv(PROM_E_SCSIFAST, dec_3000_scsifast,
    404 		    sizeof(dec_3000_scsifast));
    405 	}
    406 #endif
    407 
    408 	/*
    409 	 * Remember how many cycles there are per microsecond,
    410 	 * so that we can use delay().  Round up, for safety.
    411 	 */
    412 	cycles_per_usec = (hwrpb->rpb_cc_freq + 999999) / 1000000;
    413 
    414 	/*
    415 	 * Initalize the (temporary) bootstrap console interface, so
    416 	 * we can use printf until the VM system starts being setup.
    417 	 * The real console is initialized before then.
    418 	 */
    419 	init_bootstrap_console();
    420 
    421 	/* OUTPUT NOW ALLOWED */
    422 
    423 	/* delayed from above */
    424 	if (bootinfo_msg)
    425 		printf("WARNING: %s (0x%lx, 0x%lx, 0x%lx)\n",
    426 		    bootinfo_msg, bim, bip, biv);
    427 
    428 	/* Initialize the trap vectors on the primary processor. */
    429 	trap_init();
    430 
    431 	/*
    432 	 * Find out what hardware we're on, and do basic initialization.
    433 	 */
    434 	cputype = hwrpb->rpb_type;
    435 	if (cputype >= ncpuinit) {
    436 		platform_not_supported();
    437 		/* NOTREACHED */
    438 	}
    439 	(*cpuinit[cputype].init)();
    440 	strcpy(cpu_model, platform.model);
    441 
    442 	/*
    443 	 * Initalize the real console, so the the bootstrap console is
    444 	 * no longer necessary.
    445 	 */
    446 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    447 	if (!pmap_uses_prom_console())
    448 #endif
    449 		(*platform.cons_init)();
    450 
    451 #ifdef DIAGNOSTIC
    452 	/* Paranoid sanity checking */
    453 
    454 	/* We should always be running on the the primary. */
    455 	assert(hwrpb->rpb_primary_cpu_id == alpha_pal_whami());
    456 
    457 	/*
    458 	 * On single-CPU systypes, the primary should always be CPU 0,
    459 	 * except on Alpha 8200 systems where the CPU id is related
    460 	 * to the VID, which is related to the Turbo Laser node id.
    461 	 */
    462 	if (cputype != ST_DEC_21000)
    463 		assert(hwrpb->rpb_primary_cpu_id == 0);
    464 #endif
    465 
    466 	/* NO MORE FIRMWARE ACCESS ALLOWED */
    467 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    468 	/*
    469 	 * XXX (unless _PMAP_MAY_USE_PROM_CONSOLE is defined and
    470 	 * XXX pmap_uses_prom_console() evaluates to non-zero.)
    471 	 */
    472 #endif
    473 
    474 	/*
    475 	 * find out this system's page size
    476 	 */
    477 	PAGE_SIZE = hwrpb->rpb_page_size;
    478 	if (PAGE_SIZE != 8192)
    479 		panic("page size %d != 8192?!", PAGE_SIZE);
    480 
    481 	/*
    482 	 * Initialize PAGE_SIZE-dependent variables.
    483 	 */
    484 #if defined(UVM)
    485 	uvm_setpagesize();
    486 #else
    487 	vm_set_page_size();
    488 #endif
    489 
    490 	/*
    491 	 * Find the beginning and end of the kernel (and leave a
    492 	 * bit of space before the beginning for the bootstrap
    493 	 * stack).
    494 	 */
    495 	kernstart = trunc_page(kernel_text) - 2 * PAGE_SIZE;
    496 #ifdef DDB
    497 	ksym_start = (void *)bootinfo.ssym;
    498 	ksym_end   = (void *)bootinfo.esym;
    499 	kernend = (vaddr_t)round_page(ksym_end);
    500 #else
    501 	kernend = (vaddr_t)round_page(_end);
    502 #endif
    503 
    504 	kernstartpfn = atop(ALPHA_K0SEG_TO_PHYS(kernstart));
    505 	kernendpfn = atop(ALPHA_K0SEG_TO_PHYS(kernend));
    506 
    507 	/*
    508 	 * Find out how much memory is available, by looking at
    509 	 * the memory cluster descriptors.  This also tries to do
    510 	 * its best to detect things things that have never been seen
    511 	 * before...
    512 	 */
    513 	mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
    514 
    515 	/* MDDT SANITY CHECKING */
    516 	mddtweird = 0;
    517 	if (mddtp->mddt_cluster_cnt < 2) {
    518 		mddtweird = 1;
    519 		printf("WARNING: weird number of mem clusters: %d\n",
    520 		    mddtp->mddt_cluster_cnt);
    521 	}
    522 
    523 #if 0
    524 	printf("Memory cluster count: %d\n", mddtp->mddt_cluster_cnt);
    525 #endif
    526 
    527 	for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    528 		memc = &mddtp->mddt_clusters[i];
    529 #if 0
    530 		printf("MEMC %d: pfn 0x%lx cnt 0x%lx usage 0x%lx\n", i,
    531 		    memc->mddt_pfn, memc->mddt_pg_cnt, memc->mddt_usage);
    532 #endif
    533 		totalphysmem += memc->mddt_pg_cnt;
    534 		if (mem_cluster_cnt < VM_PHYSSEG_MAX) {	/* XXX */
    535 			mem_clusters[mem_cluster_cnt].start =
    536 			    ptoa(memc->mddt_pfn);
    537 			mem_clusters[mem_cluster_cnt].size =
    538 			    ptoa(memc->mddt_pg_cnt);
    539 			if (memc->mddt_usage & MDDT_mbz ||
    540 			    memc->mddt_usage & MDDT_NONVOLATILE || /* XXX */
    541 			    memc->mddt_usage & MDDT_PALCODE)
    542 				mem_clusters[mem_cluster_cnt].size |=
    543 				    PROT_READ;
    544 			else
    545 				mem_clusters[mem_cluster_cnt].size |=
    546 				    PROT_READ | PROT_WRITE | PROT_EXEC;
    547 			mem_cluster_cnt++;
    548 		}
    549 
    550 		if (memc->mddt_usage & MDDT_mbz) {
    551 			mddtweird = 1;
    552 			printf("WARNING: mem cluster %d has weird "
    553 			    "usage 0x%lx\n", i, memc->mddt_usage);
    554 			unknownmem += memc->mddt_pg_cnt;
    555 			continue;
    556 		}
    557 		if (memc->mddt_usage & MDDT_NONVOLATILE) {
    558 			/* XXX should handle these... */
    559 			printf("WARNING: skipping non-volatile mem "
    560 			    "cluster %d\n", i);
    561 			unusedmem += memc->mddt_pg_cnt;
    562 			continue;
    563 		}
    564 		if (memc->mddt_usage & MDDT_PALCODE) {
    565 			resvmem += memc->mddt_pg_cnt;
    566 			continue;
    567 		}
    568 
    569 		/*
    570 		 * We have a memory cluster available for system
    571 		 * software use.  We must determine if this cluster
    572 		 * holds the kernel.
    573 		 */
    574 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    575 		/*
    576 		 * XXX If the kernel uses the PROM console, we only use the
    577 		 * XXX memory after the kernel in the first system segment,
    578 		 * XXX to avoid clobbering prom mapping, data, etc.
    579 		 */
    580 	    if (!pmap_uses_prom_console() || physmem == 0) {
    581 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
    582 		physmem += memc->mddt_pg_cnt;
    583 		pfn0 = memc->mddt_pfn;
    584 		pfn1 = memc->mddt_pfn + memc->mddt_pg_cnt;
    585 		if (pfn0 <= kernstartpfn && kernendpfn <= pfn1) {
    586 			/*
    587 			 * Must compute the location of the kernel
    588 			 * within the segment.
    589 			 */
    590 #if 0
    591 			printf("Cluster %d contains kernel\n", i);
    592 #endif
    593 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    594 		    if (!pmap_uses_prom_console()) {
    595 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
    596 			if (pfn0 < kernstartpfn) {
    597 				/*
    598 				 * There is a chunk before the kernel.
    599 				 */
    600 #if 0
    601 				printf("Loading chunk before kernel: "
    602 				    "0x%lx / 0x%lx\n", pfn0, kernstartpfn);
    603 #endif
    604 #if defined(UVM)
    605 				uvm_page_physload(pfn0, kernstartpfn,
    606 				    pfn0, kernstartpfn, VM_FREELIST_DEFAULT);
    607 #else
    608 				vm_page_physload(pfn0, kernstartpfn,
    609 				    pfn0, kernstartpfn);
    610 #endif
    611 			}
    612 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    613 		    }
    614 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
    615 			if (kernendpfn < pfn1) {
    616 				/*
    617 				 * There is a chunk after the kernel.
    618 				 */
    619 #if 0
    620 				printf("Loading chunk after kernel: "
    621 				    "0x%lx / 0x%lx\n", kernendpfn, pfn1);
    622 #endif
    623 #if defined(UVM)
    624 				uvm_page_physload(kernendpfn, pfn1,
    625 				    kernendpfn, pfn1, VM_FREELIST_DEFAULT);
    626 #else
    627 				vm_page_physload(kernendpfn, pfn1,
    628 				    kernendpfn, pfn1);
    629 #endif
    630 			}
    631 		} else {
    632 			/*
    633 			 * Just load this cluster as one chunk.
    634 			 */
    635 #if 0
    636 			printf("Loading cluster %d: 0x%lx / 0x%lx\n", i,
    637 			    pfn0, pfn1);
    638 #endif
    639 #if defined(UVM)
    640 			uvm_page_physload(pfn0, pfn1, pfn0, pfn1,
    641 			    VM_FREELIST_DEFAULT);
    642 #else
    643 			vm_page_physload(pfn0, pfn1, pfn0, pfn1);
    644 #endif
    645 		}
    646 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    647 	    }
    648 #endif /* _PMAP_MAY_USE_PROM_CONSOLE */
    649 	}
    650 
    651 	/*
    652 	 * Dump out the MDDT if it looks odd...
    653 	 */
    654 	if (mddtweird) {
    655 		printf("\n");
    656 		printf("complete memory cluster information:\n");
    657 		for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    658 			printf("mddt %d:\n", i);
    659 			printf("\tpfn %lx\n",
    660 			    mddtp->mddt_clusters[i].mddt_pfn);
    661 			printf("\tcnt %lx\n",
    662 			    mddtp->mddt_clusters[i].mddt_pg_cnt);
    663 			printf("\ttest %lx\n",
    664 			    mddtp->mddt_clusters[i].mddt_pg_test);
    665 			printf("\tbva %lx\n",
    666 			    mddtp->mddt_clusters[i].mddt_v_bitaddr);
    667 			printf("\tbpa %lx\n",
    668 			    mddtp->mddt_clusters[i].mddt_p_bitaddr);
    669 			printf("\tbcksum %lx\n",
    670 			    mddtp->mddt_clusters[i].mddt_bit_cksum);
    671 			printf("\tusage %lx\n",
    672 			    mddtp->mddt_clusters[i].mddt_usage);
    673 		}
    674 		printf("\n");
    675 	}
    676 
    677 	if (totalphysmem == 0)
    678 		panic("can't happen: system seems to have no memory!");
    679 
    680 #ifdef LIMITMEM
    681 	/*
    682 	 * XXX Kludge so we can run on machines with memory larger
    683 	 * XXX than 1G until all device drivers are converted to
    684 	 * XXX use bus_dma.  (Relies on the fact that vm_physmem
    685 	 * XXX sorted in order of increasing addresses.)
    686 	 */
    687 	if (vm_physmem[vm_nphysseg - 1].end > atop(LIMITMEM * 1024 * 1024)) {
    688 
    689 		printf("******** LIMITING MEMORY TO %dMB **********\n",
    690 		    LIMITMEM);
    691 
    692 		do {
    693 			u_long ovf;
    694 
    695 			vps = &vm_physmem[vm_nphysseg - 1];
    696 
    697 			if (vps->start >= atop(LIMITMEM * 1024 * 1024)) {
    698 				/*
    699 				 * If the start is too high, just drop
    700 				 * the whole segment.
    701 				 *
    702 				 * XXX can start != avail_start in this
    703 				 * XXX case?  wouldn't that mean that
    704 				 * XXX some memory was stolen above the
    705 				 * XXX limit?  What to do?
    706 				 */
    707 				ovf = vps->end - vps->start;
    708 				vm_nphysseg--;
    709 			} else {
    710 				/*
    711 				 * If the start is OK, calculate how much
    712 				 * to drop and drop it.
    713 				 */
    714 				ovf = vps->end - atop(LIMITMEM * 1024 * 1024);
    715 				vps->end -= ovf;
    716 				vps->avail_end -= ovf;
    717 			}
    718 			physmem -= ovf;
    719 			unusedmem += ovf;
    720 		} while (vps->end > atop(LIMITMEM * 1024 * 1024));
    721 	}
    722 #endif /* LIMITMEM */
    723 
    724 	maxmem = physmem;
    725 
    726 #if 0
    727 	printf("totalphysmem = %d\n", totalphysmem);
    728 	printf("physmem = %d\n", physmem);
    729 	printf("resvmem = %d\n", resvmem);
    730 	printf("unusedmem = %d\n", unusedmem);
    731 	printf("unknownmem = %d\n", unknownmem);
    732 #endif
    733 
    734 	/*
    735 	 * Adjust some parameters if the amount of physmem
    736 	 * available would cause us to croak. This is completely
    737 	 * eyeballed and isn't meant to be the final answer.
    738 	 * vm_phys_size is probably the only one to really worry
    739 	 * about.
    740  	 *
    741 	 * It's for booting a GENERIC kernel on a large memory platform.
    742 	 */
    743 	if (physmem >= atop(128 * 1024 * 1024)) {
    744 		vm_mbuf_size <<= 1;
    745 		vm_kmem_size <<= 3;
    746 		vm_phys_size <<= 2;
    747 	}
    748 
    749 	/*
    750 	 * Initialize error message buffer (at end of core).
    751 	 */
    752 	{
    753 		size_t sz = round_page(MSGBUFSIZE);
    754 
    755 		vps = &vm_physmem[vm_nphysseg - 1];
    756 
    757 		/* shrink so that it'll fit in the last segment */
    758 		if ((vps->avail_end - vps->avail_start) < atop(sz))
    759 			sz = ptoa(vps->avail_end - vps->avail_start);
    760 
    761 		vps->end -= atop(sz);
    762 		vps->avail_end -= atop(sz);
    763 		msgbufaddr = (caddr_t) ALPHA_PHYS_TO_K0SEG(ptoa(vps->end));
    764 		initmsgbuf(msgbufaddr, sz);
    765 
    766 		/* Remove the last segment if it now has no pages. */
    767 		if (vps->start == vps->end)
    768 			vm_nphysseg--;
    769 
    770 		/* warn if the message buffer had to be shrunk */
    771 		if (sz != round_page(MSGBUFSIZE))
    772 			printf("WARNING: %d bytes not available for msgbuf in last cluster (%d used)\n",
    773 			    round_page(MSGBUFSIZE), sz);
    774 
    775 	}
    776 
    777 	/*
    778 	 * Init mapping for u page(s) for proc 0
    779 	 */
    780 	proc0.p_addr = proc0paddr =
    781 	    (struct user *)pmap_steal_memory(UPAGES * PAGE_SIZE, NULL, NULL);
    782 
    783 	/*
    784 	 * Allocate space for system data structures.  These data structures
    785 	 * are allocated here instead of cpu_startup() because physical
    786 	 * memory is directly addressable.  We don't have to map these into
    787 	 * virtual address space.
    788 	 */
    789 	size = (vsize_t)allocsys(0);
    790 	v = (caddr_t)pmap_steal_memory(size, NULL, NULL);
    791 	if ((allocsys(v) - v) != size)
    792 		panic("alpha_init: table size inconsistency");
    793 
    794 	/*
    795 	 * Initialize the virtual memory system, and set the
    796 	 * page table base register in proc 0's PCB.
    797 	 */
    798 	pmap_bootstrap(ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT),
    799 	    hwrpb->rpb_max_asn, hwrpb->rpb_pcs_cnt);
    800 
    801 	/*
    802 	 * Initialize the rest of proc 0's PCB, and cache its physical
    803 	 * address.
    804 	 */
    805 	proc0.p_md.md_pcbpaddr =
    806 	    (struct pcb *)ALPHA_K0SEG_TO_PHYS((vaddr_t)&proc0paddr->u_pcb);
    807 
    808 	/*
    809 	 * Set the kernel sp, reserving space for an (empty) trapframe,
    810 	 * and make proc0's trapframe pointer point to it for sanity.
    811 	 */
    812 	proc0paddr->u_pcb.pcb_hw.apcb_ksp =
    813 	    (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe);
    814 	proc0.p_md.md_tf =
    815 	    (struct trapframe *)proc0paddr->u_pcb.pcb_hw.apcb_ksp;
    816 
    817 	/*
    818 	 * Look at arguments passed to us and compute boothowto.
    819 	 */
    820 
    821 	boothowto = RB_SINGLE;
    822 #ifdef KADB
    823 	boothowto |= RB_KDB;
    824 #endif
    825 	for (p = bootinfo.boot_flags; p && *p != '\0'; p++) {
    826 		/*
    827 		 * Note that we'd really like to differentiate case here,
    828 		 * but the Alpha AXP Architecture Reference Manual
    829 		 * says that we shouldn't.
    830 		 */
    831 		switch (*p) {
    832 		case 'a': /* autoboot */
    833 		case 'A':
    834 			boothowto &= ~RB_SINGLE;
    835 			break;
    836 
    837 #ifdef DEBUG
    838 		case 'c': /* crash dump immediately after autoconfig */
    839 		case 'C':
    840 			boothowto |= RB_DUMP;
    841 			break;
    842 #endif
    843 
    844 #if defined(KGDB) || defined(DDB)
    845 		case 'd': /* break into the kernel debugger ASAP */
    846 		case 'D':
    847 			boothowto |= RB_KDB;
    848 			break;
    849 #endif
    850 
    851 		case 'h': /* always halt, never reboot */
    852 		case 'H':
    853 			boothowto |= RB_HALT;
    854 			break;
    855 
    856 #if 0
    857 		case 'm': /* mini root present in memory */
    858 		case 'M':
    859 			boothowto |= RB_MINIROOT;
    860 			break;
    861 #endif
    862 
    863 		case 'n': /* askname */
    864 		case 'N':
    865 			boothowto |= RB_ASKNAME;
    866 			break;
    867 
    868 		case 's': /* single-user (default, supported for sanity) */
    869 		case 'S':
    870 			boothowto |= RB_SINGLE;
    871 			break;
    872 
    873 		case '-':
    874 			/*
    875 			 * Just ignore this.  It's not required, but it's
    876 			 * common for it to be passed regardless.
    877 			 */
    878 			break;
    879 
    880 		default:
    881 			printf("Unrecognized boot flag '%c'.\n", *p);
    882 			break;
    883 		}
    884 	}
    885 
    886 
    887 	/*
    888 	 * Figure out the number of cpus in the box, from RPB fields.
    889 	 * Really.  We mean it.
    890 	 */
    891 	for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
    892 		struct pcs *pcsp;
    893 
    894 		pcsp = LOCATE_PCS(hwrpb, i);
    895 		if ((pcsp->pcs_flags & PCS_PP) != 0)
    896 			ncpus++;
    897 	}
    898 
    899 	/*
    900 	 * Initialize debuggers, and break into them if appropriate.
    901 	 */
    902 #ifdef DDB
    903 	db_machine_init();
    904 	ddb_init(ksym_start, ksym_end);
    905 	if (boothowto & RB_KDB)
    906 		Debugger();
    907 #endif
    908 #ifdef KGDB
    909 	if (boothowto & RB_KDB)
    910 		kgdb_connect(0);
    911 #endif
    912 	/*
    913 	 * Figure out our clock frequency, from RPB fields.
    914 	 */
    915 	hz = hwrpb->rpb_intr_freq >> 12;
    916 	if (!(60 <= hz && hz <= 10240)) {
    917 		hz = 1024;
    918 #ifdef DIAGNOSTIC
    919 		printf("WARNING: unbelievable rpb_intr_freq: %ld (%d hz)\n",
    920 			hwrpb->rpb_intr_freq, hz);
    921 #endif
    922 	}
    923 }
    924 
    925 /*
    926  * Allocate space for system data structures.  We are given
    927  * a starting virtual address and we return a final virtual
    928  * address; along the way we set each data structure pointer.
    929  *
    930  * We call allocsys() with 0 to find out how much space we want,
    931  * allocate that much and fill it with zeroes, and the call
    932  * allocsys() again with the correct base virtual address.
    933  */
    934 caddr_t
    935 allocsys(v)
    936 	caddr_t v;
    937 {
    938 
    939 #define valloc(name, type, num) \
    940 	    (name) = (type *)v; v = (caddr_t)ALIGN((name)+(num))
    941 
    942 #ifdef REAL_CLISTS
    943 	valloc(cfree, struct cblock, nclist);
    944 #endif
    945 	valloc(callout, struct callout, ncallout);
    946 #ifdef SYSVSHM
    947 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    948 #endif
    949 #ifdef SYSVSEM
    950 	valloc(sema, struct semid_ds, seminfo.semmni);
    951 	valloc(sem, struct sem, seminfo.semmns);
    952 	/* This is pretty disgusting! */
    953 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    954 #endif
    955 #ifdef SYSVMSG
    956 	valloc(msgpool, char, msginfo.msgmax);
    957 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    958 	valloc(msghdrs, struct msg, msginfo.msgtql);
    959 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    960 #endif
    961 
    962 	/*
    963 	 * Determine how many buffers to allocate.
    964 	 * We allocate bufcache % of memory for buffer space.  Insure a
    965 	 * minimum of 16 buffers.  We allocate 1/2 as many swap buffer
    966 	 * headers as file i/o buffers.
    967 	 */
    968 	if (bufpages == 0)
    969 		bufpages = physmem / CLSIZE * bufcache / 100;
    970 	if (nbuf == 0) {
    971 		nbuf = bufpages;
    972 		if (nbuf < 16)
    973 			nbuf = 16;
    974 	}
    975 	if (nswbuf == 0) {
    976 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
    977 		if (nswbuf > 256)
    978 			nswbuf = 256;		/* sanity */
    979 	}
    980 #if !defined(UVM)
    981 	valloc(swbuf, struct buf, nswbuf);
    982 #endif
    983 	valloc(buf, struct buf, nbuf);
    984 
    985 	/*
    986 	 * There appears to be a correlation between the number
    987 	 * of processor slots defined in the HWRPB and the whami
    988 	 * value that can be returned.
    989 	 */
    990 	valloc(mchkinfo_all_cpus, struct mchkinfo, hwrpb->rpb_pcs_cnt);
    991 
    992 	return (v);
    993 #undef valloc
    994 }
    995 
    996 void
    997 consinit()
    998 {
    999 
   1000 	/*
   1001 	 * Everything related to console initialization is done
   1002 	 * in alpha_init().
   1003 	 */
   1004 #if defined(DIAGNOSTIC) && defined(_PMAP_MAY_USE_PROM_CONSOLE)
   1005 	printf("consinit: %susing prom console\n",
   1006 	    pmap_uses_prom_console() ? "" : "not ");
   1007 #endif
   1008 }
   1009 
   1010 #include "pckbc.h"
   1011 #include "pckbd.h"
   1012 #if (NPCKBC > 0) && (NPCKBD == 0)
   1013 
   1014 #include <dev/isa/pckbcvar.h>
   1015 
   1016 /*
   1017  * This is called by the pbkbc driver if no pckbd is configured.
   1018  * On the i386, it is used to glue in the old, deprecated console
   1019  * code.  On the Alpha, it does nothing.
   1020  */
   1021 int
   1022 pckbc_machdep_cnattach(kbctag, kbcslot)
   1023 	pckbc_tag_t kbctag;
   1024 	pckbc_slot_t kbcslot;
   1025 {
   1026 
   1027 	return (ENXIO);
   1028 }
   1029 #endif /* NPCKBC > 0 && NPCKBD == 0 */
   1030 
   1031 void
   1032 cpu_startup()
   1033 {
   1034 	register unsigned i;
   1035 	int base, residual;
   1036 	vaddr_t minaddr, maxaddr;
   1037 	vsize_t size;
   1038 #if defined(DEBUG)
   1039 	extern int pmapdebug;
   1040 	int opmapdebug = pmapdebug;
   1041 
   1042 	pmapdebug = 0;
   1043 #endif
   1044 
   1045 	/*
   1046 	 * Good {morning,afternoon,evening,night}.
   1047 	 */
   1048 	printf(version);
   1049 	identifycpu();
   1050 	printf("real mem = %lu (%lu reserved for PROM, %lu used by NetBSD)\n",
   1051 	    ((psize_t) totalphysmem << (psize_t) PAGE_SHIFT),
   1052 	    ptoa(resvmem), ptoa(physmem));
   1053 	if (unusedmem)
   1054 		printf("WARNING: unused memory = %d bytes\n", ctob(unusedmem));
   1055 	if (unknownmem)
   1056 		printf("WARNING: %d bytes of memory with unknown purpose\n",
   1057 		    ctob(unknownmem));
   1058 
   1059 	/*
   1060 	 * Allocate virtual address space for file I/O buffers.
   1061 	 * Note they are different than the array of headers, 'buf',
   1062 	 * and usually occupy more virtual memory than physical.
   1063 	 */
   1064 	size = MAXBSIZE * nbuf;
   1065 #if defined(UVM)
   1066 	if (uvm_map(kernel_map, (vaddr_t *) &buffers, round_page(size),
   1067 		    NULL, UVM_UNKNOWN_OFFSET,
   1068 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
   1069 				UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
   1070 		panic("startup: cannot allocate VM for buffers");
   1071 #else
   1072 	buffer_map = kmem_suballoc(kernel_map, (vaddr_t *)&buffers,
   1073 	    &maxaddr, size, TRUE);
   1074 	minaddr = (vaddr_t)buffers;
   1075 	if (vm_map_find(buffer_map, vm_object_allocate(size), (vaddr_t)0,
   1076 			&minaddr, size, FALSE) != KERN_SUCCESS)
   1077 		panic("startup: cannot allocate buffers");
   1078 #endif /* UVM */
   1079 	base = bufpages / nbuf;
   1080 	residual = bufpages % nbuf;
   1081 	for (i = 0; i < nbuf; i++) {
   1082 #if defined(UVM)
   1083 		vsize_t curbufsize;
   1084 		vaddr_t curbuf;
   1085 		struct vm_page *pg;
   1086 
   1087 		/*
   1088 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
   1089 		 * that MAXBSIZE space, we allocate and map (base+1) pages
   1090 		 * for the first "residual" buffers, and then we allocate
   1091 		 * "base" pages for the rest.
   1092 		 */
   1093 		curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
   1094 		curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
   1095 
   1096 		while (curbufsize) {
   1097 			pg = uvm_pagealloc(NULL, 0, NULL);
   1098 			if (pg == NULL)
   1099 				panic("cpu_startup: not enough memory for "
   1100 				    "buffer cache");
   1101 #if defined(PMAP_NEW)
   1102 			pmap_kenter_pgs(curbuf, &pg, 1);
   1103 #else
   1104 			pmap_enter(kernel_map->pmap, curbuf,
   1105 				   VM_PAGE_TO_PHYS(pg), VM_PROT_ALL, TRUE);
   1106 #endif
   1107 			curbuf += PAGE_SIZE;
   1108 			curbufsize -= PAGE_SIZE;
   1109 		}
   1110 #else /* ! UVM */
   1111 		vsize_t curbufsize;
   1112 		vaddr_t curbuf;
   1113 
   1114 		/*
   1115 		 * First <residual> buffers get (base+1) physical pages
   1116 		 * allocated for them.  The rest get (base) physical pages.
   1117 		 *
   1118 		 * The rest of each buffer occupies virtual space,
   1119 		 * but has no physical memory allocated for it.
   1120 		 */
   1121 		curbuf = (vaddr_t)buffers + i * MAXBSIZE;
   1122 		curbufsize = CLBYTES * (i < residual ? base+1 : base);
   1123 		vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
   1124 		vm_map_simplify(buffer_map, curbuf);
   1125 #endif /* UVM */
   1126 	}
   1127 	/*
   1128 	 * Allocate a submap for exec arguments.  This map effectively
   1129 	 * limits the number of processes exec'ing at any time.
   1130 	 */
   1131 #if defined(UVM)
   1132 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
   1133 				   16 * NCARGS, TRUE, FALSE, NULL);
   1134 #else
   1135 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
   1136 				 16 * NCARGS, TRUE);
   1137 #endif
   1138 
   1139 	/*
   1140 	 * Allocate a submap for physio
   1141 	 */
   1142 #if defined(UVM)
   1143 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
   1144 				   VM_PHYS_SIZE, TRUE, FALSE, NULL);
   1145 #else
   1146 	phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
   1147 				 VM_PHYS_SIZE, TRUE);
   1148 #endif
   1149 
   1150 	/*
   1151 	 * Finally, allocate mbuf cluster submap.
   1152 	 */
   1153 #if defined(UVM)
   1154 	mb_map = uvm_km_suballoc(kernel_map, (vaddr_t *)&mbutl, &maxaddr,
   1155 				 VM_MBUF_SIZE, FALSE, FALSE, NULL);
   1156 #else
   1157 	mb_map = kmem_suballoc(kernel_map, (vaddr_t *)&mbutl, &maxaddr,
   1158 			       VM_MBUF_SIZE, FALSE);
   1159 #endif
   1160 	/*
   1161 	 * Initialize callouts
   1162 	 */
   1163 	callfree = callout;
   1164 	for (i = 1; i < ncallout; i++)
   1165 		callout[i-1].c_next = &callout[i];
   1166 	callout[i-1].c_next = NULL;
   1167 
   1168 #if defined(DEBUG)
   1169 	pmapdebug = opmapdebug;
   1170 #endif
   1171 #if defined(UVM)
   1172 	printf("avail mem = %ld\n", (long)ptoa(uvmexp.free));
   1173 #else
   1174 	printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
   1175 #endif
   1176 #if 0
   1177 	{
   1178 		extern u_long pmap_pages_stolen;
   1179 		printf("stolen memory for VM structures = %ld bytes\n",
   1180 		    pmap_pages_stolen * PAGE_SIZE);
   1181 	}
   1182 #endif
   1183 	printf("using %ld buffers containing %ld bytes of memory\n",
   1184 		(long)nbuf, (long)(bufpages * CLBYTES));
   1185 
   1186 	/*
   1187 	 * Set up buffers, so they can be used to read disk labels.
   1188 	 */
   1189 	bufinit();
   1190 
   1191 	/*
   1192 	 * Set up the HWPCB so that it's safe to configure secondary
   1193 	 * CPUs.
   1194 	 */
   1195 	hwrpb_primary_init();
   1196 
   1197 	/*
   1198 	 * Configure the system.
   1199 	 */
   1200 	configure();
   1201 }
   1202 
   1203 /*
   1204  * Retrieve the platform name from the DSR.
   1205  */
   1206 const char *
   1207 alpha_dsr_sysname()
   1208 {
   1209 	struct dsrdb *dsr;
   1210 	const char *sysname;
   1211 
   1212 	/*
   1213 	 * DSR does not exist on early HWRPB versions.
   1214 	 */
   1215 	if (hwrpb->rpb_version < HWRPB_DSRDB_MINVERS)
   1216 		return (NULL);
   1217 
   1218 	dsr = (struct dsrdb *)(((caddr_t)hwrpb) + hwrpb->rpb_dsrdb_off);
   1219 	sysname = (const char *)((caddr_t)dsr + (dsr->dsr_sysname_off +
   1220 	    sizeof(u_int64_t)));
   1221 	return (sysname);
   1222 }
   1223 
   1224 /*
   1225  * Lookup the system specified system variation in the provided table,
   1226  * returning the model string on match.
   1227  */
   1228 const char *
   1229 alpha_variation_name(variation, avtp)
   1230 	u_int64_t variation;
   1231 	const struct alpha_variation_table *avtp;
   1232 {
   1233 	int i;
   1234 
   1235 	for (i = 0; avtp[i].avt_model != NULL; i++)
   1236 		if (avtp[i].avt_variation == variation)
   1237 			return (avtp[i].avt_model);
   1238 	return (NULL);
   1239 }
   1240 
   1241 /*
   1242  * Generate a default platform name based for unknown system variations.
   1243  */
   1244 const char *
   1245 alpha_unknown_sysname()
   1246 {
   1247 	static char s[128];		/* safe size */
   1248 
   1249 	sprintf(s, "%s family, unknown model variation 0x%lx",
   1250 	    platform.family, hwrpb->rpb_variation & SV_ST_MASK);
   1251 	return ((const char *)s);
   1252 }
   1253 
   1254 void
   1255 identifycpu()
   1256 {
   1257 
   1258 	/*
   1259 	 * print out CPU identification information.
   1260 	 */
   1261 	printf("%s, %ldMHz\n", cpu_model,
   1262 	    hwrpb->rpb_cc_freq / 1000000);	/* XXX true for 21164? */
   1263 	printf("%ld byte page size, %d processor%s.\n",
   1264 	    hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
   1265 #if 0
   1266 	/* this isn't defined for any systems that we run on? */
   1267 	printf("serial number 0x%lx 0x%lx\n",
   1268 	    ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
   1269 
   1270 	/* and these aren't particularly useful! */
   1271 	printf("variation: 0x%lx, revision 0x%lx\n",
   1272 	    hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
   1273 #endif
   1274 }
   1275 
   1276 int	waittime = -1;
   1277 struct pcb dumppcb;
   1278 
   1279 void
   1280 cpu_reboot(howto, bootstr)
   1281 	int howto;
   1282 	char *bootstr;
   1283 {
   1284 	extern int cold;
   1285 #if defined(MULTIPROCESSOR)
   1286 #if 0 /* XXX See below. */
   1287 	u_long cpu_id;
   1288 #endif
   1289 #endif
   1290 
   1291 #if defined(MULTIPROCESSOR)
   1292 	/* We must be running on the primary CPU. */
   1293 	if (alpha_pal_whami() != hwrpb->rpb_primary_cpu_id)
   1294 		panic("cpu_reboot: not on primary CPU!");
   1295 #endif
   1296 
   1297 	/* If system is cold, just halt. */
   1298 	if (cold) {
   1299 		howto |= RB_HALT;
   1300 		goto haltsys;
   1301 	}
   1302 
   1303 	/* If "always halt" was specified as a boot flag, obey. */
   1304 	if ((boothowto & RB_HALT) != 0)
   1305 		howto |= RB_HALT;
   1306 
   1307 	boothowto = howto;
   1308 	if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
   1309 		waittime = 0;
   1310 		vfs_shutdown();
   1311 		/*
   1312 		 * If we've been adjusting the clock, the todr
   1313 		 * will be out of synch; adjust it now.
   1314 		 */
   1315 		resettodr();
   1316 	}
   1317 
   1318 	/* Disable interrupts. */
   1319 	splhigh();
   1320 
   1321 	/* If rebooting and a dump is requested do it. */
   1322 #if 0
   1323 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
   1324 #else
   1325 	if (howto & RB_DUMP)
   1326 #endif
   1327 		dumpsys();
   1328 
   1329 haltsys:
   1330 
   1331 	/* run any shutdown hooks */
   1332 	doshutdownhooks();
   1333 
   1334 #if defined(MULTIPROCESSOR)
   1335 #if 0 /* XXX doesn't work when called from here?! */
   1336 	/* Kill off any secondary CPUs. */
   1337 	for (cpu_id = 0; cpu_id < hwrpb->rpb_pcs_cnt; cpu_id++) {
   1338 		if (cpu_id == hwrpb->rpb_primary_cpu_id ||
   1339 		    cpus[cpu_id] == NULL)
   1340 			continue;
   1341 		cpu_halt_secondary(cpu_id);
   1342 	}
   1343 #endif
   1344 #endif
   1345 
   1346 #ifdef BOOTKEY
   1347 	printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
   1348 	cnpollc(1);	/* for proper keyboard command handling */
   1349 	cngetc();
   1350 	cnpollc(0);
   1351 	printf("\n");
   1352 #endif
   1353 
   1354 	/* Finally, powerdown/halt/reboot the system. */
   1355 	if ((howto && RB_POWERDOWN) == RB_POWERDOWN &&
   1356 	    platform.powerdown != NULL) {
   1357 		(*platform.powerdown)();
   1358 		printf("WARNING: powerdown failed!\n");
   1359 	}
   1360 	printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
   1361 	prom_halt(howto & RB_HALT);
   1362 	/*NOTREACHED*/
   1363 }
   1364 
   1365 /*
   1366  * These variables are needed by /sbin/savecore
   1367  */
   1368 u_long	dumpmag = 0x8fca0101;	/* magic number */
   1369 int 	dumpsize = 0;		/* pages */
   1370 long	dumplo = 0; 		/* blocks */
   1371 
   1372 /*
   1373  * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
   1374  */
   1375 int
   1376 cpu_dumpsize()
   1377 {
   1378 	int size;
   1379 
   1380 	size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) +
   1381 	    ALIGN(mem_cluster_cnt * sizeof(phys_ram_seg_t));
   1382 	if (roundup(size, dbtob(1)) != dbtob(1))
   1383 		return -1;
   1384 
   1385 	return (1);
   1386 }
   1387 
   1388 /*
   1389  * cpu_dump_mempagecnt: calculate size of RAM (in pages) to be dumped.
   1390  */
   1391 u_long
   1392 cpu_dump_mempagecnt()
   1393 {
   1394 	u_long i, n;
   1395 
   1396 	n = 0;
   1397 	for (i = 0; i < mem_cluster_cnt; i++)
   1398 		n += atop(mem_clusters[i].size);
   1399 	return (n);
   1400 }
   1401 
   1402 /*
   1403  * cpu_dump: dump machine-dependent kernel core dump headers.
   1404  */
   1405 int
   1406 cpu_dump()
   1407 {
   1408 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1409 	char buf[dbtob(1)];
   1410 	kcore_seg_t *segp;
   1411 	cpu_kcore_hdr_t *cpuhdrp;
   1412 	phys_ram_seg_t *memsegp;
   1413 	int i;
   1414 
   1415 	dump = bdevsw[major(dumpdev)].d_dump;
   1416 
   1417 	bzero(buf, sizeof buf);
   1418 	segp = (kcore_seg_t *)buf;
   1419 	cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))];
   1420 	memsegp = (phys_ram_seg_t *)&buf[ ALIGN(sizeof(*segp)) +
   1421 	    ALIGN(sizeof(*cpuhdrp))];
   1422 
   1423 	/*
   1424 	 * Generate a segment header.
   1425 	 */
   1426 	CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
   1427 	segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
   1428 
   1429 	/*
   1430 	 * Add the machine-dependent header info.
   1431 	 */
   1432 	cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vaddr_t)kernel_lev1map);
   1433 	cpuhdrp->page_size = PAGE_SIZE;
   1434 	cpuhdrp->nmemsegs = mem_cluster_cnt;
   1435 
   1436 	/*
   1437 	 * Fill in the memory segment descriptors.
   1438 	 */
   1439 	for (i = 0; i < mem_cluster_cnt; i++) {
   1440 		memsegp[i].start = mem_clusters[i].start;
   1441 		memsegp[i].size = mem_clusters[i].size & ~PAGE_MASK;
   1442 	}
   1443 
   1444 	return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1)));
   1445 }
   1446 
   1447 /*
   1448  * This is called by main to set dumplo and dumpsize.
   1449  * Dumps always skip the first CLBYTES of disk space
   1450  * in case there might be a disk label stored there.
   1451  * If there is extra space, put dump at the end to
   1452  * reduce the chance that swapping trashes it.
   1453  */
   1454 void
   1455 cpu_dumpconf()
   1456 {
   1457 	int nblks, dumpblks;	/* size of dump area */
   1458 	int maj;
   1459 
   1460 	if (dumpdev == NODEV)
   1461 		goto bad;
   1462 	maj = major(dumpdev);
   1463 	if (maj < 0 || maj >= nblkdev)
   1464 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
   1465 	if (bdevsw[maj].d_psize == NULL)
   1466 		goto bad;
   1467 	nblks = (*bdevsw[maj].d_psize)(dumpdev);
   1468 	if (nblks <= ctod(1))
   1469 		goto bad;
   1470 
   1471 	dumpblks = cpu_dumpsize();
   1472 	if (dumpblks < 0)
   1473 		goto bad;
   1474 	dumpblks += ctod(cpu_dump_mempagecnt());
   1475 
   1476 	/* If dump won't fit (incl. room for possible label), punt. */
   1477 	if (dumpblks > (nblks - ctod(1)))
   1478 		goto bad;
   1479 
   1480 	/* Put dump at end of partition */
   1481 	dumplo = nblks - dumpblks;
   1482 
   1483 	/* dumpsize is in page units, and doesn't include headers. */
   1484 	dumpsize = cpu_dump_mempagecnt();
   1485 	return;
   1486 
   1487 bad:
   1488 	dumpsize = 0;
   1489 	return;
   1490 }
   1491 
   1492 /*
   1493  * Dump the kernel's image to the swap partition.
   1494  */
   1495 #define	BYTES_PER_DUMP	NBPG
   1496 
   1497 void
   1498 dumpsys()
   1499 {
   1500 	u_long totalbytesleft, bytes, i, n, memcl;
   1501 	u_long maddr;
   1502 	int psize;
   1503 	daddr_t blkno;
   1504 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1505 	int error;
   1506 
   1507 	/* Save registers. */
   1508 	savectx(&dumppcb);
   1509 
   1510 	msgbufenabled = 0;	/* don't record dump msgs in msgbuf */
   1511 	if (dumpdev == NODEV)
   1512 		return;
   1513 
   1514 	/*
   1515 	 * For dumps during autoconfiguration,
   1516 	 * if dump device has already configured...
   1517 	 */
   1518 	if (dumpsize == 0)
   1519 		cpu_dumpconf();
   1520 	if (dumplo <= 0) {
   1521 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
   1522 		    minor(dumpdev));
   1523 		return;
   1524 	}
   1525 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
   1526 	    minor(dumpdev), dumplo);
   1527 
   1528 	psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
   1529 	printf("dump ");
   1530 	if (psize == -1) {
   1531 		printf("area unavailable\n");
   1532 		return;
   1533 	}
   1534 
   1535 	/* XXX should purge all outstanding keystrokes. */
   1536 
   1537 	if ((error = cpu_dump()) != 0)
   1538 		goto err;
   1539 
   1540 	totalbytesleft = ptoa(cpu_dump_mempagecnt());
   1541 	blkno = dumplo + cpu_dumpsize();
   1542 	dump = bdevsw[major(dumpdev)].d_dump;
   1543 	error = 0;
   1544 
   1545 	for (memcl = 0; memcl < mem_cluster_cnt; memcl++) {
   1546 		maddr = mem_clusters[memcl].start;
   1547 		bytes = mem_clusters[memcl].size & ~PAGE_MASK;
   1548 
   1549 		for (i = 0; i < bytes; i += n, totalbytesleft -= n) {
   1550 
   1551 			/* Print out how many MBs we to go. */
   1552 			if ((totalbytesleft % (1024*1024)) == 0)
   1553 				printf("%d ", totalbytesleft / (1024 * 1024));
   1554 
   1555 			/* Limit size for next transfer. */
   1556 			n = bytes - i;
   1557 			if (n > BYTES_PER_DUMP)
   1558 				n =  BYTES_PER_DUMP;
   1559 
   1560 			error = (*dump)(dumpdev, blkno,
   1561 			    (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n);
   1562 			if (error)
   1563 				goto err;
   1564 			maddr += n;
   1565 			blkno += btodb(n);			/* XXX? */
   1566 
   1567 			/* XXX should look for keystrokes, to cancel. */
   1568 		}
   1569 	}
   1570 
   1571 err:
   1572 	switch (error) {
   1573 
   1574 	case ENXIO:
   1575 		printf("device bad\n");
   1576 		break;
   1577 
   1578 	case EFAULT:
   1579 		printf("device not ready\n");
   1580 		break;
   1581 
   1582 	case EINVAL:
   1583 		printf("area improper\n");
   1584 		break;
   1585 
   1586 	case EIO:
   1587 		printf("i/o error\n");
   1588 		break;
   1589 
   1590 	case EINTR:
   1591 		printf("aborted from console\n");
   1592 		break;
   1593 
   1594 	case 0:
   1595 		printf("succeeded\n");
   1596 		break;
   1597 
   1598 	default:
   1599 		printf("error %d\n", error);
   1600 		break;
   1601 	}
   1602 	printf("\n\n");
   1603 	delay(1000);
   1604 }
   1605 
   1606 void
   1607 frametoreg(framep, regp)
   1608 	struct trapframe *framep;
   1609 	struct reg *regp;
   1610 {
   1611 
   1612 	regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
   1613 	regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
   1614 	regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
   1615 	regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
   1616 	regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
   1617 	regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
   1618 	regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
   1619 	regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
   1620 	regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
   1621 	regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
   1622 	regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
   1623 	regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
   1624 	regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
   1625 	regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
   1626 	regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
   1627 	regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
   1628 	regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0];
   1629 	regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1];
   1630 	regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2];
   1631 	regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
   1632 	regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
   1633 	regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
   1634 	regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
   1635 	regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
   1636 	regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
   1637 	regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
   1638 	regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
   1639 	regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
   1640 	regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
   1641 	regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP];
   1642 	/* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */
   1643 	regp->r_regs[R_ZERO] = 0;
   1644 }
   1645 
   1646 void
   1647 regtoframe(regp, framep)
   1648 	struct reg *regp;
   1649 	struct trapframe *framep;
   1650 {
   1651 
   1652 	framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
   1653 	framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
   1654 	framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
   1655 	framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
   1656 	framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
   1657 	framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
   1658 	framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
   1659 	framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
   1660 	framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
   1661 	framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
   1662 	framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
   1663 	framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
   1664 	framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
   1665 	framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
   1666 	framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
   1667 	framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
   1668 	framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0];
   1669 	framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1];
   1670 	framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2];
   1671 	framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
   1672 	framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
   1673 	framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
   1674 	framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
   1675 	framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
   1676 	framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
   1677 	framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
   1678 	framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
   1679 	framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
   1680 	framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
   1681 	framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP];
   1682 	/* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */
   1683 	/* ??? = regp->r_regs[R_ZERO]; */
   1684 }
   1685 
   1686 void
   1687 printregs(regp)
   1688 	struct reg *regp;
   1689 {
   1690 	int i;
   1691 
   1692 	for (i = 0; i < 32; i++)
   1693 		printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
   1694 		   i & 1 ? "\n" : "\t");
   1695 }
   1696 
   1697 void
   1698 regdump(framep)
   1699 	struct trapframe *framep;
   1700 {
   1701 	struct reg reg;
   1702 
   1703 	frametoreg(framep, &reg);
   1704 	reg.r_regs[R_SP] = alpha_pal_rdusp();
   1705 
   1706 	printf("REGISTERS:\n");
   1707 	printregs(&reg);
   1708 }
   1709 
   1710 #ifdef DEBUG
   1711 int sigdebug = 0;
   1712 int sigpid = 0;
   1713 #define	SDB_FOLLOW	0x01
   1714 #define	SDB_KSTACK	0x02
   1715 #endif
   1716 
   1717 /*
   1718  * Send an interrupt to process.
   1719  */
   1720 void
   1721 sendsig(catcher, sig, mask, code)
   1722 	sig_t catcher;
   1723 	int sig;
   1724 	sigset_t *mask;
   1725 	u_long code;
   1726 {
   1727 	struct proc *p = curproc;
   1728 	struct sigcontext *scp, ksc;
   1729 	struct trapframe *frame;
   1730 	struct sigacts *psp = p->p_sigacts;
   1731 	int onstack, fsize, rndfsize;
   1732 	extern struct proc *fpcurproc;
   1733 
   1734 	frame = p->p_md.md_tf;
   1735 
   1736 	/* Do we need to jump onto the signal stack? */
   1737 	onstack =
   1738 	    (psp->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
   1739 	    (psp->ps_sigact[sig].sa_flags & SA_ONSTACK) != 0;
   1740 
   1741 	/* Allocate space for the signal handler context. */
   1742 	fsize = sizeof(ksc);
   1743 	rndfsize = ((fsize + 15) / 16) * 16;
   1744 
   1745 	if (onstack)
   1746 		scp = (struct sigcontext *)((caddr_t)psp->ps_sigstk.ss_sp +
   1747 						     psp->ps_sigstk.ss_size);
   1748 	else
   1749 		scp = (struct sigcontext *)(alpha_pal_rdusp());
   1750 	scp = (struct sigcontext *)((caddr_t)scp - rndfsize);
   1751 
   1752 #ifdef DEBUG
   1753 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1754 		printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
   1755 		    sig, &onstack, scp);
   1756 #endif
   1757 
   1758 	/* Build stack frame for signal trampoline. */
   1759 	ksc.sc_pc = frame->tf_regs[FRAME_PC];
   1760 	ksc.sc_ps = frame->tf_regs[FRAME_PS];
   1761 
   1762 	/* Save register context. */
   1763 	frametoreg(frame, (struct reg *)ksc.sc_regs);
   1764 	ksc.sc_regs[R_ZERO] = 0xACEDBADE;		/* magic number */
   1765 	ksc.sc_regs[R_SP] = alpha_pal_rdusp();
   1766 
   1767 	/* save the floating-point state, if necessary, then copy it. */
   1768 	if (p == fpcurproc) {
   1769 		alpha_pal_wrfen(1);
   1770 		savefpstate(&p->p_addr->u_pcb.pcb_fp);
   1771 		alpha_pal_wrfen(0);
   1772 		fpcurproc = NULL;
   1773 	}
   1774 	ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
   1775 	bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
   1776 	    sizeof(struct fpreg));
   1777 	ksc.sc_fp_control = 0;					/* XXX ? */
   1778 	bzero(ksc.sc_reserved, sizeof ksc.sc_reserved);		/* XXX */
   1779 	bzero(ksc.sc_xxx, sizeof ksc.sc_xxx);			/* XXX */
   1780 
   1781 	/* Save signal stack. */
   1782 	ksc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
   1783 
   1784 	/* Save signal mask. */
   1785 	ksc.sc_mask = *mask;
   1786 
   1787 #ifdef COMPAT_13
   1788 	/*
   1789 	 * XXX We always have to save an old style signal mask because
   1790 	 * XXX we might be delivering a signal to a process which will
   1791 	 * XXX escape from the signal in a non-standard way and invoke
   1792 	 * XXX sigreturn() directly.
   1793 	 */
   1794 	{
   1795 		/* Note: it's a long in the stack frame. */
   1796 		sigset13_t mask13;
   1797 
   1798 		native_sigset_to_sigset13(mask, &mask13);
   1799 		ksc.__sc_mask13 = mask13;
   1800 	}
   1801 #endif
   1802 
   1803 #ifdef COMPAT_OSF1
   1804 	/*
   1805 	 * XXX Create an OSF/1-style sigcontext and associated goo.
   1806 	 */
   1807 #endif
   1808 
   1809 	if (copyout(&ksc, (caddr_t)scp, fsize) != 0) {
   1810 		/*
   1811 		 * Process has trashed its stack; give it an illegal
   1812 		 * instruction to halt it in its tracks.
   1813 		 */
   1814 #ifdef DEBUG
   1815 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1816 			printf("sendsig(%d): copyout failed on sig %d\n",
   1817 			    p->p_pid, sig);
   1818 #endif
   1819 		sigexit(p, SIGILL);
   1820 		/* NOTREACHED */
   1821 	}
   1822 #ifdef DEBUG
   1823 	if (sigdebug & SDB_FOLLOW)
   1824 		printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig,
   1825 		    scp, code);
   1826 #endif
   1827 
   1828 	/* Set up the registers to return to sigcode. */
   1829 	frame->tf_regs[FRAME_PC] = (u_int64_t)psp->ps_sigcode;
   1830 	frame->tf_regs[FRAME_A0] = sig;
   1831 	frame->tf_regs[FRAME_A1] = code;
   1832 	frame->tf_regs[FRAME_A2] = (u_int64_t)scp;
   1833 	frame->tf_regs[FRAME_T12] = (u_int64_t)catcher;		/* t12 is pv */
   1834 	alpha_pal_wrusp((unsigned long)scp);
   1835 
   1836 	/* Remember that we're now on the signal stack. */
   1837 	if (onstack)
   1838 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
   1839 
   1840 #ifdef DEBUG
   1841 	if (sigdebug & SDB_FOLLOW)
   1842 		printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
   1843 		    frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]);
   1844 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1845 		printf("sendsig(%d): sig %d returns\n",
   1846 		    p->p_pid, sig);
   1847 #endif
   1848 }
   1849 
   1850 /*
   1851  * System call to cleanup state after a signal
   1852  * has been taken.  Reset signal mask and
   1853  * stack state from context left by sendsig (above).
   1854  * Return to previous pc and psl as specified by
   1855  * context left by sendsig. Check carefully to
   1856  * make sure that the user has not modified the
   1857  * psl to gain improper priviledges or to cause
   1858  * a machine fault.
   1859  */
   1860 /* ARGSUSED */
   1861 int
   1862 sys___sigreturn14(p, v, retval)
   1863 	struct proc *p;
   1864 	void *v;
   1865 	register_t *retval;
   1866 {
   1867 	struct sys___sigreturn14_args /* {
   1868 		syscallarg(struct sigcontext *) sigcntxp;
   1869 	} */ *uap = v;
   1870 	struct sigcontext *scp, ksc;
   1871 	extern struct proc *fpcurproc;
   1872 
   1873 	/*
   1874 	 * The trampoline code hands us the context.
   1875 	 * It is unsafe to keep track of it ourselves, in the event that a
   1876 	 * program jumps out of a signal handler.
   1877 	 */
   1878 	scp = SCARG(uap, sigcntxp);
   1879 #ifdef DEBUG
   1880 	if (sigdebug & SDB_FOLLOW)
   1881 	    printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
   1882 #endif
   1883 	if (ALIGN(scp) != (u_int64_t)scp)
   1884 		return (EINVAL);
   1885 
   1886 	if (copyin((caddr_t)scp, &ksc, sizeof(ksc)) != 0)
   1887 		return (EFAULT);
   1888 
   1889 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
   1890 		return (EINVAL);
   1891 
   1892 	/* Restore register context. */
   1893 	p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
   1894 	p->p_md.md_tf->tf_regs[FRAME_PS] =
   1895 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
   1896 
   1897 	regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
   1898 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
   1899 
   1900 	/* XXX ksc.sc_ownedfp ? */
   1901 	if (p == fpcurproc)
   1902 		fpcurproc = NULL;
   1903 	bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
   1904 	    sizeof(struct fpreg));
   1905 	/* XXX ksc.sc_fp_control ? */
   1906 
   1907 	/* Restore signal stack. */
   1908 	if (ksc.sc_onstack & SS_ONSTACK)
   1909 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
   1910 	else
   1911 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
   1912 
   1913 	/* Restore signal mask. */
   1914 	(void) sigprocmask1(p, SIG_SETMASK, &ksc.sc_mask, 0);
   1915 
   1916 #ifdef DEBUG
   1917 	if (sigdebug & SDB_FOLLOW)
   1918 		printf("sigreturn(%d): returns\n", p->p_pid);
   1919 #endif
   1920 	return (EJUSTRETURN);
   1921 }
   1922 
   1923 /*
   1924  * machine dependent system variables.
   1925  */
   1926 int
   1927 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
   1928 	int *name;
   1929 	u_int namelen;
   1930 	void *oldp;
   1931 	size_t *oldlenp;
   1932 	void *newp;
   1933 	size_t newlen;
   1934 	struct proc *p;
   1935 {
   1936 	dev_t consdev;
   1937 
   1938 	/* all sysctl names at this level are terminal */
   1939 	if (namelen != 1)
   1940 		return (ENOTDIR);		/* overloaded */
   1941 
   1942 	switch (name[0]) {
   1943 	case CPU_CONSDEV:
   1944 		if (cn_tab != NULL)
   1945 			consdev = cn_tab->cn_dev;
   1946 		else
   1947 			consdev = NODEV;
   1948 		return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
   1949 			sizeof consdev));
   1950 
   1951 	case CPU_ROOT_DEVICE:
   1952 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1953 		    root_device->dv_xname));
   1954 
   1955 	case CPU_UNALIGNED_PRINT:
   1956 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1957 		    &alpha_unaligned_print));
   1958 
   1959 	case CPU_UNALIGNED_FIX:
   1960 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1961 		    &alpha_unaligned_fix));
   1962 
   1963 	case CPU_UNALIGNED_SIGBUS:
   1964 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1965 		    &alpha_unaligned_sigbus));
   1966 
   1967 	case CPU_BOOTED_KERNEL:
   1968 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1969 		    bootinfo.booted_kernel));
   1970 
   1971 	default:
   1972 		return (EOPNOTSUPP);
   1973 	}
   1974 	/* NOTREACHED */
   1975 }
   1976 
   1977 /*
   1978  * Set registers on exec.
   1979  */
   1980 void
   1981 setregs(p, pack, stack)
   1982 	register struct proc *p;
   1983 	struct exec_package *pack;
   1984 	u_long stack;
   1985 {
   1986 	struct trapframe *tfp = p->p_md.md_tf;
   1987 	extern struct proc *fpcurproc;
   1988 #ifdef DEBUG
   1989 	int i;
   1990 #endif
   1991 
   1992 #ifdef DEBUG
   1993 	/*
   1994 	 * Crash and dump, if the user requested it.
   1995 	 */
   1996 	if (boothowto & RB_DUMP)
   1997 		panic("crash requested by boot flags");
   1998 #endif
   1999 
   2000 #ifdef DEBUG
   2001 	for (i = 0; i < FRAME_SIZE; i++)
   2002 		tfp->tf_regs[i] = 0xbabefacedeadbeef;
   2003 #else
   2004 	bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]);
   2005 #endif
   2006 	bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
   2007 #define FP_RN 2 /* XXX */
   2008 	p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
   2009 	alpha_pal_wrusp(stack);
   2010 	tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET;
   2011 	tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3;
   2012 
   2013 	tfp->tf_regs[FRAME_A0] = stack;			/* a0 = sp */
   2014 	tfp->tf_regs[FRAME_A1] = 0;			/* a1 = rtld cleanup */
   2015 	tfp->tf_regs[FRAME_A2] = 0;			/* a2 = rtld object */
   2016 	tfp->tf_regs[FRAME_A3] = (u_int64_t)PS_STRINGS;	/* a3 = ps_strings */
   2017 	tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC];	/* a.k.a. PV */
   2018 
   2019 	p->p_md.md_flags &= ~MDP_FPUSED;
   2020 	if (fpcurproc == p)
   2021 		fpcurproc = NULL;
   2022 }
   2023 
   2024 void
   2025 netintr()
   2026 {
   2027 	int n, s;
   2028 
   2029 	s = splhigh();
   2030 	n = netisr;
   2031 	netisr = 0;
   2032 	splx(s);
   2033 
   2034 #define	DONETISR(bit, fn)						\
   2035 	do {								\
   2036 		if (n & (1 << (bit)))					\
   2037 			fn;						\
   2038 	} while (0)
   2039 
   2040 #ifdef INET
   2041 #if NARP > 0
   2042 	DONETISR(NETISR_ARP, arpintr());
   2043 #endif
   2044 	DONETISR(NETISR_IP, ipintr());
   2045 #endif
   2046 #ifdef NETATALK
   2047 	DONETISR(NETISR_ATALK, atintr());
   2048 #endif
   2049 #ifdef NS
   2050 	DONETISR(NETISR_NS, nsintr());
   2051 #endif
   2052 #ifdef ISO
   2053 	DONETISR(NETISR_ISO, clnlintr());
   2054 #endif
   2055 #ifdef CCITT
   2056 	DONETISR(NETISR_CCITT, ccittintr());
   2057 #endif
   2058 #ifdef NATM
   2059 	DONETISR(NETISR_NATM, natmintr());
   2060 #endif
   2061 #if NPPP > 1
   2062 	DONETISR(NETISR_PPP, pppintr());
   2063 #endif
   2064 
   2065 #undef DONETISR
   2066 }
   2067 
   2068 void
   2069 do_sir()
   2070 {
   2071 	u_int64_t n;
   2072 
   2073 	do {
   2074 		(void)splhigh();
   2075 		n = ssir;
   2076 		ssir = 0;
   2077 		splsoft();		/* don't recurse through spl0() */
   2078 
   2079 #if defined(UVM)
   2080 #define	COUNT_SOFT	uvmexp.softs++
   2081 #else
   2082 #define	COUNT_SOFT	cnt.v_soft++
   2083 #endif
   2084 
   2085 #define	DO_SIR(bit, fn)							\
   2086 		do {							\
   2087 			if (n & (bit)) {				\
   2088 				COUNT_SOFT;				\
   2089 				fn;					\
   2090 			}						\
   2091 		} while (0)
   2092 
   2093 		DO_SIR(SIR_NET, netintr());
   2094 		DO_SIR(SIR_CLOCK, softclock());
   2095 #if NCOM > 0
   2096 		DO_SIR(SIR_SERIAL, comsoft());
   2097 #endif
   2098 
   2099 #undef COUNT_SOFT
   2100 #undef DO_SIR
   2101 	} while (ssir != 0);
   2102 }
   2103 
   2104 int
   2105 spl0()
   2106 {
   2107 
   2108 	if (ssir)
   2109 		do_sir();		/* it lowers the IPL itself */
   2110 
   2111 	return (alpha_pal_swpipl(ALPHA_PSL_IPL_0));
   2112 }
   2113 
   2114 /*
   2115  * The following primitives manipulate the run queues.  _whichqs tells which
   2116  * of the 32 queues _qs have processes in them.  Setrunqueue puts processes
   2117  * into queues, Remrunqueue removes them from queues.  The running process is
   2118  * on no queue, other processes are on a queue related to p->p_priority,
   2119  * divided by 4 actually to shrink the 0-127 range of priorities into the 32
   2120  * available queues.
   2121  */
   2122 /*
   2123  * setrunqueue(p)
   2124  *	proc *p;
   2125  *
   2126  * Call should be made at splclock(), and p->p_stat should be SRUN.
   2127  */
   2128 
   2129 void
   2130 setrunqueue(p)
   2131 	struct proc *p;
   2132 {
   2133 	int bit;
   2134 
   2135 	/* firewall: p->p_back must be NULL */
   2136 	if (p->p_back != NULL)
   2137 		panic("setrunqueue");
   2138 
   2139 	bit = p->p_priority >> 2;
   2140 	whichqs |= (1 << bit);
   2141 	p->p_forw = (struct proc *)&qs[bit];
   2142 	p->p_back = qs[bit].ph_rlink;
   2143 	p->p_back->p_forw = p;
   2144 	qs[bit].ph_rlink = p;
   2145 }
   2146 
   2147 /*
   2148  * remrunqueue(p)
   2149  *
   2150  * Call should be made at splclock().
   2151  */
   2152 void
   2153 remrunqueue(p)
   2154 	struct proc *p;
   2155 {
   2156 	int bit;
   2157 
   2158 	bit = p->p_priority >> 2;
   2159 	if ((whichqs & (1 << bit)) == 0)
   2160 		panic("remrunqueue");
   2161 
   2162 	p->p_back->p_forw = p->p_forw;
   2163 	p->p_forw->p_back = p->p_back;
   2164 	p->p_back = NULL;	/* for firewall checking. */
   2165 
   2166 	if ((struct proc *)&qs[bit] == qs[bit].ph_link)
   2167 		whichqs &= ~(1 << bit);
   2168 }
   2169 
   2170 /*
   2171  * Return the best possible estimate of the time in the timeval
   2172  * to which tvp points.  Unfortunately, we can't read the hardware registers.
   2173  * We guarantee that the time will be greater than the value obtained by a
   2174  * previous call.
   2175  */
   2176 void
   2177 microtime(tvp)
   2178 	register struct timeval *tvp;
   2179 {
   2180 	int s = splclock();
   2181 	static struct timeval lasttime;
   2182 
   2183 	*tvp = time;
   2184 #ifdef notdef
   2185 	tvp->tv_usec += clkread();
   2186 	while (tvp->tv_usec > 1000000) {
   2187 		tvp->tv_sec++;
   2188 		tvp->tv_usec -= 1000000;
   2189 	}
   2190 #endif
   2191 	if (tvp->tv_sec == lasttime.tv_sec &&
   2192 	    tvp->tv_usec <= lasttime.tv_usec &&
   2193 	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
   2194 		tvp->tv_sec++;
   2195 		tvp->tv_usec -= 1000000;
   2196 	}
   2197 	lasttime = *tvp;
   2198 	splx(s);
   2199 }
   2200 
   2201 /*
   2202  * Wait "n" microseconds.
   2203  */
   2204 void
   2205 delay(n)
   2206 	unsigned long n;
   2207 {
   2208 	long N = cycles_per_usec * (n);
   2209 
   2210 	while (N > 0)				/* XXX */
   2211 		N -= 3;				/* XXX */
   2212 }
   2213 
   2214 #if defined(COMPAT_OSF1) || 1		/* XXX */
   2215 void	cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
   2216 	    u_long));
   2217 
   2218 void
   2219 cpu_exec_ecoff_setregs(p, epp, stack)
   2220 	struct proc *p;
   2221 	struct exec_package *epp;
   2222 	u_long stack;
   2223 {
   2224 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   2225 
   2226 	setregs(p, epp, stack);
   2227 	p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value;
   2228 }
   2229 
   2230 /*
   2231  * cpu_exec_ecoff_hook():
   2232  *	cpu-dependent ECOFF format hook for execve().
   2233  *
   2234  * Do any machine-dependent diddling of the exec package when doing ECOFF.
   2235  *
   2236  */
   2237 int
   2238 cpu_exec_ecoff_hook(p, epp)
   2239 	struct proc *p;
   2240 	struct exec_package *epp;
   2241 {
   2242 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   2243 	extern struct emul emul_netbsd;
   2244 #ifdef COMPAT_OSF1
   2245 	extern struct emul emul_osf1;
   2246 #endif
   2247 
   2248 	switch (execp->f.f_magic) {
   2249 #ifdef COMPAT_OSF1
   2250 	case ECOFF_MAGIC_ALPHA:
   2251 		epp->ep_emul = &emul_osf1;
   2252 		break;
   2253 #endif
   2254 
   2255 	case ECOFF_MAGIC_NETBSD_ALPHA:
   2256 		epp->ep_emul = &emul_netbsd;
   2257 		break;
   2258 
   2259 	default:
   2260 		return ENOEXEC;
   2261 	}
   2262 	return 0;
   2263 }
   2264 #endif
   2265 
   2266 int
   2267 alpha_pa_access(pa)
   2268 	u_long pa;
   2269 {
   2270 	int i;
   2271 
   2272 	for (i = 0; i < mem_cluster_cnt; i++) {
   2273 		if (pa < mem_clusters[i].start)
   2274 			continue;
   2275 		if ((pa - mem_clusters[i].start) >=
   2276 		    (mem_clusters[i].size & ~PAGE_MASK))
   2277 			continue;
   2278 		return (mem_clusters[i].size & PAGE_MASK);	/* prot */
   2279 	}
   2280 	return (PROT_NONE);
   2281 }
   2282 
   2283 /* XXX XXX BEGIN XXX XXX */
   2284 paddr_t alpha_XXX_dmamap_or;					/* XXX */
   2285 								/* XXX */
   2286 paddr_t								/* XXX */
   2287 alpha_XXX_dmamap(v)						/* XXX */
   2288 	vaddr_t v;						/* XXX */
   2289 {								/* XXX */
   2290 								/* XXX */
   2291 	return (vtophys(v) | alpha_XXX_dmamap_or);		/* XXX */
   2292 }								/* XXX */
   2293 /* XXX XXX END XXX XXX */
   2294 
   2295 struct mchkinfo *
   2296 cpu_mchkinfo()
   2297 {
   2298 	if (mchkinfo_all_cpus == NULL)
   2299 		return &startup_info;
   2300 	return mchkinfo_all_cpus + alpha_pal_whami();
   2301 }
   2302 
   2303 #define	NSIO_PORT  0x26e	/* Hardware enabled option: 0x398 */
   2304 #define	NSIO_BASE  0
   2305 #define	NSIO_INDEX NSIO_BASE
   2306 #define	NSIO_DATA  1
   2307 #define	NSIO_SIZE  2
   2308 #define	NSIO_CFG0  0
   2309 #define	NSIO_CFG1  1
   2310 #define	NSIO_CFG2  2
   2311 #define	NSIO_IDE_ENABLE 0x40
   2312 
   2313 #define	NSIO_MB(type) bus_space_barrier(iot, nsio, NSIO_BASE, NSIO_SIZE, (type))
   2314 
   2315 /*
   2316  * DEC uses a chip from NS for junk I/O, but SRM on some platforms
   2317  * doesn't enable that section. Do it here if called from a platform-
   2318  * specific init routine.
   2319  */
   2320 void
   2321 enable_nsio_ide(iot)
   2322 	bus_space_tag_t iot;
   2323 {
   2324 	int cfg0val;
   2325 	bus_space_handle_t nsio;
   2326 
   2327 	if (bus_space_map(iot, NSIO_PORT, NSIO_SIZE, 0, &nsio))
   2328 		return;
   2329 
   2330 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
   2331 	NSIO_MB(BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
   2332 	cfg0val = bus_space_read_1(iot, nsio, NSIO_DATA);
   2333 
   2334 	cfg0val |= NSIO_IDE_ENABLE;
   2335 
   2336 	bus_space_write_1(iot, nsio, NSIO_INDEX, NSIO_CFG0);
   2337 	NSIO_MB(BUS_SPACE_BARRIER_WRITE);
   2338 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
   2339 	NSIO_MB(BUS_SPACE_BARRIER_WRITE);
   2340 	bus_space_write_1(iot, nsio, NSIO_DATA, cfg0val);
   2341 
   2342 	/* Leave nsio mapped to catch any accidental port space collisions  */
   2343 }
   2344