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