xref: /original-bsd/sys/hp300/hp300/machdep.c (revision 2932bec8)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: machdep.c 1.63 91/04/24$
13  *
14  *	@(#)machdep.c	7.27 (Berkeley) 05/04/92
15  */
16 
17 #include "param.h"
18 #include "systm.h"
19 #include "signalvar.h"
20 #include "kernel.h"
21 #include "map.h"
22 #include "proc.h"
23 #include "buf.h"
24 #include "reboot.h"
25 #include "conf.h"
26 #include "file.h"
27 #include "clist.h"
28 #include "callout.h"
29 #include "malloc.h"
30 #include "mbuf.h"
31 #include "msgbuf.h"
32 #include "mount.h"
33 #include "user.h"
34 #include "exec.h"
35 #ifdef SYSVSHM
36 #include "shm.h"
37 #endif
38 #ifdef HPUXCOMPAT
39 #include "../hpux/hpux.h"
40 #endif
41 
42 #include "../include/cpu.h"
43 #include "../include/reg.h"
44 #include "../include/psl.h"
45 #include "isr.h"
46 #include "pte.h"
47 #include "net/netisr.h"
48 
49 #define	MAXMEM	64*1024*CLSIZE	/* XXX - from cmap.h */
50 #include "vm/vm_kern.h"
51 
52 vm_map_t buffer_map;
53 extern vm_offset_t avail_end;
54 
55 /*
56  * Declare these as initialized data so we can patch them.
57  */
58 int	nswbuf = 0;
59 #ifdef	NBUF
60 int	nbuf = NBUF;
61 #else
62 int	nbuf = 0;
63 #endif
64 #ifdef	BUFPAGES
65 int	bufpages = BUFPAGES;
66 #else
67 int	bufpages = 0;
68 #endif
69 int	msgbufmapped;		/* set when safe to use msgbuf */
70 int	maxmem;			/* max memory per process */
71 int	physmem = MAXMEM;	/* max supported memory, changes to actual */
72 /*
73  * safepri is a safe priority for sleep to set for a spin-wait
74  * during autoconfiguration or after a panic.
75  */
76 int	safepri = PSL_LOWIPL;
77 
78 extern	u_int lowram;
79 
80 /*
81  * Console initialization: called early on from main,
82  * before vm init or startup.  Do enough configuration
83  * to choose and initialize a console.
84  */
85 consinit()
86 {
87 
88 	/*
89 	 * Set cpuspeed immediately since cninit() called routines
90 	 * might use delay.
91 	 */
92 	switch (machineid) {
93 	case HP_320:
94 	case HP_330:
95 	case HP_340:
96 		cpuspeed = MHZ_16;
97 		break;
98 	case HP_350:
99 	case HP_360:
100 		cpuspeed = MHZ_25;
101 		break;
102 	case HP_370:
103 		cpuspeed = MHZ_33;
104 		break;
105 	case HP_375:
106 		cpuspeed = MHZ_50;
107 		break;
108 	}
109 	/*
110          * Find what hardware is attached to this machine.
111          */
112 	find_devs();
113 
114 	/*
115 	 * Initialize the console before we print anything out.
116 	 */
117 	cninit();
118 }
119 
120 /*
121  * cpu_startup: allocate memory for variable-sized tables,
122  * initialize cpu, and do autoconfiguration.
123  */
124 cpu_startup()
125 {
126 	register unsigned i;
127 	register caddr_t v, firstaddr;
128 	int base, residual;
129 	extern long Usrptsize;
130 	extern struct map *useriomap;
131 #ifdef DEBUG
132 	extern int pmapdebug;
133 	int opmapdebug = pmapdebug;
134 #endif
135 	vm_offset_t minaddr, maxaddr;
136 	vm_size_t size;
137 
138 	/*
139 	 * Initialize error message buffer (at end of core).
140 	 */
141 #ifdef DEBUG
142 	pmapdebug = 0;
143 #endif
144 	/* avail_end was pre-decremented in pmap_bootstrap to compensate */
145 	for (i = 0; i < btoc(sizeof (struct msgbuf)); i++)
146 		pmap_enter(kernel_pmap, (vm_offset_t)msgbufp,
147 		    avail_end + i * NBPG, VM_PROT_ALL, TRUE);
148 	msgbufmapped = 1;
149 
150 	/*
151 	 * Good {morning,afternoon,evening,night}.
152 	 */
153 	printf(version);
154 	identifycpu();
155 	printf("real mem = %d\n", ctob(physmem));
156 
157 	/*
158 	 * Allocate space for system data structures.
159 	 * The first available real memory address is in "firstaddr".
160 	 * The first available kernel virtual address is in "v".
161 	 * As pages of kernel virtual memory are allocated, "v" is incremented.
162 	 * As pages of memory are allocated and cleared,
163 	 * "firstaddr" is incremented.
164 	 * An index into the kernel page table corresponding to the
165 	 * virtual memory address maintained in "v" is kept in "mapaddr".
166 	 */
167 	/*
168 	 * Make two passes.  The first pass calculates how much memory is
169 	 * needed and allocates it.  The second pass assigns virtual
170 	 * addresses to the various data structures.
171 	 */
172 	firstaddr = 0;
173 again:
174 	v = (caddr_t)firstaddr;
175 
176 #define	valloc(name, type, num) \
177 	    (name) = (type *)v; v = (caddr_t)((name)+(num))
178 #define	valloclim(name, type, num, lim) \
179 	    (name) = (type *)v; v = (caddr_t)((lim) = ((name)+(num)))
180 	valloc(cfree, struct cblock, nclist);
181 	valloc(callout, struct callout, ncallout);
182 	valloc(swapmap, struct map, nswapmap = maxproc * 2);
183 #ifdef SYSVSHM
184 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
185 #endif
186 
187 	/*
188 	 * Determine how many buffers to allocate.
189 	 * Since HPs tend to be long on memory and short on disk speed,
190 	 * we allocate more buffer space than the BSD standard of
191 	 * use 10% of memory for the first 2 Meg, 5% of remaining.
192 	 * We just allocate a flat 10%.  Insure a minimum of 16 buffers.
193 	 * We allocate 1/2 as many swap buffer headers as file i/o buffers.
194 	 */
195 	if (bufpages == 0)
196 		bufpages = physmem / 10 / CLSIZE;
197 	if (nbuf == 0) {
198 		nbuf = bufpages;
199 		if (nbuf < 16)
200 			nbuf = 16;
201 	}
202 	if (nswbuf == 0) {
203 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
204 		if (nswbuf > 256)
205 			nswbuf = 256;		/* sanity */
206 	}
207 	valloc(swbuf, struct buf, nswbuf);
208 	valloc(buf, struct buf, nbuf);
209 	/*
210 	 * End of first pass, size has been calculated so allocate memory
211 	 */
212 	if (firstaddr == 0) {
213 		size = (vm_size_t)(v - firstaddr);
214 		firstaddr = (caddr_t) kmem_alloc(kernel_map, round_page(size));
215 		if (firstaddr == 0)
216 			panic("startup: no room for tables");
217 		goto again;
218 	}
219 	/*
220 	 * End of second pass, addresses have been assigned
221 	 */
222 	if ((vm_size_t)(v - firstaddr) != size)
223 		panic("startup: table size inconsistency");
224 	/*
225 	 * Now allocate buffers proper.  They are different than the above
226 	 * in that they usually occupy more virtual memory than physical.
227 	 */
228 	size = MAXBSIZE * nbuf;
229 	buffer_map = kmem_suballoc(kernel_map, (vm_offset_t *)&buffers,
230 				   &maxaddr, size, FALSE);
231 	minaddr = (vm_offset_t)buffers;
232 	if (vm_map_find(buffer_map, vm_object_allocate(size), (vm_offset_t)0,
233 			&minaddr, size, FALSE) != KERN_SUCCESS)
234 		panic("startup: cannot allocate buffers");
235 	base = bufpages / nbuf;
236 	residual = bufpages % nbuf;
237 	for (i = 0; i < nbuf; i++) {
238 		vm_size_t curbufsize;
239 		vm_offset_t curbuf;
240 
241 		/*
242 		 * First <residual> buffers get (base+1) physical pages
243 		 * allocated for them.  The rest get (base) physical pages.
244 		 *
245 		 * The rest of each buffer occupies virtual space,
246 		 * but has no physical memory allocated for it.
247 		 */
248 		curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
249 		curbufsize = CLBYTES * (i < residual ? base+1 : base);
250 		vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
251 		vm_map_simplify(buffer_map, curbuf);
252 	}
253 	/*
254 	 * Allocate a submap for exec arguments.  This map effectively
255 	 * limits the number of processes exec'ing at any time.
256 	 */
257 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
258 				 16*NCARGS, TRUE);
259 	/*
260 	 * Allocate a submap for physio
261 	 */
262 	phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
263 				 VM_PHYS_SIZE, TRUE);
264 
265 	/*
266 	 * Finally, allocate mbuf pool.  Since mclrefcnt is an off-size
267 	 * we use the more space efficient malloc in place of kmem_alloc.
268 	 */
269 	mclrefcnt = (char *)malloc(NMBCLUSTERS+CLBYTES/MCLBYTES,
270 				   M_MBUF, M_NOWAIT);
271 	bzero(mclrefcnt, NMBCLUSTERS+CLBYTES/MCLBYTES);
272 	mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
273 			       VM_MBUF_SIZE, FALSE);
274 	/*
275 	 * Initialize callouts
276 	 */
277 	callfree = callout;
278 	for (i = 1; i < ncallout; i++)
279 		callout[i-1].c_next = &callout[i];
280 	callout[i-1].c_next = NULL;
281 
282 #ifdef DEBUG
283 	pmapdebug = opmapdebug;
284 #endif
285 	printf("avail mem = %d\n", ptoa(cnt.v_free_count));
286 	printf("using %d buffers containing %d bytes of memory\n",
287 		nbuf, bufpages * CLBYTES);
288 	/*
289 	 * Set up CPU-specific registers, cache, etc.
290 	 */
291 	initcpu();
292 
293 	/*
294 	 * Set up buffers, so they can be used to read disk labels.
295 	 */
296 	bufinit();
297 
298 	/*
299 	 * Configure the system.
300 	 */
301 	configure();
302 }
303 
304 /*
305  * Set registers on exec.
306  * XXX Should clear registers except sp, pc,
307  * but would break init; should be fixed soon.
308  */
309 setregs(p, entry, retval)
310 	register struct proc *p;
311 	u_long entry;
312 	int retval[2];
313 {
314 	p->p_md.md_regs[PC] = entry & ~1;
315 #ifdef FPCOPROC
316 	/* restore a null state frame */
317 	p->p_addr->u_pcb.pcb_fpregs.fpf_null = 0;
318 	m68881_restore(&p->p_addr->u_pcb.pcb_fpregs);
319 #endif
320 #ifdef HPUXCOMPAT
321 	if (p->p_flag & SHPUX) {
322 
323 		p->p_md.md_regs[A0] = 0; /* not 68010 (bit 31), no FPA (30) */
324 		retval[0] = 0;		/* no float card */
325 #ifdef FPCOPROC
326 		retval[1] = 1;		/* yes 68881 */
327 #else
328 		retval[1] = 0;		/* no 68881 */
329 #endif
330 	}
331 	/*
332 	 * Ensure we perform the right action on traps type 1 and 2:
333 	 * If our parent is an HPUX process and we are being traced, turn
334 	 * on HPUX style interpretation.  Else if we were using the HPUX
335 	 * style interpretation, revert to the BSD interpretation.
336 	 *
337 	 * XXX This doesn't have much to do with setting registers but
338 	 * I didn't want to muck up kern_exec.c with this code, so I
339 	 * stuck it here.
340 	 */
341 	if ((p->p_pptr->p_flag & SHPUX) &&
342 	    (p->p_flag & STRC)) {
343 		tweaksigcode(1);
344 		p->p_addr->u_pcb.pcb_flags |= PCB_HPUXTRACE;
345 	} else if (p->p_addr->u_pcb.pcb_flags & PCB_HPUXTRACE) {
346 		tweaksigcode(0);
347 		p->p_addr->u_pcb.pcb_flags &= ~PCB_HPUXTRACE;
348 	}
349 #endif
350 }
351 
352 identifycpu()
353 {
354 
355 	printf("HP9000/");
356 	switch (machineid) {
357 	case HP_320:
358 		printf("320 (16.67Mhz");
359 		break;
360 	case HP_330:
361 		printf("318/319/330 (16.67Mhz");
362 		break;
363 	case HP_340:
364 		printf("340 (16.67Mhz");
365 		break;
366 	case HP_350:
367 		printf("350 (25Mhz");
368 		break;
369 	case HP_360:
370 		printf("360 (25Mhz");
371 		break;
372 	case HP_370:
373 		printf("370 (33.33Mhz");
374 		break;
375 	case HP_375:
376 		printf("345/375 (50Mhz");
377 		break;
378 	default:
379 		printf("\nunknown machine type %d\n", machineid);
380 		panic("startup");
381 	}
382 	printf(" MC680%s CPU", mmutype == MMU_68030 ? "30" : "20");
383 	switch (mmutype) {
384 	case MMU_68030:
385 		printf("+MMU");
386 		break;
387 	case MMU_68851:
388 		printf(", MC68851 MMU");
389 		break;
390 	case MMU_HP:
391 		printf(", HP MMU");
392 		break;
393 	default:
394 		printf("\nunknown MMU type %d\n", mmutype);
395 		panic("startup");
396 	}
397 	if (mmutype == MMU_68030)
398 		printf(", %sMhz MC68882 FPU",
399 		       machineid == HP_340 ? "16.67" :
400 		       (machineid == HP_360 ? "25" :
401 			(machineid == HP_370 ? "33.33" : "50")));
402 	else
403 		printf(", %sMhz MC68881 FPU",
404 		       machineid == HP_350 ? "20" : "16.67");
405 	switch (ectype) {
406 	case EC_VIRT:
407 		printf(", %dK virtual-address cache",
408 		       machineid == HP_320 ? 16 : 32);
409 		break;
410 	case EC_PHYS:
411 		printf(", %dK physical-address cache",
412 		       machineid == HP_370 ? 64 : 32);
413 		break;
414 	}
415 	printf(")\n");
416 	/*
417 	 * Now that we have told the user what they have,
418 	 * let them know if that machine type isn't configured.
419 	 */
420 	switch (machineid) {
421 	case -1:		/* keep compilers happy */
422 #if !defined(HP320) && !defined(HP350)
423 	case HP_320:
424 	case HP_350:
425 #endif
426 #ifndef HP330
427 	case HP_330:
428 #endif
429 #if !defined(HP360) && !defined(HP370)
430 	case HP_340:
431 	case HP_360:
432 	case HP_370:
433 #endif
434 		panic("CPU type not configured");
435 	default:
436 		break;
437 	}
438 }
439 
440 #ifdef HPUXCOMPAT
441 tweaksigcode(ishpux)
442 {
443 	static short *sigtrap = NULL;
444 	extern short sigcode[], esigcode[];
445 
446 	/* locate trap instruction in pcb_sigc */
447 	if (sigtrap == NULL) {
448 		sigtrap = esigcode;
449 		while (--sigtrap >= sigcode)
450 			if ((*sigtrap & 0xFFF0) == 0x4E40)
451 				break;
452 		if (sigtrap < sigcode)
453 			panic("bogus sigcode\n");
454 	}
455 	*sigtrap = ishpux ? 0x4E42 : 0x4E41;
456 }
457 #endif
458 
459 #define SS_RTEFRAME	1
460 #define SS_FPSTATE	2
461 #define SS_USERREGS	4
462 
463 struct sigstate {
464 	int	ss_flags;		/* which of the following are valid */
465 	struct	frame ss_frame;		/* original exception frame */
466 	struct	fpframe ss_fpstate;	/* 68881/68882 state info */
467 };
468 
469 /*
470  * WARNING: code in locore.s assumes the layout shown for sf_signum
471  * thru sf_handler so... don't screw with them!
472  */
473 struct sigframe {
474 	int	sf_signum;		/* signo for handler */
475 	int	sf_code;		/* additional info for handler */
476 	struct	sigcontext *sf_scp;	/* context ptr for handler */
477 	sig_t	sf_handler;		/* handler addr for u_sigc */
478 	struct	sigstate sf_state;	/* state of the hardware */
479 	struct	sigcontext sf_sc;	/* actual context */
480 };
481 
482 #ifdef HPUXCOMPAT
483 struct	hpuxsigcontext {
484 	int	hsc_syscall;
485 	char	hsc_action;
486 	char	hsc_pad1;
487 	char	hsc_pad2;
488 	char	hsc_onstack;
489 	int	hsc_mask;
490 	int	hsc_sp;
491 	short	hsc_ps;
492 	int	hsc_pc;
493 /* the rest aren't part of the context but are included for our convenience */
494 	short	hsc_pad;
495 	u_int	hsc_magic;		/* XXX sigreturn: cookie */
496 	struct	sigcontext *hsc_realsc;	/* XXX sigreturn: ptr to BSD context */
497 };
498 
499 /*
500  * For an HP-UX process, a partial hpuxsigframe follows the normal sigframe.
501  * Tremendous waste of space, but some HP-UX applications (e.g. LCL) need it.
502  */
503 struct hpuxsigframe {
504 	int	hsf_signum;
505 	int	hsf_code;
506 	struct	sigcontext *hsf_scp;
507 	struct	hpuxsigcontext hsf_sc;
508 	int	hsf_regs[15];
509 };
510 #endif
511 
512 #ifdef DEBUG
513 int sigdebug = 0;
514 int sigpid = 0;
515 #define SDB_FOLLOW	0x01
516 #define SDB_KSTACK	0x02
517 #define SDB_FPSTATE	0x04
518 #endif
519 
520 /*
521  * Send an interrupt to process.
522  */
523 void
524 sendsig(catcher, sig, mask, code)
525 	sig_t catcher;
526 	int sig, mask;
527 	unsigned code;
528 {
529 	register struct proc *p = curproc;
530 	register struct sigframe *fp, *kfp;
531 	register struct frame *frame;
532 	register struct sigacts *psp = p->p_sigacts;
533 	register short ft;
534 	int oonstack, fsize;
535 	extern short exframesize[];
536 	extern char sigcode[], esigcode[];
537 
538 	frame = (struct frame *)p->p_md.md_regs;
539 	ft = frame->f_format;
540 	oonstack = psp->ps_sigstk.ss_flags & SA_ONSTACK;
541 	/*
542 	 * Allocate and validate space for the signal handler
543 	 * context. Note that if the stack is in P0 space, the
544 	 * call to grow() is a nop, and the useracc() check
545 	 * will fail if the process has not already allocated
546 	 * the space with a `brk'.
547 	 */
548 #ifdef HPUXCOMPAT
549 	if (p->p_flag & SHPUX)
550 		fsize = sizeof(struct sigframe) + sizeof(struct hpuxsigframe);
551 	else
552 #endif
553 	fsize = sizeof(struct sigframe);
554 	if ((psp->ps_flags & SAS_ALTSTACK) &&
555 	    (psp->ps_sigstk.ss_flags & SA_ONSTACK) == 0 &&
556 	    (psp->ps_sigonstack & sigmask(sig))) {
557 		fp = (struct sigframe *)(psp->ps_sigstk.ss_base +
558 		    psp->ps_sigstk.ss_size - fsize);
559 		psp->ps_sigstk.ss_flags |= SA_ONSTACK;
560 	} else
561 		fp = (struct sigframe *)(frame->f_regs[SP] - fsize);
562 	if ((unsigned)fp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
563 		(void)grow(p, (unsigned)fp);
564 #ifdef DEBUG
565 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
566 		printf("sendsig(%d): sig %d ssp %x usp %x scp %x ft %d\n",
567 		       p->p_pid, sig, &oonstack, fp, &fp->sf_sc, ft);
568 #endif
569 	if (useracc((caddr_t)fp, fsize, B_WRITE) == 0) {
570 #ifdef DEBUG
571 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
572 			printf("sendsig(%d): useracc failed on sig %d\n",
573 			       p->p_pid, sig);
574 #endif
575 		/*
576 		 * Process has trashed its stack; give it an illegal
577 		 * instruction to halt it in its tracks.
578 		 */
579 		SIGACTION(p, SIGILL) = SIG_DFL;
580 		sig = sigmask(SIGILL);
581 		p->p_sigignore &= ~sig;
582 		p->p_sigcatch &= ~sig;
583 		p->p_sigmask &= ~sig;
584 		psignal(p, SIGILL);
585 		return;
586 	}
587 	kfp = (struct sigframe *)malloc((u_long)fsize, M_TEMP, M_WAITOK);
588 	/*
589 	 * Build the argument list for the signal handler.
590 	 */
591 	kfp->sf_signum = sig;
592 	kfp->sf_code = code;
593 	kfp->sf_scp = &fp->sf_sc;
594 	kfp->sf_handler = catcher;
595 	/*
596 	 * Save necessary hardware state.  Currently this includes:
597 	 *	- general registers
598 	 *	- original exception frame (if not a "normal" frame)
599 	 *	- FP coprocessor state
600 	 */
601 	kfp->sf_state.ss_flags = SS_USERREGS;
602 	bcopy((caddr_t)frame->f_regs,
603 	      (caddr_t)kfp->sf_state.ss_frame.f_regs, sizeof frame->f_regs);
604 	if (ft >= FMT9) {
605 #ifdef DEBUG
606 		if (ft != FMT9 && ft != FMTA && ft != FMTB)
607 			panic("sendsig: bogus frame type");
608 #endif
609 		kfp->sf_state.ss_flags |= SS_RTEFRAME;
610 		kfp->sf_state.ss_frame.f_format = frame->f_format;
611 		kfp->sf_state.ss_frame.f_vector = frame->f_vector;
612 		bcopy((caddr_t)&frame->F_u,
613 		      (caddr_t)&kfp->sf_state.ss_frame.F_u, exframesize[ft]);
614 		/*
615 		 * Leave an indicator that we need to clean up the kernel
616 		 * stack.  We do this by setting the "pad word" above the
617 		 * hardware stack frame to the amount the stack must be
618 		 * adjusted by.
619 		 *
620 		 * N.B. we increment rather than just set f_stackadj in
621 		 * case we are called from syscall when processing a
622 		 * sigreturn.  In that case, f_stackadj may be non-zero.
623 		 */
624 		frame->f_stackadj += exframesize[ft];
625 		frame->f_format = frame->f_vector = 0;
626 #ifdef DEBUG
627 		if (sigdebug & SDB_FOLLOW)
628 			printf("sendsig(%d): copy out %d of frame %d\n",
629 			       p->p_pid, exframesize[ft], ft);
630 #endif
631 	}
632 #ifdef FPCOPROC
633 	kfp->sf_state.ss_flags |= SS_FPSTATE;
634 	m68881_save(&kfp->sf_state.ss_fpstate);
635 #ifdef DEBUG
636 	if ((sigdebug & SDB_FPSTATE) && *(char *)&kfp->sf_state.ss_fpstate)
637 		printf("sendsig(%d): copy out FP state (%x) to %x\n",
638 		       p->p_pid, *(u_int *)&kfp->sf_state.ss_fpstate,
639 		       &kfp->sf_state.ss_fpstate);
640 #endif
641 #endif
642 	/*
643 	 * Build the signal context to be used by sigreturn.
644 	 */
645 	kfp->sf_sc.sc_onstack = oonstack;
646 	kfp->sf_sc.sc_mask = mask;
647 	kfp->sf_sc.sc_sp = frame->f_regs[SP];
648 	kfp->sf_sc.sc_fp = frame->f_regs[A6];
649 	kfp->sf_sc.sc_ap = (int)&fp->sf_state;
650 	kfp->sf_sc.sc_pc = frame->f_pc;
651 	kfp->sf_sc.sc_ps = frame->f_sr;
652 #ifdef HPUXCOMPAT
653 	/*
654 	 * Create an HP-UX style sigcontext structure and associated goo
655 	 */
656 	if (p->p_flag & SHPUX) {
657 		register struct hpuxsigframe *hkfp;
658 
659 		hkfp = (struct hpuxsigframe *)&kfp[1];
660 		hkfp->hsf_signum = bsdtohpuxsig(kfp->sf_signum);
661 		hkfp->hsf_code = kfp->sf_code;
662 		hkfp->hsf_scp = (struct sigcontext *)
663 			&((struct hpuxsigframe *)(&fp[1]))->hsf_sc;
664 		hkfp->hsf_sc.hsc_syscall = 0;		/* XXX */
665 		hkfp->hsf_sc.hsc_action = 0;		/* XXX */
666 		hkfp->hsf_sc.hsc_pad1 = hkfp->hsf_sc.hsc_pad2 = 0;
667 		hkfp->hsf_sc.hsc_onstack = kfp->sf_sc.sc_onstack;
668 		hkfp->hsf_sc.hsc_mask = kfp->sf_sc.sc_mask;
669 		hkfp->hsf_sc.hsc_sp = kfp->sf_sc.sc_sp;
670 		hkfp->hsf_sc.hsc_ps = kfp->sf_sc.sc_ps;
671 		hkfp->hsf_sc.hsc_pc = kfp->sf_sc.sc_pc;
672 		hkfp->hsf_sc.hsc_pad = 0;
673 		hkfp->hsf_sc.hsc_magic = 0xdeadbeef;
674 		hkfp->hsf_sc.hsc_realsc = kfp->sf_scp;
675 		bcopy((caddr_t)frame->f_regs, (caddr_t)hkfp->hsf_regs,
676 		      sizeof (hkfp->hsf_regs));
677 
678 		kfp->sf_signum = hkfp->hsf_signum;
679 		kfp->sf_scp = hkfp->hsf_scp;
680 	}
681 #endif
682 	(void) copyout((caddr_t)kfp, (caddr_t)fp, fsize);
683 	frame->f_regs[SP] = (int)fp;
684 #ifdef DEBUG
685 	if (sigdebug & SDB_FOLLOW)
686 		printf("sendsig(%d): sig %d scp %x fp %x sc_sp %x sc_ap %x\n",
687 		       p->p_pid, sig, kfp->sf_scp, fp,
688 		       kfp->sf_sc.sc_sp, kfp->sf_sc.sc_ap);
689 #endif
690 	/*
691 	 * Signal trampoline code is at base of user stack.
692 	 */
693 	frame->f_pc = (int)PS_STRINGS - (esigcode - sigcode);
694 #ifdef DEBUG
695 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
696 		printf("sendsig(%d): sig %d returns\n",
697 		       p->p_pid, sig);
698 #endif
699 	free((caddr_t)kfp, M_TEMP);
700 }
701 
702 /*
703  * System call to cleanup state after a signal
704  * has been taken.  Reset signal mask and
705  * stack state from context left by sendsig (above).
706  * Return to previous pc and psl as specified by
707  * context left by sendsig. Check carefully to
708  * make sure that the user has not modified the
709  * psl to gain improper priviledges or to cause
710  * a machine fault.
711  */
712 /* ARGSUSED */
713 sigreturn(p, uap, retval)
714 	struct proc *p;
715 	struct args {
716 		struct sigcontext *sigcntxp;
717 	} *uap;
718 	int *retval;
719 {
720 	register struct sigcontext *scp;
721 	register struct frame *frame;
722 	register int rf;
723 	struct sigcontext tsigc;
724 	struct sigstate tstate;
725 	int flags;
726 	extern short exframesize[];
727 
728 	scp = uap->sigcntxp;
729 #ifdef DEBUG
730 	if (sigdebug & SDB_FOLLOW)
731 		printf("sigreturn: pid %d, scp %x\n", p->p_pid, scp);
732 #endif
733 	if ((int)scp & 1)
734 		return (EINVAL);
735 #ifdef HPUXCOMPAT
736 	/*
737 	 * Grab context as an HP-UX style context and determine if it
738 	 * was one that we contructed in sendsig.
739 	 */
740 	if (p->p_flag & SHPUX) {
741 		struct hpuxsigcontext *hscp = (struct hpuxsigcontext *)scp;
742 		struct hpuxsigcontext htsigc;
743 
744 		if (useracc((caddr_t)hscp, sizeof (*hscp), B_WRITE) == 0 ||
745 		    copyin((caddr_t)hscp, (caddr_t)&htsigc, sizeof htsigc))
746 			return (EINVAL);
747 		/*
748 		 * If not generated by sendsig or we cannot restore the
749 		 * BSD-style sigcontext, just restore what we can -- state
750 		 * will be lost, but them's the breaks.
751 		 */
752 		hscp = &htsigc;
753 		if (hscp->hsc_magic != 0xdeadbeef ||
754 		    (scp = hscp->hsc_realsc) == 0 ||
755 		    useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
756 		    copyin((caddr_t)scp, (caddr_t)&tsigc, sizeof tsigc)) {
757 			if (hscp->hsc_onstack & 01)
758 				p->p_sigacts->ps_sigstk.ss_flags |= SA_ONSTACK;
759 			else
760 				p->p_sigacts->ps_sigstk.ss_flags &= ~SA_ONSTACK;
761 			p->p_sigmask = hscp->hsc_mask &~ sigcantmask;
762 			frame = (struct frame *) p->p_md.md_regs;
763 			frame->f_regs[SP] = hscp->hsc_sp;
764 			frame->f_pc = hscp->hsc_pc;
765 			frame->f_sr = hscp->hsc_ps &~ PSL_USERCLR;
766 			return (EJUSTRETURN);
767 		}
768 		/*
769 		 * Otherwise, overlay BSD context with possibly modified
770 		 * HP-UX values.
771 		 */
772 		tsigc.sc_onstack = hscp->hsc_onstack;
773 		tsigc.sc_mask = hscp->hsc_mask;
774 		tsigc.sc_sp = hscp->hsc_sp;
775 		tsigc.sc_ps = hscp->hsc_ps;
776 		tsigc.sc_pc = hscp->hsc_pc;
777 	} else
778 #endif
779 	/*
780 	 * Test and fetch the context structure.
781 	 * We grab it all at once for speed.
782 	 */
783 	if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
784 	    copyin((caddr_t)scp, (caddr_t)&tsigc, sizeof tsigc))
785 		return (EINVAL);
786 	scp = &tsigc;
787 	if ((scp->sc_ps & (PSL_MBZ|PSL_IPL|PSL_S)) != 0)
788 		return (EINVAL);
789 	/*
790 	 * Restore the user supplied information
791 	 */
792 	if (scp->sc_onstack & 01)
793 		p->p_sigacts->ps_sigstk.ss_flags |= SA_ONSTACK;
794 	else
795 		p->p_sigacts->ps_sigstk.ss_flags &= ~SA_ONSTACK;
796 	p->p_sigmask = scp->sc_mask &~ sigcantmask;
797 	frame = (struct frame *) p->p_md.md_regs;
798 	frame->f_regs[SP] = scp->sc_sp;
799 	frame->f_regs[A6] = scp->sc_fp;
800 	frame->f_pc = scp->sc_pc;
801 	frame->f_sr = scp->sc_ps;
802 	/*
803 	 * Grab pointer to hardware state information.
804 	 * If zero, the user is probably doing a longjmp.
805 	 */
806 	if ((rf = scp->sc_ap) == 0)
807 		return (EJUSTRETURN);
808 	/*
809 	 * See if there is anything to do before we go to the
810 	 * expense of copying in close to 1/2K of data
811 	 */
812 	flags = fuword((caddr_t)rf);
813 #ifdef DEBUG
814 	if (sigdebug & SDB_FOLLOW)
815 		printf("sigreturn(%d): sc_ap %x flags %x\n",
816 		       p->p_pid, rf, flags);
817 #endif
818 	/*
819 	 * fuword failed (bogus sc_ap value).
820 	 */
821 	if (flags == -1)
822 		return (EINVAL);
823 	if (flags == 0 || copyin((caddr_t)rf, (caddr_t)&tstate, sizeof tstate))
824 		return (EJUSTRETURN);
825 #ifdef DEBUG
826 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
827 		printf("sigreturn(%d): ssp %x usp %x scp %x ft %d\n",
828 		       p->p_pid, &flags, scp->sc_sp, uap->sigcntxp,
829 		       (flags&SS_RTEFRAME) ? tstate.ss_frame.f_format : -1);
830 #endif
831 	/*
832 	 * Restore most of the users registers except for A6 and SP
833 	 * which were handled above.
834 	 */
835 	if (flags & SS_USERREGS)
836 		bcopy((caddr_t)tstate.ss_frame.f_regs,
837 		      (caddr_t)frame->f_regs, sizeof(frame->f_regs)-2*NBPW);
838 	/*
839 	 * Restore long stack frames.  Note that we do not copy
840 	 * back the saved SR or PC, they were picked up above from
841 	 * the sigcontext structure.
842 	 */
843 	if (flags & SS_RTEFRAME) {
844 		register int sz;
845 
846 		/* grab frame type and validate */
847 		sz = tstate.ss_frame.f_format;
848 		if (sz > 15 || (sz = exframesize[sz]) < 0)
849 			return (EINVAL);
850 		frame->f_stackadj -= sz;
851 		frame->f_format = tstate.ss_frame.f_format;
852 		frame->f_vector = tstate.ss_frame.f_vector;
853 		bcopy((caddr_t)&tstate.ss_frame.F_u, (caddr_t)&frame->F_u, sz);
854 #ifdef DEBUG
855 		if (sigdebug & SDB_FOLLOW)
856 			printf("sigreturn(%d): copy in %d of frame type %d\n",
857 			       p->p_pid, sz, tstate.ss_frame.f_format);
858 #endif
859 	}
860 #ifdef FPCOPROC
861 	/*
862 	 * Finally we restore the original FP context
863 	 */
864 	if (flags & SS_FPSTATE)
865 		m68881_restore(&tstate.ss_fpstate);
866 #ifdef DEBUG
867 	if ((sigdebug & SDB_FPSTATE) && *(char *)&tstate.ss_fpstate)
868 		printf("sigreturn(%d): copied in FP state (%x) at %x\n",
869 		       p->p_pid, *(u_int *)&tstate.ss_fpstate,
870 		       &tstate.ss_fpstate);
871 #endif
872 #endif
873 #ifdef DEBUG
874 	if ((sigdebug & SDB_FOLLOW) ||
875 	    ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
876 		printf("sigreturn(%d): returns\n", p->p_pid);
877 #endif
878 	return (EJUSTRETURN);
879 }
880 
881 int	waittime = -1;
882 
883 boot(howto)
884 	register int howto;
885 {
886 	/* take a snap shot before clobbering any registers */
887 	if (curproc)
888 		savectx(curproc->p_addr, 0);
889 
890 	boothowto = howto;
891 	if ((howto&RB_NOSYNC) == 0 && waittime < 0 && bfreelist[0].b_forw) {
892 		register struct buf *bp;
893 		int iter, nbusy;
894 
895 		waittime = 0;
896 		(void) spl0();
897 		printf("syncing disks... ");
898 		/*
899 		 * Release vnodes held by texts before sync.
900 		 */
901 		if (panicstr == 0)
902 			vnode_pager_umount(NULL);
903 #ifdef notdef
904 #include "fd.h"
905 #if NFD > 0
906 		fdshutdown();
907 #endif
908 #endif
909 		sync(&proc0, (void *)NULL, (int *)NULL);
910 
911 		for (iter = 0; iter < 20; iter++) {
912 			nbusy = 0;
913 			for (bp = &buf[nbuf]; --bp >= buf; )
914 				if ((bp->b_flags & (B_BUSY|B_INVAL)) == B_BUSY)
915 					nbusy++;
916 			if (nbusy == 0)
917 				break;
918 			printf("%d ", nbusy);
919 			DELAY(40000 * iter);
920 		}
921 		if (nbusy)
922 			printf("giving up\n");
923 		else
924 			printf("done\n");
925 		/*
926 		 * If we've been adjusting the clock, the todr
927 		 * will be out of synch; adjust it now.
928 		 */
929 		resettodr();
930 	}
931 	splhigh();			/* extreme priority */
932 	if (howto&RB_HALT) {
933 		printf("halted\n\n");
934 		asm("	stop	#0x2700");
935 	} else {
936 		if (howto & RB_DUMP)
937 			dumpsys();
938 		doboot();
939 		/*NOTREACHED*/
940 	}
941 	/*NOTREACHED*/
942 }
943 
944 int	dumpmag = 0x8fca0101;	/* magic number for savecore */
945 int	dumpsize = 0;		/* also for savecore */
946 long	dumplo = 0;
947 
948 dumpconf()
949 {
950 	int nblks;
951 
952 	dumpsize = physmem;
953 	if (dumpdev != NODEV && bdevsw[major(dumpdev)].d_psize) {
954 		nblks = (*bdevsw[major(dumpdev)].d_psize)(dumpdev);
955 		if (dumpsize > btoc(dbtob(nblks - dumplo)))
956 			dumpsize = btoc(dbtob(nblks - dumplo));
957 		else if (dumplo == 0)
958 			dumplo = nblks - btodb(ctob(physmem));
959 	}
960 	/*
961 	 * Don't dump on the first CLBYTES (why CLBYTES?)
962 	 * in case the dump device includes a disk label.
963 	 */
964 	if (dumplo < btodb(CLBYTES))
965 		dumplo = btodb(CLBYTES);
966 }
967 
968 /*
969  * Doadump comes here after turning off memory management and
970  * getting on the dump stack, either when called above, or by
971  * the auto-restart code.
972  */
973 dumpsys()
974 {
975 
976 	msgbufmapped = 0;
977 	if (dumpdev == NODEV)
978 		return;
979 	/*
980 	 * For dumps during autoconfiguration,
981 	 * if dump device has already configured...
982 	 */
983 	if (dumpsize == 0)
984 		dumpconf();
985 	if (dumplo < 0)
986 		return;
987 	printf("\ndumping to dev %x, offset %d\n", dumpdev, dumplo);
988 	printf("dump ");
989 	switch ((*bdevsw[major(dumpdev)].d_dump)(dumpdev)) {
990 
991 	case ENXIO:
992 		printf("device bad\n");
993 		break;
994 
995 	case EFAULT:
996 		printf("device not ready\n");
997 		break;
998 
999 	case EINVAL:
1000 		printf("area improper\n");
1001 		break;
1002 
1003 	case EIO:
1004 		printf("i/o error\n");
1005 		break;
1006 
1007 	default:
1008 		printf("succeeded\n");
1009 		break;
1010 	}
1011 }
1012 
1013 /*
1014  * Return the best possible estimate of the time in the timeval
1015  * to which tvp points.  We do this by returning the current time
1016  * plus the amount of time since the last clock interrupt (clock.c:clkread).
1017  *
1018  * Check that this time is no less than any previously-reported time,
1019  * which could happen around the time of a clock adjustment.  Just for fun,
1020  * we guarantee that the time will be greater than the value obtained by a
1021  * previous call.
1022  */
1023 microtime(tvp)
1024 	register struct timeval *tvp;
1025 {
1026 	int s = splhigh();
1027 	static struct timeval lasttime;
1028 
1029 	*tvp = time;
1030 	tvp->tv_usec += clkread();
1031 	while (tvp->tv_usec > 1000000) {
1032 		tvp->tv_sec++;
1033 		tvp->tv_usec -= 1000000;
1034 	}
1035 	if (tvp->tv_sec == lasttime.tv_sec &&
1036 	    tvp->tv_usec <= lasttime.tv_usec &&
1037 	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {
1038 		tvp->tv_sec++;
1039 		tvp->tv_usec -= 1000000;
1040 	}
1041 	lasttime = *tvp;
1042 	splx(s);
1043 }
1044 
1045 initcpu()
1046 {
1047 	parityenable();
1048 }
1049 
1050 straytrap(pc, evec)
1051 	int pc;
1052 	u_short evec;
1053 {
1054 	printf("unexpected trap (vector offset %x) from %x\n",
1055 	       evec & 0xFFF, pc);
1056 }
1057 
1058 int	*nofault;
1059 
1060 badaddr(addr)
1061 	register caddr_t addr;
1062 {
1063 	register int i;
1064 	label_t	faultbuf;
1065 
1066 #ifdef lint
1067 	i = *addr; if (i) return(0);
1068 #endif
1069 	nofault = (int *) &faultbuf;
1070 	if (setjmp((label_t *)nofault)) {
1071 		nofault = (int *) 0;
1072 		return(1);
1073 	}
1074 	i = *(volatile short *)addr;
1075 	nofault = (int *) 0;
1076 	return(0);
1077 }
1078 
1079 badbaddr(addr)
1080 	register caddr_t addr;
1081 {
1082 	register int i;
1083 	label_t	faultbuf;
1084 
1085 #ifdef lint
1086 	i = *addr; if (i) return(0);
1087 #endif
1088 	nofault = (int *) &faultbuf;
1089 	if (setjmp((label_t *)nofault)) {
1090 		nofault = (int *) 0;
1091 		return(1);
1092 	}
1093 	i = *(volatile char *)addr;
1094 	nofault = (int *) 0;
1095 	return(0);
1096 }
1097 
1098 netintr()
1099 {
1100 #ifdef INET
1101 	if (netisr & (1 << NETISR_ARP)) {
1102 		netisr &= ~(1 << NETISR_ARP);
1103 		arpintr();
1104 	}
1105 	if (netisr & (1 << NETISR_IP)) {
1106 		netisr &= ~(1 << NETISR_IP);
1107 		ipintr();
1108 	}
1109 #endif
1110 #ifdef NS
1111 	if (netisr & (1 << NETISR_NS)) {
1112 		netisr &= ~(1 << NETISR_NS);
1113 		nsintr();
1114 	}
1115 #endif
1116 #ifdef ISO
1117 	if (netisr & (1 << NETISR_ISO)) {
1118 		netisr &= ~(1 << NETISR_ISO);
1119 		clnlintr();
1120 	}
1121 #endif
1122 }
1123 
1124 intrhand(sr)
1125 	int sr;
1126 {
1127 	register struct isr *isr;
1128 	register int found = 0;
1129 	register int ipl;
1130 	extern struct isr isrqueue[];
1131 
1132 	ipl = (sr >> 8) & 7;
1133 	switch (ipl) {
1134 
1135 	case 3:
1136 	case 4:
1137 	case 5:
1138 		ipl = ISRIPL(ipl);
1139 		isr = isrqueue[ipl].isr_forw;
1140 		for (; isr != &isrqueue[ipl]; isr = isr->isr_forw) {
1141 			if ((isr->isr_intr)(isr->isr_arg)) {
1142 				found++;
1143 				break;
1144 			}
1145 		}
1146 		if (found == 0)
1147 			printf("stray interrupt, sr 0x%x\n", sr);
1148 		break;
1149 
1150 	case 0:
1151 	case 1:
1152 	case 2:
1153 	case 6:
1154 	case 7:
1155 		printf("intrhand: unexpected sr 0x%x\n", sr);
1156 		break;
1157 	}
1158 }
1159 
1160 #if defined(DEBUG) && !defined(PANICBUTTON)
1161 #define PANICBUTTON
1162 #endif
1163 
1164 #ifdef PANICBUTTON
1165 int panicbutton = 1;	/* non-zero if panic buttons are enabled */
1166 int crashandburn = 0;
1167 int candbdelay = 50;	/* give em half a second */
1168 
1169 candbtimer()
1170 {
1171 	crashandburn = 0;
1172 }
1173 #endif
1174 
1175 /*
1176  * Level 7 interrupts can be caused by the keyboard or parity errors.
1177  */
1178 nmihand(frame)
1179 	struct frame frame;
1180 {
1181 	if (kbdnmi()) {
1182 #ifdef PANICBUTTON
1183 		static int innmihand = 0;
1184 
1185 		/*
1186 		 * Attempt to reduce the window of vulnerability for recursive
1187 		 * NMIs (e.g. someone holding down the keyboard reset button).
1188 		 */
1189 		if (innmihand == 0) {
1190 			innmihand = 1;
1191 			printf("Got a keyboard NMI\n");
1192 			innmihand = 0;
1193 		}
1194 		if (panicbutton) {
1195 			if (crashandburn) {
1196 				crashandburn = 0;
1197 				panic(panicstr ?
1198 				      "forced crash, nosync" : "forced crash");
1199 			}
1200 			crashandburn++;
1201 			timeout(candbtimer, (caddr_t)0, candbdelay);
1202 		}
1203 #endif
1204 		return;
1205 	}
1206 	if (parityerror(&frame))
1207 		return;
1208 	/* panic?? */
1209 	printf("unexpected level 7 interrupt ignored\n");
1210 }
1211 
1212 /*
1213  * Parity error section.  Contains magic.
1214  */
1215 #define PARREG		((volatile short *)IIOV(0x5B0000))
1216 static int gotparmem = 0;
1217 #ifdef DEBUG
1218 int ignorekperr = 0;	/* ignore kernel parity errors */
1219 #endif
1220 
1221 /*
1222  * Enable parity detection
1223  */
1224 parityenable()
1225 {
1226 	label_t	faultbuf;
1227 
1228 	nofault = (int *) &faultbuf;
1229 	if (setjmp((label_t *)nofault)) {
1230 		nofault = (int *) 0;
1231 #ifdef DEBUG
1232 		printf("No parity memory\n");
1233 #endif
1234 		return;
1235 	}
1236 	*PARREG = 1;
1237 	nofault = (int *) 0;
1238 	gotparmem = 1;
1239 #ifdef DEBUG
1240 	printf("Parity detection enabled\n");
1241 #endif
1242 }
1243 
1244 /*
1245  * Determine if level 7 interrupt was caused by a parity error
1246  * and deal with it if it was.  Returns 1 if it was a parity error.
1247  */
1248 parityerror(fp)
1249 	struct frame *fp;
1250 {
1251 	if (!gotparmem)
1252 		return(0);
1253 	*PARREG = 0;
1254 	DELAY(10);
1255 	*PARREG = 1;
1256 	if (panicstr) {
1257 		printf("parity error after panic ignored\n");
1258 		return(1);
1259 	}
1260 	if (!findparerror())
1261 		printf("WARNING: transient parity error ignored\n");
1262 	else if (USERMODE(fp->f_sr)) {
1263 		printf("pid %d: parity error\n", curproc->p_pid);
1264 		uprintf("sorry, pid %d killed due to memory parity error\n",
1265 			curproc->p_pid);
1266 		psignal(curproc, SIGKILL);
1267 #ifdef DEBUG
1268 	} else if (ignorekperr) {
1269 		printf("WARNING: kernel parity error ignored\n");
1270 #endif
1271 	} else {
1272 		regdump(fp->f_regs, 128);
1273 		panic("kernel parity error");
1274 	}
1275 	return(1);
1276 }
1277 
1278 /*
1279  * Yuk!  There has got to be a better way to do this!
1280  * Searching all of memory with interrupts blocked can lead to disaster.
1281  */
1282 findparerror()
1283 {
1284 	static label_t parcatch;
1285 	static int looking = 0;
1286 	volatile struct pte opte;
1287 	volatile int pg, o, s;
1288 	register volatile int *ip;
1289 	register int i;
1290 	int found;
1291 
1292 #ifdef lint
1293 	ip = &found;
1294 	i = o = pg = 0; if (i) return(0);
1295 #endif
1296 	/*
1297 	 * If looking is true we are searching for a known parity error
1298 	 * and it has just occured.  All we do is return to the higher
1299 	 * level invocation.
1300 	 */
1301 	if (looking)
1302 		longjmp(&parcatch);
1303 	s = splhigh();
1304 	/*
1305 	 * If setjmp returns true, the parity error we were searching
1306 	 * for has just occured (longjmp above) at the current pg+o
1307 	 */
1308 	if (setjmp(&parcatch)) {
1309 		printf("Parity error at 0x%x\n", ctob(pg)|o);
1310 		found = 1;
1311 		goto done;
1312 	}
1313 	/*
1314 	 * If we get here, a parity error has occured for the first time
1315 	 * and we need to find it.  We turn off any external caches and
1316 	 * loop thru memory, testing every longword til a fault occurs and
1317 	 * we regain control at setjmp above.  Note that because of the
1318 	 * setjmp, pg and o need to be volatile or their values will be lost.
1319 	 */
1320 	looking = 1;
1321 	ecacheoff();
1322 	for (pg = btoc(lowram); pg < btoc(lowram)+physmem; pg++) {
1323 		pmap_enter(kernel_pmap, (vm_offset_t)vmmap, ctob(pg),
1324 		    VM_PROT_READ, TRUE);
1325 		for (o = 0; o < NBPG; o += sizeof(int))
1326 			i = *(int *)(&vmmap[o]);
1327 	}
1328 	/*
1329 	 * Getting here implies no fault was found.  Should never happen.
1330 	 */
1331 	printf("Couldn't locate parity error\n");
1332 	found = 0;
1333 done:
1334 	looking = 0;
1335 	pmap_remove(kernel_pmap, (vm_offset_t)vmmap,
1336 	    (vm_offset_t)&vmmap[NBPG]);
1337 	ecacheon();
1338 	splx(s);
1339 	return(found);
1340 }
1341 
1342 regdump(rp, sbytes)
1343   int *rp; /* must not be register */
1344   int sbytes;
1345 {
1346 	static int doingdump = 0;
1347 	register int i;
1348 	int s;
1349 	extern char *hexstr();
1350 
1351 	if (doingdump)
1352 		return;
1353 	s = splhigh();
1354 	doingdump = 1;
1355 	printf("pid = %d, pc = %s, ", curproc->p_pid, hexstr(rp[PC], 8));
1356 	printf("ps = %s, ", hexstr(rp[PS], 4));
1357 	printf("sfc = %s, ", hexstr(getsfc(), 4));
1358 	printf("dfc = %s\n", hexstr(getdfc(), 4));
1359 	printf("Registers:\n     ");
1360 	for (i = 0; i < 8; i++)
1361 		printf("        %d", i);
1362 	printf("\ndreg:");
1363 	for (i = 0; i < 8; i++)
1364 		printf(" %s", hexstr(rp[i], 8));
1365 	printf("\nareg:");
1366 	for (i = 0; i < 8; i++)
1367 		printf(" %s", hexstr(rp[i+8], 8));
1368 	if (sbytes > 0) {
1369 		if (rp[PS] & PSL_S) {
1370 			printf("\n\nKernel stack (%s):",
1371 			       hexstr((int)(((int *)&rp)-1), 8));
1372 			dumpmem(((int *)&rp)-1, sbytes, 0);
1373 		} else {
1374 			printf("\n\nUser stack (%s):", hexstr(rp[SP], 8));
1375 			dumpmem((int *)rp[SP], sbytes, 1);
1376 		}
1377 	}
1378 	doingdump = 0;
1379 	splx(s);
1380 }
1381 
1382 extern char kstack[];
1383 #define KSADDR	((int *)&(kstack[(UPAGES-1)*NBPG]))
1384 
1385 dumpmem(ptr, sz, ustack)
1386 	register int *ptr;
1387 	int sz;
1388 {
1389 	register int i, val;
1390 	extern char *hexstr();
1391 
1392 	for (i = 0; i < sz; i++) {
1393 		if ((i & 7) == 0)
1394 			printf("\n%s: ", hexstr((int)ptr, 6));
1395 		else
1396 			printf(" ");
1397 		if (ustack == 1) {
1398 			if ((val = fuword(ptr++)) == -1)
1399 				break;
1400 		} else {
1401 			if (ustack == 0 &&
1402 			    (ptr < KSADDR || ptr > KSADDR+(NBPG/4-1)))
1403 				break;
1404 			val = *ptr++;
1405 		}
1406 		printf("%s", hexstr(val, 8));
1407 	}
1408 	printf("\n");
1409 }
1410 
1411 char *
1412 hexstr(val, len)
1413 	register int val;
1414 {
1415 	static char nbuf[9];
1416 	register int x, i;
1417 
1418 	if (len > 8)
1419 		return("");
1420 	nbuf[len] = '\0';
1421 	for (i = len-1; i >= 0; --i) {
1422 		x = val & 0xF;
1423 		if (x > 9)
1424 			nbuf[i] = x - 10 + 'A';
1425 		else
1426 			nbuf[i] = x + '0';
1427 		val >>= 4;
1428 	}
1429 	return(nbuf);
1430 }
1431