Home | History | Annotate | Line # | Download | only in ofppc
machdep.c revision 1.49
      1  1.49   thorpej /*	$NetBSD: machdep.c,v 1.49 1999/12/18 01:37:00 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.21  jonathan 
     34  1.27   thorpej #include "opt_compat_netbsd.h"
     35  1.21  jonathan #include "opt_ddb.h"
     36  1.22  jonathan #include "opt_inet.h"
     37  1.23  jonathan #include "opt_ccitt.h"
     38  1.24  jonathan #include "opt_iso.h"
     39  1.25  jonathan #include "opt_ns.h"
     40   1.4        ws #include "ipkdb.h"
     41   1.1        ws 
     42   1.1        ws #include <sys/param.h>
     43   1.1        ws #include <sys/buf.h>
     44   1.1        ws #include <sys/callout.h>
     45   1.1        ws #include <sys/exec.h>
     46   1.1        ws #include <sys/malloc.h>
     47   1.1        ws #include <sys/map.h>
     48   1.1        ws #include <sys/mbuf.h>
     49   1.1        ws #include <sys/mount.h>
     50   1.1        ws #include <sys/msgbuf.h>
     51   1.1        ws #include <sys/proc.h>
     52   1.1        ws #include <sys/reboot.h>
     53   1.1        ws #include <sys/syscallargs.h>
     54   1.1        ws #include <sys/syslog.h>
     55   1.1        ws #include <sys/systm.h>
     56  1.43   thorpej #include <sys/kernel.h>
     57   1.1        ws #include <sys/user.h>
     58   1.1        ws 
     59   1.1        ws #include <vm/vm.h>
     60   1.1        ws #include <vm/vm_kern.h>
     61   1.1        ws 
     62  1.19  sakamoto #include <uvm/uvm_extern.h>
     63  1.19  sakamoto 
     64   1.1        ws #include <net/netisr.h>
     65   1.1        ws 
     66   1.1        ws #include <machine/bat.h>
     67   1.1        ws #include <machine/pmap.h>
     68   1.1        ws #include <machine/powerpc.h>
     69   1.1        ws #include <machine/trap.h>
     70   1.1        ws 
     71   1.1        ws /*
     72   1.1        ws  * Global variables used here and there
     73   1.1        ws  */
     74  1.19  sakamoto vm_map_t exec_map = NULL;
     75  1.19  sakamoto vm_map_t mb_map = NULL;
     76  1.19  sakamoto vm_map_t phys_map = NULL;
     77  1.19  sakamoto 
     78   1.1        ws struct pcb *curpcb;
     79   1.1        ws struct pmap *curpm;
     80   1.1        ws struct proc *fpuproc;
     81   1.1        ws 
     82   1.1        ws extern struct user *proc0paddr;
     83   1.1        ws 
     84   1.1        ws struct bat battable[16];
     85   1.1        ws 
     86   1.1        ws int astpending;
     87   1.1        ws 
     88   1.1        ws char *bootpath;
     89   1.1        ws 
     90  1.39   thorpej paddr_t msgbuf_paddr;
     91  1.39   thorpej vaddr_t msgbuf_vaddr;
     92  1.18  sakamoto 
     93   1.7   thorpej static int fake_spl __P((void));
     94   1.7   thorpej static int fake_splx __P((int));
     95   1.7   thorpej static void fake_setsoft __P((void));
     96   1.7   thorpej static void fake_clock_return __P((struct clockframe *, int));
     97   1.1        ws static void fake_irq_establish __P((int, int, void (*)(void *), void *));
     98   1.1        ws 
     99   1.1        ws struct machvec machine_interface = {
    100  1.44  wrstuden 	fake_spl,
    101   1.7   thorpej 	fake_spl,
    102   1.7   thorpej 	fake_spl,
    103   1.7   thorpej 	fake_spl,
    104   1.7   thorpej 	fake_spl,
    105   1.7   thorpej 	fake_spl,
    106   1.7   thorpej 	fake_spl,
    107   1.7   thorpej 	fake_spl,
    108   1.7   thorpej 	fake_spl,
    109   1.7   thorpej 	fake_spl,
    110   1.1        ws 	fake_splx,
    111   1.7   thorpej 	fake_setsoft,
    112   1.7   thorpej 	fake_setsoft,
    113   1.7   thorpej 	fake_clock_return,
    114   1.1        ws 	fake_irq_establish,
    115   1.1        ws };
    116   1.1        ws 
    117   1.1        ws void
    118   1.1        ws initppc(startkernel, endkernel, args)
    119   1.1        ws 	u_int startkernel, endkernel;
    120   1.1        ws 	char *args;
    121   1.1        ws {
    122   1.1        ws 	int phandle, qhandle;
    123   1.1        ws 	char name[32];
    124   1.1        ws 	struct machvec *mp;
    125   1.1        ws 	extern trapcode, trapsize;
    126   1.1        ws 	extern dsitrap, dsisize;
    127   1.1        ws 	extern isitrap, isisize;
    128   1.1        ws 	extern decrint, decrsize;
    129   1.1        ws 	extern tlbimiss, tlbimsize;
    130   1.1        ws 	extern tlbdlmiss, tlbdlmsize;
    131   1.1        ws 	extern tlbdsmiss, tlbdsmsize;
    132  1.14  sakamoto #ifdef DDB
    133  1.14  sakamoto 	extern ddblow, ddbsize;
    134  1.14  sakamoto 	extern void *startsym, *endsym;
    135  1.14  sakamoto #endif
    136   1.4        ws #if NIPKDB > 0
    137   1.4        ws 	extern ipkdblow, ipkdbsize;
    138   1.1        ws #endif
    139   1.1        ws 	extern void consinit __P((void));
    140   1.1        ws 	extern void callback __P((void *));
    141   1.1        ws 	int exc, scratch;
    142   1.1        ws 
    143   1.1        ws 	proc0.p_addr = proc0paddr;
    144   1.1        ws 	bzero(proc0.p_addr, sizeof *proc0.p_addr);
    145  1.29  sakamoto 
    146   1.1        ws 	curpcb = &proc0paddr->u_pcb;
    147  1.29  sakamoto 
    148   1.1        ws 	curpm = curpcb->pcb_pmreal = curpcb->pcb_pm = pmap_kernel();
    149  1.29  sakamoto 
    150   1.1        ws 	/*
    151   1.1        ws 	 * i386 port says, that this shouldn't be here,
    152   1.1        ws 	 * but I really think the console should be initialized
    153   1.1        ws 	 * as early as possible.
    154   1.1        ws 	 */
    155   1.1        ws 	consinit();
    156   1.1        ws 
    157   1.1        ws #ifdef	__notyet__		/* Needs some rethinking regarding real/virtual OFW */
    158   1.1        ws 	OF_set_callback(callback);
    159   1.1        ws #endif
    160   1.1        ws 	/*
    161   1.1        ws 	 * Initialize BAT registers to unmapped to not generate
    162   1.1        ws 	 * overlapping mappings below.
    163   1.1        ws 	 */
    164   1.1        ws 	asm volatile ("mtibatu 0,%0" :: "r"(0));
    165   1.1        ws 	asm volatile ("mtibatu 1,%0" :: "r"(0));
    166   1.1        ws 	asm volatile ("mtibatu 2,%0" :: "r"(0));
    167   1.1        ws 	asm volatile ("mtibatu 3,%0" :: "r"(0));
    168   1.1        ws 	asm volatile ("mtdbatu 0,%0" :: "r"(0));
    169   1.1        ws 	asm volatile ("mtdbatu 1,%0" :: "r"(0));
    170   1.1        ws 	asm volatile ("mtdbatu 2,%0" :: "r"(0));
    171   1.1        ws 	asm volatile ("mtdbatu 3,%0" :: "r"(0));
    172  1.29  sakamoto 
    173   1.1        ws 	/*
    174   1.1        ws 	 * Set up initial BAT table to only map the lowest 256 MB area
    175   1.1        ws 	 */
    176  1.49   thorpej 	battable[0].batl = BATL(0x00000000, BAT_M, BAT_PP_RW);
    177  1.49   thorpej 	battable[0].batu = BATU(0x00000000, BAT_BL_256M, BAT_Vs);
    178   1.1        ws 
    179   1.1        ws 	/*
    180   1.1        ws 	 * Now setup fixed bat registers
    181   1.1        ws 	 *
    182   1.1        ws 	 * Note that we still run in real mode, and the BAT
    183   1.1        ws 	 * registers were cleared above.
    184   1.1        ws 	 */
    185   1.1        ws 	/* IBAT0 used for initial 256 MB segment */
    186   1.1        ws 	asm volatile ("mtibatl 0,%0; mtibatu 0,%1"
    187   1.1        ws 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    188   1.1        ws 	/* DBAT0 used similar */
    189   1.1        ws 	asm volatile ("mtdbatl 0,%0; mtdbatu 0,%1"
    190   1.1        ws 		      :: "r"(battable[0].batl), "r"(battable[0].batu));
    191  1.29  sakamoto 
    192   1.1        ws 	/*
    193   1.1        ws 	 * Set up trap vectors
    194   1.1        ws 	 */
    195   1.1        ws 	for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
    196   1.1        ws 		switch (exc) {
    197   1.1        ws 		default:
    198   1.1        ws 			bcopy(&trapcode, (void *)exc, (size_t)&trapsize);
    199   1.1        ws 			break;
    200   1.1        ws 		case EXC_EXI:
    201   1.1        ws 			/*
    202   1.1        ws 			 * This one is (potentially) installed during autoconf
    203   1.1        ws 			 */
    204   1.1        ws 			break;
    205   1.1        ws 		case EXC_DSI:
    206   1.1        ws 			bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
    207   1.1        ws 			break;
    208   1.1        ws 		case EXC_ISI:
    209   1.1        ws 			bcopy(&isitrap, (void *)EXC_ISI, (size_t)&isisize);
    210   1.1        ws 			break;
    211   1.1        ws 		case EXC_DECR:
    212   1.1        ws 			bcopy(&decrint, (void *)EXC_DECR, (size_t)&decrsize);
    213   1.1        ws 			break;
    214   1.1        ws 		case EXC_IMISS:
    215   1.1        ws 			bcopy(&tlbimiss, (void *)EXC_IMISS, (size_t)&tlbimsize);
    216   1.1        ws 			break;
    217   1.1        ws 		case EXC_DLMISS:
    218   1.1        ws 			bcopy(&tlbdlmiss, (void *)EXC_DLMISS, (size_t)&tlbdlmsize);
    219   1.1        ws 			break;
    220   1.1        ws 		case EXC_DSMISS:
    221   1.1        ws 			bcopy(&tlbdsmiss, (void *)EXC_DSMISS, (size_t)&tlbdsmsize);
    222   1.1        ws 			break;
    223  1.15   thorpej #if defined(DDB) || NIPKDB > 0
    224  1.14  sakamoto 		case EXC_PGM:
    225  1.14  sakamoto 		case EXC_TRC:
    226  1.14  sakamoto 		case EXC_BPT:
    227  1.15   thorpej #if defined(DDB)
    228  1.14  sakamoto 			bcopy(&ddblow, (void *)exc, (size_t)&ddbsize);
    229  1.15   thorpej #else
    230  1.15   thorpej 			bcopy(&ipkdblow, (void *)exc, (size_t)&ipkdbsize);
    231  1.14  sakamoto #endif
    232   1.1        ws 			break;
    233  1.15   thorpej #endif /* DDB || NIPKDB > 0 */
    234   1.1        ws 		}
    235   1.1        ws 
    236  1.38        ws 	__syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
    237   1.1        ws 
    238   1.1        ws 	/*
    239   1.1        ws 	 * Now enable translation (and machine checks/recoverable interrupts).
    240   1.1        ws 	 */
    241   1.1        ws 	asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    242   1.1        ws 		      : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    243   1.1        ws 
    244   1.1        ws 	/*
    245   1.1        ws 	 * Parse arg string.
    246   1.1        ws 	 */
    247   1.1        ws 	bootpath = args;
    248   1.7   thorpej 	while (*++args && *args != ' ');
    249   1.1        ws 	if (*args) {
    250   1.1        ws 		*args++ = 0;
    251   1.1        ws 		while (*args) {
    252   1.1        ws 			switch (*args++) {
    253   1.1        ws 			case 'a':
    254   1.1        ws 				boothowto |= RB_ASKNAME;
    255   1.1        ws 				break;
    256   1.1        ws 			case 's':
    257   1.1        ws 				boothowto |= RB_SINGLE;
    258   1.1        ws 				break;
    259   1.1        ws 			case 'd':
    260   1.1        ws 				boothowto |= RB_KDB;
    261   1.1        ws 				break;
    262   1.1        ws 			}
    263   1.1        ws 		}
    264  1.29  sakamoto 	}
    265   1.1        ws 
    266  1.14  sakamoto #ifdef DDB
    267  1.31   thorpej 	/* ddb_init((int)(endsym - startsym), startsym, endsym); */
    268  1.14  sakamoto #endif
    269   1.4        ws #if NIPKDB > 0
    270   1.1        ws 	/*
    271   1.4        ws 	 * Now trap to IPKDB
    272   1.1        ws 	 */
    273   1.4        ws 	ipkdb_init();
    274   1.1        ws 	if (boothowto & RB_KDB)
    275   1.4        ws 		ipkdb_connect(0);
    276   1.1        ws #endif
    277  1.16   thorpej 
    278  1.16   thorpej 	/*
    279  1.16   thorpej 	 * Set the page size.
    280  1.16   thorpej 	 */
    281  1.19  sakamoto 	uvm_setpagesize();
    282   1.1        ws 
    283   1.1        ws 	/*
    284   1.1        ws 	 * Initialize pmap module.
    285   1.1        ws 	 */
    286   1.1        ws 	pmap_bootstrap(startkernel, endkernel);
    287   1.1        ws }
    288   1.1        ws 
    289   1.1        ws /*
    290   1.1        ws  * This should probably be in autoconf!				XXX
    291   1.1        ws  */
    292   1.1        ws int cpu;
    293   1.1        ws char cpu_model[80];
    294   1.9     veego char machine[] = MACHINE;		/* from <machine/param.h> */
    295   1.9     veego char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    296   1.1        ws 
    297   1.1        ws void
    298   1.1        ws identifycpu()
    299   1.1        ws {
    300   1.1        ws 	int phandle, pvr;
    301   1.1        ws 	char name[32];
    302   1.1        ws 
    303   1.1        ws 	/*
    304   1.1        ws 	 * Find cpu type (Do it by OpenFirmware?)
    305   1.1        ws 	 */
    306   1.1        ws 	asm ("mfpvr %0" : "=r"(pvr));
    307   1.1        ws 	cpu = pvr >> 16;
    308   1.1        ws 	switch (cpu) {
    309   1.1        ws 	case 1:
    310   1.3  christos 		sprintf(cpu_model, "601");
    311   1.1        ws 		break;
    312   1.1        ws 	case 3:
    313   1.3  christos 		sprintf(cpu_model, "603");
    314   1.1        ws 		break;
    315   1.1        ws 	case 4:
    316   1.3  christos 		sprintf(cpu_model, "604");
    317   1.1        ws 		break;
    318   1.1        ws 	case 5:
    319   1.3  christos 		sprintf(cpu_model, "602");
    320   1.1        ws 		break;
    321   1.1        ws 	case 6:
    322   1.3  christos 		sprintf(cpu_model, "603e");
    323   1.1        ws 		break;
    324   1.1        ws 	case 7:
    325   1.3  christos 		sprintf(cpu_model, "603ev");
    326   1.1        ws 		break;
    327   1.1        ws 	case 9:
    328   1.3  christos 		sprintf(cpu_model, "604ev");
    329   1.1        ws 		break;
    330   1.1        ws 	case 20:
    331   1.3  christos 		sprintf(cpu_model, "620");
    332   1.1        ws 		break;
    333   1.1        ws 	default:
    334   1.3  christos 		sprintf(cpu_model, "Version %x", cpu);
    335   1.1        ws 		break;
    336   1.1        ws 	}
    337   1.1        ws 	sprintf(cpu_model + strlen(cpu_model), " (Revision %x)", pvr & 0xffff);
    338   1.3  christos 	printf("CPU: %s\n", cpu_model);
    339   1.1        ws }
    340   1.1        ws 
    341   1.1        ws void
    342   1.1        ws install_extint(handler)
    343   1.1        ws 	void (*handler) __P((void));
    344   1.1        ws {
    345   1.1        ws 	extern extint, extsize;
    346   1.1        ws 	extern u_long extint_call;
    347   1.1        ws 	u_long offset = (u_long)handler - (u_long)&extint_call;
    348   1.1        ws 	int omsr, msr;
    349  1.29  sakamoto 
    350   1.1        ws #ifdef	DIAGNOSTIC
    351   1.1        ws 	if (offset > 0x1ffffff)
    352   1.1        ws 		panic("install_extint: too far away");
    353   1.1        ws #endif
    354   1.7   thorpej 	asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    355   1.1        ws 		      : "=r"(omsr), "=r"(msr) : "K"((u_short)~PSL_EE));
    356   1.1        ws 	extint_call = (extint_call & 0xfc000003) | offset;
    357   1.1        ws 	bcopy(&extint, (void *)EXC_EXI, (size_t)&extsize);
    358  1.38        ws 	__syncicache((void *)&extint_call, sizeof extint_call);
    359  1.38        ws 	__syncicache((void *)EXC_EXI, (int)&extsize);
    360   1.1        ws 	asm volatile ("mtmsr %0" :: "r"(omsr));
    361   1.1        ws }
    362   1.1        ws 
    363   1.1        ws /*
    364   1.1        ws  * Machine dependent startup code.
    365   1.1        ws  */
    366   1.1        ws void
    367   1.1        ws cpu_startup()
    368   1.1        ws {
    369   1.1        ws 	int sz, i;
    370   1.1        ws 	caddr_t v;
    371  1.26  sakamoto 	paddr_t minaddr, maxaddr;
    372   1.1        ws 	int base, residual;
    373  1.40     lukem 	char pbuf[9];
    374  1.18  sakamoto 
    375  1.39   thorpej 	proc0.p_addr = proc0paddr;
    376  1.39   thorpej 	v = (caddr_t)proc0paddr + USPACE;
    377  1.39   thorpej 
    378  1.18  sakamoto 	/*
    379  1.18  sakamoto 	 * Initialize error message buffer (at end of core).
    380  1.18  sakamoto 	 */
    381  1.39   thorpej 	if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE))))
    382  1.39   thorpej 		panic("startup: no room for message buffer");
    383  1.39   thorpej 	for (i = 0; i < btoc(MSGBUFSIZE); i++)
    384  1.39   thorpej 		pmap_enter(pmap_kernel(), msgbuf_vaddr + i * NBPG,
    385  1.45   thorpej 		    msgbuf_paddr + i * NBPG, VM_PROT_READ|VM_PROT_WRITE,
    386  1.45   thorpej 		    VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
    387  1.39   thorpej 	initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE));
    388   1.1        ws 
    389   1.3  christos 	printf("%s", version);
    390   1.1        ws 	identifycpu();
    391  1.29  sakamoto 
    392  1.40     lukem 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    393  1.40     lukem 	printf("total memory = %s\n", pbuf);
    394  1.19  sakamoto 
    395   1.1        ws 	/*
    396   1.1        ws 	 * Find out how much space we need, allocate it,
    397   1.1        ws 	 * and then give everything true virtual addresses.
    398   1.1        ws 	 */
    399  1.40     lukem 	sz = (int)allocsys(NULL, NULL);
    400  1.19  sakamoto 	if ((v = (caddr_t)uvm_km_zalloc(kernel_map, round_page(sz))) == 0)
    401  1.19  sakamoto 		panic("startup: no room for tables");
    402  1.40     lukem 	if (allocsys(v, NULL) - v != sz)
    403   1.1        ws 		panic("startup: table size inconsistency");
    404  1.19  sakamoto 
    405   1.1        ws 	/*
    406   1.1        ws 	 * Now allocate buffers proper.  They are different than the above
    407   1.1        ws 	 * in that they usually occupy more virtual memory than physical.
    408   1.1        ws 	 */
    409   1.1        ws 	sz = MAXBSIZE * nbuf;
    410  1.26  sakamoto 	if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(sz),
    411  1.19  sakamoto 		    NULL, UVM_UNKNOWN_OFFSET,
    412  1.19  sakamoto 		    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    413  1.19  sakamoto 				UVM_ADV_NORMAL, 0)) != KERN_SUCCESS)
    414  1.19  sakamoto 		panic("startup: cannot allocate VM for buffers");
    415  1.29  sakamoto 	minaddr = (vaddr_t)buffers;
    416   1.1        ws 	base = bufpages / nbuf;
    417   1.1        ws 	residual = bufpages % nbuf;
    418   1.1        ws 	if (base >= MAXBSIZE) {
    419   1.1        ws 		/* Don't want to alloc more physical mem than ever needed */
    420   1.1        ws 		base = MAXBSIZE;
    421   1.1        ws 		residual = 0;
    422   1.1        ws 	}
    423   1.1        ws 	for (i = 0; i < nbuf; i++) {
    424  1.26  sakamoto 		vsize_t curbufsize;
    425  1.26  sakamoto 		vaddr_t curbuf;
    426  1.19  sakamoto 		struct vm_page *pg;
    427  1.19  sakamoto 
    428  1.19  sakamoto 		/*
    429  1.19  sakamoto 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    430  1.19  sakamoto 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    431  1.19  sakamoto 		 * for the first "residual" buffers, and then we allocate
    432  1.19  sakamoto 		 * "base" pages for the rest.
    433  1.19  sakamoto 		 */
    434  1.26  sakamoto 		curbuf = (vaddr_t) buffers + (i * MAXBSIZE);
    435  1.48     ragge 		curbufsize = NBPG * ((i < residual) ? (base+1) : base);
    436  1.19  sakamoto 
    437  1.19  sakamoto 		while (curbufsize) {
    438  1.36       chs 			pg = uvm_pagealloc(NULL, 0, NULL, 0);
    439  1.19  sakamoto 			if (pg == NULL)
    440  1.19  sakamoto 				panic("startup: not enough memory for "
    441  1.19  sakamoto 					"buffer cache");
    442  1.19  sakamoto 			pmap_enter(kernel_map->pmap, curbuf,
    443  1.34   mycroft 			    VM_PAGE_TO_PHYS(pg), VM_PROT_READ|VM_PROT_WRITE,
    444  1.46    kleink 			    VM_PROT_READ|VM_PROT_WRITE|PMAP_WIRED);
    445  1.19  sakamoto 			curbuf += PAGE_SIZE;
    446  1.19  sakamoto 			curbufsize -= PAGE_SIZE;
    447  1.19  sakamoto 		}
    448   1.1        ws 	}
    449   1.1        ws 
    450   1.1        ws 	/*
    451   1.1        ws 	 * Allocate a submap for exec arguments.  This map effectively
    452   1.1        ws 	 * limits the number of processes exec'ing at any time.
    453   1.1        ws 	 */
    454  1.19  sakamoto 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    455  1.41   thorpej 				 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    456   1.1        ws 
    457   1.1        ws 	/*
    458   1.1        ws 	 * Allocate a submap for physio
    459   1.1        ws 	 */
    460  1.19  sakamoto 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    461  1.41   thorpej 				 VM_PHYS_SIZE, 0, FALSE, NULL);
    462  1.19  sakamoto 
    463   1.1        ws 	/*
    464  1.37   thorpej 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    465  1.37   thorpej 	 * are allocated via the pool allocator, and we use direct-mapped
    466  1.37   thorpej 	 * pool pages.
    467   1.1        ws 	 */
    468  1.19  sakamoto 
    469   1.1        ws 	/*
    470   1.1        ws 	 * Initialize callouts.
    471   1.1        ws 	 */
    472   1.1        ws 	callfree = callout;
    473   1.1        ws 	for (i = 1; i < ncallout; i++)
    474   1.1        ws 		callout[i - 1].c_next = &callout[i];
    475  1.19  sakamoto 
    476  1.40     lukem 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    477  1.40     lukem 	printf("avail memory = %s\n", pbuf);
    478  1.48     ragge 	format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
    479  1.40     lukem 	printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
    480  1.29  sakamoto 
    481   1.1        ws 	/*
    482   1.1        ws 	 * Set up the buffers.
    483   1.1        ws 	 */
    484   1.1        ws 	bufinit();
    485   1.1        ws 
    486   1.1        ws 	/*
    487   1.7   thorpej 	 * For now, use soft spl handling.
    488   1.7   thorpej 	 */
    489   1.7   thorpej 	{
    490   1.7   thorpej 		extern struct machvec soft_machvec;
    491   1.7   thorpej 
    492   1.7   thorpej 		machine_interface = soft_machvec;
    493   1.7   thorpej 	}
    494   1.7   thorpej 
    495   1.7   thorpej 	/*
    496   1.1        ws 	 * Now allow hardware interrupts.
    497   1.1        ws 	 */
    498   1.1        ws 	{
    499   1.1        ws 		int msr;
    500  1.29  sakamoto 
    501   1.1        ws 		splhigh();
    502   1.7   thorpej 		asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
    503   1.7   thorpej 			      : "=r"(msr) : "K"((u_short)(PSL_EE|PSL_RI)));
    504   1.1        ws 	}
    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.29  sakamoto 
    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.11   mycroft setregs(p, pack, stack)
    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 {
    531   1.1        ws 	struct trapframe *tf = trapframe(p);
    532   1.7   thorpej 	struct ps_strings arginfo;
    533   1.1        ws 
    534   1.1        ws 	bzero(tf, sizeof *tf);
    535   1.1        ws 	tf->fixreg[1] = -roundup(-stack + 8, 16);
    536   1.7   thorpej 
    537   1.7   thorpej 	/*
    538   1.7   thorpej 	 * XXX Machine-independent code has already copied arguments and
    539   1.7   thorpej 	 * XXX environment to userland.  Get them back here.
    540   1.7   thorpej 	 */
    541  1.29  sakamoto 	(void)copyin((char *)PS_STRINGS, &arginfo, sizeof (arginfo));
    542   1.7   thorpej 
    543   1.7   thorpej 	/*
    544   1.7   thorpej 	 * Set up arguments for _start():
    545   1.7   thorpej 	 *	_start(argc, argv, envp, obj, cleanup, ps_strings);
    546   1.7   thorpej 	 *
    547   1.7   thorpej 	 * Notes:
    548   1.7   thorpej 	 *	- obj and cleanup are the auxilliary and termination
    549   1.7   thorpej 	 *	  vectors.  They are fixed up by ld.elf_so.
    550   1.7   thorpej 	 *	- ps_strings is a NetBSD extention, and will be
    551   1.7   thorpej 	 * 	  ignored by executables which are strictly
    552   1.7   thorpej 	 *	  compliant with the SVR4 ABI.
    553   1.7   thorpej 	 *
    554   1.7   thorpej 	 * XXX We have to set both regs and retval here due to different
    555   1.7   thorpej 	 * XXX calling convention in trap.c and init_main.c.
    556   1.7   thorpej 	 */
    557  1.12   mycroft 	tf->fixreg[3] = arginfo.ps_nargvstr;
    558  1.12   mycroft 	tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
    559   1.7   thorpej 	tf->fixreg[5] = (register_t)arginfo.ps_envstr;
    560   1.7   thorpej 	tf->fixreg[6] = 0;			/* auxillary vector */
    561   1.7   thorpej 	tf->fixreg[7] = 0;			/* termination vector */
    562   1.7   thorpej 	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
    563   1.7   thorpej 
    564   1.1        ws 	tf->srr0 = pack->ep_entry;
    565   1.1        ws 	tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
    566   1.1        ws 	p->p_addr->u_pcb.pcb_flags = 0;
    567   1.1        ws }
    568   1.1        ws 
    569   1.1        ws /*
    570   1.1        ws  * Machine dependent system variables.
    571   1.1        ws  */
    572   1.1        ws int
    573   1.1        ws cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    574   1.1        ws 	int *name;
    575   1.1        ws 	u_int namelen;
    576   1.1        ws 	void *oldp;
    577   1.1        ws 	size_t *oldlenp;
    578   1.1        ws 	void *newp;
    579   1.1        ws 	size_t newlen;
    580   1.1        ws 	struct proc *p;
    581   1.1        ws {
    582   1.1        ws 	/* all sysctl names at this level are terminal */
    583   1.1        ws 	if (namelen != 1)
    584  1.29  sakamoto 		return (ENOTDIR);
    585  1.38        ws 
    586   1.1        ws 	switch (name[0]) {
    587  1.38        ws 	case CPU_CACHELINE:
    588  1.38        ws 		return sysctl_rdint(oldp, oldlenp, newp, CACHELINESIZE);
    589   1.1        ws 	default:
    590  1.29  sakamoto 		return (EOPNOTSUPP);
    591   1.1        ws 	}
    592   1.1        ws }
    593   1.1        ws 
    594   1.1        ws /*
    595   1.1        ws  * Crash dump handling.
    596   1.1        ws  */
    597   1.1        ws u_long dumpmag = 0x8fca0101;		/* magic number */
    598   1.1        ws int dumpsize = 0;			/* size of dump in pages */
    599   1.1        ws long dumplo = -1;			/* blocks */
    600   1.1        ws 
    601   1.1        ws void
    602   1.1        ws dumpsys()
    603   1.1        ws {
    604   1.3  christos 	printf("dumpsys: TBD\n");
    605   1.1        ws }
    606   1.1        ws 
    607   1.1        ws /*
    608   1.1        ws  * Soft networking interrupts.
    609   1.1        ws  */
    610   1.1        ws void
    611   1.1        ws softnet()
    612   1.1        ws {
    613   1.1        ws 	int isr = netisr;
    614   1.1        ws 
    615   1.1        ws 	netisr = 0;
    616   1.1        ws #ifdef	INET
    617  1.13     veego #include "arp.h"
    618  1.13     veego #if NARP > 0
    619   1.1        ws 	if (isr & (1 << NETISR_ARP))
    620   1.1        ws 		arpintr();
    621   1.1        ws #endif
    622   1.1        ws 	if (isr & (1 << NETISR_IP))
    623   1.1        ws 		ipintr();
    624  1.42    itojun #endif
    625  1.42    itojun #ifdef	INET6
    626  1.42    itojun 	if (isr & (1 << NETISR_IPV6))
    627  1.42    itojun 		ip6intr();
    628   1.1        ws #endif
    629   1.1        ws #ifdef	IMP
    630   1.1        ws 	if (isr & (1 << NETISR_IMP))
    631   1.1        ws 		impintr();
    632   1.1        ws #endif
    633   1.1        ws #ifdef	NS
    634   1.1        ws 	if (isr & (1 << NETISR_NS))
    635   1.1        ws 		nsintr();
    636   1.1        ws #endif
    637   1.1        ws #ifdef	ISO
    638   1.1        ws 	if (isr & (1 << NETISR_ISO))
    639   1.1        ws 		clnlintr();
    640   1.1        ws #endif
    641   1.1        ws #ifdef	CCITT
    642   1.1        ws 	if (isr & (1 << NETISR_CCITT))
    643   1.1        ws 		ccittintr();
    644   1.1        ws #endif
    645   1.1        ws #include "ppp.h"
    646   1.1        ws #if NPPP > 0
    647   1.1        ws 	if (isr & (1 << NETISR_PPP))
    648   1.1        ws 		pppintr();
    649   1.1        ws #endif
    650   1.1        ws }
    651   1.1        ws 
    652   1.1        ws /*
    653   1.1        ws  * Stray interrupts.
    654   1.1        ws  */
    655   1.1        ws void
    656   1.1        ws strayintr(irq)
    657   1.1        ws 	int irq;
    658   1.1        ws {
    659   1.1        ws 	log(LOG_ERR, "stray interrupt %d\n", irq);
    660   1.1        ws }
    661   1.1        ws 
    662   1.1        ws /*
    663   1.1        ws  * Halt or reboot the machine after syncing/dumping according to howto.
    664   1.1        ws  */
    665   1.1        ws void
    666   1.5       gwr cpu_reboot(howto, what)
    667   1.1        ws 	int howto;
    668   1.1        ws 	char *what;
    669   1.1        ws {
    670   1.1        ws 	static int syncing;
    671   1.1        ws 	static char str[256];
    672   1.1        ws 	char *ap = str, *ap1 = ap;
    673   1.1        ws 
    674   1.1        ws 	boothowto = howto;
    675   1.1        ws 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    676   1.1        ws 		syncing = 1;
    677   1.1        ws 		vfs_shutdown();		/* sync */
    678   1.1        ws 		resettodr();		/* set wall clock */
    679   1.1        ws 	}
    680   1.1        ws 	splhigh();
    681   1.1        ws 	if (howto & RB_HALT) {
    682   1.1        ws 		doshutdownhooks();
    683   1.3  christos 		printf("halted\n\n");
    684   1.1        ws 		ppc_exit();
    685   1.1        ws 	}
    686   1.1        ws 	if (!cold && (howto & RB_DUMP))
    687   1.1        ws 		dumpsys();
    688   1.1        ws 	doshutdownhooks();
    689   1.3  christos 	printf("rebooting\n\n");
    690   1.1        ws 	if (what && *what) {
    691   1.1        ws 		if (strlen(what) > sizeof str - 5)
    692   1.3  christos 			printf("boot string too large, ignored\n");
    693   1.1        ws 		else {
    694   1.1        ws 			strcpy(str, what);
    695   1.1        ws 			ap1 = ap = str + strlen(str);
    696   1.1        ws 			*ap++ = ' ';
    697   1.1        ws 		}
    698   1.1        ws 	}
    699   1.1        ws 	*ap++ = '-';
    700   1.1        ws 	if (howto & RB_SINGLE)
    701   1.1        ws 		*ap++ = 's';
    702   1.1        ws 	if (howto & RB_KDB)
    703   1.1        ws 		*ap++ = 'd';
    704   1.1        ws 	*ap++ = 0;
    705   1.1        ws 	if (ap[-2] == '-')
    706   1.1        ws 		*ap1 = 0;
    707   1.1        ws 	ppc_boot(str);
    708   1.1        ws }
    709   1.1        ws 
    710   1.1        ws /*
    711   1.1        ws  * OpenFirmware callback routine
    712   1.1        ws  */
    713   1.1        ws void
    714   1.1        ws callback(p)
    715   1.1        ws 	void *p;
    716   1.1        ws {
    717   1.1        ws 	panic("callback");	/* for now			XXX */
    718   1.1        ws }
    719   1.1        ws 
    720   1.1        ws /*
    721   1.7   thorpej  * Initial Machine Interface.
    722   1.1        ws  */
    723   1.7   thorpej static int
    724   1.7   thorpej fake_spl()
    725   1.7   thorpej {
    726   1.7   thorpej 	int scratch;
    727   1.7   thorpej 
    728   1.7   thorpej 	asm volatile ("mfmsr %0; andi. %0,%0,%1; mtmsr %0; isync"
    729   1.7   thorpej 	    : "=r"(scratch) : "K"((u_short)~(PSL_EE|PSL_ME)));
    730  1.29  sakamoto 	return (-1);
    731   1.7   thorpej }
    732   1.7   thorpej 
    733   1.1        ws static void
    734   1.7   thorpej fake_setsoft()
    735   1.7   thorpej {
    736   1.7   thorpej 	/* Do nothing */
    737   1.7   thorpej }
    738   1.7   thorpej 
    739   1.7   thorpej static int
    740   1.1        ws fake_splx(new)
    741   1.1        ws 	int new;
    742   1.1        ws {
    743  1.29  sakamoto 	return (fake_spl());
    744   1.7   thorpej }
    745   1.7   thorpej 
    746   1.7   thorpej static void
    747   1.7   thorpej fake_clock_return(frame, nticks)
    748   1.7   thorpej 	struct clockframe *frame;
    749   1.7   thorpej 	int nticks;
    750   1.7   thorpej {
    751   1.7   thorpej 	/* Do nothing */
    752   1.1        ws }
    753   1.1        ws 
    754   1.1        ws static void
    755   1.1        ws fake_irq_establish(irq, level, handler, arg)
    756   1.1        ws 	int irq, level;
    757   1.1        ws 	void (*handler) __P((void *));
    758   1.1        ws 	void *arg;
    759   1.1        ws {
    760   1.1        ws 	panic("fake_irq_establish");
    761   1.1        ws }
    762