Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.37
      1 /*	$NetBSD: machdep.c,v 1.37 1999/04/16 21:47:12 thorpej 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 
     34 #include "opt_compat_netbsd.h"
     35 #include "opt_ddb.h"
     36 #include "opt_inet.h"
     37 #include "opt_ccitt.h"
     38 #include "opt_iso.h"
     39 #include "opt_ns.h"
     40 #include "opt_sysv.h"
     41 #include "ipkdb.h"
     42 
     43 #include <sys/param.h>
     44 #include <sys/buf.h>
     45 #include <sys/callout.h>
     46 #include <sys/exec.h>
     47 #include <sys/malloc.h>
     48 #include <sys/map.h>
     49 #include <sys/mbuf.h>
     50 #include <sys/mount.h>
     51 #include <sys/msgbuf.h>
     52 #include <sys/proc.h>
     53 #include <sys/reboot.h>
     54 #include <sys/syscallargs.h>
     55 #include <sys/syslog.h>
     56 #include <sys/systm.h>
     57 #include <sys/user.h>
     58 
     59 #include <vm/vm.h>
     60 #include <vm/vm_kern.h>
     61 
     62 #include <uvm/uvm_extern.h>
     63 
     64 #include <net/netisr.h>
     65 
     66 #include <machine/bat.h>
     67 #include <machine/pmap.h>
     68 #include <machine/powerpc.h>
     69 #include <machine/trap.h>
     70 
     71 /*
     72  * Global variables used here and there
     73  */
     74 vm_map_t exec_map = NULL;
     75 vm_map_t mb_map = NULL;
     76 vm_map_t phys_map = NULL;
     77 
     78 struct pcb *curpcb;
     79 struct pmap *curpm;
     80 struct proc *fpuproc;
     81 
     82 extern struct user *proc0paddr;
     83 
     84 struct bat battable[16];
     85 
     86 int astpending;
     87 
     88 char *bootpath;
     89 
     90 #define MSGBUFADDR 0x3000
     91 
     92 caddr_t allocsys __P((caddr_t));
     93 
     94 static int fake_spl __P((void));
     95 static int fake_splx __P((int));
     96 static void fake_setsoft __P((void));
     97 static void fake_clock_return __P((struct clockframe *, int));
     98 static void fake_irq_establish __P((int, int, void (*)(void *), void *));
     99 
    100 struct machvec machine_interface = {
    101 	fake_spl,
    102 	fake_spl,
    103 	fake_spl,
    104 	fake_spl,
    105 	fake_spl,
    106 	fake_spl,
    107 	fake_spl,
    108 	fake_spl,
    109 	fake_spl,
    110 	fake_splx,
    111 	fake_setsoft,
    112 	fake_setsoft,
    113 	fake_clock_return,
    114 	fake_irq_establish,
    115 };
    116 
    117 int cold = 1;
    118 
    119 void
    120 initppc(startkernel, endkernel, args)
    121 	u_int startkernel, endkernel;
    122 	char *args;
    123 {
    124 	int phandle, qhandle;
    125 	char name[32];
    126 	struct machvec *mp;
    127 	extern trapcode, trapsize;
    128 	extern dsitrap, dsisize;
    129 	extern isitrap, isisize;
    130 	extern decrint, decrsize;
    131 	extern tlbimiss, tlbimsize;
    132 	extern tlbdlmiss, tlbdlmsize;
    133 	extern tlbdsmiss, tlbdsmsize;
    134 #ifdef DDB
    135 	extern ddblow, ddbsize;
    136 	extern void *startsym, *endsym;
    137 #endif
    138 #if NIPKDB > 0
    139 	extern ipkdblow, ipkdbsize;
    140 #endif
    141 	extern void consinit __P((void));
    142 	extern void callback __P((void *));
    143 	int exc, scratch;
    144 
    145 	proc0.p_addr = proc0paddr;
    146 	bzero(proc0.p_addr, sizeof *proc0.p_addr);
    147 
    148 	curpcb = &proc0paddr->u_pcb;
    149 
    150 	curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
    151 
    152 	/*
    153 	 * i386 port says, that this shouldn't be here,
    154 	 * but I really think the console should be initialized
    155 	 * as early as possible.
    156 	 */
    157 	consinit();
    158 
    159 #ifdef	__notyet__		/* Needs some rethinking regarding real/virtual OFW */
    160 	OF_set_callback(callback);
    161 #endif
    162 	/*
    163 	 * Initialize BAT registers to unmapped to not generate
    164 	 * overlapping mappings below.
    165 	 */
    166 	asm volatile ("mtibatu 0,%0" :: "r"(0));
    167 	asm volatile ("mtibatu 1,%0" :: "r"(0));
    168 	asm volatile ("mtibatu 2,%0" :: "r"(0));
    169 	asm volatile ("mtibatu 3,%0" :: "r"(0));
    170 	asm volatile ("mtdbatu 0,%0" :: "r"(0));
    171 	asm volatile ("mtdbatu 1,%0" :: "r"(0));
    172 	asm volatile ("mtdbatu 2,%0" :: "r"(0));
    173 	asm volatile ("mtdbatu 3,%0" :: "r"(0));
    174 
    175 	/*
    176 	 * Set up initial BAT table to only map the lowest 256 MB area
    177 	 */
    178 	battable[0].batl = BATL(0x00000000, BAT_M);
    179 	battable[0].batu = BATU(0x00000000);
    180 
    181 	/*
    182 	 * Now setup fixed bat registers
    183 	 *
    184 	 * Note that we still run in real mode, and the BAT
    185 	 * registers were cleared above.
    186 	 */
    187 	/* IBAT0 used for initial 256 MB segment */
    188 	asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
    189 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    190 	/* DBAT0 used similar */
    191 	asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
    192 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    193 
    194 	/*
    195 	 * Set up trap vectors
    196 	 */
    197 	for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
    198 		switch (exc) {
    199 		default:
    200 			bcopy(&trapcode, (void *)exc, (size_t)&trapsize);
    201 			break;
    202 		case EXC_EXI:
    203 			/*
    204 			 * This one is (potentially) installed during autoconf
    205 			 */
    206 			break;
    207 		case EXC_DSI:
    208 			bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
    209 			break;
    210 		case EXC_ISI:
    211 			bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
    212 			break;
    213 		case EXC_DECR:
    214 			bcopy(&decrint, (void *)EXC_DECR, (size_t)&decrsize);
    215 			break;
    216 		case EXC_IMISS:
    217 			bcopy(&tlbimiss, (void *)EXC_IMISS, (size_t)&tlbimsize);
    218 			break;
    219 		case EXC_DLMISS:
    220 			bcopy(&tlbdlmiss, (void *)EXC_DLMISS, (size_t)&tlbdlmsize);
    221 			break;
    222 		case EXC_DSMISS:
    223 			bcopy(&tlbdsmiss, (void *)EXC_DSMISS, (size_t)&tlbdsmsize);
    224 			break;
    225 #if defined(DDB) || NIPKDB > 0
    226 		case EXC_PGM:
    227 		case EXC_TRC:
    228 		case EXC_BPT:
    229 #if defined(DDB)
    230 			bcopy(&ddblow, (void *)exc, (size_t)&ddbsize);
    231 #else
    232 			bcopy(&ipkdblow, (void *)exc, (size_t)&ipkdbsize);
    233 #endif
    234 			break;
    235 #endif /* DDB || NIPKDB > 0 */
    236 		}
    237 
    238 	syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
    239 
    240 	/*
    241 	 * Now enable translation (and machine checks/recoverable interrupts).
    242 	 */
    243 	asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    244 		      : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    245 
    246 	/*
    247 	 * Parse arg string.
    248 	 */
    249 	bootpath = args;
    250 	while (*++args && *args != ' ');
    251 	if (*args) {
    252 		*args++ = 0;
    253 		while (*args) {
    254 			switch (*args++) {
    255 			case 'a':
    256 				boothowto |= RB_ASKNAME;
    257 				break;
    258 			case 's':
    259 				boothowto |= RB_SINGLE;
    260 				break;
    261 			case 'd':
    262 				boothowto |= RB_KDB;
    263 				break;
    264 			}
    265 		}
    266 	}
    267 
    268 #ifdef DDB
    269 	/* ddb_init((int)(endsym - startsym), startsym, endsym); */
    270 #endif
    271 #if NIPKDB > 0
    272 	/*
    273 	 * Now trap to IPKDB
    274 	 */
    275 	ipkdb_init();
    276 	if (boothowto & RB_KDB)
    277 		ipkdb_connect(0);
    278 #endif
    279 
    280 	/*
    281 	 * Set the page size.
    282 	 */
    283 	uvm_setpagesize();
    284 
    285 	/*
    286 	 * Initialize pmap module.
    287 	 */
    288 	pmap_bootstrap(startkernel, endkernel);
    289 }
    290 
    291 /*
    292  * This should probably be in autoconf!				XXX
    293  */
    294 int cpu;
    295 char cpu_model[80];
    296 char machine[] = MACHINE;		/* from <machine/param.h> */
    297 char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    298 
    299 void
    300 identifycpu()
    301 {
    302 	int phandle, pvr;
    303 	char name[32];
    304 
    305 	/*
    306 	 * Find cpu type (Do it by OpenFirmware?)
    307 	 */
    308 	asm ("mfpvr %0" : "=r"(pvr));
    309 	cpu = pvr >> 16;
    310 	switch (cpu) {
    311 	case 1:
    312 		sprintf(cpu_model, "601");
    313 		break;
    314 	case 3:
    315 		sprintf(cpu_model, "603");
    316 		break;
    317 	case 4:
    318 		sprintf(cpu_model, "604");
    319 		break;
    320 	case 5:
    321 		sprintf(cpu_model, "602");
    322 		break;
    323 	case 6:
    324 		sprintf(cpu_model, "603e");
    325 		break;
    326 	case 7:
    327 		sprintf(cpu_model, "603ev");
    328 		break;
    329 	case 9:
    330 		sprintf(cpu_model, "604ev");
    331 		break;
    332 	case 20:
    333 		sprintf(cpu_model, "620");
    334 		break;
    335 	default:
    336 		sprintf(cpu_model, "Version %x", cpu);
    337 		break;
    338 	}
    339 	sprintf(cpu_model + strlen(cpu_model), " (Revision %x)", pvr & 0xffff);
    340 	printf("CPU: %s\n", cpu_model);
    341 }
    342 
    343 void
    344 install_extint(handler)
    345 	void (*handler) __P((void));
    346 {
    347 	extern extint, extsize;
    348 	extern u_long extint_call;
    349 	u_long offset = (u_long)handler - (u_long)&extint_call;
    350 	int omsr, msr;
    351 
    352 #ifdef	DIAGNOSTIC
    353 	if (offset > 0x1ffffff)
    354 		panic("install_extint: too far away");
    355 #endif
    356 	asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    357 		      : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
    358 	extint_call = (extint_call & 0xfc000003) | offset;
    359 	bcopy(&extint, (void *)EXC_EXI, (size_t)&extsize);
    360 	syncicache((void *)&extint_call, sizeof extint_call);
    361 	syncicache((void *)EXC_EXI, (int)&extsize);
    362 	asm volatile ("mtmsr %0" :: "r"(omsr));
    363 }
    364 
    365 /*
    366  * Machine dependent startup code.
    367  */
    368 void
    369 cpu_startup()
    370 {
    371 	int sz, i;
    372 	caddr_t v;
    373 	paddr_t minaddr, maxaddr;
    374 	int base, residual;
    375 
    376 	/*
    377 	 * Initialize error message buffer (at end of core).
    378 	 */
    379 	initmsgbuf((caddr_t)MSGBUFADDR, round_page(MSGBUFSIZE));
    380 
    381 	proc0.p_addr = proc0paddr;
    382 	v = (caddr_t)proc0paddr + USPACE;
    383 
    384 	printf("%s", version);
    385 	identifycpu();
    386 
    387 	printf("real mem = %d\n", ctob(physmem));
    388 
    389 	/*
    390 	 * Find out how much space we need, allocate it,
    391 	 * and then give everything true virtual addresses.
    392 	 */
    393 	sz = (int)allocsys((caddr_t)0);
    394 	if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
    395 		panic("startup: no room for tables");
    396 	if (allocsys(v) - v != sz)
    397 		panic("startup: table size inconsistency");
    398 
    399 	/*
    400 	 * Now allocate buffers proper.  They are different than the above
    401 	 * in that they usually occupy more virtual memory than physical.
    402 	 */
    403 	sz = MAXBSIZE * nbuf;
    404 	if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
    405 		    NULL, UVM_UNKNOWN_OFFSET,
    406 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    407 				UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
    408 		panic("startup: cannot allocate VM for buffers");
    409 	minaddr = (vaddr_t)buffers;
    410 	base = bufpages / nbuf;
    411 	residual = bufpages % nbuf;
    412 	if (base >= MAXBSIZE) {
    413 		/* Don't want to alloc more physical mem than ever needed */
    414 		base = MAXBSIZE;
    415 		residual = 0;
    416 	}
    417 	for (i = 0; i < nbuf; i++) {
    418 		vsize_t curbufsize;
    419 		vaddr_t curbuf;
    420 		struct vm_page *pg;
    421 
    422 		/*
    423 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    424 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    425 		 * for the first "residual" buffers, and then we allocate
    426 		 * "base" pages for the rest.
    427 		 */
    428 		curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
    429 		curbufsize = CLBYTES * ((i < residual) ? (base+1) : base);
    430 
    431 		while (curbufsize) {
    432 			pg = uvm_pagealloc(NULL, 0, NULL, 0);
    433 			if (pg == NULL)
    434 				panic("startup: not enough memory for "
    435 					"buffer cache");
    436 			pmap_enter(kernel_map->pmap, curbuf,
    437 			    VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
    438 			    TRUE, VM_PROT_READ|VM_PROT_WRITE);
    439 			curbuf += PAGE_SIZE;
    440 			curbufsize -= PAGE_SIZE;
    441 		}
    442 	}
    443 
    444 	/*
    445 	 * Allocate a submap for exec arguments.  This map effectively
    446 	 * limits the number of processes exec'ing at any time.
    447 	 */
    448 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    449 				 16*NCARGS, TRUE, FALSE, NULL);
    450 
    451 	/*
    452 	 * Allocate a submap for physio
    453 	 */
    454 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    455 				 VM_PHYS_SIZE, TRUE, FALSE, NULL);
    456 
    457 	/*
    458 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    459 	 * are allocated via the pool allocator, and we use direct-mapped
    460 	 * pool pages.
    461 	 */
    462 
    463 	/*
    464 	 * Initialize callouts.
    465 	 */
    466 	callfree = callout;
    467 	for (i = 1; i < ncallout; i++)
    468 		callout[i - 1].c_next = &callout[i];
    469 
    470 	printf("avail memory = %d\n", ptoa(uvmexp.free));
    471 	printf("using %d buffers containing %d bytes of memory\n",
    472 	       nbuf, bufpages * CLBYTES);
    473 
    474 	/*
    475 	 * Set up the buffers.
    476 	 */
    477 	bufinit();
    478 
    479 	/*
    480 	 * For now, use soft spl handling.
    481 	 */
    482 	{
    483 		extern struct machvec soft_machvec;
    484 
    485 		machine_interface = soft_machvec;
    486 	}
    487 
    488 	/*
    489 	 * Now allow hardware interrupts.
    490 	 */
    491 	{
    492 		int msr;
    493 
    494 		splhigh();
    495 		asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    496 			      : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
    497 	}
    498 }
    499 
    500 /*
    501  * Allocate space for system data structures.
    502  */
    503 caddr_t
    504 allocsys(v)
    505 	caddr_t v;
    506 {
    507 #define	valloc(name, type, num) \
    508 	v = (caddr_t)(((name) = (type *)v) + (num))
    509 
    510 	valloc(callout, struct callout, ncallout);
    511 #ifdef	SYSVSHM
    512 	valloc(shmsegs, struct shmid_ds, shminfo.shmmni);
    513 #endif
    514 #ifdef	SYSVSEM
    515 	valloc(sema, struct semid_ds, seminfo.semmni);
    516 	valloc(sem, struct sem, seminfo.semmns);
    517 	valloc(semu, int, (seminfo.semmnu * seminfo.semusz) / sizeof (int));
    518 #endif
    519 #ifdef	SYSVMSG
    520 	valloc(msgpool, char, msginfo.msgmax);
    521 	valloc(msgmaps, struct msgmap, msginfo.msgseg);
    522 	valloc(msghdrs, struct msg, msginfo.msgtql);
    523 	valloc(msqids, struct msqid_ds, msginfo.msgmni);
    524 #endif
    525 
    526 	/*
    527 	 * Decide on buffer space to use.
    528 	 */
    529 	if (bufpages == 0)
    530 		bufpages = (physmem / 20) / CLSIZE;
    531 	if (nbuf == 0) {
    532 		nbuf = bufpages;
    533 		if (nbuf < 16)
    534 			nbuf = 16;
    535 	}
    536 	if (nswbuf == 0) {
    537 		nswbuf = (nbuf / 2) & ~1;
    538 		if (nswbuf > 256)
    539 			nswbuf = 256;
    540 	}
    541 	valloc(buf, struct buf, nbuf);
    542 
    543 	return (v);
    544 }
    545 
    546 /*
    547  * consinit
    548  * Initialize system console.
    549  */
    550 void
    551 consinit()
    552 {
    553 	static int initted;
    554 
    555 	if (initted)
    556 		return;
    557 	initted = 1;
    558 	cninit();
    559 }
    560 
    561 /*
    562  * Set set up registers on exec.
    563  */
    564 void
    565 setregs(p, pack, stack)
    566 	struct proc *p;
    567 	struct exec_package *pack;
    568 	u_long stack;
    569 {
    570 	struct trapframe *tf = trapframe(p);
    571 	struct ps_strings arginfo;
    572 
    573 	bzero(tf, sizeof *tf);
    574 	tf->fixreg[1] = -roundup(-stack + 8, 16);
    575 
    576 	/*
    577 	 * XXX Machine-independent code has already copied arguments and
    578 	 * XXX environment to userland.  Get them back here.
    579 	 */
    580 	(void)copyin((char *)PS_STRINGS, &arginfo, sizeof (arginfo));
    581 
    582 	/*
    583 	 * Set up arguments for _start():
    584 	 *	_start(argc, argv, envp, obj, cleanup, ps_strings);
    585 	 *
    586 	 * Notes:
    587 	 *	- obj and cleanup are the auxilliary and termination
    588 	 *	  vectors.  They are fixed up by ld.elf_so.
    589 	 *	- ps_strings is a NetBSD extention, and will be
    590 	 * 	  ignored by executables which are strictly
    591 	 *	  compliant with the SVR4 ABI.
    592 	 *
    593 	 * XXX We have to set both regs and retval here due to different
    594 	 * XXX calling convention in trap.c and init_main.c.
    595 	 */
    596 	tf->fixreg[3] = arginfo.ps_nargvstr;
    597 	tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
    598 	tf->fixreg[5] = (register_t)arginfo.ps_envstr;
    599 	tf->fixreg[6] = 0;			/* auxillary vector */
    600 	tf->fixreg[7] = 0;			/* termination vector */
    601 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
    602 
    603 	tf->srr0 = pack->ep_entry;
    604 	tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
    605 	p->p_addr->u_pcb.pcb_flags = 0;
    606 }
    607 
    608 /*
    609  * Send a signal to process.
    610  */
    611 void
    612 sendsig(catcher, sig, mask, code)
    613 	sig_t catcher;
    614 	int sig;
    615 	sigset_t *mask;
    616 	u_long code;
    617 {
    618 	struct proc *p = curproc;
    619 	struct trapframe *tf;
    620 	struct sigframe *fp, frame;
    621 	struct sigacts *psp = p->p_sigacts;
    622 	int onstack;
    623 
    624 	tf = trapframe(p);
    625 
    626 	/* Do we need to jump onto the signal stack? */
    627 	onstack =
    628 	    (psp->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    629 	    (psp->ps_sigact[sig].sa_flags & SA_ONSTACK) != 0;
    630 
    631 	/* Allocate space for the signal handler context. */
    632 	if (onstack)
    633 		fp = (struct sigframe *)((caddr_t)psp->ps_sigstk.ss_sp +
    634 						  psp->ps_sigstk.ss_size);
    635 	else
    636 		fp = (struct sigframe *)tf->fixreg[1];
    637 	fp = (struct sigframe *)((int)(fp - 1) & ~0xf);
    638 
    639 	/* Build stack frame for signal trampoline. */
    640 	frame.sf_signum = sig;
    641 	frame.sf_code = code;
    642 
    643 	/* Save register context. */
    644 	bcopy(tf, &frame.sf_sc.sc_frame, sizeof *tf);
    645 
    646 	/* Save signal stack. */
    647 	frame.sf_sc.sc_onstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
    648 
    649 	/* Save signal mask. */
    650 	frame.sf_sc.sc_mask = *mask;
    651 
    652 #ifdef COMPAT_13
    653 	/*
    654 	 * XXX We always have to save an old style signal mask because
    655 	 * XXX we might be delivering a signal to a process which will
    656 	 * XXX escape from the signal in a non-standard way and invoke
    657 	 * XXX sigreturn() directly.
    658 	 */
    659 	native_sigset_to_sigset13(mask, &frame.sf_sc.__sc_mask13);
    660 #endif
    661 
    662 	if (copyout(&frame, fp, sizeof frame) != 0) {
    663 		/*
    664 		 * Process has trashed its stack; give it an illegal
    665 		 * instructoin to halt it in its tracks.
    666 		 */
    667 		sigexit(p, SIGILL);
    668 		/* NOTREACHED */
    669 	}
    670 
    671 	/*
    672 	 * Build context to run handler in.
    673 	 */
    674 	tf->fixreg[1] = (int)fp;
    675 	tf->lr = (int)catcher;
    676 	tf->fixreg[3] = (int)sig;
    677 	tf->fixreg[4] = (int)code;
    678 	tf->fixreg[5] = (int)&frame.sf_sc;
    679 	tf->srr0 = (int)psp->ps_sigcode;
    680 
    681 	/* Remember that we're now on the signal stack. */
    682 	if (onstack)
    683 		psp->ps_sigstk.ss_flags |= SS_ONSTACK;
    684 }
    685 
    686 /*
    687  * System call to cleanup state after a signal handler returns.
    688  */
    689 int
    690 sys___sigreturn14(p, v, retval)
    691 	struct proc *p;
    692 	void *v;
    693 	register_t *retval;
    694 {
    695 	struct sys___sigreturn14_args /* {
    696 		syscallarg(struct sigcontext *) sigcntxp;
    697 	} */ *uap = v;
    698 	struct sigcontext sc;
    699 	struct trapframe *tf;
    700 	int error;
    701 
    702 	/*
    703 	 * The trampoline hands us the context.
    704 	 * It is unsafe to keep track of it ourselves, in the event that a
    705 	 * program jumps out of a signal hander.
    706 	 */
    707 	if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
    708 		return (error);
    709 
    710 	/* Restore the register context. */
    711 	tf = trapframe(p);
    712 	if ((sc.sc_frame.srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
    713 		return (EINVAL);
    714 	bcopy(&sc.sc_frame, tf, sizeof *tf);
    715 
    716 	/* Restore signal stack. */
    717 	if (sc.sc_onstack & SS_ONSTACK)
    718 		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
    719 	else
    720 		p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
    721 
    722 	/* Restore signal mask. */
    723 	(void) sigprocmask1(p, SIG_SETMASK, &sc.sc_mask, 0);
    724 
    725 	return (EJUSTRETURN);
    726 }
    727 
    728 /*
    729  * Machine dependent system variables.
    730  * None for now.
    731  */
    732 int
    733 cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    734 	int *name;
    735 	u_int namelen;
    736 	void *oldp;
    737 	size_t *oldlenp;
    738 	void *newp;
    739 	size_t newlen;
    740 	struct proc *p;
    741 {
    742 	/* all sysctl names at this level are terminal */
    743 	if (namelen != 1)
    744 		return (ENOTDIR);
    745 	switch (name[0]) {
    746 	default:
    747 		return (EOPNOTSUPP);
    748 	}
    749 }
    750 
    751 /*
    752  * Crash dump handling.
    753  */
    754 u_long dumpmag = 0x8fca0101;		/* magic number */
    755 int dumpsize = 0;			/* size of dump in pages */
    756 long dumplo = -1;			/* blocks */
    757 
    758 void
    759 dumpsys()
    760 {
    761 	printf("dumpsys: TBD\n");
    762 }
    763 
    764 /*
    765  * Soft networking interrupts.
    766  */
    767 void
    768 softnet()
    769 {
    770 	int isr = netisr;
    771 
    772 	netisr = 0;
    773 #ifdef	INET
    774 #include "arp.h"
    775 #if NARP > 0
    776 	if (isr & (1 << NETISR_ARP))
    777 		arpintr();
    778 #endif
    779 	if (isr & (1 << NETISR_IP))
    780 		ipintr();
    781 #endif
    782 #ifdef	IMP
    783 	if (isr & (1 << NETISR_IMP))
    784 		impintr();
    785 #endif
    786 #ifdef	NS
    787 	if (isr & (1 << NETISR_NS))
    788 		nsintr();
    789 #endif
    790 #ifdef	ISO
    791 	if (isr & (1 << NETISR_ISO))
    792 		clnlintr();
    793 #endif
    794 #ifdef	CCITT
    795 	if (isr & (1 << NETISR_CCITT))
    796 		ccittintr();
    797 #endif
    798 #include "ppp.h"
    799 #if NPPP > 0
    800 	if (isr & (1 << NETISR_PPP))
    801 		pppintr();
    802 #endif
    803 }
    804 
    805 /*
    806  * Stray interrupts.
    807  */
    808 void
    809 strayintr(irq)
    810 	int irq;
    811 {
    812 	log(LOG_ERR, "stray interrupt %d\n", irq);
    813 }
    814 
    815 /*
    816  * Halt or reboot the machine after syncing/dumping according to howto.
    817  */
    818 void
    819 cpu_reboot(howto, what)
    820 	int howto;
    821 	char *what;
    822 {
    823 	static int syncing;
    824 	static char str[256];
    825 	char *ap = str, *ap1 = ap;
    826 
    827 	boothowto = howto;
    828 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    829 		syncing = 1;
    830 		vfs_shutdown();		/* sync */
    831 		resettodr();		/* set wall clock */
    832 	}
    833 	splhigh();
    834 	if (howto & RB_HALT) {
    835 		doshutdownhooks();
    836 		printf("halted\n\n");
    837 		ppc_exit();
    838 	}
    839 	if (!cold && (howto & RB_DUMP))
    840 		dumpsys();
    841 	doshutdownhooks();
    842 	printf("rebooting\n\n");
    843 	if (what && *what) {
    844 		if (strlen(what) > sizeof str - 5)
    845 			printf("boot string too large, ignored\n");
    846 		else {
    847 			strcpy(str, what);
    848 			ap1 = ap = str + strlen(str);
    849 			*ap++ = ' ';
    850 		}
    851 	}
    852 	*ap++ = '-';
    853 	if (howto & RB_SINGLE)
    854 		*ap++ = 's';
    855 	if (howto & RB_KDB)
    856 		*ap++ = 'd';
    857 	*ap++ = 0;
    858 	if (ap[-2] == '-')
    859 		*ap1 = 0;
    860 	ppc_boot(str);
    861 }
    862 
    863 /*
    864  * OpenFirmware callback routine
    865  */
    866 void
    867 callback(p)
    868 	void *p;
    869 {
    870 	panic("callback");	/* for now			XXX */
    871 }
    872 
    873 /*
    874  * Initial Machine Interface.
    875  */
    876 static int
    877 fake_spl()
    878 {
    879 	int scratch;
    880 
    881 	asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
    882 	    : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
    883 	return (-1);
    884 }
    885 
    886 static void
    887 fake_setsoft()
    888 {
    889 	/* Do nothing */
    890 }
    891 
    892 static int
    893 fake_splx(new)
    894 	int new;
    895 {
    896 	return (fake_spl());
    897 }
    898 
    899 static void
    900 fake_clock_return(frame, nticks)
    901 	struct clockframe *frame;
    902 	int nticks;
    903 {
    904 	/* Do nothing */
    905 }
    906 
    907 static void
    908 fake_irq_establish(irq, level, handler, arg)
    909 	int irq, level;
    910 	void (*handler) __P((void *));
    911 	void *arg;
    912 {
    913 	panic("fake_irq_establish");
    914 }
    915