Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.11
      1 /*	$NetBSD: machdep.c,v 1.11 1997/09/11 23:02:17 mycroft Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 #include "ipkdb.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/buf.h>
     37 #include <sys/callout.h>
     38 #include <sys/exec.h>
     39 #include <sys/malloc.h>
     40 #include <sys/map.h>
     41 #include <sys/mbuf.h>
     42 #include <sys/mount.h>
     43 #include <sys/msgbuf.h>
     44 #include <sys/proc.h>
     45 #include <sys/reboot.h>
     46 #include <sys/syscallargs.h>
     47 #include <sys/syslog.h>
     48 #include <sys/systm.h>
     49 #include <sys/user.h>
     50 
     51 #include <vm/vm.h>
     52 #include <vm/vm_kern.h>
     53 
     54 #include <net/netisr.h>
     55 
     56 #include <machine/bat.h>
     57 #include <machine/pmap.h>
     58 #include <machine/powerpc.h>
     59 #include <machine/trap.h>
     60 
     61 /*
     62  * Global variables used here and there
     63  */
     64 struct pcb *curpcb;
     65 struct pmap *curpm;
     66 struct proc *fpuproc;
     67 
     68 extern struct user *proc0paddr;
     69 
     70 struct bat battable[16];
     71 
     72 int astpending;
     73 
     74 char *bootpath;
     75 
     76 /*
     77  * We use the page just above the interrupt vector as message buffer
     78  */
     79 #if 0
     80 struct msgbuf *msgbufp = (struct msgbuf *)0x3000;
     81 int msgbufmapped = 1;		/* message buffer is always mapped */
     82 #else
     83 int msgbufmapped = 0;
     84 #endif
     85 
     86 caddr_t allocsys __P((caddr_t));
     87 
     88 static int fake_spl __P((void));
     89 static int fake_splx __P((int));
     90 static void fake_setsoft __P((void));
     91 static void fake_clock_return __P((struct clockframe *, int));
     92 static void fake_irq_establish __P((int, int, void (*)(void *), void *));
     93 
     94 struct machvec machine_interface = {
     95 	fake_spl,
     96 	fake_spl,
     97 	fake_spl,
     98 	fake_spl,
     99 	fake_spl,
    100 	fake_spl,
    101 	fake_spl,
    102 	fake_spl,
    103 	fake_spl,
    104 	fake_splx,
    105 	fake_setsoft,
    106 	fake_setsoft,
    107 	fake_clock_return,
    108 	fake_irq_establish,
    109 };
    110 
    111 int cold = 1;
    112 
    113 void
    114 initppc(startkernel, endkernel, args)
    115 	u_int startkernel, endkernel;
    116 	char *args;
    117 {
    118 	int phandle, qhandle;
    119 	char name[32];
    120 	struct machvec *mp;
    121 	extern trapcode, trapsize;
    122 	extern dsitrap, dsisize;
    123 	extern isitrap, isisize;
    124 	extern decrint, decrsize;
    125 	extern tlbimiss, tlbimsize;
    126 	extern tlbdlmiss, tlbdlmsize;
    127 	extern tlbdsmiss, tlbdsmsize;
    128 #if NIPKDB > 0
    129 	extern ipkdblow, ipkdbsize;
    130 #endif
    131 	extern void consinit __P((void));
    132 	extern void callback __P((void *));
    133 	int exc, scratch;
    134 
    135 	proc0.p_addr = proc0paddr;
    136 	bzero(proc0.p_addr, sizeof *proc0.p_addr);
    137 
    138 	curpcb = &proc0paddr->u_pcb;
    139 
    140 	curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
    141 
    142 	/*
    143 	 * i386 port says, that this shouldn't be here,
    144 	 * but I really think the console should be initialized
    145 	 * as early as possible.
    146 	 */
    147 	consinit();
    148 
    149 #ifdef	__notyet__		/* Needs some rethinking regarding real/virtual OFW */
    150 	OF_set_callback(callback);
    151 #endif
    152 	/*
    153 	 * Initialize BAT registers to unmapped to not generate
    154 	 * overlapping mappings below.
    155 	 */
    156 	asm volatile ("mtibatu 0,%0" :: "r"(0));
    157 	asm volatile ("mtibatu 1,%0" :: "r"(0));
    158 	asm volatile ("mtibatu 2,%0" :: "r"(0));
    159 	asm volatile ("mtibatu 3,%0" :: "r"(0));
    160 	asm volatile ("mtdbatu 0,%0" :: "r"(0));
    161 	asm volatile ("mtdbatu 1,%0" :: "r"(0));
    162 	asm volatile ("mtdbatu 2,%0" :: "r"(0));
    163 	asm volatile ("mtdbatu 3,%0" :: "r"(0));
    164 
    165 	/*
    166 	 * Set up initial BAT table to only map the lowest 256 MB area
    167 	 */
    168 	battable[0].batl = BATL(0x00000000, BAT_M);
    169 	battable[0].batu = BATU(0x00000000);
    170 
    171 	/*
    172 	 * Now setup fixed bat registers
    173 	 *
    174 	 * Note that we still run in real mode, and the BAT
    175 	 * registers were cleared above.
    176 	 */
    177 	/* IBAT0 used for initial 256 MB segment */
    178 	asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
    179 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    180 	/* DBAT0 used similar */
    181 	asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
    182 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    183 
    184 	/*
    185 	 * Set up trap vectors
    186 	 */
    187 	for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
    188 		switch (exc) {
    189 		default:
    190 			bcopy(&trapcode, (void *)exc, (size_t)&trapsize);
    191 			break;
    192 		case EXC_EXI:
    193 			/*
    194 			 * This one is (potentially) installed during autoconf
    195 			 */
    196 			break;
    197 		case EXC_DSI:
    198 			bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
    199 			break;
    200 		case EXC_ISI:
    201 			bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
    202 			break;
    203 		case EXC_DECR:
    204 			bcopy(&decrint, (void *)EXC_DECR, (size_t)&decrsize);
    205 			break;
    206 		case EXC_IMISS:
    207 			bcopy(&tlbimiss, (void *)EXC_IMISS, (size_t)&tlbimsize);
    208 			break;
    209 		case EXC_DLMISS:
    210 			bcopy(&tlbdlmiss, (void *)EXC_DLMISS, (size_t)&tlbdlmsize);
    211 			break;
    212 		case EXC_DSMISS:
    213 			bcopy(&tlbdsmiss, (void *)EXC_DSMISS, (size_t)&tlbdsmsize);
    214 			break;
    215 #if NIPKDB > 0
    216 		case EXC_PGM:
    217 		case EXC_TRC:
    218 		case EXC_BPT:
    219 			bcopy(&ipkdblow, (void *)exc, (size_t)&ipkdbsize);
    220 			break;
    221 #endif
    222 		}
    223 
    224 	syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
    225 
    226 	/*
    227 	 * Now enable translation (and machine checks/recoverable interrupts).
    228 	 */
    229 	asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    230 		      : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    231 
    232 	/*
    233 	 * Parse arg string.
    234 	 */
    235 	bootpath = args;
    236 	while (*++args && *args != ' ');
    237 	if (*args) {
    238 		*args++ = 0;
    239 		while (*args) {
    240 			switch (*args++) {
    241 			case 'a':
    242 				boothowto |= RB_ASKNAME;
    243 				break;
    244 			case 's':
    245 				boothowto |= RB_SINGLE;
    246 				break;
    247 			case 'd':
    248 				boothowto |= RB_KDB;
    249 				break;
    250 			}
    251 		}
    252 	}
    253 
    254 #if NIPKDB > 0
    255 	/*
    256 	 * Now trap to IPKDB
    257 	 */
    258 	ipkdb_init();
    259 	if (boothowto & RB_KDB)
    260 		ipkdb_connect(0);
    261 #endif
    262 
    263 	/*
    264 	 * Initialize pmap module.
    265 	 */
    266 	pmap_bootstrap(startkernel, endkernel);
    267 }
    268 
    269 /*
    270  * This should probably be in autoconf!				XXX
    271  */
    272 int cpu;
    273 char cpu_model[80];
    274 char machine[] = MACHINE;		/* from <machine/param.h> */
    275 char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    276 
    277 void
    278 identifycpu()
    279 {
    280 	int phandle, pvr;
    281 	char name[32];
    282 
    283 	/*
    284 	 * Find cpu type (Do it by OpenFirmware?)
    285 	 */
    286 	asm ("mfpvr %0" : "=r"(pvr));
    287 	cpu = pvr >> 16;
    288 	switch (cpu) {
    289 	case 1:
    290 		sprintf(cpu_model, "601");
    291 		break;
    292 	case 3:
    293 		sprintf(cpu_model, "603");
    294 		break;
    295 	case 4:
    296 		sprintf(cpu_model, "604");
    297 		break;
    298 	case 5:
    299 		sprintf(cpu_model, "602");
    300 		break;
    301 	case 6:
    302 		sprintf(cpu_model, "603e");
    303 		break;
    304 	case 7:
    305 		sprintf(cpu_model, "603ev");
    306 		break;
    307 	case 9:
    308 		sprintf(cpu_model, "604ev");
    309 		break;
    310 	case 20:
    311 		sprintf(cpu_model, "620");
    312 		break;
    313 	default:
    314 		sprintf(cpu_model, "Version %x", cpu);
    315 		break;
    316 	}
    317 	sprintf(cpu_model + strlen(cpu_model), " (Revision %x)", pvr & 0xffff);
    318 	printf("CPU: %s\n", cpu_model);
    319 }
    320 
    321 void
    322 install_extint(handler)
    323 	void (*handler) __P((void));
    324 {
    325 	extern extint, extsize;
    326 	extern u_long extint_call;
    327 	u_long offset = (u_long)handler - (u_long)&extint_call;
    328 	int omsr, msr;
    329 
    330 #ifdef	DIAGNOSTIC
    331 	if (offset > 0x1ffffff)
    332 		panic("install_extint: too far away");
    333 #endif
    334 	asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    335 		      : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
    336 	extint_call = (extint_call & 0xfc000003) | offset;
    337 	bcopy(&extint, (void *)EXC_EXI, (size_t)&extsize);
    338 	syncicache((void *)&extint_call, sizeof extint_call);
    339 	syncicache((void *)EXC_EXI, (int)&extsize);
    340 	asm volatile ("mtmsr %0" :: "r"(omsr));
    341 }
    342 
    343 /*
    344  * Machine dependent startup code.
    345  */
    346 void
    347 cpu_startup()
    348 {
    349 	int sz, i;
    350 	caddr_t v;
    351 	vm_offset_t minaddr, maxaddr;
    352 	int base, residual;
    353 
    354 	proc0.p_addr = proc0paddr;
    355 	v = (caddr_t)proc0paddr + USPACE;
    356 
    357 	printf("%s", version);
    358 	identifycpu();
    359 
    360 	printf("real mem = %d\n", ctob(physmem));
    361 
    362 	/*
    363 	 * Find out how much space we need, allocate it,
    364 	 * and then give everything true virtual addresses.
    365 	 */
    366 	sz = (int)allocsys((caddr_t)0);
    367 	if ((v = (caddr_t)kmem_alloc(kernel_map, round_page(sz))) == 0)
    368 		panic("startup: no room for tables");
    369 	if (allocsys(v) - v != sz)
    370 		panic("startup: table size inconsistency");
    371 
    372 	/*
    373 	 * Now allocate buffers proper.  They are different than the above
    374 	 * in that they usually occupy more virtual memory than physical.
    375 	 */
    376 	sz = MAXBSIZE * nbuf;
    377 	buffer_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, sz, TRUE);
    378 	buffers = (char *)minaddr;
    379 	if (vm_map_find(buffer_map, vm_object_allocate(sz), (vm_offset_t)0,
    380 			&minaddr, sz, FALSE) != KERN_SUCCESS)
    381 		panic("startup: cannot allocate buffers");
    382 	base = bufpages / nbuf;
    383 	residual = bufpages % nbuf;
    384 	if (base >= MAXBSIZE) {
    385 		/* Don't want to alloc more physical mem than ever needed */
    386 		base = MAXBSIZE;
    387 		residual = 0;
    388 	}
    389 	for (i = 0; i < nbuf; i++) {
    390 		vm_size_t curbufsize;
    391 		vm_offset_t curbuf;
    392 
    393 		curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
    394 		curbufsize = CLBYTES * (i < residual ? base + 1 : base);
    395 		vm_map_pageable(buffer_map, curbuf, curbuf + curbufsize, FALSE);
    396 		vm_map_simplify(buffer_map, curbuf);
    397 	}
    398 
    399 	/*
    400 	 * Allocate a submap for exec arguments.  This map effectively
    401 	 * limits the number of processes exec'ing at any time.
    402 	 */
    403 	exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    404 				 16*NCARGS, TRUE);
    405 
    406 	/*
    407 	 * Allocate a submap for physio
    408 	 */
    409 	phys_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
    410 				 VM_PHYS_SIZE, TRUE);
    411 
    412 	/*
    413 	 * Finally, allocate mbuf cluster submap.
    414 	 */
    415 	mb_map = kmem_suballoc(kernel_map, (vm_offset_t *)&mbutl, &maxaddr,
    416 			       VM_MBUF_SIZE, FALSE);
    417 
    418 	/*
    419 	 * Initialize callouts.
    420 	 */
    421 	callfree = callout;
    422 	for (i = 1; i < ncallout; i++)
    423 		callout[i - 1].c_next = &callout[i];
    424 
    425 	printf("avail mem = %d\n", ptoa(cnt.v_free_count));
    426 	printf("using %d buffers containing %d bytes of memory\n",
    427 	       nbuf, bufpages * CLBYTES);
    428 
    429 	/*
    430 	 * Set up the buffers.
    431 	 */
    432 	bufinit();
    433 
    434 	/*
    435 	 * For now, use soft spl handling.
    436 	 */
    437 	{
    438 		extern struct machvec soft_machvec;
    439 
    440 		machine_interface = soft_machvec;
    441 	}
    442 
    443 	/*
    444 	 * Now allow hardware interrupts.
    445 	 */
    446 	{
    447 		int msr;
    448 
    449 		splhigh();
    450 		asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    451 			      : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
    452 	}
    453 
    454 	/*
    455 	 * Configure devices.
    456 	 */
    457 	configure();
    458 }
    459 
    460 /*
    461  * Allocate space for system data structures.
    462  */
    463 caddr_t
    464 allocsys(v)
    465 	caddr_t v;
    466 {
    467 #define	valloc(name, type, num) \
    468 	v = (caddr_t)(((name) = (type *)v) + (num))
    469 
    470 	valloc(callout, struct callout, ncallout);
    471 #ifdef	SYSVSHM
    472 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    473 #endif
    474 #ifdef	SYSVSEM
    475 	valloc(sema, struct semid_ds, seminfo.semmni);
    476 	valloc(sem, struct sem, seminfo.semmns);
    477 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    478 #endif
    479 #ifdef	SYSVMSG
    480 	valloc(msgpool, char, msginfo.msgmax);
    481 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    482 	valloc(msghdrs, struct msg, msginfo.msgtql);
    483 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    484 #endif
    485 
    486 	/*
    487 	 * Decide on buffer space to use.
    488 	 */
    489 	if (bufpages == 0)
    490 		bufpages = (physmem / 20) / CLSIZE;
    491 	if (nbuf == 0) {
    492 		nbuf = bufpages;
    493 		if (nbuf < 16)
    494 			nbuf = 16;
    495 	}
    496 	if (nswbuf == 0) {
    497 		nswbuf = (nbuf / 2) & ~1;
    498 		if (nswbuf > 256)
    499 			nswbuf = 256;
    500 	}
    501 	valloc(swbuf, struct buf, nswbuf);
    502 	valloc(buf, struct buf, nbuf);
    503 
    504 	return v;
    505 }
    506 
    507 /*
    508  * consinit
    509  * Initialize system console.
    510  */
    511 void
    512 consinit()
    513 {
    514 	static int initted;
    515 
    516 	if (initted)
    517 		return;
    518 	initted = 1;
    519 	cninit();
    520 }
    521 
    522 /*
    523  * Set set up registers on exec.
    524  */
    525 void
    526 setregs(p, pack, stack)
    527 	struct proc *p;
    528 	struct exec_package *pack;
    529 	u_long stack;
    530 {
    531 	struct trapframe *tf = trapframe(p);
    532 	struct ps_strings arginfo;
    533 
    534 	bzero(tf, sizeof *tf);
    535 	tf->fixreg[1] = -roundup(-stack + 8, 16);
    536 
    537 	/*
    538 	 * XXX Machine-independent code has already copied arguments and
    539 	 * XXX environment to userland.  Get them back here.
    540 	 */
    541 	(void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
    542 
    543 	/*
    544 	 * Set up arguments for _start():
    545 	 *	_start(argc, argv, envp, obj, cleanup, ps_strings);
    546 	 *
    547 	 * Notes:
    548 	 *	- obj and cleanup are the auxilliary and termination
    549 	 *	  vectors.  They are fixed up by ld.elf_so.
    550 	 *	- ps_strings is a NetBSD extention, and will be
    551 	 * 	  ignored by executables which are strictly
    552 	 *	  compliant with the SVR4 ABI.
    553 	 *
    554 	 * XXX We have to set both regs and retval here due to different
    555 	 * XXX calling convention in trap.c and init_main.c.
    556 	 */
    557 	tf->fixreg[3] = retval[0] = arginfo.ps_nargvstr;
    558 	tf->fixreg[4] = retval[1] = (register_t)arginfo.ps_argvstr;
    559 	tf->fixreg[5] = (register_t)arginfo.ps_envstr;
    560 	tf->fixreg[6] = 0;			/* auxillary vector */
    561 	tf->fixreg[7] = 0;			/* termination vector */
    562 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
    563 
    564 	tf->srr0 = pack->ep_entry;
    565 	tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
    566 	p->p_addr->u_pcb.pcb_flags = 0;
    567 }
    568 
    569 /*
    570  * Send a signal to process.
    571  */
    572 void
    573 sendsig(catcher, sig, mask, code)
    574 	sig_t catcher;
    575 	int sig, mask;
    576 	u_long code;
    577 {
    578 	struct proc *p = curproc;
    579 	struct trapframe *tf;
    580 	struct sigframe *fp, frame;
    581 	struct sigacts *psp = p->p_sigacts;
    582 	int oldonstack;
    583 
    584 	frame.sf_signum = sig;
    585 
    586 	tf = trapframe(p);
    587 	oldonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
    588 
    589 	/*
    590 	 * Allocate stack space for signal handler.
    591 	 */
    592 	if ((psp->ps_flags & SAS_ALTSTACK)
    593 	    && !oldonstack
    594 	    && (psp->ps_sigonstack & sigmask(sig))) {
    595 		fp = (struct sigframe *)(psp->ps_sigstk.ss_sp
    596 					 + psp->ps_sigstk.ss_size);
    597 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
    598 	} else
    599 		fp = (struct sigframe *)tf->fixreg[1];
    600 	fp = (struct sigframe *)((int)(fp - 1) & ~0xf);
    601 
    602 	frame.sf_code = code;
    603 
    604 	/*
    605 	 * Generate signal context for SYS_sigreturn.
    606 	 */
    607 	frame.sf_sc.sc_onstack = oldonstack;
    608 	frame.sf_sc.sc_mask = mask;
    609 	bcopy(tf, &frame.sf_sc.sc_frame, sizeof *tf);
    610 	if (copyout(&frame, fp, sizeof frame) != 0)
    611 		sigexit(p, SIGILL);
    612 
    613 	tf->fixreg[1] = (int)fp;
    614 	tf->lr = (int)catcher;
    615 	tf->fixreg[3] = (int)sig;
    616 	tf->fixreg[4] = (int)code;
    617 	tf->fixreg[5] = (int)&frame.sf_sc;
    618 	tf->srr0 = (int)(((char *)PS_STRINGS)
    619 			 - (p->p_emul->e_esigcode - p->p_emul->e_sigcode));
    620 }
    621 
    622 /*
    623  * System call to cleanup state after a signal handler returns.
    624  */
    625 int
    626 sys_sigreturn(p, v, retval)
    627 	struct proc *p;
    628 	void *v;
    629 	register_t *retval;
    630 {
    631 	struct sys_sigreturn_args /* {
    632 		syscallarg(struct sigcontext *) sigcntxp;
    633 	} */ *uap = v;
    634 	struct sigcontext sc;
    635 	struct trapframe *tf;
    636 	int error;
    637 
    638 	if (error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc))
    639 		return error;
    640 	tf = trapframe(p);
    641 	if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
    642 		return EINVAL;
    643 	bcopy(&sc.sc_frame, tf, sizeof *tf);
    644 	if (sc.sc_onstack & 1)
    645 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
    646 	else
    647 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
    648 	p->p_sigmask = sc.sc_mask & ~sigcantmask;
    649 	return EJUSTRETURN;
    650 }
    651 
    652 /*
    653  * Machine dependent system variables.
    654  * None for now.
    655  */
    656 int
    657 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    658 	int *name;
    659 	u_int namelen;
    660 	void *oldp;
    661 	size_t *oldlenp;
    662 	void *newp;
    663 	size_t newlen;
    664 	struct proc *p;
    665 {
    666 	/* all sysctl names at this level are terminal */
    667 	if (namelen != 1)
    668 		return ENOTDIR;
    669 	switch (name[0]) {
    670 	default:
    671 		return EOPNOTSUPP;
    672 	}
    673 }
    674 
    675 /*
    676  * Crash dump handling.
    677  */
    678 u_long dumpmag = 0x8fca0101;		/* magic number */
    679 int dumpsize = 0;			/* size of dump in pages */
    680 long dumplo = -1;			/* blocks */
    681 
    682 void
    683 dumpsys()
    684 {
    685 	printf("dumpsys: TBD\n");
    686 }
    687 
    688 /*
    689  * Soft networking interrupts.
    690  */
    691 void
    692 softnet()
    693 {
    694 	int isr = netisr;
    695 
    696 	netisr = 0;
    697 #ifdef	INET
    698 #include "ether.h"
    699 #if NETHER > 0
    700 	if (isr & (1 << NETISR_ARP))
    701 		arpintr();
    702 #endif
    703 	if (isr & (1 << NETISR_IP))
    704 		ipintr();
    705 #endif
    706 #ifdef	IMP
    707 	if (isr & (1 << NETISR_IMP))
    708 		impintr();
    709 #endif
    710 #ifdef	NS
    711 	if (isr & (1 << NETISR_NS))
    712 		nsintr();
    713 #endif
    714 #ifdef	ISO
    715 	if (isr & (1 << NETISR_ISO))
    716 		clnlintr();
    717 #endif
    718 #ifdef	CCITT
    719 	if (isr & (1 << NETISR_CCITT))
    720 		ccittintr();
    721 #endif
    722 #include "ppp.h"
    723 #if NPPP > 0
    724 	if (isr & (1 << NETISR_PPP))
    725 		pppintr();
    726 #endif
    727 }
    728 
    729 /*
    730  * Stray interrupts.
    731  */
    732 void
    733 strayintr(irq)
    734 	int irq;
    735 {
    736 	log(LOG_ERR, "stray interrupt %d\n", irq);
    737 }
    738 
    739 /*
    740  * Halt or reboot the machine after syncing/dumping according to howto.
    741  */
    742 void
    743 cpu_reboot(howto, what)
    744 	int howto;
    745 	char *what;
    746 {
    747 	static int syncing;
    748 	static char str[256];
    749 	char *ap = str, *ap1 = ap;
    750 
    751 	boothowto = howto;
    752 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    753 		syncing = 1;
    754 		vfs_shutdown();		/* sync */
    755 		resettodr();		/* set wall clock */
    756 	}
    757 	splhigh();
    758 	if (howto & RB_HALT) {
    759 		doshutdownhooks();
    760 		printf("halted\n\n");
    761 		ppc_exit();
    762 	}
    763 	if (!cold && (howto & RB_DUMP))
    764 		dumpsys();
    765 	doshutdownhooks();
    766 	printf("rebooting\n\n");
    767 	if (what && *what) {
    768 		if (strlen(what) > sizeof str - 5)
    769 			printf("boot string too large, ignored\n");
    770 		else {
    771 			strcpy(str, what);
    772 			ap1 = ap = str + strlen(str);
    773 			*ap++ = ' ';
    774 		}
    775 	}
    776 	*ap++ = '-';
    777 	if (howto & RB_SINGLE)
    778 		*ap++ = 's';
    779 	if (howto & RB_KDB)
    780 		*ap++ = 'd';
    781 	*ap++ = 0;
    782 	if (ap[-2] == '-')
    783 		*ap1 = 0;
    784 	ppc_boot(str);
    785 }
    786 
    787 /*
    788  * OpenFirmware callback routine
    789  */
    790 void
    791 callback(p)
    792 	void *p;
    793 {
    794 	panic("callback");	/* for now			XXX */
    795 }
    796 
    797 /*
    798  * Initial Machine Interface.
    799  */
    800 static int
    801 fake_spl()
    802 {
    803 	int scratch;
    804 
    805 	asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
    806 	    : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
    807 	return -1;
    808 }
    809 
    810 static void
    811 fake_setsoft()
    812 {
    813 	/* Do nothing */
    814 }
    815 
    816 static int
    817 fake_splx(new)
    818 	int new;
    819 {
    820 	return fake_spl();
    821 }
    822 
    823 static void
    824 fake_clock_return(frame, nticks)
    825 	struct clockframe *frame;
    826 	int nticks;
    827 {
    828 	/* Do nothing */
    829 }
    830 
    831 static void
    832 fake_irq_establish(irq, level, handler, arg)
    833 	int irq, level;
    834 	void (*handler) __P((void *));
    835 	void *arg;
    836 {
    837 	panic("fake_irq_establish");
    838 }
    839