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