Home | History | Annotate | Line # | Download | only in alpha
machdep.c revision 1.3
      1 /*	$NetBSD: machdep.c,v 1.3 1995/03/24 15:04:14 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1995 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/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/signalvar.h>
     33 #include <sys/kernel.h>
     34 #include <sys/map.h>
     35 #include <sys/proc.h>
     36 #include <sys/buf.h>
     37 #include <sys/reboot.h>
     38 #include <sys/conf.h>
     39 #include <sys/file.h>
     40 #ifdef REAL_CLISTS
     41 #include <sys/clist.h>
     42 #endif
     43 #include <sys/callout.h>
     44 #include <sys/malloc.h>
     45 #include <sys/mbuf.h>
     46 #include <sys/msgbuf.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/tty.h>
     49 #include <sys/user.h>
     50 #include <sys/exec.h>
     51 #include <sys/exec_ecoff.h>
     52 #include <sys/sysctl.h>
     53 #ifdef SYSVMSG
     54 #include <sys/msg.h>
     55 #endif
     56 #ifdef SYSVSEM
     57 #include <sys/sem.h>
     58 #endif
     59 #ifdef SYSVSHM
     60 #include <sys/shm.h>
     61 #endif
     62 
     63 #include <sys/mount.h>
     64 #include <sys/syscallargs.h>
     65 
     66 #include <vm/vm_kern.h>
     67 
     68 #include <dev/cons.h>
     69 
     70 #include <machine/cpu.h>
     71 #include <machine/reg.h>
     72 #include <machine/rpb.h>
     73 #include <machine/prom.h>
     74 
     75 #include <net/netisr.h>
     76 #include "ether.h"
     77 
     78 #include "le.h"			/* XXX for le_iomem creation */
     79 #include "esp.h"		/* XXX for esp_iomem creation */
     80 
     81 vm_map_t buffer_map;
     82 
     83 /*
     84  * Declare these as initialized data so we can patch them.
     85  */
     86 int	nswbuf = 0;
     87 #ifdef	NBUF
     88 int	nbuf = NBUF;
     89 #else
     90 int	nbuf = 0;
     91 #endif
     92 #ifdef	BUFPAGES
     93 int	bufpages = BUFPAGES;
     94 #else
     95 int	bufpages = 0;
     96 #endif
     97 int	msgbufmapped = 0;	/* set when safe to use msgbuf */
     98 int	maxmem;			/* max memory per process */
     99 int	physmem;		/* amount of physical memory in system */
    100 int	resvmem;		/* amount of memory reserved for PROM */
    101 
    102 int	cputype;		/* system type, from the RPB */
    103 
    104 /*
    105  * XXX We need an address to which we can assign things so that they
    106  * won't be optimized away because we didn't use the value.
    107  */
    108 u_int32_t no_optimize;
    109 
    110 /* the following is used externally (sysctl_hw) */
    111 char	machine[] = "alpha";
    112 char	*cpu_model;
    113 char	*model_names[] = {
    114 	"UNKNOWN (0)",
    115 	"Alpha Demonstration Unit",
    116 	"DEC 4000 (\"Cobra\")",
    117 	"DEC 7000 (\"Ruby\")",
    118 	"DEC 3000/500 (\"Flamingo\") family",
    119 	"UNKNOWN (5)",
    120 	"DEC 2000/300 (\"Jensen\")",
    121 	"DEC 3000/300 (\"Pelican\")",
    122 	"UNKNOWN (8)",
    123 	"DEC 2100/A500 (\"Sable\")",
    124 	"AXPvme 64",
    125 	"AXPpci 33 (\"NoName\")",
    126 	"UNKNOWN (12)",
    127 	"DEC 2100/A50 (\"Avanti\")",
    128 	"Mustang",
    129 	"DEC 1000 (\"Mikasa\")",
    130 };
    131 int	nmodel_names = sizeof model_names/sizeof model_names[0];
    132 
    133 struct	user *proc0paddr;
    134 
    135 /* Number of machine cycles per microsecond */
    136 u_int64_t	cycles_per_usec;
    137 
    138 /* some memory areas for device DMA.  "ick." */
    139 caddr_t		le_iomem;		/* XXX iomem for LANCE DMA */
    140 caddr_t		esp_iomem;		/* XXX iomem for SCSI DMA */
    141 
    142 /* Interrupt vectors (in locore) */
    143 extern int XentInt(), XentArith(), XentMM(), XentIF(), XentUna(), XentSys();
    144 
    145 int
    146 alpha_init(pfn, ptb, argc, argv, envp)
    147 	u_long pfn;		/* first free PFN number */
    148 	u_long ptb;		/* PFN of current level 1 page table */
    149 	u_long argc;
    150 	char *argv[], *envp[];
    151 {
    152 	extern char _end[];
    153 	caddr_t start, v;
    154 	struct mddt *mddtp;
    155 	int i;
    156 	char *p;
    157 
    158 	/*
    159 	 * Turn off interrupts and floating point.
    160 	 * Make sure the instruction and data streams are consistent.
    161 	 */
    162 	(void)splhigh();
    163 	pal_wrfen(0);
    164 	TBIA();
    165 	IMB();
    166 
    167 	/*
    168 	 * get address of the restart block, while we the bootstrap
    169 	 * mapping is still around.
    170 	 */
    171 	hwrpb = (struct rpb *) phystok0seg(*(struct rpb **)HWRPB_ADDR);
    172 
    173 	/*
    174 	 * Remember how many cycles there are per microsecond,
    175 	 * so that we can use delay()
    176 	 */
    177 	cycles_per_usec = hwrpb->rpb_cc_freq / 1000000;
    178 
    179 	/*
    180 	 * Init the PROM interface, so we can use printf
    181 	 * until PROM mappings go away in consinit.
    182 	 */
    183 	init_prom_interface();
    184 
    185 	/*
    186 	 * Point interrupt/exception vectors to our own.
    187 	 */
    188 	pal_wrent(XentInt, 0);
    189 	pal_wrent(XentArith, 1);
    190 	pal_wrent(XentMM, 2);
    191 	pal_wrent(XentIF, 3);
    192 	pal_wrent(XentUna, 4);
    193 	pal_wrent(XentSys, 5);
    194 
    195 	/*
    196 	 * Find out how much memory is available, by looking at
    197 	 * the memory cluster descriptors.
    198 	 * XXX Assumes that the first "system" cluster is the
    199 	 * only one we can use.  Can there be more than two clusters?
    200 	 * Is the second (etc.) system cluster guaranteed to be
    201 	 * discontiguous?
    202 	 */
    203 	mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
    204 	physmem = 0;
    205 	if (mddtp->mddt_cluster_cnt != 2) {
    206 		printf("warning: strange number of memory clusters (%d).\n",
    207 		    mddtp->mddt_cluster_cnt);
    208 		printf("memory cluster information:\n");
    209 		for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    210 			printf("mddt %d:\n", i);
    211 			printf("\tpfn %lx\n",
    212 			    mddtp->mddt_clusters[i].mddt_pfn);
    213 			printf("\tcnt %lx\n",
    214 			    mddtp->mddt_clusters[i].mddt_pg_cnt);
    215 			printf("\ttest %lx\n",
    216 			    mddtp->mddt_clusters[i].mddt_pg_test);
    217 			printf("\tbva %lx\n",
    218 			    mddtp->mddt_clusters[i].mddt_v_bitaddr);
    219 			printf("\tbpa %lx\n",
    220 			    mddtp->mddt_clusters[i].mddt_p_bitaddr);
    221 			printf("\tbcksum %lx\n",
    222 			    mddtp->mddt_clusters[i].mddt_bit_cksum);
    223 			printf("\tusage %lx\n",
    224 			    mddtp->mddt_clusters[i].mddt_usage);
    225 		}
    226 	}
    227 
    228 	physmem = 0;
    229 	for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
    230 		/* add up physmem, stopping on first OS-available space. */
    231 		physmem += mddtp->mddt_clusters[i].mddt_pg_cnt;
    232 		if ((mddtp->mddt_clusters[i].mddt_usage & 0x01) == 0)
    233 			break;
    234 		else
    235 			resvmem += mddtp->mddt_clusters[i].mddt_pg_cnt;
    236 	}
    237 	if (physmem == 0)
    238 		panic("can't happen: system seems to have no memory!");
    239 	maxmem = physmem;
    240 
    241 	/*
    242 	 * find out this CPU's page size
    243 	 */
    244 	PAGE_SIZE = hwrpb->rpb_page_size;
    245 
    246 	v = (caddr_t)alpha_round_page(_end);
    247 	/*
    248 	 * Init mapping for u page(s) for proc 0
    249 	 */
    250 	start = v;
    251 	curproc->p_addr = proc0paddr = (struct user *)v;
    252 	v += UPAGES * NBPG;
    253 
    254 	/*
    255 	 * Find out what hardware we're on, and remember its type name.
    256 	 * XXX and start dealing with config?
    257 	 */
    258 	cputype = hwrpb->rpb_type;
    259 	switch (cputype) {
    260 #ifdef ADU
    261 	case ST_ADU:
    262 		THIS SYSTEM NOT SUPPORTED
    263 #endif
    264 
    265 #ifdef DEC_4000
    266 	case ST_DEC_4000:
    267 		THIS SYSTEM NOT SUPPORTED
    268 #endif
    269 
    270 #ifdef DEC_7000
    271 	case ST_DEC_7000:
    272 		THIS SYSTEM NOT SUPPORTED
    273 #endif
    274 
    275 #ifdef DEC_3000_500				/* and 400, [6-9]00 */
    276 	case ST_DEC_3000_500:
    277 		switch (hwrpb->rpb_variation & SV_ST_MASK) {
    278 		case SV_ST_SANDPIPER:
    279 systype_sandpiper:
    280 			cpu_model = "DEC 3000/400 (\"Sandpiper\")";
    281 			break;
    282 
    283 		case SV_ST_FLAMINGO:
    284 systype_flamingo:
    285 			cpu_model = "DEC 3000/500 (\"Flamingo\")";
    286 			break;
    287 
    288 		case SV_ST_HOTPINK:
    289 			cpu_model = "DEC 3000/500X (\"Hot Pink\")";
    290 			break;
    291 
    292 		case SV_ST_FLAMINGOPLUS:
    293 		case SV_ST_ULTRA:
    294 			cpu_model = "DEC 3000/800 (\"Flamingo+\")";
    295 			break;
    296 
    297 		case SV_ST_SANDPLUS:
    298 			cpu_model = "DEC 3000/600 (\"Sandpiper+\")";
    299 			break;
    300 
    301 		case SV_ST_SANDPIPER45:
    302 			cpu_model = "DEC 3000/700 (\"Sandpiper45\")";
    303 			break;
    304 
    305 		case SV_ST_FLAMINGO45:
    306 			cpu_model = "DEC 3000/900 (\"Flamingo45\")";
    307 			break;
    308 
    309 		case SV_ST_RESERVED: /* this is how things used to be done */
    310 			if (hwrpb->rpb_variation & SV_GRAPHICS)
    311 				goto systype_flamingo;
    312 			else
    313 				goto systype_sandpiper;
    314 			/* NOTREACHED */
    315 
    316 		default:
    317 			printf("unknown system variation %lx\n",
    318 			    hwrpb->rpb_variation & SV_ST_MASK);
    319 		}
    320 		break;
    321 #endif
    322 
    323 #ifdef DEC_2000_300
    324 	case ST_DEC_2000_300:
    325 		/* XXX XXX XXX */
    326 		break;
    327 #endif
    328 
    329 #ifdef DEC_3000_300
    330 	case ST_DEC_3000_300:
    331 		switch (hwrpb->rpb_variation & SV_ST_MASK) {
    332 		case SV_ST_PELICAN:
    333 			cpu_model = "DEC 3000/300 (\"Pelican\")";
    334 			break;
    335 
    336 		case SV_ST_PELICA:
    337 			cpu_model = "DEC 3000/300L (\"Pelica\")";
    338 			break;
    339 
    340 		case SV_ST_PELICANPLUS:
    341 			cpu_model = "DEC 3000/300X (\"Pelican+\")";
    342 			break;
    343 
    344 		case SV_ST_PELICAPLUS:
    345 			cpu_model = "DEC 3000/300LX (\"Pelica+\")";
    346 			break;
    347 
    348 		default:
    349 			printf("unknown system variation %lx\n",
    350 			    hwrpb->rpb_variation & SV_ST_MASK);
    351 		}
    352 		break;
    353 #endif
    354 
    355 #ifdef DEC_2100_A500
    356 	case ST_DEC_2100_A500:
    357 		THIS SYSTEM NOT SUPPORTED
    358 #endif
    359 
    360 #ifdef DEC_AXPVME_64
    361 	case ST_DEC_AXPVME_64:
    362 		THIS SYSTEM NOT SUPPORTED
    363 #endif
    364 
    365 #ifdef DEC_AXPPCI_33
    366 	case ST_DEC_AXPPCI_33:
    367 		THIS SYSTEM NOT SUPPORTED
    368 #endif
    369 
    370 #ifdef DEC_2100_A50
    371 	case ST_DEC_2100_A50:
    372 		/* XXX */
    373 		printf("unknown system variation %lx\n",
    374 		    hwrpb->rpb_variation & SV_ST_MASK);
    375 		break;
    376 #endif
    377 
    378 #ifdef DEC_MUSTANG
    379 	case ST_DEC_MUSTANG:
    380 		THIS SYSTEM NOT SUPPORTED
    381 #endif
    382 
    383 #ifdef DEC_1000
    384 	case ST_DEC_1000:
    385 		THIS SYSTEM NOT SUPPORTED
    386 #endif
    387 
    388 	default:
    389 		if (cputype > nmodel_names)
    390 			panic("Unknown system type %d", cputype);
    391 		else
    392 			panic("Support for %s system type not in kernel.",
    393 			    model_names[cputype]);
    394 	}
    395 	if (cpu_model == NULL)
    396 		cpu_model = model_names[cputype];
    397 
    398 #if NLE > 0
    399 	/*
    400 	 * Grab 128K at the top of physical memory for the lance chip
    401 	 * on machines where it does dma through the I/O ASIC.
    402 	 * It must be physically contiguous and aligned on a 128K boundary.
    403 	 */
    404 	if (cputype == ST_DEC_3000_500 ||
    405 	    cputype == ST_DEC_3000_300) {	/* XXX possibly others? */
    406 		maxmem -= btoc(128 * 1024);
    407 		le_iomem = (caddr_t)phystok0seg(maxmem << PGSHIFT);
    408 	}
    409 #endif /* NLE */
    410 #if NESP > 0
    411 	/*
    412 	 * Ditto for the scsi chip. There is probably a way to make esp.c
    413 	 * do dma without these buffers, but it would require major
    414 	 * re-engineering of the esp driver.
    415 	 * They must be 8K in size and page aligned.
    416 	 */
    417 	if (cputype == ST_DEC_3000_500 ||
    418 	    cputype == ST_DEC_3000_300) {	/* XXX possibly others? */
    419 		maxmem -= btoc(NESP * 8192);
    420 		esp_iomem = (caddr_t)phystok0seg(maxmem << PGSHIFT);
    421 	}
    422 #endif /* NESP */
    423 
    424 	/*
    425 	 * Initialize error message buffer (at end of core).
    426 	 */
    427 	maxmem -= btoc(sizeof (struct msgbuf));
    428 	msgbufp = (struct msgbuf *)phystok0seg(maxmem << PGSHIFT);
    429 	msgbufmapped = 1;
    430 
    431 	/*
    432 	 * Allocate space for system data structures.
    433 	 * The first available kernel virtual address is in "v".
    434 	 * As pages of kernel virtual memory are allocated, "v" is incremented.
    435 	 *
    436 	 * These data structures are allocated here instead of cpu_startup()
    437 	 * because physical memory is directly addressable. We don't have
    438 	 * to map these into virtual address space.
    439 	 */
    440 #define valloc(name, type, num) \
    441 	    (name) = (type *)v; v = (caddr_t)((name)+(num))
    442 #define valloclim(name, type, num, lim) \
    443 	    (name) = (type *)v; v = (caddr_t)((lim) = ((name)+(num)))
    444 #ifdef REAL_CLISTS
    445 	valloc(cfree, struct cblock, nclist);
    446 #endif
    447 	valloc(callout, struct callout, ncallout);
    448 	valloc(swapmap, struct map, nswapmap = maxproc * 2);
    449 #ifdef SYSVSHM
    450 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    451 #endif
    452 #ifdef SYSVSEM
    453 	valloc(sema, struct semid_ds, seminfo.semmni);
    454 	valloc(sem, struct sem, seminfo.semmns);
    455 	/* This is pretty disgusting! */
    456 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    457 #endif
    458 #ifdef SYSVMSG
    459 	valloc(msgpool, char, msginfo.msgmax);
    460 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    461 	valloc(msghdrs, struct msg, msginfo.msgtql);
    462 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    463 #endif
    464 
    465 	/*
    466 	 * Determine how many buffers to allocate.
    467 	 * We allocate the BSD standard of 10% of memory for the first
    468 	 * 2 Meg, and 5% of remaining memory for buffer space.  Insure a
    469 	 * minimum of 16 buffers.  We allocate 1/2 as many swap buffer
    470 	 * headers as file i/o buffers.
    471 	 */
    472 	if (bufpages == 0)
    473 		bufpages = (btoc(2 * 1024 * 1024) + (physmem - resvmem)) /
    474 		    (20 * CLSIZE);
    475 	if (nbuf == 0) {
    476 		nbuf = bufpages;
    477 		if (nbuf < 16)
    478 			nbuf = 16;
    479 	}
    480 	if (nswbuf == 0) {
    481 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
    482 		if (nswbuf > 256)
    483 			nswbuf = 256;		/* sanity */
    484 	}
    485 	valloc(swbuf, struct buf, nswbuf);
    486 	valloc(buf, struct buf, nbuf);
    487 
    488 	/*
    489 	 * Clear allocated memory.
    490 	 */
    491 	bzero(start, v - start);
    492 
    493 	/*
    494 	 * Initialize the virtual memory system, and set the
    495 	 * page table base register in proc 0's PCB.
    496 	 */
    497 	pmap_bootstrap((vm_offset_t)v, phystok0seg(ptb << PGSHIFT));
    498 
    499 	/*
    500 	 * Initialize the rest of proc 0's PCB, and cache its physical
    501 	 * address.
    502 	 */
    503 	proc0.p_md.md_pcbpaddr =
    504 	    (struct pcb *)k0segtophys(&proc0paddr->u_pcb);
    505 
    506 	/*
    507 	 * Set the kernel sp, reserving space for an (empty) trapframe,
    508 	 * and make proc0's trapframe pointer point to it for sanity.
    509 	 */
    510 	proc0paddr->u_pcb.pcb_ksp =
    511 	    (u_int64_t)proc0paddr + USPACE - sizeof(struct trapframe);
    512 	proc0.p_md.md_tf = (struct trapframe *)proc0paddr->u_pcb.pcb_ksp;
    513 
    514 	/*
    515 	 * Look at arguments and compute bootdev.
    516 	 *
    517 	 * XXX
    518 	 * Boot currently doesn't pass any arguments concerning booting
    519 	 * or the root device.
    520 	 */
    521 	{ extern dev_t bootdev;
    522 	bootdev = MAKEBOOTDEV(8, 0, 0, 0, 0);	/* sd0a. XXX */
    523 	}
    524 
    525 	/*
    526 	 * Look at arguments passed to us and compute boothowto.
    527 	 */
    528 #ifdef GENERIC
    529 	boothowto = RB_SINGLE | RB_ASKNAME;
    530 #else
    531 	boothowto = RB_SINGLE;
    532 #endif
    533 #ifdef KADB
    534 	boothowto |= RB_KDB;
    535 #endif
    536 
    537 	printf("argc = %d\n", argc);
    538 	printf("argv = %lx\n", argv);
    539 	for (i = 0; i < argc; i++)
    540 		printf("argv[%d] = (%lx) \"%s\"\n", i, argv[i], argv[i]);
    541 
    542 	if (argc > 1) {
    543 		/* we have arguments. argv[1] is the flags. */
    544 		for (p = argv[1]; *p != '\0'; p++) {
    545 			switch (*p) {
    546 			case 'a': /* autoboot */
    547 			case 'A': /* DEC's notion of autoboot */
    548 				boothowto &= ~RB_SINGLE;
    549 				break;
    550 
    551 			case 'd': /* use compiled in default root */
    552 				boothowto |= RB_DFLTROOT;
    553 				break;
    554 
    555 			case 'm': /* mini root present in memory */
    556 				boothowto |= RB_MINIROOT;
    557 				break;
    558 
    559 			case 'n': /* ask for names */
    560 				boothowto |= RB_ASKNAME;
    561 				break;
    562 
    563 			case 'N': /* don't ask for names */
    564 				boothowto &= ~RB_ASKNAME;
    565 			}
    566 		}
    567 	}
    568 
    569 	return (0);
    570 }
    571 
    572 /* for cons.c */
    573 struct  consdev constab[] = {
    574 	{ 0 },
    575 };
    576 
    577 consinit()
    578 {
    579 	/* XXX SET UP THE CONSOLE TAB TO HAVE REASONABLE ENTRIES */
    580 	/* XXX */
    581 
    582 	/* XXX PICK A NEW CONSOLE DEVICE */
    583 	/* cninit(); */
    584 
    585 	pmap_unmap_prom();
    586 }
    587 
    588 cpu_startup()
    589 {
    590 	register unsigned i;
    591 	register caddr_t v;
    592 	int base, residual;
    593 	vm_offset_t minaddr, maxaddr;
    594 	vm_size_t size;
    595 #ifdef DEBUG
    596 	extern int pmapdebug;
    597 	int opmapdebug = pmapdebug;
    598 
    599 	pmapdebug = 0;
    600 #endif
    601 
    602 	/*
    603 	 * Good {morning,afternoon,evening,night}.
    604 	 */
    605 	printf(version);
    606 	identifycpu();
    607 	printf("real mem = %d (%d reserved for PROM)\n", ctob(physmem),
    608 	    ctob(resvmem));
    609 
    610 	/*
    611 	 * Allocate virtual address space for file I/O buffers.
    612 	 * Note they are different than the array of headers, 'buf',
    613 	 * and usually occupy more virtual memory than physical.
    614 	 */
    615 	size = MAXBSIZE * nbuf;
    616 	buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
    617 	    &maxaddr, size, TRUE);
    618 	minaddr = (vm_offset_t)buffers;
    619 	if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
    620 			&minaddr, size, FALSE) != KERN_SUCCESS)
    621 		panic("startup: cannot allocate buffers");
    622 	base = bufpages / nbuf;
    623 	residual = bufpages % nbuf;
    624 	for (i = 0; i < nbuf; i++) {
    625 		vm_size_t curbufsize;
    626 		vm_offset_t curbuf;
    627 
    628 		/*
    629 		 * First <residual> buffers get (base+1) physical pages
    630 		 * allocated for them.  The rest get (base) physical pages.
    631 		 *
    632 		 * The rest of each buffer occupies virtual space,
    633 		 * but has no physical memory allocated for it.
    634 		 */
    635 		curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
    636 		curbufsize = CLBYTES * (i < residual ? base+1 : base);
    637 		vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
    638 		vm_map_simplify(buffer_map, curbuf);
    639 	}
    640 	/*
    641 	 * Allocate a submap for exec arguments.  This map effectively
    642 	 * limits the number of processes exec'ing at any time.
    643 	 */
    644 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    645 				 16 * NCARGS, TRUE);
    646 
    647 	/*
    648 	 * Allocate a submap for physio
    649 	 */
    650 	phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    651 				 VM_PHYS_SIZE, TRUE);
    652 
    653 	/*
    654 	 * Finally, allocate mbuf pool.  Since mclrefcnt is an off-size
    655 	 * we use the more space efficient malloc in place of kmem_alloc.
    656 	 */
    657 	mclrefcnt = (char *)malloc(NMBCLUSTERS+CLBYTES/MCLBYTES,
    658 	    M_MBUF, M_NOWAIT);
    659 	bzero(mclrefcnt, NMBCLUSTERS+CLBYTES/MCLBYTES);
    660 	mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
    661 	    VM_MBUF_SIZE, FALSE);
    662 	/*
    663 	 * Initialize callouts
    664 	 */
    665 	callfree = callout;
    666 	for (i = 1; i < ncallout; i++)
    667 		callout[i-1].c_next = &callout[i];
    668 	callout[i-1].c_next = NULL;
    669 
    670 #ifdef DEBUG
    671 	pmapdebug = opmapdebug;
    672 #endif
    673 	printf("avail mem = %ld\n", (long)ptoa(cnt.v_free_count));
    674 	printf("using %ld buffers containing %ld bytes of memory\n",
    675 		(long)nbuf, (long)(bufpages * CLBYTES));
    676 
    677 	/*
    678 	 * Set up buffers, so they can be used to read disk labels.
    679 	 */
    680 	bufinit();
    681 
    682 	/*
    683 	 * Configure the system.
    684 	 */
    685 	configure();
    686 }
    687 
    688 identifycpu()
    689 {
    690 
    691 	/* most of the work here is taken care of in alpha_init(). */
    692 	printf("%s, serial number 0x%lx 0x%lx\n", cpu_model,
    693 	    ((long *)hwrpb->rpb_ssn)[0], ((long *)hwrpb->rpb_ssn)[1]);
    694 	printf("variation: 0x%lx, revision 0x%lx\n",
    695 	    hwrpb->rpb_variation, *(long *)hwrpb->rpb_revision);
    696 	printf("%d byte page size, %d processor%s.\n", hwrpb->rpb_page_size,
    697 	    hwrpb->rpb_pcs_cnt, hwrpb->rpb_pcs_cnt == 1 ? "" : "s");
    698 }
    699 
    700 int	waittime = -1;
    701 
    702 boot(howto)
    703 	int howto;
    704 {
    705 	extern int cold;
    706 
    707 	/* Take a snapshot before clobbering any registers. */
    708 	if (curproc)
    709 		savectx(curproc->p_addr, 0);
    710 
    711 	/* If system is cold, just halt. */
    712 	if (cold) {
    713 		howto |= RB_HALT;
    714 		goto haltsys;
    715 	}
    716 
    717 	/* Sync the disks, if appropriate */
    718 	if ((howto & RB_NOSYNC) == 0 && waittime < 0 && 0 /* XXX */) {
    719 		register struct buf *bp;
    720 		int iter, nbusy;
    721 
    722 		waittime = 0;
    723 		(void) spl0();
    724 		printf("syncing disks... ");
    725 #ifdef notdef /* XXX */
    726 		/*
    727 		 * Release vnodes held by texts before sync.
    728 		 */
    729 		if (panicstr == 0)
    730 			vnode_pager_umount(NULL);
    731 
    732 		sync(&proc0, (void *)NULL, (int *)NULL);
    733 
    734 		for (iter = 0; iter < 20; iter++) {
    735 			nbusy = 0;
    736 			for (bp = &buf[nbuf]; --bp >= buf; )
    737 				if ((bp->b_flags & (B_BUSY|B_INVAL)) == B_BUSY)
    738 					nbusy++;
    739 			if (nbusy == 0)
    740 				break;
    741 			printf("%d ", nbusy);
    742 			DELAY(40000 * iter);
    743 		}
    744 		if (nbusy)
    745 			printf("giving up\n");
    746 		else
    747 #endif
    748 			printf("done\n");
    749 #ifdef notdef /* XXX */
    750 		/*
    751 		 * If we've been adjusting the clock, the todr
    752 		 * will be out of synch; adjust it now.
    753 		 */
    754 		resettodr();
    755 #endif
    756 	}
    757 
    758 	/* Disable interrupts. */
    759 	splhigh();
    760 
    761 #ifdef notdef /* XXX */
    762 	/* If rebooting and a dump is requested do the dump. */
    763 	if ((howto & (RB_DUMP|RB_HALT)) == RB_DUMP)
    764 		dumpsys();
    765 #endif
    766 
    767 haltsys:
    768 	/* Finally, halt/reboot the system. */
    769 	printf("%s\n\n", howto & RB_HALT ? "halted." : "rebooting...");
    770 	prom_halt(howto & RB_HALT);
    771 	/*NOTREACHED*/
    772 }
    773 
    774 void
    775 frametoreg(framep, regp)
    776 	struct trapframe *framep;
    777 	struct reg *regp;
    778 {
    779 
    780 	regp->r_regs[R_V0] = framep->tf_regs[FRAME_V0];
    781 	regp->r_regs[R_T0] = framep->tf_regs[FRAME_T0];
    782 	regp->r_regs[R_T1] = framep->tf_regs[FRAME_T1];
    783 	regp->r_regs[R_T2] = framep->tf_regs[FRAME_T2];
    784 	regp->r_regs[R_T3] = framep->tf_regs[FRAME_T3];
    785 	regp->r_regs[R_T4] = framep->tf_regs[FRAME_T4];
    786 	regp->r_regs[R_T5] = framep->tf_regs[FRAME_T5];
    787 	regp->r_regs[R_T6] = framep->tf_regs[FRAME_T6];
    788 	regp->r_regs[R_T7] = framep->tf_regs[FRAME_T7];
    789 	regp->r_regs[R_S0] = framep->tf_regs[FRAME_S0];
    790 	regp->r_regs[R_S1] = framep->tf_regs[FRAME_S1];
    791 	regp->r_regs[R_S2] = framep->tf_regs[FRAME_S2];
    792 	regp->r_regs[R_S3] = framep->tf_regs[FRAME_S3];
    793 	regp->r_regs[R_S4] = framep->tf_regs[FRAME_S4];
    794 	regp->r_regs[R_S5] = framep->tf_regs[FRAME_S5];
    795 	regp->r_regs[R_S6] = framep->tf_regs[FRAME_S6];
    796 	regp->r_regs[R_A0] = framep->tf_a0;
    797 	regp->r_regs[R_A1] = framep->tf_a1;
    798 	regp->r_regs[R_A2] = framep->tf_a2;
    799 	regp->r_regs[R_A3] = framep->tf_regs[FRAME_A3];
    800 	regp->r_regs[R_A4] = framep->tf_regs[FRAME_A4];
    801 	regp->r_regs[R_A5] = framep->tf_regs[FRAME_A5];
    802 	regp->r_regs[R_T8] = framep->tf_regs[FRAME_T8];
    803 	regp->r_regs[R_T9] = framep->tf_regs[FRAME_T9];
    804 	regp->r_regs[R_T10] = framep->tf_regs[FRAME_T10];
    805 	regp->r_regs[R_T11] = framep->tf_regs[FRAME_T11];
    806 	regp->r_regs[R_RA] = framep->tf_regs[FRAME_RA];
    807 	regp->r_regs[R_T12] = framep->tf_regs[FRAME_T12];
    808 	regp->r_regs[R_AT] = framep->tf_regs[FRAME_AT];
    809 	regp->r_regs[R_GP] = framep->tf_gp;
    810 	regp->r_regs[R_SP] = framep->tf_regs[FRAME_SP];
    811 	regp->r_regs[R_ZERO] = 0;
    812 }
    813 
    814 void
    815 regtoframe(regp, framep)
    816 	struct reg *regp;
    817 	struct trapframe *framep;
    818 {
    819 
    820 	framep->tf_regs[FRAME_V0] = regp->r_regs[R_V0];
    821 	framep->tf_regs[FRAME_T0] = regp->r_regs[R_T0];
    822 	framep->tf_regs[FRAME_T1] = regp->r_regs[R_T1];
    823 	framep->tf_regs[FRAME_T2] = regp->r_regs[R_T2];
    824 	framep->tf_regs[FRAME_T3] = regp->r_regs[R_T3];
    825 	framep->tf_regs[FRAME_T4] = regp->r_regs[R_T4];
    826 	framep->tf_regs[FRAME_T5] = regp->r_regs[R_T5];
    827 	framep->tf_regs[FRAME_T6] = regp->r_regs[R_T6];
    828 	framep->tf_regs[FRAME_T7] = regp->r_regs[R_T7];
    829 	framep->tf_regs[FRAME_S0] = regp->r_regs[R_S0];
    830 	framep->tf_regs[FRAME_S1] = regp->r_regs[R_S1];
    831 	framep->tf_regs[FRAME_S2] = regp->r_regs[R_S2];
    832 	framep->tf_regs[FRAME_S3] = regp->r_regs[R_S3];
    833 	framep->tf_regs[FRAME_S4] = regp->r_regs[R_S4];
    834 	framep->tf_regs[FRAME_S5] = regp->r_regs[R_S5];
    835 	framep->tf_regs[FRAME_S6] = regp->r_regs[R_S6];
    836 	framep->tf_a0 = regp->r_regs[R_A0];
    837 	framep->tf_a1 = regp->r_regs[R_A1];
    838 	framep->tf_a2 = regp->r_regs[R_A2];
    839 	framep->tf_regs[FRAME_A3] = regp->r_regs[R_A3];
    840 	framep->tf_regs[FRAME_A4] = regp->r_regs[R_A4];
    841 	framep->tf_regs[FRAME_A5] = regp->r_regs[R_A5];
    842 	framep->tf_regs[FRAME_T8] = regp->r_regs[R_T8];
    843 	framep->tf_regs[FRAME_T9] = regp->r_regs[R_T9];
    844 	framep->tf_regs[FRAME_T10] = regp->r_regs[R_T10];
    845 	framep->tf_regs[FRAME_T11] = regp->r_regs[R_T11];
    846 	framep->tf_regs[FRAME_RA] = regp->r_regs[R_RA];
    847 	framep->tf_regs[FRAME_T12] = regp->r_regs[R_T12];
    848 	framep->tf_regs[FRAME_AT] = regp->r_regs[R_AT];
    849 	framep->tf_gp = regp->r_regs[R_GP];
    850 	framep->tf_regs[FRAME_SP] = regp->r_regs[R_SP];
    851 	/* ??? = regp->r_regs[R_ZERO]; */
    852 }
    853 
    854 void
    855 printregs(regp)
    856 	struct reg *regp;
    857 {
    858 	int i;
    859 
    860 	for (i = 0; i < 32; i++)
    861 		printf("R%d:\t0x%016lx%s", i, regp->r_regs[i],
    862 		   i & 1 ? "\n" : "\t");
    863 }
    864 
    865 void
    866 regdump(framep)
    867 	struct trapframe *framep;
    868 {
    869 	struct reg reg;
    870 
    871 	frametoreg(framep, &reg);
    872 	printf("REGISTERS:\n");
    873 	printregs(&reg);
    874 }
    875 
    876 #ifdef DEBUG
    877 int sigdebug = 0;
    878 int sigpid = 0;
    879 #define	SDB_FOLLOW	0x01
    880 #define	SDB_KSTACK	0x02
    881 #endif
    882 
    883 /*
    884  * Send an interrupt to process.
    885  */
    886 void
    887 sendsig(catcher, sig, mask, code)
    888 	sig_t catcher;
    889 	int sig, mask;
    890 	u_long code;
    891 {
    892 	struct proc *p = curproc;
    893 	struct sigcontext *scp, ksc;
    894 	struct trapframe *frame;
    895 	struct sigacts *psp = p->p_sigacts;
    896 	int oonstack, fsize, rndfsize;
    897 	extern char sigcode[], esigcode[];
    898 	extern struct proc *fpcurproc;
    899 
    900 	frame = p->p_md.md_tf;
    901 	oonstack = psp->ps_sigstk.ss_flags & SA_ONSTACK;
    902 	fsize = sizeof ksc;
    903 	rndfsize = ((fsize + 15) / 16) * 16;
    904 	/*
    905 	 * Allocate and validate space for the signal handler
    906 	 * context. Note that if the stack is in P0 space, the
    907 	 * call to grow() is a nop, and the useracc() check
    908 	 * will fail if the process has not already allocated
    909 	 * the space with a `brk'.
    910 	 */
    911 	if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
    912 	    (psp->ps_sigonstack & sigmask(sig))) {
    913 		scp = (struct sigcontext *)(psp->ps_sigstk.ss_base +
    914 		    psp->ps_sigstk.ss_size - rndfsize);
    915 		psp->ps_sigstk.ss_flags |= SA_ONSTACK;
    916 	} else
    917 		scp = (struct sigcontext *)(frame->tf_regs[FRAME_SP] -
    918 		    rndfsize);
    919 	if ((u_long)scp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
    920 		(void)grow(p, (u_long)scp);
    921 #ifdef DEBUG
    922 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    923 		printf("sendsig(%d): sig %d ssp %lx usp %lx\n", p->p_pid,
    924 		    sig, &oonstack, scp);
    925 #endif
    926 	if (useracc((caddr_t)scp, fsize, B_WRITE) == 0) {
    927 #ifdef DEBUG
    928 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    929 			printf("sendsig(%d): useracc failed on sig %d\n",
    930 			    p->p_pid, sig);
    931 #endif
    932 		/*
    933 		 * Process has trashed its stack; give it an illegal
    934 		 * instruction to halt it in its tracks.
    935 		 */
    936 		SIGACTION(p, SIGILL) = SIG_DFL;
    937 		sig = sigmask(SIGILL);
    938 		p->p_sigignore &= ~sig;
    939 		p->p_sigcatch &= ~sig;
    940 		p->p_sigmask &= ~sig;
    941 		psignal(p, SIGILL);
    942 		return;
    943 	}
    944 
    945 	/*
    946 	 * Build the signal context to be used by sigreturn.
    947 	 */
    948 	ksc.sc_onstack = oonstack;
    949 	ksc.sc_mask = mask;
    950 	ksc.sc_pc = frame->tf_pc;
    951 	ksc.sc_ps = frame->tf_ps;
    952 
    953 	/* copy the registers. */
    954 	frametoreg(frame, (struct reg *)ksc.sc_regs);
    955 	ksc.sc_regs[R_ZERO] = 0xACEDBADE;		/* magic number */
    956 
    957 	/* save the floating-point state, if necessary, then copy it. */
    958 	if (p == fpcurproc) {
    959 		pal_wrfen(1);
    960 		savefpstate(&p->p_addr->u_pcb.pcb_fp);
    961 		pal_wrfen(0);
    962 		fpcurproc = NULL;
    963 	}
    964 	ksc.sc_ownedfp = p->p_md.md_flags & MDP_FPUSED;
    965 	bcopy(&p->p_addr->u_pcb.pcb_fp, (struct fpreg *)ksc.sc_fpregs,
    966 	    sizeof(struct fpreg));
    967 	ksc.sc_fp_control = 0;					/* XXX ? */
    968 	bzero(ksc.sc_reserved, sizeof ksc.sc_reserved);		/* XXX */
    969 	bzero(ksc.sc_xxx, sizeof ksc.sc_xxx);			/* XXX */
    970 
    971 
    972 #ifdef COMPAT_OSF1
    973 	/*
    974 	 * XXX Create an OSF/1-style sigcontext and associated goo.
    975 	 */
    976 #endif
    977 
    978 	/*
    979 	 * copy the frame out to userland.
    980 	 */
    981 	(void) copyout((caddr_t)&ksc, (caddr_t)scp, fsize);
    982 #ifdef DEBUG
    983 	if (sigdebug & SDB_FOLLOW)
    984 		printf("sendsig(%d): sig %d scp %lx code %lx\n", p->p_pid, sig,
    985 		    scp, code);
    986 #endif
    987 
    988 	/*
    989 	 * Set up the registers to return to sigcode.
    990 	 */
    991 	frame->tf_pc = (u_int64_t)PS_STRINGS - (esigcode - sigcode);
    992 	frame->tf_regs[FRAME_SP] = (u_int64_t)scp;
    993 	frame->tf_a0 = sig;
    994 	frame->tf_a1 = code;
    995 	frame->tf_a2 = (u_int64_t)scp;
    996 	frame->tf_regs[FRAME_T12] = (u_int64_t)catcher;		/* t12 is pv */
    997 
    998 #ifdef DEBUG
    999 	if (sigdebug & SDB_FOLLOW)
   1000 		printf("sendsig(%d): pc %lx, catcher %lx\n", p->p_pid,
   1001 		    frame->tf_pc, frame->tf_regs[FRAME_A3]);
   1002 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
   1003 		printf("sendsig(%d): sig %d returns\n",
   1004 		    p->p_pid, sig);
   1005 #endif
   1006 }
   1007 
   1008 /*
   1009  * System call to cleanup state after a signal
   1010  * has been taken.  Reset signal mask and
   1011  * stack state from context left by sendsig (above).
   1012  * Return to previous pc and psl as specified by
   1013  * context left by sendsig. Check carefully to
   1014  * make sure that the user has not modified the
   1015  * psl to gain improper priviledges or to cause
   1016  * a machine fault.
   1017  */
   1018 /* ARGSUSED */
   1019 sigreturn(p, uap, retval)
   1020 	struct proc *p;
   1021 	struct sigreturn_args /* {
   1022 		syscallarg(struct sigcontext *) sigcntxp;
   1023 	} */ *uap;
   1024 	register_t *retval;
   1025 {
   1026 	struct sigcontext *scp, ksc;
   1027 	extern struct proc *fpcurproc;
   1028 
   1029 	scp = SCARG(uap, sigcntxp);
   1030 #ifdef DEBUG
   1031 	if (sigdebug & SDB_FOLLOW)
   1032 	    printf("sigreturn: pid %d, scp %lx\n", p->p_pid, scp);
   1033 #endif
   1034 
   1035 	if (ALIGN(scp) != (u_int64_t)scp)
   1036 		return (EINVAL);
   1037 
   1038 	/*
   1039 	 * Test and fetch the context structure.
   1040 	 * We grab it all at once for speed.
   1041 	 */
   1042 	if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
   1043 	    copyin((caddr_t)scp, (caddr_t)&ksc, sizeof ksc))
   1044 		return (EINVAL);
   1045 
   1046 	if (ksc.sc_regs[R_ZERO] != 0xACEDBADE)		/* magic number */
   1047 		return (EINVAL);
   1048 	/*
   1049 	 * Restore the user-supplied information
   1050 	 */
   1051 	if (ksc.sc_onstack)
   1052 		p->p_sigacts->ps_sigstk.ss_flags |= SA_ONSTACK;
   1053 	else
   1054 		p->p_sigacts->ps_sigstk.ss_flags &= ~SA_ONSTACK;
   1055 	p->p_sigmask = ksc.sc_mask &~ sigcantmask;
   1056 
   1057 	p->p_md.md_tf->tf_pc = ksc.sc_pc;
   1058 	p->p_md.md_tf->tf_ps = (ksc.sc_ps | PSL_USERSET) & ~PSL_USERCLR;
   1059 
   1060 	regtoframe((struct reg *)ksc.sc_regs, p->p_md.md_tf);
   1061 
   1062 	/* XXX ksc.sc_ownedfp ? */
   1063 	if (p == fpcurproc)
   1064 		fpcurproc = NULL;
   1065 	bcopy((struct fpreg *)ksc.sc_fpregs, &p->p_addr->u_pcb.pcb_fp,
   1066 	    sizeof(struct fpreg));
   1067 	/* XXX ksc.sc_fp_control ? */
   1068 
   1069 #ifdef DEBUG
   1070 	if (sigdebug & SDB_FOLLOW)
   1071 		printf("sigreturn(%d): returns\n", p->p_pid);
   1072 #endif
   1073 	return (EJUSTRETURN);
   1074 }
   1075 
   1076 /*
   1077  * machine dependent system variables.
   1078  */
   1079 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
   1080 	int *name;
   1081 	u_int namelen;
   1082 	void *oldp;
   1083 	size_t *oldlenp;
   1084 	void *newp;
   1085 	size_t newlen;
   1086 	struct proc *p;
   1087 {
   1088 	dev_t consdev;
   1089 
   1090 	/* all sysctl names at this level are terminal */
   1091 	if (namelen != 1)
   1092 		return (ENOTDIR);		/* overloaded */
   1093 
   1094 	switch (name[0]) {
   1095 	case CPU_CONSDEV:
   1096 		if (cn_tab != NULL)
   1097 			consdev = cn_tab->cn_dev;
   1098 		else
   1099 			consdev = NODEV;
   1100 		return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
   1101 			sizeof consdev));
   1102 	default:
   1103 		return (EOPNOTSUPP);
   1104 	}
   1105 	/* NOTREACHED */
   1106 }
   1107 
   1108 /*
   1109  * Set registers on exec.
   1110  */
   1111 void
   1112 setregs(p, entry, stack, retval)
   1113 	register struct proc *p;
   1114 	u_long entry;
   1115 	u_long stack;
   1116 	register_t *retval;
   1117 {
   1118 	struct trapframe *tfp = p->p_md.md_tf;
   1119 	int i;
   1120 	extern struct proc *fpcurproc;
   1121 
   1122 #ifdef DEBUG
   1123 	for (i = 0; i < FRAME_NSAVEREGS; i++)
   1124 		tfp->tf_regs[i] = 0xbabefacedeadbeef;
   1125 	tfp->tf_gp = 0xbabefacedeadbeef;
   1126 	tfp->tf_a0 = 0xbabefacedeadbeef;
   1127 	tfp->tf_a1 = 0xbabefacedeadbeef;
   1128 	tfp->tf_a2 = 0xbabefacedeadbeef;
   1129 #else
   1130 	bzero(tfp->tf_regs, FRAME_NSAVEREGS * sizeof tfp->tf_regs[0]);
   1131 	tfp->tf_gp = 0;
   1132 	tfp->tf_a0 = 0;
   1133 	tfp->tf_a1 = 0;
   1134 	tfp->tf_a2 = 0;
   1135 #endif
   1136 	bzero(&p->p_addr->u_pcb.pcb_fp, sizeof p->p_addr->u_pcb.pcb_fp);
   1137 
   1138 	tfp->tf_regs[FRAME_SP] = stack;	/* restored to usp in trap return */
   1139 	tfp->tf_ps = PSL_USERSET;
   1140 	tfp->tf_pc = entry & ~3;
   1141 
   1142 	p->p_md.md_flags & ~MDP_FPUSED;
   1143 	if (fpcurproc == p)
   1144 		fpcurproc = NULL;
   1145 
   1146 	retval[0] = retval[1] = 0;
   1147 }
   1148 
   1149 void
   1150 netintr()
   1151 {
   1152 #ifdef INET
   1153 #if NETHER > 0
   1154 	if (netisr & (1 << NETISR_ARP)) {
   1155 		netisr &= ~(1 << NETISR_ARP);
   1156 		arpintr();
   1157 	}
   1158 #endif
   1159 	if (netisr & (1 << NETISR_IP)) {
   1160 		netisr &= ~(1 << NETISR_IP);
   1161 		ipintr();
   1162 	}
   1163 #endif
   1164 #ifdef NS
   1165 	if (netisr & (1 << NETISR_NS)) {
   1166 		netisr &= ~(1 << NETISR_NS);
   1167 		nsintr();
   1168 	}
   1169 #endif
   1170 #ifdef ISO
   1171 	if (netisr & (1 << NETISR_ISO)) {
   1172 		netisr &= ~(1 << NETISR_ISO);
   1173 		clnlintr();
   1174 	}
   1175 #endif
   1176 #ifdef CCITT
   1177 	if (netisr & (1 << NETISR_CCITT)) {
   1178 		netisr &= ~(1 << NETISR_CCITT);
   1179 		ccittintr();
   1180 	}
   1181 #endif
   1182 }
   1183 
   1184 void
   1185 do_sir()
   1186 {
   1187 
   1188 	if (ssir & SIR_NET) {
   1189 		siroff(SIR_NET);
   1190 		cnt.v_soft++;
   1191 		netintr();
   1192 	}
   1193 	if (ssir & SIR_CLOCK) {
   1194 		siroff(SIR_CLOCK);
   1195 		cnt.v_soft++;
   1196 		softclock();
   1197 	}
   1198 }
   1199 
   1200 int
   1201 spl0()
   1202 {
   1203 
   1204 	if (ssir) {
   1205 		splsoft();
   1206 		do_sir();
   1207 	}
   1208 
   1209 	return (pal_swpipl(PSL_IPL_0));
   1210 }
   1211 
   1212 /*
   1213  * The following primitives manipulate the run queues.  _whichqs tells which
   1214  * of the 32 queues _qs have processes in them.  Setrunqueue puts processes
   1215  * into queues, Remrq removes them from queues.  The running process is on
   1216  * no queue, other processes are on a queue related to p->p_priority, divided
   1217  * by 4 actually to shrink the 0-127 range of priorities into the 32 available
   1218  * queues.
   1219  */
   1220 /*
   1221  * setrunqueue(p)
   1222  *	proc *p;
   1223  *
   1224  * Call should be made at splclock(), and p->p_stat should be SRUN.
   1225  */
   1226 
   1227 void
   1228 setrunqueue(p)
   1229 	struct proc *p;
   1230 {
   1231 	int bit;
   1232 
   1233 	/* firewall: p->p_back must be NULL */
   1234 	if (p->p_back != NULL)
   1235 		panic("setrunqueue");
   1236 
   1237 	bit = p->p_priority >> 2;
   1238 	whichqs |= (1 << bit);
   1239 	p->p_forw = (struct proc *)&qs[bit];
   1240 	p->p_back = qs[bit].ph_rlink;
   1241 	p->p_back->p_forw = p;
   1242 	qs[bit].ph_rlink = p;
   1243 }
   1244 
   1245 /*
   1246  * Remrq(p)
   1247  *
   1248  * Call should be made at splclock().
   1249  */
   1250 void
   1251 remrq(p)
   1252 	struct proc *p;
   1253 {
   1254 	int bit;
   1255 
   1256 	bit = p->p_priority >> 2;
   1257 	if ((whichqs & (1 << bit)) == 0)
   1258 		panic("remrq");
   1259 
   1260 	p->p_back->p_forw = p->p_forw;
   1261 	p->p_forw->p_back = p->p_back;
   1262 	p->p_back = NULL;	/* for firewall checking. */
   1263 
   1264 	if ((struct proc *)&qs[bit] == qs[bit].ph_link)
   1265 		whichqs &= ~(1 << bit);
   1266 }
   1267 
   1268 /*
   1269  * Return the best possible estimate of the time in the timeval
   1270  * to which tvp points.  Unfortunately, we can't read the hardware registers.
   1271  * We guarantee that the time will be greater than the value obtained by a
   1272  * previous call.
   1273  */
   1274 void
   1275 microtime(tvp)
   1276 	register struct timeval *tvp;
   1277 {
   1278 	int s = splclock();
   1279 	static struct timeval lasttime;
   1280 
   1281 	*tvp = time;
   1282 #ifdef notdef
   1283 	tvp->tv_usec += clkread();
   1284 	while (tvp->tv_usec > 1000000) {
   1285 		tvp->tv_sec++;
   1286 		tvp->tv_usec -= 1000000;
   1287 	}
   1288 #endif
   1289 	if (tvp->tv_sec == lasttime.tv_sec &&
   1290 	    tvp->tv_usec <= lasttime.tv_usec &&
   1291 	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
   1292 		tvp->tv_sec++;
   1293 		tvp->tv_usec -= 1000000;
   1294 	}
   1295 	lasttime = *tvp;
   1296 	splx(s);
   1297 }
   1298 
   1299 #ifdef COMPAT_OSF1
   1300 void
   1301 cpu_exec_ecoff_setup(cmd, p, epp, sp)
   1302 	int cmd;
   1303 	struct proc *p;
   1304 	struct exec_package *epp;
   1305 	void *sp;
   1306 {
   1307 	struct ecoff_aouthdr *eap;
   1308 
   1309 	if (cmd != EXEC_SETUP_FINISH)
   1310 		return;
   1311 
   1312 	eap = (struct ecoff_aouthdr *)
   1313 	    ((caddr_t)epp->ep_hdr + sizeof(struct ecoff_filehdr));
   1314 	p->p_md.md_tf->tf_gp = eap->ea_gp_value;
   1315 }
   1316 
   1317 /*
   1318  * cpu_exec_ecoff_hook():
   1319  *	cpu-dependent ECOFF format hook for execve().
   1320  *
   1321  * Do any machine-dependent diddling of the exec package when doing ECOFF.
   1322  *
   1323  */
   1324 int
   1325 cpu_exec_ecoff_hook(p, epp, eap)
   1326 	struct proc *p;
   1327 	struct exec_package *epp;
   1328 	struct ecoff_aouthdr *eap;
   1329 {
   1330 	struct ecoff_filehdr *efp = epp->ep_hdr;
   1331 
   1332 	switch (efp->ef_magic) {
   1333 	case ECOFF_MAGIC_ALPHA:
   1334 		epp->ep_emul = EMUL_OSF1;
   1335 		break;
   1336 
   1337 	case ECOFF_MAGIC_NETBSD_ALPHA:
   1338 		epp->ep_emul = EMUL_NETBSD;
   1339 		break;
   1340 
   1341 #ifdef DIAGNOSTIC
   1342 	default:
   1343 		panic("cpu_exec_ecoff_hook: can't get here from there.");
   1344 #endif
   1345 	}
   1346 	epp->ep_setup = cpu_exec_ecoff_setup;
   1347 	return 0;
   1348 }
   1349 #endif
   1350