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