Home | History | Annotate | Line # | Download | only in alpha
machdep.c revision 1.107
      1 /* $NetBSD: machdep.c,v 1.107 1998/02/14 00:53:26 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.107 1998/02/14 00:53:26 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 	if (roundup(size, dbtob(1)) != dbtob(1))
   1030 		return -1;
   1031 
   1032 	return (1);
   1033 }
   1034 
   1035 /*
   1036  * cpu_dump: dump machine-dependent kernel core dump headers.
   1037  */
   1038 int
   1039 cpu_dump()
   1040 {
   1041 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1042 	char buf[dbtob(1)];
   1043 	kcore_seg_t *segp;
   1044 	cpu_kcore_hdr_t *cpuhdrp;
   1045 	phys_ram_seg_t *memsegp;
   1046 
   1047 	dump = bdevsw[major(dumpdev)].d_dump;
   1048 
   1049 	bzero(buf, sizeof buf);
   1050 	segp = (kcore_seg_t *)buf;
   1051 	cpuhdrp = (cpu_kcore_hdr_t *)&buf[ALIGN(sizeof(*segp))];
   1052 	memsegp = (phys_ram_seg_t *)&buf[ ALIGN(sizeof(*segp)) +
   1053 	    ALIGN(sizeof(*cpuhdrp))];
   1054 
   1055 	/*
   1056 	 * Generate a segment header.
   1057 	 */
   1058 	CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
   1059 	segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
   1060 
   1061 	/*
   1062 	 * Add the machine-dependent header info.
   1063 	 */
   1064 	cpuhdrp->lev1map_pa = ALPHA_K0SEG_TO_PHYS((vm_offset_t)Lev1map);
   1065 	cpuhdrp->page_size = PAGE_SIZE;
   1066 	cpuhdrp->nmemsegs = 1;
   1067 
   1068 	/*
   1069 	 * Fill in the memory segment descriptors.
   1070 	 */
   1071 	memsegp[0].start = ctob(firstusablepage);
   1072 	memsegp[0].size = ctob(physmem);
   1073 
   1074 	return (dump(dumpdev, dumplo, (caddr_t)buf, dbtob(1)));
   1075 }
   1076 
   1077 /*
   1078  * This is called by main to set dumplo and dumpsize.
   1079  * Dumps always skip the first CLBYTES of disk space
   1080  * in case there might be a disk label stored there.
   1081  * If there is extra space, put dump at the end to
   1082  * reduce the chance that swapping trashes it.
   1083  */
   1084 void
   1085 cpu_dumpconf()
   1086 {
   1087 	int nblks, dumpblks;	/* size of dump area */
   1088 	int maj;
   1089 
   1090 	if (dumpdev == NODEV)
   1091 		goto bad;
   1092 	maj = major(dumpdev);
   1093 	if (maj < 0 || maj >= nblkdev)
   1094 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
   1095 	if (bdevsw[maj].d_psize == NULL)
   1096 		goto bad;
   1097 	nblks = (*bdevsw[maj].d_psize)(dumpdev);
   1098 	if (nblks <= ctod(1))
   1099 		goto bad;
   1100 
   1101 	dumpblks = cpu_dumpsize();
   1102 	if (dumpblks < 0)
   1103 		goto bad;
   1104 	dumpblks += ctod(physmem);
   1105 
   1106 	/* If dump won't fit (incl. room for possible label), punt. */
   1107 	if (dumpblks > (nblks - ctod(1)))
   1108 		goto bad;
   1109 
   1110 	/* Put dump at end of partition */
   1111 	dumplo = nblks - dumpblks;
   1112 
   1113 	/* dumpsize is in page units, and doesn't include headers. */
   1114 	dumpsize = physmem;
   1115 	return;
   1116 
   1117 bad:
   1118 	dumpsize = 0;
   1119 	return;
   1120 }
   1121 
   1122 /*
   1123  * Dump the kernel's image to the swap partition.
   1124  */
   1125 #define	BYTES_PER_DUMP	NBPG
   1126 
   1127 void
   1128 dumpsys()
   1129 {
   1130 	unsigned bytes, i, n;
   1131 	int maddr, psize;
   1132 	daddr_t blkno;
   1133 	int (*dump) __P((dev_t, daddr_t, caddr_t, size_t));
   1134 	int error;
   1135 
   1136 	/* Save registers. */
   1137 	savectx(&dumppcb);
   1138 
   1139 	msgbufmapped = 0;	/* don't record dump msgs in msgbuf */
   1140 	if (dumpdev == NODEV)
   1141 		return;
   1142 
   1143 	/*
   1144 	 * For dumps during autoconfiguration,
   1145 	 * if dump device has already configured...
   1146 	 */
   1147 	if (dumpsize == 0)
   1148 		cpu_dumpconf();
   1149 	if (dumplo <= 0) {
   1150 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
   1151 		    minor(dumpdev));
   1152 		return;
   1153 	}
   1154 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
   1155 	    minor(dumpdev), dumplo);
   1156 
   1157 	psize = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
   1158 	printf("dump ");
   1159 	if (psize == -1) {
   1160 		printf("area unavailable\n");
   1161 		return;
   1162 	}
   1163 
   1164 	/* XXX should purge all outstanding keystrokes. */
   1165 
   1166 	if ((error = cpu_dump()) != 0)
   1167 		goto err;
   1168 
   1169 	bytes = ctob(physmem);
   1170 	maddr = ctob(firstusablepage);
   1171 	blkno = dumplo + cpu_dumpsize();
   1172 	dump = bdevsw[major(dumpdev)].d_dump;
   1173 	error = 0;
   1174 	for (i = 0; i < bytes; i += n) {
   1175 
   1176 		/* Print out how many MBs we to go. */
   1177 		n = bytes - i;
   1178 		if (n && (n % (1024*1024)) == 0)
   1179 			printf("%d ", n / (1024 * 1024));
   1180 
   1181 		/* Limit size for next transfer. */
   1182 		if (n > BYTES_PER_DUMP)
   1183 			n =  BYTES_PER_DUMP;
   1184 
   1185 		error = (*dump)(dumpdev, blkno,
   1186 		    (caddr_t)ALPHA_PHYS_TO_K0SEG(maddr), n);
   1187 		if (error)
   1188 			break;
   1189 		maddr += n;
   1190 		blkno += btodb(n);			/* XXX? */
   1191 
   1192 		/* XXX should look for keystrokes, to cancel. */
   1193 	}
   1194 
   1195 err:
   1196 	switch (error) {
   1197 
   1198 	case ENXIO:
   1199 		printf("device bad\n");
   1200 		break;
   1201 
   1202 	case EFAULT:
   1203 		printf("device not ready\n");
   1204 		break;
   1205 
   1206 	case EINVAL:
   1207 		printf("area improper\n");
   1208 		break;
   1209 
   1210 	case EIO:
   1211 		printf("i/o error\n");
   1212 		break;
   1213 
   1214 	case EINTR:
   1215 		printf("aborted from console\n");
   1216 		break;
   1217 
   1218 	case 0:
   1219 		printf("succeeded\n");
   1220 		break;
   1221 
   1222 	default:
   1223 		printf("error %d\n", error);
   1224 		break;
   1225 	}
   1226 	printf("\n\n");
   1227 	delay(1000);
   1228 }
   1229 
   1230 void
   1231 frametoreg(framep, regp)
   1232 	struct trapframe *framep;
   1233 	struct reg *regp;
   1234 {
   1235 
   1236 	regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
   1237 	regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
   1238 	regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
   1239 	regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
   1240 	regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
   1241 	regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
   1242 	regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
   1243 	regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
   1244 	regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
   1245 	regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
   1246 	regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
   1247 	regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
   1248 	regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
   1249 	regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
   1250 	regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
   1251 	regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
   1252 	regp->r_regs[R_A0] = framep->tf_regs[FRAME_A0];
   1253 	regp->r_regs[R_A1] = framep->tf_regs[FRAME_A1];
   1254 	regp->r_regs[R_A2] = framep->tf_regs[FRAME_A2];
   1255 	regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
   1256 	regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
   1257 	regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
   1258 	regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
   1259 	regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
   1260 	regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
   1261 	regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
   1262 	regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
   1263 	regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
   1264 	regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
   1265 	regp->r_regs[R_GP] = framep->tf_regs[FRAME_GP];
   1266 	/* regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP]; XXX */
   1267 	regp->r_regs[R_ZERO] = 0;
   1268 }
   1269 
   1270 void
   1271 regtoframe(regp, framep)
   1272 	struct reg *regp;
   1273 	struct trapframe *framep;
   1274 {
   1275 
   1276 	framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
   1277 	framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
   1278 	framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
   1279 	framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
   1280 	framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
   1281 	framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
   1282 	framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
   1283 	framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
   1284 	framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
   1285 	framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
   1286 	framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
   1287 	framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
   1288 	framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
   1289 	framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
   1290 	framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
   1291 	framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
   1292 	framep->tf_regs[FRAME_A0] = regp->r_regs[R_A0];
   1293 	framep->tf_regs[FRAME_A1] = regp->r_regs[R_A1];
   1294 	framep->tf_regs[FRAME_A2] = regp->r_regs[R_A2];
   1295 	framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
   1296 	framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
   1297 	framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
   1298 	framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
   1299 	framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
   1300 	framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
   1301 	framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
   1302 	framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
   1303 	framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
   1304 	framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
   1305 	framep->tf_regs[FRAME_GP] = regp->r_regs[R_GP];
   1306 	/* framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP]; XXX */
   1307 	/* ??? = regp->r_regs[R_ZERO]; */
   1308 }
   1309 
   1310 void
   1311 printregs(regp)
   1312 	struct reg *regp;
   1313 {
   1314 	int i;
   1315 
   1316 	for (i = 0; i < 32; i++)
   1317 		printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
   1318 		   i & 1 ? "\n" : "\t");
   1319 }
   1320 
   1321 void
   1322 regdump(framep)
   1323 	struct trapframe *framep;
   1324 {
   1325 	struct reg reg;
   1326 
   1327 	frametoreg(framep, &reg);
   1328 	reg.r_regs[R_SP] = alpha_pal_rdusp();
   1329 
   1330 	printf("REGISTERS:\n");
   1331 	printregs(&reg);
   1332 }
   1333 
   1334 #ifdef DEBUG
   1335 int sigdebug = 0;
   1336 int sigpid = 0;
   1337 #define	SDB_FOLLOW	0x01
   1338 #define	SDB_KSTACK	0x02
   1339 #endif
   1340 
   1341 /*
   1342  * Send an interrupt to process.
   1343  */
   1344 void
   1345 sendsig(catcher, sig, mask, code)
   1346 	sig_t catcher;
   1347 	int sig, mask;
   1348 	u_long code;
   1349 {
   1350 	struct proc *p = curproc;
   1351 	struct sigcontext *scp, ksc;
   1352 	struct trapframe *frame;
   1353 	struct sigacts *psp = p->p_sigacts;
   1354 	int oonstack, fsize, rndfsize;
   1355 	extern char sigcode[], esigcode[];
   1356 	extern struct proc *fpcurproc;
   1357 
   1358 	frame = p->p_md.md_tf;
   1359 	oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
   1360 	fsize = sizeof ksc;
   1361 	rndfsize = ((fsize + 15) / 16) * 16;
   1362 	/*
   1363 	 * Allocate and validate space for the signal handler
   1364 	 * context. Note that if the stack is in P0 space, the
   1365 	 * call to grow() is a nop, and the useracc() check
   1366 	 * will fail if the process has not already allocated
   1367 	 * the space with a `brk'.
   1368 	 */
   1369 	if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
   1370 	    (psp->ps_sigonstack & sigmask(sig))) {
   1371 		scp = (struct sigcontext *)(psp->ps_sigstk.ss_sp +
   1372 		    psp->ps_sigstk.ss_size - rndfsize);
   1373 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
   1374 	} else
   1375 		scp = (struct sigcontext *)(alpha_pal_rdusp() - rndfsize);
   1376 	if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
   1377 		(void)grow(p, (u_long)scp);
   1378 #ifdef DEBUG
   1379 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1380 		printf("sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
   1381 		    sig, &oonstack, scp);
   1382 #endif
   1383 	if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
   1384 #ifdef DEBUG
   1385 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1386 			printf("sendsig(%d): useracc failed on sig %d\n",
   1387 			    p->p_pid, sig);
   1388 #endif
   1389 		/*
   1390 		 * Process has trashed its stack; give it an illegal
   1391 		 * instruction to halt it in its tracks.
   1392 		 */
   1393 		SIGACTION(p, SIGILL) = SIG_DFL;
   1394 		sig = sigmask(SIGILL);
   1395 		p->p_sigignore &= ~sig;
   1396 		p->p_sigcatch &= ~sig;
   1397 		p->p_sigmask &= ~sig;
   1398 		psignal(p, SIGILL);
   1399 		return;
   1400 	}
   1401 
   1402 	/*
   1403 	 * Build the signal context to be used by sigreturn.
   1404 	 */
   1405 	ksc.sc_onstack = oonstack;
   1406 	ksc.sc_mask = mask;
   1407 	ksc.sc_pc = frame->tf_regs[FRAME_PC];
   1408 	ksc.sc_ps = frame->tf_regs[FRAME_PS];
   1409 
   1410 	/* copy the registers. */
   1411 	frametoreg(frame, (struct reg *)ksc.sc_regs);
   1412 	ksc.sc_regs[R_ZERO] = 0xACEDBADE;		/* magic number */
   1413 	ksc.sc_regs[R_SP] = alpha_pal_rdusp();
   1414 
   1415 	/* save the floating-point state, if necessary, then copy it. */
   1416 	if (p == fpcurproc) {
   1417 		alpha_pal_wrfen(1);
   1418 		savefpstate(&p->p_addr->u_pcb.pcb_fp);
   1419 		alpha_pal_wrfen(0);
   1420 		fpcurproc = NULL;
   1421 	}
   1422 	ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
   1423 	bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
   1424 	    sizeof(struct fpreg));
   1425 	ksc.sc_fp_control = 0;					/* XXX ? */
   1426 	bzero(ksc.sc_reserved, sizeof ksc.sc_reserved);		/* XXX */
   1427 	bzero(ksc.sc_xxx, sizeof ksc.sc_xxx);			/* XXX */
   1428 
   1429 
   1430 #ifdef COMPAT_OSF1
   1431 	/*
   1432 	 * XXX Create an OSF/1-style sigcontext and associated goo.
   1433 	 */
   1434 #endif
   1435 
   1436 	/*
   1437 	 * copy the frame out to userland.
   1438 	 */
   1439 	(void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
   1440 #ifdef DEBUG
   1441 	if (sigdebug & SDB_FOLLOW)
   1442 		printf("sendsig(%d): sig %d scp %p code %lx\n", p->p_pid, sig,
   1443 		    scp, code);
   1444 #endif
   1445 
   1446 	/*
   1447 	 * Set up the registers to return to sigcode.
   1448 	 */
   1449 	frame->tf_regs[FRAME_PC] =
   1450 	    (u_int64_t)PS_STRINGS - (esigcode - sigcode);
   1451 	frame->tf_regs[FRAME_A0] = sig;
   1452 	frame->tf_regs[FRAME_A1] = code;
   1453 	frame->tf_regs[FRAME_A2] = (u_int64_t)scp;
   1454 	frame->tf_regs[FRAME_T12] = (u_int64_t)catcher;		/* t12 is pv */
   1455 	alpha_pal_wrusp((unsigned long)scp);
   1456 
   1457 #ifdef DEBUG
   1458 	if (sigdebug & SDB_FOLLOW)
   1459 		printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
   1460 		    frame->tf_regs[FRAME_PC], frame->tf_regs[FRAME_A3]);
   1461 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1462 		printf("sendsig(%d): sig %d returns\n",
   1463 		    p->p_pid, sig);
   1464 #endif
   1465 }
   1466 
   1467 /*
   1468  * System call to cleanup state after a signal
   1469  * has been taken.  Reset signal mask and
   1470  * stack state from context left by sendsig (above).
   1471  * Return to previous pc and psl as specified by
   1472  * context left by sendsig. Check carefully to
   1473  * make sure that the user has not modified the
   1474  * psl to gain improper priviledges or to cause
   1475  * a machine fault.
   1476  */
   1477 /* ARGSUSED */
   1478 int
   1479 sys_sigreturn(p, v, retval)
   1480 	struct proc *p;
   1481 	void *v;
   1482 	register_t *retval;
   1483 {
   1484 	struct sys_sigreturn_args /* {
   1485 		syscallarg(struct sigcontext *) sigcntxp;
   1486 	} */ *uap = v;
   1487 	struct sigcontext *scp, ksc;
   1488 	extern struct proc *fpcurproc;
   1489 
   1490 	scp = SCARG(uap, sigcntxp);
   1491 #ifdef DEBUG
   1492 	if (sigdebug & SDB_FOLLOW)
   1493 	    printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
   1494 #endif
   1495 
   1496 	if (ALIGN(scp) != (u_int64_t)scp)
   1497 		return (EINVAL);
   1498 
   1499 	/*
   1500 	 * Test and fetch the context structure.
   1501 	 * We grab it all at once for speed.
   1502 	 */
   1503 	if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
   1504 	    copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
   1505 		return (EINVAL);
   1506 
   1507 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
   1508 		return (EINVAL);
   1509 	/*
   1510 	 * Restore the user-supplied information
   1511 	 */
   1512 	if (ksc.sc_onstack)
   1513 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
   1514 	else
   1515 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
   1516 	p->p_sigmask = ksc.sc_mask &~ sigcantmask;
   1517 
   1518 	p->p_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
   1519 	p->p_md.md_tf->tf_regs[FRAME_PS] =
   1520 	    (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
   1521 
   1522 	regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
   1523 	alpha_pal_wrusp(ksc.sc_regs[R_SP]);
   1524 
   1525 	/* XXX ksc.sc_ownedfp ? */
   1526 	if (p == fpcurproc)
   1527 		fpcurproc = NULL;
   1528 	bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
   1529 	    sizeof(struct fpreg));
   1530 	/* XXX ksc.sc_fp_control ? */
   1531 
   1532 #ifdef DEBUG
   1533 	if (sigdebug & SDB_FOLLOW)
   1534 		printf("sigreturn(%d): returns\n", p->p_pid);
   1535 #endif
   1536 	return (EJUSTRETURN);
   1537 }
   1538 
   1539 /*
   1540  * machine dependent system variables.
   1541  */
   1542 int
   1543 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
   1544 	int *name;
   1545 	u_int namelen;
   1546 	void *oldp;
   1547 	size_t *oldlenp;
   1548 	void *newp;
   1549 	size_t newlen;
   1550 	struct proc *p;
   1551 {
   1552 	dev_t consdev;
   1553 
   1554 	/* all sysctl names at this level are terminal */
   1555 	if (namelen != 1)
   1556 		return (ENOTDIR);		/* overloaded */
   1557 
   1558 	switch (name[0]) {
   1559 	case CPU_CONSDEV:
   1560 		if (cn_tab != NULL)
   1561 			consdev = cn_tab->cn_dev;
   1562 		else
   1563 			consdev = NODEV;
   1564 		return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
   1565 			sizeof consdev));
   1566 
   1567 	case CPU_ROOT_DEVICE:
   1568 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1569 		    root_device->dv_xname));
   1570 
   1571 	case CPU_UNALIGNED_PRINT:
   1572 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1573 		    &alpha_unaligned_print));
   1574 
   1575 	case CPU_UNALIGNED_FIX:
   1576 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1577 		    &alpha_unaligned_fix));
   1578 
   1579 	case CPU_UNALIGNED_SIGBUS:
   1580 		return (sysctl_int(oldp, oldlenp, newp, newlen,
   1581 		    &alpha_unaligned_sigbus));
   1582 
   1583 	case CPU_BOOTED_KERNEL:
   1584 		return (sysctl_rdstring(oldp, oldlenp, newp,
   1585 		    bootinfo.booted_kernel));
   1586 
   1587 	default:
   1588 		return (EOPNOTSUPP);
   1589 	}
   1590 	/* NOTREACHED */
   1591 }
   1592 
   1593 /*
   1594  * Set registers on exec.
   1595  */
   1596 void
   1597 setregs(p, pack, stack)
   1598 	register struct proc *p;
   1599 	struct exec_package *pack;
   1600 	u_long stack;
   1601 {
   1602 	struct trapframe *tfp = p->p_md.md_tf;
   1603 	extern struct proc *fpcurproc;
   1604 #ifdef DEBUG
   1605 	int i;
   1606 #endif
   1607 
   1608 #ifdef DEBUG
   1609 	/*
   1610 	 * Crash and dump, if the user requested it.
   1611 	 */
   1612 	if (boothowto & RB_DUMP)
   1613 		panic("crash requested by boot flags");
   1614 #endif
   1615 
   1616 #ifdef DEBUG
   1617 	for (i = 0; i < FRAME_SIZE; i++)
   1618 		tfp->tf_regs[i] = 0xbabefacedeadbeef;
   1619 #else
   1620 	bzero(tfp->tf_regs, FRAME_SIZE * sizeof tfp->tf_regs[0]);
   1621 #endif
   1622 	bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
   1623 #define FP_RN 2 /* XXX */
   1624 	p->p_addr->u_pcb.pcb_fp.fpr_cr = (long)FP_RN << 58;
   1625 	alpha_pal_wrusp(stack);
   1626 	tfp->tf_regs[FRAME_PS] = ALPHA_PSL_USERSET;
   1627 	tfp->tf_regs[FRAME_PC] = pack->ep_entry & ~3;
   1628 
   1629 	tfp->tf_regs[FRAME_A0] = stack;			/* a0 = sp */
   1630 	tfp->tf_regs[FRAME_A1] = 0;			/* a1 = rtld cleanup */
   1631 	tfp->tf_regs[FRAME_A2] = 0;			/* a2 = rtld object */
   1632 	tfp->tf_regs[FRAME_A3] = (u_int64_t)PS_STRINGS;	/* a3 = ps_strings */
   1633 	tfp->tf_regs[FRAME_T12] = tfp->tf_regs[FRAME_PC];	/* a.k.a. PV */
   1634 
   1635 	p->p_md.md_flags &= ~MDP_FPUSED;
   1636 	if (fpcurproc == p)
   1637 		fpcurproc = NULL;
   1638 }
   1639 
   1640 void
   1641 netintr()
   1642 {
   1643 	int n, s;
   1644 
   1645 	s = splhigh();
   1646 	n = netisr;
   1647 	netisr = 0;
   1648 	splx(s);
   1649 
   1650 #define	DONETISR(bit, fn)						\
   1651 	do {								\
   1652 		if (n & (1 << (bit)))					\
   1653 			fn;						\
   1654 	} while (0)
   1655 
   1656 #ifdef INET
   1657 #if NARP > 0
   1658 	DONETISR(NETISR_ARP, arpintr());
   1659 #endif
   1660 	DONETISR(NETISR_IP, ipintr());
   1661 #endif
   1662 #ifdef NETATALK
   1663 	DONETISR(NETISR_ATALK, atintr());
   1664 #endif
   1665 #ifdef NS
   1666 	DONETISR(NETISR_NS, nsintr());
   1667 #endif
   1668 #ifdef ISO
   1669 	DONETISR(NETISR_ISO, clnlintr());
   1670 #endif
   1671 #ifdef CCITT
   1672 	DONETISR(NETISR_CCITT, ccittintr());
   1673 #endif
   1674 #ifdef NATM
   1675 	DONETISR(NETISR_NATM, natmintr());
   1676 #endif
   1677 #if NPPP > 1
   1678 	DONETISR(NETISR_PPP, pppintr());
   1679 #endif
   1680 
   1681 #undef DONETISR
   1682 }
   1683 
   1684 void
   1685 do_sir()
   1686 {
   1687 	u_int64_t n;
   1688 
   1689 	do {
   1690 		(void)splhigh();
   1691 		n = ssir;
   1692 		ssir = 0;
   1693 		splsoft();		/* don't recurse through spl0() */
   1694 
   1695 #define	DO_SIR(bit, fn)							\
   1696 		do {							\
   1697 			if (n & (bit)) {				\
   1698 				cnt.v_soft++;				\
   1699 				fn;					\
   1700 			}						\
   1701 		} while (0)
   1702 
   1703 		DO_SIR(SIR_NET, netintr());
   1704 		DO_SIR(SIR_CLOCK, softclock());
   1705 
   1706 #undef DO_SIR
   1707 	} while (ssir != 0);
   1708 }
   1709 
   1710 int
   1711 spl0()
   1712 {
   1713 
   1714 	if (ssir)
   1715 		do_sir();		/* it lowers the IPL itself */
   1716 
   1717 	return (alpha_pal_swpipl(ALPHA_PSL_IPL_0));
   1718 }
   1719 
   1720 /*
   1721  * The following primitives manipulate the run queues.  _whichqs tells which
   1722  * of the 32 queues _qs have processes in them.  Setrunqueue puts processes
   1723  * into queues, Remrunqueue removes them from queues.  The running process is
   1724  * on no queue, other processes are on a queue related to p->p_priority,
   1725  * divided by 4 actually to shrink the 0-127 range of priorities into the 32
   1726  * available queues.
   1727  */
   1728 /*
   1729  * setrunqueue(p)
   1730  *	proc *p;
   1731  *
   1732  * Call should be made at splclock(), and p->p_stat should be SRUN.
   1733  */
   1734 
   1735 void
   1736 setrunqueue(p)
   1737 	struct proc *p;
   1738 {
   1739 	int bit;
   1740 
   1741 	/* firewall: p->p_back must be NULL */
   1742 	if (p->p_back != NULL)
   1743 		panic("setrunqueue");
   1744 
   1745 	bit = p->p_priority >> 2;
   1746 	whichqs |= (1 << bit);
   1747 	p->p_forw = (struct proc *)&qs[bit];
   1748 	p->p_back = qs[bit].ph_rlink;
   1749 	p->p_back->p_forw = p;
   1750 	qs[bit].ph_rlink = p;
   1751 }
   1752 
   1753 /*
   1754  * remrunqueue(p)
   1755  *
   1756  * Call should be made at splclock().
   1757  */
   1758 void
   1759 remrunqueue(p)
   1760 	struct proc *p;
   1761 {
   1762 	int bit;
   1763 
   1764 	bit = p->p_priority >> 2;
   1765 	if ((whichqs & (1 << bit)) == 0)
   1766 		panic("remrunqueue");
   1767 
   1768 	p->p_back->p_forw = p->p_forw;
   1769 	p->p_forw->p_back = p->p_back;
   1770 	p->p_back = NULL;	/* for firewall checking. */
   1771 
   1772 	if ((struct proc *)&qs[bit] == qs[bit].ph_link)
   1773 		whichqs &= ~(1 << bit);
   1774 }
   1775 
   1776 /*
   1777  * Return the best possible estimate of the time in the timeval
   1778  * to which tvp points.  Unfortunately, we can't read the hardware registers.
   1779  * We guarantee that the time will be greater than the value obtained by a
   1780  * previous call.
   1781  */
   1782 void
   1783 microtime(tvp)
   1784 	register struct timeval *tvp;
   1785 {
   1786 	int s = splclock();
   1787 	static struct timeval lasttime;
   1788 
   1789 	*tvp = time;
   1790 #ifdef notdef
   1791 	tvp->tv_usec += clkread();
   1792 	while (tvp->tv_usec > 1000000) {
   1793 		tvp->tv_sec++;
   1794 		tvp->tv_usec -= 1000000;
   1795 	}
   1796 #endif
   1797 	if (tvp->tv_sec == lasttime.tv_sec &&
   1798 	    tvp->tv_usec <= lasttime.tv_usec &&
   1799 	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
   1800 		tvp->tv_sec++;
   1801 		tvp->tv_usec -= 1000000;
   1802 	}
   1803 	lasttime = *tvp;
   1804 	splx(s);
   1805 }
   1806 
   1807 /*
   1808  * Wait "n" microseconds.
   1809  */
   1810 void
   1811 delay(n)
   1812 	unsigned long n;
   1813 {
   1814 	long N = cycles_per_usec * (n);
   1815 
   1816 	while (N > 0)				/* XXX */
   1817 		N -= 3;				/* XXX */
   1818 }
   1819 
   1820 #if defined(COMPAT_OSF1) || 1		/* XXX */
   1821 void	cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
   1822 	    u_long));
   1823 
   1824 void
   1825 cpu_exec_ecoff_setregs(p, epp, stack)
   1826 	struct proc *p;
   1827 	struct exec_package *epp;
   1828 	u_long stack;
   1829 {
   1830 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   1831 
   1832 	setregs(p, epp, stack);
   1833 	p->p_md.md_tf->tf_regs[FRAME_GP] = execp->a.gp_value;
   1834 }
   1835 
   1836 /*
   1837  * cpu_exec_ecoff_hook():
   1838  *	cpu-dependent ECOFF format hook for execve().
   1839  *
   1840  * Do any machine-dependent diddling of the exec package when doing ECOFF.
   1841  *
   1842  */
   1843 int
   1844 cpu_exec_ecoff_hook(p, epp)
   1845 	struct proc *p;
   1846 	struct exec_package *epp;
   1847 {
   1848 	struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr;
   1849 	extern struct emul emul_netbsd;
   1850 #ifdef COMPAT_OSF1
   1851 	extern struct emul emul_osf1;
   1852 #endif
   1853 
   1854 	switch (execp->f.f_magic) {
   1855 #ifdef COMPAT_OSF1
   1856 	case ECOFF_MAGIC_ALPHA:
   1857 		epp->ep_emul = &emul_osf1;
   1858 		break;
   1859 #endif
   1860 
   1861 	case ECOFF_MAGIC_NETBSD_ALPHA:
   1862 		epp->ep_emul = &emul_netbsd;
   1863 		break;
   1864 
   1865 	default:
   1866 		return ENOEXEC;
   1867 	}
   1868 	return 0;
   1869 }
   1870 #endif
   1871 
   1872 /* XXX XXX BEGIN XXX XXX */
   1873 vm_offset_t alpha_XXX_dmamap_or;				/* XXX */
   1874 								/* XXX */
   1875 vm_offset_t							/* XXX */
   1876 alpha_XXX_dmamap(v)						/* XXX */
   1877 	vm_offset_t v;						/* XXX */
   1878 {								/* XXX */
   1879 								/* XXX */
   1880 	return (vtophys(v) | alpha_XXX_dmamap_or);		/* XXX */
   1881 }								/* XXX */
   1882 /* XXX XXX END XXX XXX */
   1883