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