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