Home | History | Annotate | Line # | Download | only in alpha
machdep.c revision 1.108
      1 /* $NetBSD: machdep.c,v 1.108 1998/02/14 01:17:19 cgd Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.108 1998/02/14 01:17:19 cgd Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/signalvar.h>
     37 #include <sys/kernel.h>
     38 #include <sys/map.h>
     39 #include <sys/proc.h>
     40 #include <sys/buf.h>
     41 #include <sys/reboot.h>
     42 #include <sys/device.h>
     43 #include <sys/file.h>
     44 #ifdef REAL_CLISTS
     45 #include <sys/clist.h>
     46 #endif
     47 #include <sys/callout.h>
     48 #include <sys/malloc.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/msgbuf.h>
     51 #include <sys/ioctl.h>
     52 #include <sys/tty.h>
     53 #include <sys/user.h>
     54 #include <sys/exec.h>
     55 #include <sys/exec_ecoff.h>
     56 #include <vm/vm.h>
     57 #include <sys/sysctl.h>
     58 #include <sys/core.h>
     59 #include <sys/kcore.h>
     60 #include <machine/kcore.h>
     61 #ifdef SYSVMSG
     62 #include <sys/msg.h>
     63 #endif
     64 #ifdef SYSVSEM
     65 #include <sys/sem.h>
     66 #endif
     67 #ifdef SYSVSHM
     68 #include <sys/shm.h>
     69 #endif
     70 
     71 #include <sys/mount.h>
     72 #include <sys/syscallargs.h>
     73 
     74 #include <vm/vm_kern.h>
     75 
     76 #include <dev/cons.h>
     77 
     78 #include <machine/autoconf.h>
     79 #include <machine/cpu.h>
     80 #include <machine/reg.h>
     81 #include <machine/rpb.h>
     82 #include <machine/prom.h>
     83 #include <machine/conf.h>
     84 
     85 #include <net/netisr.h>
     86 #include <net/if.h>
     87 
     88 #ifdef INET
     89 #include <netinet/in.h>
     90 #include <netinet/ip_var.h>
     91 #include "arp.h"
     92 #if NARP > 0
     93 #include <netinet/if_inarp.h>
     94 #endif
     95 #endif
     96 #ifdef NS
     97 #include <netns/ns_var.h>
     98 #endif
     99 #ifdef ISO
    100 #include <netiso/iso.h>
    101 #include <netiso/clnp.h>
    102 #endif
    103 #ifdef CCITT
    104 #include <netccitt/x25.h>
    105 #include <netccitt/pk.h>
    106 #include <netccitt/pk_extern.h>
    107 #endif
    108 #ifdef NATM
    109 #include <netnatm/natm.h>
    110 #endif
    111 #ifdef NETATALK
    112 #include <netatalk/at_extern.h>
    113 #endif
    114 #include "ppp.h"
    115 #if NPPP > 0
    116 #include <net/ppp_defs.h>
    117 #include <net/if_ppp.h>
    118 #endif
    119 
    120 #ifdef DDB
    121 #include <machine/db_machdep.h>
    122 #include <ddb/db_access.h>
    123 #include <ddb/db_sym.h>
    124 #include <ddb/db_extern.h>
    125 #include <ddb/db_interface.h>
    126 #endif
    127 
    128 vm_map_t buffer_map;
    129 
    130 /*
    131  * Declare these as initialized data so we can patch them.
    132  */
    133 int	nswbuf = 0;
    134 #ifdef	NBUF
    135 int	nbuf = NBUF;
    136 #else
    137 int	nbuf = 0;
    138 #endif
    139 #ifdef	BUFPAGES
    140 int	bufpages = BUFPAGES;
    141 #else
    142 int	bufpages = 0;
    143 #endif
    144 caddr_t msgbufaddr;
    145 
    146 int	maxmem;			/* max memory per process */
    147 
    148 int	totalphysmem;		/* total amount of physical memory in system */
    149 int	physmem;		/* physical memory used by NetBSD + some rsvd */
    150 int	firstusablepage;	/* first usable memory page */
    151 int	lastusablepage;		/* last usable memory page */
    152 int	resvmem;		/* amount of memory reserved for PROM */
    153 int	unusedmem;		/* amount of memory for OS that we don't use */
    154 int	unknownmem;		/* amount of memory with an unknown use */
    155 
    156 int	cputype;		/* system type, from the RPB */
    157 
    158 /*
    159  * XXX We need an address to which we can assign things so that they
    160  * won't be optimized away because we didn't use the value.
    161  */
    162 u_int32_t no_optimize;
    163 
    164 /* the following is used externally (sysctl_hw) */
    165 char	machine[] = MACHINE;		/* from <machine/param.h> */
    166 char	machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    167 char	cpu_model[128];
    168 
    169 struct	user *proc0paddr;
    170 
    171 /* Number of machine cycles per microsecond */
    172 u_int64_t	cycles_per_usec;
    173 
    174 /* number of cpus in the box.  really! */
    175 int		ncpus;
    176 
    177 struct bootinfo_kernel bootinfo;
    178 
    179 struct platform platform;
    180 
    181 u_int32_t vm_mbuf_size = _VM_MBUF_SIZE;
    182 u_int32_t vm_kmem_size = _VM_KMEM_SIZE;
    183 u_int32_t vm_phys_size = _VM_PHYS_SIZE;
    184 
    185 #ifdef DDB
    186 /* start and end of kernel symbol table */
    187 void	*ksym_start, *ksym_end;
    188 #endif
    189 
    190 /* for cpu_sysctl() */
    191 int	alpha_unaligned_print = 1;	/* warn about unaligned accesses */
    192 int	alpha_unaligned_fix = 1;	/* fix up unaligned accesses */
    193 int	alpha_unaligned_sigbus = 0;	/* don't SIGBUS on fixed-up accesses */
    194 
    195 caddr_t	allocsys __P((caddr_t));
    196 int	cpu_dump __P((void));
    197 int	cpu_dumpsize __P((void));
    198 void	dumpsys __P((void));
    199 void	identifycpu __P((void));
    200 void	netintr __P((void));
    201 void	printregs __P((struct reg *));
    202 
    203 void
    204 alpha_init(pfn, ptb, bim, bip, biv)
    205 	u_long pfn;		/* first free PFN number */
    206 	u_long ptb;		/* PFN of current level 1 page table */
    207 	u_long bim;		/* bootinfo magic */
    208 	u_long bip;		/* bootinfo pointer */
    209 	u_long biv;		/* bootinfo version */
    210 {
    211 	extern char kernel_text[], _end[];
    212 	struct mddt *mddtp;
    213 	int i, mddtweird;
    214 	vm_offset_t kernstart, kernend;
    215 	vm_size_t size;
    216 	char *p;
    217 	caddr_t v;
    218 	caddr_t start, w;
    219 	char *bootinfo_msg;
    220 
    221 	/* NO OUTPUT ALLOWED UNTIL FURTHER NOTICE */
    222 
    223 	/*
    224 	 * Turn off interrupts (not mchecks) and floating point.
    225 	 * Make sure the instruction and data streams are consistent.
    226 	 */
    227 	(void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
    228 	alpha_pal_wrfen(0);
    229 	ALPHA_TBIA();
    230 	alpha_pal_imb();
    231 
    232 	/*
    233 	 * Get critical system information (if possible, from the
    234 	 * information provided by the boot program).
    235 	 */
    236 	bootinfo_msg = NULL;
    237 	if (bim == BOOTINFO_MAGIC) {
    238 		if (biv == 0) {		/* backward compat */
    239 			biv = *(u_long *)bip;
    240 			bip += 8;
    241 		}
    242 		switch (biv) {
    243 		case 1: {
    244 			struct bootinfo_v1 *v1p = (struct bootinfo_v1 *)bip;
    245 
    246 			bootinfo.ssym = v1p->ssym;
    247 			bootinfo.esym = v1p->esym;
    248 			/* hwrpb may not be provided by boot block in v1 */
    249 			if (v1p->hwrpb != NULL) {
    250 				bootinfo.hwrpb_phys =
    251 				    ((struct rpb *)v1p->hwrpb)->rpb_phys;
    252 				bootinfo.hwrpb_size = v1p->hwrpbsize;
    253 			} else {
    254 				bootinfo.hwrpb_phys =
    255 				    ((struct rpb *)HWRPB_ADDR)->rpb_phys;
    256 				bootinfo.hwrpb_size =
    257 				    ((struct rpb *)HWRPB_ADDR)->rpb_size;
    258 			}
    259 			bcopy(v1p->boot_flags, bootinfo.boot_flags,
    260 			    min(sizeof v1p->boot_flags,
    261 			      sizeof bootinfo.boot_flags));
    262 			bcopy(v1p->booted_kernel, bootinfo.booted_kernel,
    263 			    min(sizeof v1p->booted_kernel,
    264 			      sizeof bootinfo.booted_kernel));
    265 			/* booted dev not provided in bootinfo */
    266 			init_prom_interface((struct rpb *)
    267 			    ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys));
    268                 	prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
    269 			    sizeof bootinfo.booted_dev);
    270 			break;
    271 		}
    272 		default:
    273 			bootinfo_msg = "unknown bootinfo version";
    274 			goto nobootinfo;
    275 		}
    276 	} else {
    277 		bootinfo_msg = "boot program did not pass bootinfo";
    278 nobootinfo:
    279 		bootinfo.ssym = (u_long)_end;
    280 		bootinfo.esym = (u_long)_end;
    281 		bootinfo.hwrpb_phys = ((struct rpb *)HWRPB_ADDR)->rpb_phys;
    282 		bootinfo.hwrpb_size = ((struct rpb *)HWRPB_ADDR)->rpb_size;
    283 		init_prom_interface((struct rpb *)HWRPB_ADDR);
    284 		prom_getenv(PROM_E_BOOTED_OSFLAGS, bootinfo.boot_flags,
    285 		    sizeof bootinfo.boot_flags);
    286 		prom_getenv(PROM_E_BOOTED_FILE, bootinfo.booted_kernel,
    287 		    sizeof bootinfo.booted_kernel);
    288 		prom_getenv(PROM_E_BOOTED_DEV, bootinfo.booted_dev,
    289 		    sizeof bootinfo.booted_dev);
    290 	}
    291 
    292 	/*
    293 	 * Initialize the kernel's mapping of the RPB.  It's needed for
    294 	 * lots of things.
    295 	 */
    296 	hwrpb = (struct rpb *)ALPHA_PHYS_TO_K0SEG(bootinfo.hwrpb_phys);
    297 
    298 	/*
    299 	 * Remember how many cycles there are per microsecond,
    300 	 * so that we can use delay().  Round up, for safety.
    301 	 */
    302 	cycles_per_usec = (hwrpb->rpb_cc_freq + 999999) / 1000000;
    303 
    304 	/*
    305 	 * Initalize the (temporary) bootstrap console interface, so
    306 	 * we can use printf until the VM system starts being setup.
    307 	 * The real console is initialized before then.
    308 	 */
    309 	init_bootstrap_console();
    310 
    311 	/* OUTPUT NOW ALLOWED */
    312 
    313 	/* delayed from above */
    314 	if (bootinfo_msg)
    315 		printf("WARNING: %s (0x%lx, 0x%lx, 0x%lx)\n",
    316 		    bootinfo_msg, bim, bip, biv);
    317 
    318 	/*
    319 	 * Point interrupt/exception vectors to our own.
    320 	 */
    321 	alpha_pal_wrent(XentInt, ALPHA_KENTRY_INT);
    322 	alpha_pal_wrent(XentArith, ALPHA_KENTRY_ARITH);
    323 	alpha_pal_wrent(XentMM, ALPHA_KENTRY_MM);
    324 	alpha_pal_wrent(XentIF, ALPHA_KENTRY_IF);
    325 	alpha_pal_wrent(XentUna, ALPHA_KENTRY_UNA);
    326 	alpha_pal_wrent(XentSys, ALPHA_KENTRY_SYS);
    327 
    328 	/*
    329 	 * Clear pending machine checks and error reports, and enable
    330 	 * system- and processor-correctable error reporting.
    331 	 */
    332 	alpha_pal_wrmces(alpha_pal_rdmces() &
    333 	    ~(ALPHA_MCES_DSC|ALPHA_MCES_DPC));
    334 
    335 	/*
    336 	 * Find out what hardware we're on, and do basic initialization.
    337 	 */
    338 	cputype = hwrpb->rpb_type;
    339 	if (cputype >= ncpuinit) {
    340 		platform_not_supported();
    341 		/* NOTREACHED */
    342 	}
    343 	(*cpuinit[cputype].init)();
    344 	strcpy(cpu_model, platform.model);
    345 
    346 	/*
    347 	 * Initalize the real console, so the the bootstrap console is
    348 	 * no longer necessary.
    349 	 */
    350 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    351 	if (!pmap_uses_prom_console())
    352 #endif
    353 		(*platform.cons_init)();
    354 
    355 #ifdef DIAGNOSTIC
    356 	/* Paranoid sanity checking */
    357 
    358 	/* We should always be running on the the primary. */
    359 	assert(hwrpb->rpb_primary_cpu_id == alpha_pal_whami());
    360 
    361 	/* On single-CPU systypes, the primary should always be CPU 0. */
    362 	if (cputype != ST_DEC_21000)
    363 		assert(hwrpb->rpb_primary_cpu_id == 0);
    364 #endif
    365 
    366 	/* NO MORE FIRMWARE ACCESS ALLOWED */
    367 #ifdef _PMAP_MAY_USE_PROM_CONSOLE
    368 	/*
    369 	 * XXX (unless _PMAP_MAY_USE_PROM_CONSOLE is defined and
    370 	 * XXX pmap_uses_prom_console() evaluates to non-zero.)
    371 	 */
    372 #endif
    373 
    374 	/*
    375 	 * find out this system's page size
    376 	 */
    377 	PAGE_SIZE = hwrpb->rpb_page_size;
    378 	if (PAGE_SIZE != 8192)
    379 		panic("page size %d != 8192?!", PAGE_SIZE);
    380 
    381 	/*
    382 	 * Initialize PAGE_SIZE-dependent variables.
    383 	 */
    384 	vm_set_page_size();
    385 
    386 	/*
    387 	 * Find the beginning and end of the kernel (and leave a
    388 	 * bit of space before the beginning for the bootstrap
    389 	 * stack).
    390 	 */
    391 	kernstart = trunc_page(kernel_text) - 2 * PAGE_SIZE;
    392 #ifdef DDB
    393 	ksym_start = (void *)bootinfo.ssym;
    394 	ksym_end   = (void *)bootinfo.esym;
    395 	kernend = (vm_offset_t)round_page(ksym_end);
    396 #else
    397 	kernend = (vm_offset_t)round_page(_end);
    398 #endif
    399 
    400 	/*
    401 	 * Find out how much memory is available, by looking at
    402 	 * the memory cluster descriptors.  This also tries to do
    403 	 * its best to detect things things that have never been seen
    404 	 * before...
    405 	 *
    406 	 * XXX Assumes that the first "system" cluster is the
    407 	 * only one we can use. Is the second (etc.) system cluster
    408 	 * (if one happens to exist) guaranteed to be contiguous?  or...?
    409 	 */
    410 	mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
    411 
    412 	/*
    413 	 * BEGIN MDDT WEIRDNESS CHECKING
    414 	 */
    415 	mddtweird = 0;
    416 
    417 #define cnt	 mddtp->mddt_cluster_cnt
    418 #define	usage(n) mddtp->mddt_clusters[(n)].mddt_usage
    419 	if (cnt != 2 && cnt != 3) {
    420 		printf("WARNING: weird number (%ld) of mem clusters\n", cnt);
    421 		mddtweird = 1;
    422 	} else if (usage(0) != MDDT_PALCODE ||
    423 		   usage(1) != MDDT_SYSTEM ||
    424 	           (cnt == 3 && usage(2) != MDDT_PALCODE)) {
    425 		mddtweird = 1;
    426 		printf("WARNING: %ld mem clusters, but weird config\n", cnt);
    427 	}
    428 
    429 	for (i = 0; i < cnt; i++) {
    430 		if ((usage(i) & MDDT_mbz) != 0) {
    431 			printf("WARNING: mem cluster %d has weird usage %lx\n",
    432 			    i, usage(i));
    433 			mddtweird = 1;
    434 		}
    435 		if (mddtp->mddt_clusters[i].mddt_pg_cnt == 0) {
    436 			printf("WARNING: mem cluster %d has pg cnt == 0\n", i);
    437 			mddtweird = 1;
    438 		}
    439 		/* XXX other things to check? */
    440 	}
    441 #undef cnt
    442 #undef usage
    443 
    444 	if (mddtweird) {
    445 		printf("\n");
    446 		printf("complete memory cluster information:\n");
    447 		for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    448 			printf("mddt %d:\n", i);
    449 			printf("\tpfn %lx\n",
    450 			    mddtp->mddt_clusters[i].mddt_pfn);
    451 			printf("\tcnt %lx\n",
    452 			    mddtp->mddt_clusters[i].mddt_pg_cnt);
    453 			printf("\ttest %lx\n",
    454 			    mddtp->mddt_clusters[i].mddt_pg_test);
    455 			printf("\tbva %lx\n",
    456 			    mddtp->mddt_clusters[i].mddt_v_bitaddr);
    457 			printf("\tbpa %lx\n",
    458 			    mddtp->mddt_clusters[i].mddt_p_bitaddr);
    459 			printf("\tbcksum %lx\n",
    460 			    mddtp->mddt_clusters[i].mddt_bit_cksum);
    461 			printf("\tusage %lx\n",
    462 			    mddtp->mddt_clusters[i].mddt_usage);
    463 		}
    464 		printf("\n");
    465 	}
    466 	/*
    467 	 * END MDDT WEIRDNESS CHECKING
    468 	 */
    469 
    470 	for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    471 		totalphysmem += mddtp->mddt_clusters[i].mddt_pg_cnt;
    472 #define	usage(n) mddtp->mddt_clusters[(n)].mddt_usage
    473 #define	pgcnt(n) mddtp->mddt_clusters[(n)].mddt_pg_cnt
    474 		if ((usage(i) & MDDT_mbz) != 0)
    475 			unknownmem += pgcnt(i);
    476 		else if ((usage(i) & ~MDDT_mbz) == MDDT_PALCODE)
    477 			resvmem += pgcnt(i);
    478 		else if ((usage(i) & ~MDDT_mbz) == MDDT_SYSTEM) {
    479 			/*
    480 			 * assumes that the system cluster listed is
    481 			 * one we're in...
    482 			 */
    483 			if (physmem != resvmem) {
    484 				physmem += pgcnt(i);
    485 				firstusablepage =
    486 				    mddtp->mddt_clusters[i].mddt_pfn;
    487 				lastusablepage = firstusablepage + pgcnt(i) - 1;
    488 			} else
    489 				unusedmem += pgcnt(i);
    490 		}
    491 #undef usage
    492 #undef pgcnt
    493 	}
    494 	if (totalphysmem == 0)
    495 		panic("can't happen: system seems to have no memory!");
    496 #ifdef        LIMITMEM
    497 	if (totalphysmem >= btoc(LIMITMEM << 20)) {
    498 		u_int64_t ovf = totalphysmem - btoc(LIMITMEM << 20);
    499 		printf("********LIMITING MEMORY TO %dMB**********\n", LIMITMEM);
    500 		physmem = totalphysmem = btoc(LIMITMEM << 20);
    501 		unusedmem += ovf;
    502 		lastusablepage = firstusablepage + physmem - 1;
    503 	}
    504 #endif
    505 	maxmem = physmem;
    506 
    507 #if 0
    508 	printf("totalphysmem = %d\n", totalphysmem);
    509 	printf("physmem = %d\n", physmem);
    510 	printf("firstusablepage = %d\n", firstusablepage);
    511 	printf("lastusablepage = %d\n", lastusablepage);
    512 	printf("resvmem = %d\n", resvmem);
    513 	printf("unusedmem = %d\n", unusedmem);
    514 	printf("unknownmem = %d\n", unknownmem);
    515 #endif
    516 
    517 	/*
    518 	 * Adjust some parameters if the amount of physmem
    519 	 * available would cause us to croak. This is completely
    520 	 * eyeballed and isn't meant to be the final answer.
    521 	 * vm_phys_size is probably the only one to really worry
    522 	 * about.
    523  	 *
    524 	 * It's for booting a GENERIC kernel on a large memory platform.
    525 	 */
    526 	if (physmem >= btoc(128 << 20)) {
    527 		vm_mbuf_size <<= 1;
    528 		vm_kmem_size <<= 3;
    529 		vm_phys_size <<= 2;
    530 	}
    531 
    532 	/*
    533 	 * Initialize error message buffer (at end of core).
    534 	 */
    535 	lastusablepage -= btoc(MSGBUFSIZE);
    536 	msgbufaddr = (caddr_t) ALPHA_PHYS_TO_K0SEG(ctob(lastusablepage + 1));
    537 	initmsgbuf(msgbufaddr, alpha_round_page(MSGBUFSIZE));
    538 
    539 	/*
    540 	 * Init mapping for u page(s) for proc 0
    541 	 */
    542 	start = v = (caddr_t)kernend;
    543 	curproc->p_addr = proc0paddr = (struct user *)v;
    544 	v += UPAGES * NBPG;
    545 
    546 	/*
    547 	 * Allocate space for system data structures.  These data structures
    548 	 * are allocated here instead of cpu_startup() because physical
    549 	 * memory is directly addressable.  We don't have to map these into
    550 	 * virtual address space.
    551 	 */
    552 	size = (vm_size_t)allocsys(0);
    553 	w = allocsys(v);
    554 	if ((w - v) != size)
    555 		panic("alpha_init: table size inconsistency");
    556 	v = w;
    557 
    558 	/*
    559 	 * Clear allocated memory.
    560 	 */
    561 	bzero(start, v - start);
    562 
    563 	/*
    564 	 * Initialize the virtual memory system, and set the
    565 	 * page table base register in proc 0's PCB.
    566 	 */
    567 #ifndef NEW_PMAP
    568 	pmap_bootstrap((vm_offset_t)v, ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT));
    569 #else
    570 	pmap_bootstrap((vm_offset_t)v, ALPHA_PHYS_TO_K0SEG(ptb << PGSHIFT),
    571 	    hwrpb->rpb_max_asn);
    572 #endif
    573 
    574 	/*
    575 	 * Initialize the rest of proc 0's PCB, and cache its physical
    576 	 * address.
    577 	 */
    578 	proc0.p_md.md_pcbpaddr =
    579 	    (struct pcb *)ALPHA_K0SEG_TO_PHYS((vm_offset_t)&proc0paddr->u_pcb);
    580 
    581 	/*
    582 	 * Set the kernel sp, reserving space for an (empty) trapframe,
    583 	 * and make proc0's trapframe pointer point to it for sanity.
    584 	 */
    585 	proc0paddr->u_pcb.pcb_hw.apcb_ksp =
    586 	    (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe);
    587 	proc0.p_md.md_tf =
    588 	    (struct trapframe *)proc0paddr->u_pcb.pcb_hw.apcb_ksp;
    589 
    590 #ifdef NEW_PMAP
    591 	/*
    592 	 * Set up the kernel address space in proc0's hwpcb.
    593 	 */
    594 	PMAP_ACTIVATE(kernel_pmap, &proc0paddr->u_pcb.pcb_hw, 0);
    595 #endif
    596 
    597 	/*
    598 	 * Look at arguments passed to us and compute boothowto.
    599 	 */
    600 
    601 	boothowto = RB_SINGLE;
    602 #ifdef KADB
    603 	boothowto |= RB_KDB;
    604 #endif
    605 	for (p = bootinfo.boot_flags; p && *p != '\0'; p++) {
    606 		/*
    607 		 * Note that we'd really like to differentiate case here,
    608 		 * but the Alpha AXP Architecture Reference Manual
    609 		 * says that we shouldn't.
    610 		 */
    611 		switch (*p) {
    612 		case 'a': /* autoboot */
    613 		case 'A':
    614 			boothowto &= ~RB_SINGLE;
    615 			break;
    616 
    617 #ifdef DEBUG
    618 		case 'c': /* crash dump immediately after autoconfig */
    619 		case 'C':
    620 			boothowto |= RB_DUMP;
    621 			break;
    622 #endif
    623 
    624 #if defined(KGDB) || defined(DDB)
    625 		case 'd': /* break into the kernel debugger ASAP */
    626 		case 'D':
    627 			boothowto |= RB_KDB;
    628 			break;
    629 #endif
    630 
    631 		case 'h': /* always halt, never reboot */
    632 		case 'H':
    633 			boothowto |= RB_HALT;
    634 			break;
    635 
    636 #if 0
    637 		case 'm': /* mini root present in memory */
    638 		case 'M':
    639 			boothowto |= RB_MINIROOT;
    640 			break;
    641 #endif
    642 
    643 		case 'n': /* askname */
    644 		case 'N':
    645 			boothowto |= RB_ASKNAME;
    646 			break;
    647 
    648 		case 's': /* single-user (default, supported for sanity) */
    649 		case 'S':
    650 			boothowto |= RB_SINGLE;
    651 			break;
    652 
    653 		default:
    654 			printf("Unrecognized boot flag '%c'.\n", *p);
    655 			break;
    656 		}
    657 	}
    658 
    659 	/*
    660 	 * Initialize debuggers, and break into them if appropriate.
    661 	 */
    662 #ifdef DDB
    663 	db_machine_init();
    664 	ddb_init(ksym_start, ksym_end);
    665 	if (boothowto & RB_KDB)
    666 		Debugger();
    667 #endif
    668 #ifdef KGDB
    669 	if (boothowto & RB_KDB)
    670 		kgdb_connect(0);
    671 #endif
    672 
    673 	/*
    674 	 * Figure out the number of cpus in the box, from RPB fields.
    675 	 * Really.  We mean it.
    676 	 */
    677 	for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) {
    678 		struct pcs *pcsp;
    679 
    680 		pcsp = (struct pcs *)((char *)hwrpb + hwrpb->rpb_pcs_off +
    681 		    (i * hwrpb->rpb_pcs_size));
    682 		if ((pcsp->pcs_flags & PCS_PP) != 0)
    683 			ncpus++;
    684 	}
    685 
    686 	/*
    687 	 * Figure out our clock frequency, from RPB fields.
    688 	 */
    689 	hz = hwrpb->rpb_intr_freq >> 12;
    690 	if (!(60 <= hz && hz <= 10240)) {
    691 		hz = 1024;
    692 #ifdef DIAGNOSTIC
    693 		printf("WARNING: unbelievable rpb_intr_freq: %ld (%d hz)\n",
    694 			hwrpb->rpb_intr_freq, hz);
    695 #endif
    696 	}
    697 
    698 }
    699 
    700 /*
    701  * Allocate space for system data structures.  We are given
    702  * a starting virtual address and we return a final virtual
    703  * address; along the way we set each data structure pointer.
    704  *
    705  * We call allocsys() with 0 to find out how much space we want,
    706  * allocate that much and fill it with zeroes, and the call
    707  * allocsys() again with the correct base virtual address.
    708  */
    709 caddr_t
    710 allocsys(v)
    711 	caddr_t v;
    712 {
    713 
    714 #define valloc(name, type, num) \
    715 	    (name) = (type *)v; v = (caddr_t)ALIGN((name)+(num))
    716 #ifdef REAL_CLISTS
    717 	valloc(cfree, struct cblock, nclist);
    718 #endif
    719 	valloc(callout, struct callout, ncallout);
    720 #ifdef SYSVSHM
    721 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    722 #endif
    723 #ifdef SYSVSEM
    724 	valloc(sema, struct semid_ds, seminfo.semmni);
    725 	valloc(sem, struct sem, seminfo.semmns);
    726 	/* This is pretty disgusting! */
    727 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    728 #endif
    729 #ifdef SYSVMSG
    730 	valloc(msgpool, char, msginfo.msgmax);
    731 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    732 	valloc(msghdrs, struct msg, msginfo.msgtql);
    733 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    734 #endif
    735 
    736 	/*
    737 	 * Determine how many buffers to allocate.
    738 	 * We allocate 10% of memory for buffer space.  Insure a
    739 	 * minimum of 16 buffers.  We allocate 1/2 as many swap buffer
    740 	 * headers as file i/o buffers.
    741 	 */
    742 	if (bufpages == 0)
    743 		bufpages = (physmem * 10) / (CLSIZE * 100);
    744 	if (nbuf == 0) {
    745 		nbuf = bufpages;
    746 		if (nbuf < 16)
    747 			nbuf = 16;
    748 	}
    749 	if (nswbuf == 0) {
    750 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
    751 		if (nswbuf > 256)
    752 			nswbuf = 256;		/* sanity */
    753 	}
    754 	valloc(swbuf, struct buf, nswbuf);
    755 	valloc(buf, struct buf, nbuf);
    756 	return (v);
    757 #undef valloc
    758 }
    759 
    760 void
    761 consinit()
    762 {
    763 
    764 	/*
    765 	 * Everything related to console initialization is done
    766 	 * in alpha_init().
    767 	 */
    768 #if defined(DIAGNOSTIC) && defined(_PMAP_MAY_USE_PROM_CONSOLE)
    769 	printf("consinit: %susing prom console\n",
    770 	    pmap_uses_prom_console() ? "" : "not ");
    771 #endif
    772 }
    773 
    774 void
    775 cpu_startup()
    776 {
    777 	register unsigned i;
    778 	int base, residual;
    779 	vm_offset_t minaddr, maxaddr;
    780 	vm_size_t size;
    781 #if defined(DEBUG)
    782 	extern int pmapdebug;
    783 	int opmapdebug = pmapdebug;
    784 
    785 	pmapdebug = 0;
    786 #endif
    787 
    788 	/*
    789 	 * Good {morning,afternoon,evening,night}.
    790 	 */
    791 	printf(version);
    792 	identifycpu();
    793 	printf("real mem = %u (%u reserved for PROM, %u used by NetBSD)\n",
    794 	    ctob(totalphysmem), ctob(resvmem), ctob(physmem));
    795 	if (unusedmem)
    796 		printf("WARNING: unused memory = %d bytes\n", ctob(unusedmem));
    797 	if (unknownmem)
    798 		printf("WARNING: %d bytes of memory with unknown purpose\n",
    799 		    ctob(unknownmem));
    800 
    801 	/*
    802 	 * Allocate virtual address space for file I/O buffers.
    803 	 * Note they are different than the array of headers, 'buf',
    804 	 * and usually occupy more virtual memory than physical.
    805 	 */
    806 	size = MAXBSIZE * nbuf;
    807 	buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
    808 	    &maxaddr, size, TRUE);
    809 	minaddr = (vm_offset_t)buffers;
    810 	if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
    811 			&minaddr, size, FALSE) != KERN_SUCCESS)
    812 		panic("startup: cannot allocate buffers");
    813 	base = bufpages / nbuf;
    814 	residual = bufpages % nbuf;
    815 	for (i = 0; i < nbuf; i++) {
    816 		vm_size_t curbufsize;
    817 		vm_offset_t curbuf;
    818 
    819 		/*
    820 		 * First <residual> buffers get (base+1) physical pages
    821 		 * allocated for them.  The rest get (base) physical pages.
    822 		 *
    823 		 * The rest of each buffer occupies virtual space,
    824 		 * but has no physical memory allocated for it.
    825 		 */
    826 		curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
    827 		curbufsize = CLBYTES * (i < residual ? base+1 : base);
    828 		vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
    829 		vm_map_simplify(buffer_map, curbuf);
    830 	}
    831 	/*
    832 	 * Allocate a submap for exec arguments.  This map effectively
    833 	 * limits the number of processes exec'ing at any time.
    834 	 */
    835 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    836 				 16 * NCARGS, TRUE);
    837 
    838 	/*
    839 	 * Allocate a submap for physio
    840 	 */
    841 	phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    842 				 VM_PHYS_SIZE, TRUE);
    843 
    844 	/*
    845 	 * Finally, allocate mbuf cluster submap.
    846 	 */
    847 	mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
    848 	    VM_MBUF_SIZE, FALSE);
    849 	/*
    850 	 * Initialize callouts
    851 	 */
    852 	callfree = callout;
    853 	for (i = 1; i < ncallout; i++)
    854 		callout[i-1].c_next = &callout[i];
    855 	callout[i-1].c_next = NULL;
    856 
    857 #if defined(DEBUG)
    858 	pmapdebug = opmapdebug;
    859 #endif
    860 	printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
    861 	printf("using %ld buffers containing %ld bytes of memory\n",
    862 		(long)nbuf, (long)(bufpages * CLBYTES));
    863 
    864 	/*
    865 	 * Set up buffers, so they can be used to read disk labels.
    866 	 */
    867 	bufinit();
    868 
    869 	/*
    870 	 * Configure the system.
    871 	 */
    872 	configure();
    873 
    874 	/*
    875 	 * Note that bootstrapping is finished, and set the HWRPB up
    876 	 * to do restarts.
    877 	 */
    878 	hwrpb_restart_setup();
    879 }
    880 
    881 /*
    882  * Retrieve the platform name from the DSR.
    883  */
    884 const char *
    885 alpha_dsr_sysname()
    886 {
    887 	struct dsrdb *dsr;
    888 	const char *sysname;
    889 
    890 	/*
    891 	 * DSR does not exist on early HWRPB versions.
    892 	 */
    893 	if (hwrpb->rpb_version < HWRPB_DSRDB_MINVERS)
    894 		return (NULL);
    895 
    896 	dsr = (struct dsrdb *)(((caddr_t)hwrpb) + hwrpb->rpb_dsrdb_off);
    897 	sysname = (const char *)((caddr_t)dsr + (dsr->dsr_sysname_off +
    898 	    sizeof(u_int64_t)));
    899 	return (sysname);
    900 }
    901 
    902 /*
    903  * Lookup the system specified system variation in the provided table,
    904  * returning the model string on match.
    905  */
    906 const char *
    907 alpha_variation_name(variation, avtp)
    908 	u_int64_t variation;
    909 	const struct alpha_variation_table *avtp;
    910 {
    911 	int i;
    912 
    913 	for (i = 0; avtp[i].avt_model != NULL; i++)
    914 		if (avtp[i].avt_variation == variation)
    915 			return (avtp[i].avt_model);
    916 	return (NULL);
    917 }
    918 
    919 /*
    920  * Generate a default platform name based for unknown system variations.
    921  */
    922 const char *
    923 alpha_unknown_sysname()
    924 {
    925 	static char s[128];		/* safe size */
    926 
    927 	sprintf(s, "%s family, unknown model variation 0x%lx",
    928 	    platform.family, hwrpb->rpb_variation & SV_ST_MASK);
    929 	return ((const char *)s);
    930 }
    931 
    932 void
    933 identifycpu()
    934 {
    935 
    936 	/*
    937 	 * print out CPU identification information.
    938 	 */
    939 	printf("%s, %ldMHz\n", cpu_model,
    940 	    hwrpb->rpb_cc_freq / 1000000);	/* XXX true for 21164? */
    941 	printf("%ld byte page size, %d processor%s.\n",
    942 	    hwrpb->rpb_page_size, ncpus, ncpus == 1 ? "" : "s");
    943 #if 0
    944 	/* this isn't defined for any systems that we run on? */
    945 	printf("serial number 0x%lx 0x%lx\n",
    946 	    ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
    947 
    948 	/* and these aren't particularly useful! */
    949 	printf("variation: 0x%lx, revision 0x%lx\n",
    950 	    hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
    951 #endif
    952 }
    953 
    954 int	waittime = -1;
    955 struct pcb dumppcb;
    956 
    957 void
    958 cpu_reboot(howto, bootstr)
    959 	int howto;
    960 	char *bootstr;
    961 {
    962 	extern int cold;
    963 
    964 	/* If system is cold, just halt. */
    965 	if (cold) {
    966 		howto |= RB_HALT;
    967 		goto haltsys;
    968 	}
    969 
    970 	/* If "always halt" was specified as a boot flag, obey. */
    971 	if ((boothowto & RB_HALT) != 0)
    972 		howto |= RB_HALT;
    973 
    974 	boothowto = howto;
    975 	if ((howto & RB_NOSYNC) == 0 && waittime < 0) {
    976 		waittime = 0;
    977 		vfs_shutdown();
    978 		/*
    979 		 * If we've been adjusting the clock, the todr
    980 		 * will be out of synch; adjust it now.
    981 		 */
    982 		resettodr();
    983 	}
    984 
    985 	/* Disable interrupts. */
    986 	splhigh();
    987 
    988 	/* If rebooting and a dump is requested do it. */
    989 #if 0
    990 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    991 #else
    992 	if (howto & RB_DUMP)
    993 #endif
    994 		dumpsys();
    995 
    996 haltsys:
    997 
    998 	/* run any shutdown hooks */
    999 	doshutdownhooks();
   1000 
   1001 #ifdef BOOTKEY
   1002 	printf("hit any key to %s...\n", howto & RB_HALT ? "halt" : "reboot");
   1003 	cngetc();
   1004 	printf("\n");
   1005 #endif
   1006 
   1007 	/* Finally, halt/reboot the system. */
   1008 	printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
   1009 	prom_halt(howto & RB_HALT);
   1010 	/*NOTREACHED*/
   1011 }
   1012 
   1013 /*
   1014  * These variables are needed by /sbin/savecore
   1015  */
   1016 u_long	dumpmag = 0x8fca0101;	/* magic number */
   1017 int 	dumpsize = 0;		/* pages */
   1018 long	dumplo = 0; 		/* blocks */
   1019 
   1020 /*
   1021  * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
   1022  */
   1023 int
   1024 cpu_dumpsize()
   1025 {
   1026 	int size;
   1027 
   1028 	size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) +
   1029 	    ALIGN(mem_cluster_cnt * sizeof(phys_ram_seg_t));
   1030 	if (roundup(size, dbtob(1)) != dbtob(1))
   1031 		return -1;
   1032 
   1033 	return (1);
   1034 }
   1035 
   1036 /*
   1037  * cpu_dump: dump machine-dependent kernel core dump headers.
   1038  */
   1039 int
   1040 cpu_dump()
   1041 {
   1042 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1043 	char buf[dbtob(1)];
   1044 	kcore_seg_t *segp;
   1045 	cpu_kcore_hdr_t *cpuhdrp;
   1046 	phys_ram_seg_t *memsegp;
   1047 
   1048 	dump = bdevsw[major(dumpdev)].d_dump;
   1049 
   1050 	bzero(buf, sizeof buf);
   1051 	segp = (kcore_seg_t *)buf;
   1052 	cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))];
   1053 	memsegp = (phys_ram_seg_t *)&buf[ ALIGN(sizeof(*segp)) +
   1054 	    ALIGN(sizeof(*cpuhdrp))];
   1055 
   1056 	/*
   1057 	 * Generate a segment header.
   1058 	 */
   1059 	CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
   1060 	segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
   1061 
   1062 	/*
   1063 	 * Add the machine-dependent header info.
   1064 	 */
   1065 	cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vm_offset_t)Lev1map);
   1066 	cpuhdrp->page_size = PAGE_SIZE;
   1067 	cpuhdrp->nmemsegs = 1;
   1068 
   1069 	/*
   1070 	 * Fill in the memory segment descriptors.
   1071 	 */
   1072 	memsegp[0].start = ctob(firstusablepage);
   1073 	memsegp[0].size = ctob(physmem);
   1074 
   1075 	return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1)));
   1076 }
   1077 
   1078 /*
   1079  * This is called by main to set dumplo and dumpsize.
   1080  * Dumps always skip the first CLBYTES of disk space
   1081  * in case there might be a disk label stored there.
   1082  * If there is extra space, put dump at the end to
   1083  * reduce the chance that swapping trashes it.
   1084  */
   1085 void
   1086 cpu_dumpconf()
   1087 {
   1088 	int nblks, dumpblks;	/* size of dump area */
   1089 	int maj;
   1090 
   1091 	if (dumpdev == NODEV)
   1092 		goto bad;
   1093 	maj = major(dumpdev);
   1094 	if (maj < 0 || maj >= nblkdev)
   1095 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
   1096 	if (bdevsw[maj].d_psize == NULL)
   1097 		goto bad;
   1098 	nblks = (*bdevsw[maj].d_psize)(dumpdev);
   1099 	if (nblks <= ctod(1))
   1100 		goto bad;
   1101 
   1102 	dumpblks = cpu_dumpsize();
   1103 	if (dumpblks < 0)
   1104 		goto bad;
   1105 	dumpblks += ctod(physmem);
   1106 
   1107 	/* If dump won't fit (incl. room for possible label), punt. */
   1108 	if (dumpblks > (nblks - ctod(1)))
   1109 		goto bad;
   1110 
   1111 	/* Put dump at end of partition */
   1112 	dumplo = nblks - dumpblks;
   1113 
   1114 	/* dumpsize is in page units, and doesn't include headers. */
   1115 	dumpsize = physmem;
   1116 	return;
   1117 
   1118 bad:
   1119 	dumpsize = 0;
   1120 	return;
   1121 }
   1122 
   1123 /*
   1124  * Dump the kernel's image to the swap partition.
   1125  */
   1126 #define	BYTES_PER_DUMP	NBPG
   1127 
   1128 void
   1129 dumpsys()
   1130 {
   1131 	unsigned bytes, i, n;
   1132 	int maddr, psize;
   1133 	daddr_t blkno;
   1134 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1135 	int error;
   1136 
   1137 	/* Save registers. */
   1138 	savectx(&dumppcb);
   1139 
   1140 	msgbufmapped = 0;	/* don't record dump msgs in msgbuf */
   1141 	if (dumpdev == NODEV)
   1142 		return;
   1143 
   1144 	/*
   1145 	 * For dumps during autoconfiguration,
   1146 	 * if dump device has already configured...
   1147 	 */
   1148 	if (dumpsize == 0)
   1149 		cpu_dumpconf();
   1150 	if (dumplo <= 0) {
   1151 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
   1152 		    minor(dumpdev));
   1153 		return;
   1154 	}
   1155 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
   1156 	    minor(dumpdev), dumplo);
   1157 
   1158 	psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
   1159 	printf("dump ");
   1160 	if (psize == -1) {
   1161 		printf("area unavailable\n");
   1162 		return;
   1163 	}
   1164 
   1165 	/* XXX should purge all outstanding keystrokes. */
   1166 
   1167 	if ((error = cpu_dump()) != 0)
   1168 		goto err;
   1169 
   1170 	bytes = ctob(physmem);
   1171 	maddr = ctob(firstusablepage);
   1172 	blkno = dumplo + cpu_dumpsize();
   1173 	dump = bdevsw[major(dumpdev)].d_dump;
   1174 	error = 0;
   1175 	for (i = 0; i < bytes; i += n) {
   1176 
   1177 		/* Print out how many MBs we to go. */
   1178 		n = bytes - i;
   1179 		if (n && (n % (1024*1024)) == 0)
   1180 			printf("%d ", n / (1024 * 1024));
   1181 
   1182 		/* Limit size for next transfer. */
   1183 		if (n > BYTES_PER_DUMP)
   1184 			n =  BYTES_PER_DUMP;
   1185 
   1186 		error = (*dump)(dumpdev, blkno,
   1187 		    (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n);
   1188 		if (error)
   1189 			break;
   1190 		maddr += n;
   1191 		blkno += btodb(n);			/* XXX? */
   1192 
   1193 		/* XXX should look for keystrokes, to cancel. */
   1194 	}
   1195 
   1196 err:
   1197 	switch (error) {
   1198 
   1199 	case ENXIO:
   1200 		printf("device bad\n");
   1201 		break;
   1202 
   1203 	case EFAULT:
   1204 		printf("device not ready\n");
   1205 		break;
   1206 
   1207 	case EINVAL:
   1208 		printf("area improper\n");
   1209 		break;
   1210 
   1211 	case EIO:
   1212 		printf("i/o error\n");
   1213 		break;
   1214 
   1215 	case EINTR:
   1216 		printf("aborted from console\n");
   1217 		break;
   1218 
   1219 	case 0:
   1220 		printf("succeeded\n");
   1221 		break;
   1222 
   1223 	default:
   1224 		printf("error %d\n", error);
   1225 		break;
   1226 	}
   1227 	printf("\n\n");
   1228 	delay(1000);
   1229 }
   1230 
   1231 void
   1232 frametoreg(framep, regp)
   1233 	struct trapframe *framep;
   1234 	struct reg *regp;
   1235 {
   1236 
   1237 	regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
   1238 	regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
   1239 	regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
   1240 	regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
   1241 	regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
   1242 	regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
   1243 	regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
   1244 	regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
   1245 	regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
   1246 	regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
   1247 	regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
   1248 	regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
   1249 	regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
   1250 	regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
   1251 	regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
   1252 	regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
   1253 	regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0];
   1254 	regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1];
   1255 	regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2];
   1256 	regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
   1257 	regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
   1258 	regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
   1259 	regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
   1260 	regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
   1261 	regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
   1262 	regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
   1263 	regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
   1264 	regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
   1265 	regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
   1266 	regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP];
   1267 	/* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */
   1268 	regp->r_regs[R_ZERO] = 0;
   1269 }
   1270 
   1271 void
   1272 regtoframe(regp, framep)
   1273 	struct reg *regp;
   1274 	struct trapframe *framep;
   1275 {
   1276 
   1277 	framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
   1278 	framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
   1279 	framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
   1280 	framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
   1281 	framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
   1282 	framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
   1283 	framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
   1284 	framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
   1285 	framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
   1286 	framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
   1287 	framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
   1288 	framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
   1289 	framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
   1290 	framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
   1291 	framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
   1292 	framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
   1293 	framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0];
   1294 	framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1];
   1295 	framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2];
   1296 	framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
   1297 	framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
   1298 	framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
   1299 	framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
   1300 	framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
   1301 	framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
   1302 	framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
   1303 	framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
   1304 	framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
   1305 	framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
   1306 	framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP];
   1307 	/* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */
   1308 	/* ??? = regp->r_regs[R_ZERO]; */
   1309 }
   1310 
   1311 void
   1312 printregs(regp)
   1313 	struct reg *regp;
   1314 {
   1315 	int i;
   1316 
   1317 	for (i = 0; i < 32; i++)
   1318 		printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
   1319 		   i & 1 ? "\n" : "\t");
   1320 }
   1321 
   1322 void
   1323 regdump(framep)
   1324 	struct trapframe *framep;
   1325 {
   1326 	struct reg reg;
   1327 
   1328 	frametoreg(framep, &reg);
   1329 	reg.r_regs[R_SP] = alpha_pal_rdusp();
   1330 
   1331 	printf("REGISTERS:\n");
   1332 	printregs(&reg);
   1333 }
   1334 
   1335 #ifdef DEBUG
   1336 int sigdebug = 0;
   1337 int sigpid = 0;
   1338 #define	SDB_FOLLOW	0x01
   1339 #define	SDB_KSTACK	0x02
   1340 #endif
   1341 
   1342 /*
   1343  * Send an interrupt to process.
   1344  */
   1345 void
   1346 sendsig(catcher, sig, mask, code)
   1347 	sig_t catcher;
   1348 	int sig, mask;
   1349 	u_long code;
   1350 {
   1351 	struct proc *p = curproc;
   1352 	struct sigcontext *scp, ksc;
   1353 	struct trapframe *frame;
   1354 	struct sigacts *psp = p->p_sigacts;
   1355 	int oonstack, fsize, rndfsize;
   1356 	extern char sigcode[], esigcode[];
   1357 	extern struct proc *fpcurproc;
   1358 
   1359 	frame = p->p_md.md_tf;
   1360 	oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
   1361 	fsize = sizeof ksc;
   1362 	rndfsize = ((fsize + 15) / 16) * 16;
   1363 	/*
   1364 	 * Allocate and validate space for the signal handler
   1365 	 * context. Note that if the stack is in P0 space, the
   1366 	 * call to grow() is a nop, and the useracc() check
   1367 	 * will fail if the process has not already allocated
   1368 	 * the space with a `brk'.
   1369 	 */
   1370 	if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
   1371 	    (psp->ps_sigonstack & sigmask(sig))) {
   1372 		scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp +
   1373 		    psp->ps_sigstk.ss_size - rndfsize);
   1374 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
   1375 	} else
   1376 		scp = (struct sigcontext *)(alpha_pal_rdusp() - rndfsize);
   1377 	if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
   1378 		(void)grow(p, (u_long)scp);
   1379 #ifdef DEBUG
   1380 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1381 		printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
   1382 		    sig, &oonstack, scp);
   1383 #endif
   1384 	if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
   1385 #ifdef DEBUG
   1386 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1387 			printf("sendsig(%d): useracc failed on sig %d\n",
   1388 			    p->p_pid, sig);
   1389 #endif
   1390 		/*
   1391 		 * Process has trashed its stack; give it an illegal
   1392 		 * instruction to halt it in its tracks.
   1393 		 */
   1394 		SIGACTION(p, SIGILL) = SIG_DFL;
   1395 		sig = sigmask(SIGILL);
   1396 		p->p_sigignore &= ~sig;
   1397 		p->p_sigcatch &= ~sig;
   1398 		p->p_sigmask &= ~sig;
   1399 		psignal(p, SIGILL);
   1400 		return;
   1401 	}
   1402 
   1403 	/*
   1404 	 * Build the signal context to be used by sigreturn.
   1405 	 */
   1406 	ksc.sc_onstack = oonstack;
   1407 	ksc.sc_mask = mask;
   1408 	ksc.sc_pc = frame->tf_regs[FRAME_PC];
   1409 	ksc.sc_ps = frame->tf_regs[FRAME_PS];
   1410 
   1411 	/* copy the registers. */
   1412 	frametoreg(frame, (struct reg *)ksc.sc_regs);
   1413 	ksc.sc_regs[R_ZERO] = 0xACEDBADE;		/* magic number */
   1414 	ksc.sc_regs[R_SP] = alpha_pal_rdusp();
   1415 
   1416 	/* save the floating-point state, if necessary, then copy it. */
   1417 	if (p == fpcurproc) {
   1418 		alpha_pal_wrfen(1);
   1419 		savefpstate(&p->p_addr->u_pcb.pcb_fp);
   1420 		alpha_pal_wrfen(0);
   1421 		fpcurproc = NULL;
   1422 	}
   1423 	ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
   1424 	bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
   1425 	    sizeof(struct fpreg));
   1426 	ksc.sc_fp_control = 0;					/* XXX ? */
   1427 	bzero(ksc.sc_reserved, sizeof ksc.sc_reserved);		/* XXX */
   1428 	bzero(ksc.sc_xxx, sizeof ksc.sc_xxx);			/* XXX */
   1429 
   1430 
   1431 #ifdef COMPAT_OSF1
   1432 	/*
   1433 	 * XXX Create an OSF/1-style sigcontext and associated goo.
   1434 	 */
   1435 #endif
   1436 
   1437 	/*
   1438 	 * copy the frame out to userland.
   1439 	 */
   1440 	(void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
   1441 #ifdef DEBUG
   1442 	if (sigdebug & SDB_FOLLOW)
   1443 		printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig,
   1444 		    scp, code);
   1445 #endif
   1446 
   1447 	/*
   1448 	 * Set up the registers to return to sigcode.
   1449 	 */
   1450 	frame->tf_regs[FRAME_PC] =
   1451 	    (u_int64_t)PS_STRINGS - (esigcode - sigcode);
   1452 	frame->tf_regs[FRAME_A0] = sig;
   1453 	frame->tf_regs[FRAME_A1] = code;
   1454 	frame->tf_regs[FRAME_A2] = (u_int64_t)scp;
   1455 	frame->tf_regs[FRAME_T12] = (u_int64_t)catcher;		/* t12 is pv */
   1456 	alpha_pal_wrusp((unsigned long)scp);
   1457 
   1458 #ifdef DEBUG
   1459 	if (sigdebug & SDB_FOLLOW)
   1460 		printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
   1461 		    frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]);
   1462 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1463 		printf("sendsig(%d): sig %d returns\n",
   1464 		    p->p_pid, sig);
   1465 #endif
   1466 }
   1467 
   1468 /*
   1469  * System call to cleanup state after a signal
   1470  * has been taken.  Reset signal mask and
   1471  * stack state from context left by sendsig (above).
   1472  * Return to previous pc and psl as specified by
   1473  * context left by sendsig. Check carefully to
   1474  * make sure that the user has not modified the
   1475  * psl to gain improper priviledges or to cause
   1476  * a machine fault.
   1477  */
   1478 /* ARGSUSED */
   1479 int
   1480 sys_sigreturn(p, v, retval)
   1481 	struct proc *p;
   1482 	void *v;
   1483 	register_t *retval;
   1484 {
   1485 	struct sys_sigreturn_args /* {
   1486 		syscallarg(struct sigcontext *) sigcntxp;
   1487 	} */ *uap = v;
   1488 	struct sigcontext *scp, ksc;
   1489 	extern struct proc *fpcurproc;
   1490 
   1491 	scp = SCARG(uap, sigcntxp);
   1492 #ifdef DEBUG
   1493 	if (sigdebug & SDB_FOLLOW)
   1494 	    printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
   1495 #endif
   1496 
   1497 	if (ALIGN(scp) != (u_int64_t)scp)
   1498 		return (EINVAL);
   1499 
   1500 	/*
   1501 	 * Test and fetch the context structure.
   1502 	 * We grab it all at once for speed.
   1503 	 */
   1504 	if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
   1505 	    copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
   1506 		return (EINVAL);
   1507 
   1508 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
   1509 		return (EINVAL);
   1510 	/*
   1511 	 * Restore the user-supplied information
   1512 	 */
   1513 	if (ksc.sc_onstack)
   1514 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
   1515 	else
   1516 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
   1517 	p->p_sigmask = ksc.sc_mask &~ sigcantmask;
   1518 
   1519 	p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
   1520 	p->p_md.md_tf->tf_regs[FRAME_PS] =
   1521 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
   1522 
   1523 	regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
   1524 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
   1525 
   1526 	/* XXX ksc.sc_ownedfp ? */
   1527 	if (p == fpcurproc)
   1528 		fpcurproc = NULL;
   1529 	bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
   1530 	    sizeof(struct fpreg));
   1531 	/* XXX ksc.sc_fp_control ? */
   1532 
   1533 #ifdef DEBUG
   1534 	if (sigdebug & SDB_FOLLOW)
   1535 		printf("sigreturn(%d): returns\n", p->p_pid);
   1536 #endif
   1537 	return (EJUSTRETURN);
   1538 }
   1539 
   1540 /*
   1541  * machine dependent system variables.
   1542  */
   1543 int
   1544 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
   1545 	int *name;
   1546 	u_int namelen;
   1547 	void *oldp;
   1548 	size_t *oldlenp;
   1549 	void *newp;
   1550 	size_t newlen;
   1551 	struct proc *p;
   1552 {
   1553 	dev_t consdev;
   1554 
   1555 	/* all sysctl names at this level are terminal */
   1556 	if (namelen != 1)
   1557 		return (ENOTDIR);		/* overloaded */
   1558 
   1559 	switch (name[0]) {
   1560 	case CPU_CONSDEV:
   1561 		if (cn_tab != NULL)
   1562 			consdev = cn_tab->cn_dev;
   1563 		else
   1564 			consdev = NODEV;
   1565 		return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
   1566 			sizeof consdev));
   1567 
   1568 	case CPU_ROOT_DEVICE:
   1569 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1570 		    root_device->dv_xname));
   1571 
   1572 	case CPU_UNALIGNED_PRINT:
   1573 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1574 		    &alpha_unaligned_print));
   1575 
   1576 	case CPU_UNALIGNED_FIX:
   1577 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1578 		    &alpha_unaligned_fix));
   1579 
   1580 	case CPU_UNALIGNED_SIGBUS:
   1581 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1582 		    &alpha_unaligned_sigbus));
   1583 
   1584 	case CPU_BOOTED_KERNEL:
   1585 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1586 		    bootinfo.booted_kernel));
   1587 
   1588 	default:
   1589 		return (EOPNOTSUPP);
   1590 	}
   1591 	/* NOTREACHED */
   1592 }
   1593 
   1594 /*
   1595  * Set registers on exec.
   1596  */
   1597 void
   1598 setregs(p, pack, stack)
   1599 	register struct proc *p;
   1600 	struct exec_package *pack;
   1601 	u_long stack;
   1602 {
   1603 	struct trapframe *tfp = p->p_md.md_tf;
   1604 	extern struct proc *fpcurproc;
   1605 #ifdef DEBUG
   1606 	int i;
   1607 #endif
   1608 
   1609 #ifdef DEBUG
   1610 	/*
   1611 	 * Crash and dump, if the user requested it.
   1612 	 */
   1613 	if (boothowto & RB_DUMP)
   1614 		panic("crash requested by boot flags");
   1615 #endif
   1616 
   1617 #ifdef DEBUG
   1618 	for (i = 0; i < FRAME_SIZE; i++)
   1619 		tfp->tf_regs[i] = 0xbabefacedeadbeef;
   1620 #else
   1621 	bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]);
   1622 #endif
   1623 	bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
   1624 #define FP_RN 2 /* XXX */
   1625 	p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
   1626 	alpha_pal_wrusp(stack);
   1627 	tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET;
   1628 	tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3;
   1629 
   1630 	tfp->tf_regs[FRAME_A0] = stack;			/* a0 = sp */
   1631 	tfp->tf_regs[FRAME_A1] = 0;			/* a1 = rtld cleanup */
   1632 	tfp->tf_regs[FRAME_A2] = 0;			/* a2 = rtld object */
   1633 	tfp->tf_regs[FRAME_A3] = (u_int64_t)PS_STRINGS;	/* a3 = ps_strings */
   1634 	tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC];	/* a.k.a. PV */
   1635 
   1636 	p->p_md.md_flags &= ~MDP_FPUSED;
   1637 	if (fpcurproc == p)
   1638 		fpcurproc = NULL;
   1639 }
   1640 
   1641 void
   1642 netintr()
   1643 {
   1644 	int n, s;
   1645 
   1646 	s = splhigh();
   1647 	n = netisr;
   1648 	netisr = 0;
   1649 	splx(s);
   1650 
   1651 #define	DONETISR(bit, fn)						\
   1652 	do {								\
   1653 		if (n & (1 << (bit)))					\
   1654 			fn;						\
   1655 	} while (0)
   1656 
   1657 #ifdef INET
   1658 #if NARP > 0
   1659 	DONETISR(NETISR_ARP, arpintr());
   1660 #endif
   1661 	DONETISR(NETISR_IP, ipintr());
   1662 #endif
   1663 #ifdef NETATALK
   1664 	DONETISR(NETISR_ATALK, atintr());
   1665 #endif
   1666 #ifdef NS
   1667 	DONETISR(NETISR_NS, nsintr());
   1668 #endif
   1669 #ifdef ISO
   1670 	DONETISR(NETISR_ISO, clnlintr());
   1671 #endif
   1672 #ifdef CCITT
   1673 	DONETISR(NETISR_CCITT, ccittintr());
   1674 #endif
   1675 #ifdef NATM
   1676 	DONETISR(NETISR_NATM, natmintr());
   1677 #endif
   1678 #if NPPP > 1
   1679 	DONETISR(NETISR_PPP, pppintr());
   1680 #endif
   1681 
   1682 #undef DONETISR
   1683 }
   1684 
   1685 void
   1686 do_sir()
   1687 {
   1688 	u_int64_t n;
   1689 
   1690 	do {
   1691 		(void)splhigh();
   1692 		n = ssir;
   1693 		ssir = 0;
   1694 		splsoft();		/* don't recurse through spl0() */
   1695 
   1696 #define	DO_SIR(bit, fn)							\
   1697 		do {							\
   1698 			if (n & (bit)) {				\
   1699 				cnt.v_soft++;				\
   1700 				fn;					\
   1701 			}						\
   1702 		} while (0)
   1703 
   1704 		DO_SIR(SIR_NET, netintr());
   1705 		DO_SIR(SIR_CLOCK, softclock());
   1706 
   1707 #undef DO_SIR
   1708 	} while (ssir != 0);
   1709 }
   1710 
   1711 int
   1712 spl0()
   1713 {
   1714 
   1715 	if (ssir)
   1716 		do_sir();		/* it lowers the IPL itself */
   1717 
   1718 	return (alpha_pal_swpipl(ALPHA_PSL_IPL_0));
   1719 }
   1720 
   1721 /*
   1722  * The following primitives manipulate the run queues.  _whichqs tells which
   1723  * of the 32 queues _qs have processes in them.  Setrunqueue puts processes
   1724  * into queues, Remrunqueue removes them from queues.  The running process is
   1725  * on no queue, other processes are on a queue related to p->p_priority,
   1726  * divided by 4 actually to shrink the 0-127 range of priorities into the 32
   1727  * available queues.
   1728  */
   1729 /*
   1730  * setrunqueue(p)
   1731  *	proc *p;
   1732  *
   1733  * Call should be made at splclock(), and p->p_stat should be SRUN.
   1734  */
   1735 
   1736 void
   1737 setrunqueue(p)
   1738 	struct proc *p;
   1739 {
   1740 	int bit;
   1741 
   1742 	/* firewall: p->p_back must be NULL */
   1743 	if (p->p_back != NULL)
   1744 		panic("setrunqueue");
   1745 
   1746 	bit = p->p_priority >> 2;
   1747 	whichqs |= (1 << bit);
   1748 	p->p_forw = (struct proc *)&qs[bit];
   1749 	p->p_back = qs[bit].ph_rlink;
   1750 	p->p_back->p_forw = p;
   1751 	qs[bit].ph_rlink = p;
   1752 }
   1753 
   1754 /*
   1755  * remrunqueue(p)
   1756  *
   1757  * Call should be made at splclock().
   1758  */
   1759 void
   1760 remrunqueue(p)
   1761 	struct proc *p;
   1762 {
   1763 	int bit;
   1764 
   1765 	bit = p->p_priority >> 2;
   1766 	if ((whichqs & (1 << bit)) == 0)
   1767 		panic("remrunqueue");
   1768 
   1769 	p->p_back->p_forw = p->p_forw;
   1770 	p->p_forw->p_back = p->p_back;
   1771 	p->p_back = NULL;	/* for firewall checking. */
   1772 
   1773 	if ((struct proc *)&qs[bit] == qs[bit].ph_link)
   1774 		whichqs &= ~(1 << bit);
   1775 }
   1776 
   1777 /*
   1778  * Return the best possible estimate of the time in the timeval
   1779  * to which tvp points.  Unfortunately, we can't read the hardware registers.
   1780  * We guarantee that the time will be greater than the value obtained by a
   1781  * previous call.
   1782  */
   1783 void
   1784 microtime(tvp)
   1785 	register struct timeval *tvp;
   1786 {
   1787 	int s = splclock();
   1788 	static struct timeval lasttime;
   1789 
   1790 	*tvp = time;
   1791 #ifdef notdef
   1792 	tvp->tv_usec += clkread();
   1793 	while (tvp->tv_usec > 1000000) {
   1794 		tvp->tv_sec++;
   1795 		tvp->tv_usec -= 1000000;
   1796 	}
   1797 #endif
   1798 	if (tvp->tv_sec == lasttime.tv_sec &&
   1799 	    tvp->tv_usec <= lasttime.tv_usec &&
   1800 	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
   1801 		tvp->tv_sec++;
   1802 		tvp->tv_usec -= 1000000;
   1803 	}
   1804 	lasttime = *tvp;
   1805 	splx(s);
   1806 }
   1807 
   1808 /*
   1809  * Wait "n" microseconds.
   1810  */
   1811 void
   1812 delay(n)
   1813 	unsigned long n;
   1814 {
   1815 	long N = cycles_per_usec * (n);
   1816 
   1817 	while (N > 0)				/* XXX */
   1818 		N -= 3;				/* XXX */
   1819 }
   1820 
   1821 #if defined(COMPAT_OSF1) || 1		/* XXX */
   1822 void	cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
   1823 	    u_long));
   1824 
   1825 void
   1826 cpu_exec_ecoff_setregs(p, epp, stack)
   1827 	struct proc *p;
   1828 	struct exec_package *epp;
   1829 	u_long stack;
   1830 {
   1831 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   1832 
   1833 	setregs(p, epp, stack);
   1834 	p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value;
   1835 }
   1836 
   1837 /*
   1838  * cpu_exec_ecoff_hook():
   1839  *	cpu-dependent ECOFF format hook for execve().
   1840  *
   1841  * Do any machine-dependent diddling of the exec package when doing ECOFF.
   1842  *
   1843  */
   1844 int
   1845 cpu_exec_ecoff_hook(p, epp)
   1846 	struct proc *p;
   1847 	struct exec_package *epp;
   1848 {
   1849 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   1850 	extern struct emul emul_netbsd;
   1851 #ifdef COMPAT_OSF1
   1852 	extern struct emul emul_osf1;
   1853 #endif
   1854 
   1855 	switch (execp->f.f_magic) {
   1856 #ifdef COMPAT_OSF1
   1857 	case ECOFF_MAGIC_ALPHA:
   1858 		epp->ep_emul = &emul_osf1;
   1859 		break;
   1860 #endif
   1861 
   1862 	case ECOFF_MAGIC_NETBSD_ALPHA:
   1863 		epp->ep_emul = &emul_netbsd;
   1864 		break;
   1865 
   1866 	default:
   1867 		return ENOEXEC;
   1868 	}
   1869 	return 0;
   1870 }
   1871 #endif
   1872 
   1873 /* XXX XXX BEGIN XXX XXX */
   1874 vm_offset_t alpha_XXX_dmamap_or;				/* XXX */
   1875 								/* XXX */
   1876 vm_offset_t							/* XXX */
   1877 alpha_XXX_dmamap(v)						/* XXX */
   1878 	vm_offset_t v;						/* XXX */
   1879 {								/* XXX */
   1880 								/* XXX */
   1881 	return (vtophys(v) | alpha_XXX_dmamap_or);		/* XXX */
   1882 }								/* XXX */
   1883 /* XXX XXX END XXX XXX */
   1884