Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.9
      1 /*	$NetBSD: machdep.c,v 1.9 1997/06/09 00:00:02 veego 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 	valloc(swapmap, struct map, nswapmap = maxproc * 2);
    472 #ifdef	SYSVSHM
    473 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    474 #endif
    475 #ifdef	SYSVSEM
    476 	valloc(sema, struct semid_ds, seminfo.semmni);
    477 	valloc(sem, struct sem, seminfo.semmns);
    478 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof(int));
    479 #endif
    480 #ifdef	SYSVMSG
    481 	valloc(msgpool, char, msginfo.msgmax);
    482 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    483 	valloc(msghdrs, struct msg, msginfo.msgtql);
    484 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    485 #endif
    486 
    487 	/*
    488 	 * Decide on buffer space to use.
    489 	 */
    490 	if (bufpages == 0)
    491 		bufpages = (physmem / 20) / CLSIZE;
    492 	if (nbuf == 0) {
    493 		nbuf = bufpages;
    494 		if (nbuf < 16)
    495 			nbuf = 16;
    496 	}
    497 	if (nswbuf == 0) {
    498 		nswbuf = (nbuf / 2) & ~1;
    499 		if (nswbuf > 256)
    500 			nswbuf = 256;
    501 	}
    502 	valloc(swbuf, struct buf, nswbuf);
    503 	valloc(buf, struct buf, nbuf);
    504 
    505 	return v;
    506 }
    507 
    508 /*
    509  * consinit
    510  * Initialize system console.
    511  */
    512 void
    513 consinit()
    514 {
    515 	static int initted;
    516 
    517 	if (initted)
    518 		return;
    519 	initted = 1;
    520 	cninit();
    521 }
    522 
    523 /*
    524  * Set set up registers on exec.
    525  */
    526 void
    527 setregs(p, pack, stack, retval)
    528 	struct proc *p;
    529 	struct exec_package *pack;
    530 	u_long stack;
    531 	register_t *retval;
    532 {
    533 	struct trapframe *tf = trapframe(p);
    534 	struct ps_strings arginfo;
    535 
    536 	bzero(tf, sizeof *tf);
    537 	tf->fixreg[1] = -roundup(-stack + 8, 16);
    538 
    539 	/*
    540 	 * XXX Machine-independent code has already copied arguments and
    541 	 * XXX environment to userland.  Get them back here.
    542 	 */
    543 	(void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
    544 
    545 	/*
    546 	 * Set up arguments for _start():
    547 	 *	_start(argc, argv, envp, obj, cleanup, ps_strings);
    548 	 *
    549 	 * Notes:
    550 	 *	- obj and cleanup are the auxilliary and termination
    551 	 *	  vectors.  They are fixed up by ld.elf_so.
    552 	 *	- ps_strings is a NetBSD extention, and will be
    553 	 * 	  ignored by executables which are strictly
    554 	 *	  compliant with the SVR4 ABI.
    555 	 *
    556 	 * XXX We have to set both regs and retval here due to different
    557 	 * XXX calling convention in trap.c and init_main.c.
    558 	 */
    559 	tf->fixreg[3] = retval[0] = arginfo.ps_nargvstr;
    560 	tf->fixreg[4] = retval[1] = (register_t)arginfo.ps_argvstr;
    561 	tf->fixreg[5] = (register_t)arginfo.ps_envstr;
    562 	tf->fixreg[6] = 0;			/* auxillary vector */
    563 	tf->fixreg[7] = 0;			/* termination vector */
    564 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
    565 
    566 	tf->srr0 = pack->ep_entry;
    567 	tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
    568 	p->p_addr->u_pcb.pcb_flags = 0;
    569 }
    570 
    571 /*
    572  * Send a signal to process.
    573  */
    574 void
    575 sendsig(catcher, sig, mask, code)
    576 	sig_t catcher;
    577 	int sig, mask;
    578 	u_long code;
    579 {
    580 	struct proc *p = curproc;
    581 	struct trapframe *tf;
    582 	struct sigframe *fp, frame;
    583 	struct sigacts *psp = p->p_sigacts;
    584 	int oldonstack;
    585 
    586 	frame.sf_signum = sig;
    587 
    588 	tf = trapframe(p);
    589 	oldonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
    590 
    591 	/*
    592 	 * Allocate stack space for signal handler.
    593 	 */
    594 	if ((psp->ps_flags & SAS_ALTSTACK)
    595 	    && !oldonstack
    596 	    && (psp->ps_sigonstack & sigmask(sig))) {
    597 		fp = (struct sigframe *)(psp->ps_sigstk.ss_sp
    598 					 + psp->ps_sigstk.ss_size);
    599 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
    600 	} else
    601 		fp = (struct sigframe *)tf->fixreg[1];
    602 	fp = (struct sigframe *)((int)(fp - 1) & ~0xf);
    603 
    604 	frame.sf_code = code;
    605 
    606 	/*
    607 	 * Generate signal context for SYS_sigreturn.
    608 	 */
    609 	frame.sf_sc.sc_onstack = oldonstack;
    610 	frame.sf_sc.sc_mask = mask;
    611 	bcopy(tf, &frame.sf_sc.sc_frame, sizeof *tf);
    612 	if (copyout(&frame, fp, sizeof frame) != 0)
    613 		sigexit(p, SIGILL);
    614 
    615 	tf->fixreg[1] = (int)fp;
    616 	tf->lr = (int)catcher;
    617 	tf->fixreg[3] = (int)sig;
    618 	tf->fixreg[4] = (int)code;
    619 	tf->fixreg[5] = (int)&frame.sf_sc;
    620 	tf->srr0 = (int)(((char *)PS_STRINGS)
    621 			 - (p->p_emul->e_esigcode - p->p_emul->e_sigcode));
    622 }
    623 
    624 /*
    625  * System call to cleanup state after a signal handler returns.
    626  */
    627 int
    628 sys_sigreturn(p, v, retval)
    629 	struct proc *p;
    630 	void *v;
    631 	register_t *retval;
    632 {
    633 	struct sys_sigreturn_args /* {
    634 		syscallarg(struct sigcontext *) sigcntxp;
    635 	} */ *uap = v;
    636 	struct sigcontext sc;
    637 	struct trapframe *tf;
    638 	int error;
    639 
    640 	if (error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc))
    641 		return error;
    642 	tf = trapframe(p);
    643 	if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
    644 		return EINVAL;
    645 	bcopy(&sc.sc_frame, tf, sizeof *tf);
    646 	if (sc.sc_onstack & 1)
    647 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
    648 	else
    649 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
    650 	p->p_sigmask = sc.sc_mask & ~sigcantmask;
    651 	return EJUSTRETURN;
    652 }
    653 
    654 /*
    655  * Machine dependent system variables.
    656  * None for now.
    657  */
    658 int
    659 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    660 	int *name;
    661 	u_int namelen;
    662 	void *oldp;
    663 	size_t *oldlenp;
    664 	void *newp;
    665 	size_t newlen;
    666 	struct proc *p;
    667 {
    668 	/* all sysctl names at this level are terminal */
    669 	if (namelen != 1)
    670 		return ENOTDIR;
    671 	switch (name[0]) {
    672 	default:
    673 		return EOPNOTSUPP;
    674 	}
    675 }
    676 
    677 /*
    678  * Crash dump handling.
    679  */
    680 u_long dumpmag = 0x8fca0101;		/* magic number */
    681 int dumpsize = 0;			/* size of dump in pages */
    682 long dumplo = -1;			/* blocks */
    683 
    684 void
    685 dumpsys()
    686 {
    687 	printf("dumpsys: TBD\n");
    688 }
    689 
    690 /*
    691  * Soft networking interrupts.
    692  */
    693 void
    694 softnet()
    695 {
    696 	int isr = netisr;
    697 
    698 	netisr = 0;
    699 #ifdef	INET
    700 #include "ether.h"
    701 #if NETHER > 0
    702 	if (isr & (1 << NETISR_ARP))
    703 		arpintr();
    704 #endif
    705 	if (isr & (1 << NETISR_IP))
    706 		ipintr();
    707 #endif
    708 #ifdef	IMP
    709 	if (isr & (1 << NETISR_IMP))
    710 		impintr();
    711 #endif
    712 #ifdef	NS
    713 	if (isr & (1 << NETISR_NS))
    714 		nsintr();
    715 #endif
    716 #ifdef	ISO
    717 	if (isr & (1 << NETISR_ISO))
    718 		clnlintr();
    719 #endif
    720 #ifdef	CCITT
    721 	if (isr & (1 << NETISR_CCITT))
    722 		ccittintr();
    723 #endif
    724 #include "ppp.h"
    725 #if NPPP > 0
    726 	if (isr & (1 << NETISR_PPP))
    727 		pppintr();
    728 #endif
    729 }
    730 
    731 /*
    732  * Stray interrupts.
    733  */
    734 void
    735 strayintr(irq)
    736 	int irq;
    737 {
    738 	log(LOG_ERR, "stray interrupt %d\n", irq);
    739 }
    740 
    741 /*
    742  * Halt or reboot the machine after syncing/dumping according to howto.
    743  */
    744 void
    745 cpu_reboot(howto, what)
    746 	int howto;
    747 	char *what;
    748 {
    749 	static int syncing;
    750 	static char str[256];
    751 	char *ap = str, *ap1 = ap;
    752 
    753 	boothowto = howto;
    754 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    755 		syncing = 1;
    756 		vfs_shutdown();		/* sync */
    757 		resettodr();		/* set wall clock */
    758 	}
    759 	splhigh();
    760 	if (howto & RB_HALT) {
    761 		doshutdownhooks();
    762 		printf("halted\n\n");
    763 		ppc_exit();
    764 	}
    765 	if (!cold && (howto & RB_DUMP))
    766 		dumpsys();
    767 	doshutdownhooks();
    768 	printf("rebooting\n\n");
    769 	if (what && *what) {
    770 		if (strlen(what) > sizeof str - 5)
    771 			printf("boot string too large, ignored\n");
    772 		else {
    773 			strcpy(str, what);
    774 			ap1 = ap = str + strlen(str);
    775 			*ap++ = ' ';
    776 		}
    777 	}
    778 	*ap++ = '-';
    779 	if (howto & RB_SINGLE)
    780 		*ap++ = 's';
    781 	if (howto & RB_KDB)
    782 		*ap++ = 'd';
    783 	*ap++ = 0;
    784 	if (ap[-2] == '-')
    785 		*ap1 = 0;
    786 	ppc_boot(str);
    787 }
    788 
    789 /*
    790  * OpenFirmware callback routine
    791  */
    792 void
    793 callback(p)
    794 	void *p;
    795 {
    796 	panic("callback");	/* for now			XXX */
    797 }
    798 
    799 /*
    800  * Initial Machine Interface.
    801  */
    802 static int
    803 fake_spl()
    804 {
    805 	int scratch;
    806 
    807 	asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
    808 	    : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
    809 	return -1;
    810 }
    811 
    812 static void
    813 fake_setsoft()
    814 {
    815 	/* Do nothing */
    816 }
    817 
    818 static int
    819 fake_splx(new)
    820 	int new;
    821 {
    822 	return fake_spl();
    823 }
    824 
    825 static void
    826 fake_clock_return(frame, nticks)
    827 	struct clockframe *frame;
    828 	int nticks;
    829 {
    830 	/* Do nothing */
    831 }
    832 
    833 static void
    834 fake_irq_establish(irq, level, handler, arg)
    835 	int irq, level;
    836 	void (*handler) __P((void *));
    837 	void *arg;
    838 {
    839 	panic("fake_irq_establish");
    840 }
    841