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