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