Home | History | Annotate | Line # | Download | only in arm32
arm32_machdep.c revision 1.13
      1  1.13  thorpej /*	$NetBSD: arm32_machdep.c,v 1.13 2002/02/20 00:10:17 thorpej Exp $	*/
      2   1.1    chris 
      3   1.1    chris /*
      4   1.1    chris  * Copyright (c) 1994-1998 Mark Brinicombe.
      5   1.1    chris  * Copyright (c) 1994 Brini.
      6   1.1    chris  * All rights reserved.
      7   1.1    chris  *
      8   1.1    chris  * This code is derived from software written for Brini by Mark Brinicombe
      9   1.1    chris  *
     10   1.1    chris  * Redistribution and use in source and binary forms, with or without
     11   1.1    chris  * modification, are permitted provided that the following conditions
     12   1.1    chris  * are met:
     13   1.1    chris  * 1. Redistributions of source code must retain the above copyright
     14   1.1    chris  *    notice, this list of conditions and the following disclaimer.
     15   1.1    chris  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    chris  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    chris  *    documentation and/or other materials provided with the distribution.
     18   1.1    chris  * 3. All advertising materials mentioning features or use of this software
     19   1.1    chris  *    must display the following acknowledgement:
     20   1.1    chris  *	This product includes software developed by Mark Brinicombe
     21   1.1    chris  *	for the NetBSD Project.
     22   1.1    chris  * 4. The name of the company nor the name of the author may be used to
     23   1.1    chris  *    endorse or promote products derived from this software without specific
     24   1.1    chris  *    prior written permission.
     25   1.1    chris  *
     26   1.1    chris  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     27   1.1    chris  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     28   1.1    chris  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29   1.1    chris  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     30   1.1    chris  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     31   1.1    chris  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     32   1.1    chris  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.1    chris  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.1    chris  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.1    chris  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.1    chris  * SUCH DAMAGE.
     37   1.1    chris  *
     38   1.1    chris  * Machine dependant functions for kernel setup
     39   1.1    chris  *
     40   1.1    chris  * Created      : 17/09/94
     41   1.1    chris  * Updated	: 18/04/01 updated for new wscons
     42   1.1    chris  */
     43   1.1    chris 
     44   1.1    chris #include "opt_md.h"
     45   1.1    chris #include "opt_pmap_debug.h"
     46   1.1    chris 
     47   1.1    chris #include <sys/param.h>
     48   1.1    chris #include <sys/systm.h>
     49   1.1    chris #include <sys/reboot.h>
     50   1.1    chris #include <sys/proc.h>
     51   1.1    chris #include <sys/user.h>
     52   1.1    chris #include <sys/kernel.h>
     53   1.1    chris #include <sys/mbuf.h>
     54   1.1    chris #include <sys/mount.h>
     55   1.1    chris #include <sys/buf.h>
     56   1.1    chris #include <sys/msgbuf.h>
     57   1.1    chris #include <sys/device.h>
     58   1.1    chris #include <uvm/uvm_extern.h>
     59   1.1    chris #include <sys/sysctl.h>
     60   1.1    chris 
     61   1.1    chris #include <dev/cons.h>
     62   1.1    chris 
     63   1.7  thorpej #include <arm/arm32/katelib.h>
     64   1.9    chris #include <arm/arm32/machdep.h>
     65   1.1    chris #include <machine/bootconfig.h>
     66   1.1    chris 
     67   1.1    chris #include "opt_ipkdb.h"
     68   1.1    chris #include "opt_mdsize.h"
     69   1.1    chris #include "md.h"
     70   1.1    chris 
     71   1.1    chris struct vm_map *exec_map = NULL;
     72   1.1    chris struct vm_map *mb_map = NULL;
     73   1.1    chris struct vm_map *phys_map = NULL;
     74   1.1    chris 
     75   1.1    chris extern int physmem;
     76   1.1    chris 
     77   1.1    chris #ifndef PMAP_STATIC_L1S
     78   1.1    chris extern int max_processes;
     79   1.1    chris #endif	/* !PMAP_STATIC_L1S */
     80   1.1    chris #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MINIROOTSIZE)
     81   1.1    chris extern u_int memory_disc_size;		/* Memory disc size */
     82   1.1    chris #endif	/* NMD && MEMORY_DISK_HOOKS && !MINIROOTSIZE */
     83   1.1    chris 
     84   1.1    chris pv_addr_t systempage;
     85   1.1    chris pv_addr_t kernelstack;
     86   1.1    chris 
     87   1.1    chris /* the following is used externally (sysctl_hw) */
     88   1.1    chris char	machine[] = MACHINE;		/* from <machine/param.h> */
     89   1.1    chris char	machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
     90   1.1    chris 
     91   1.1    chris /* Our exported CPU info; we can have only one. */
     92   1.1    chris struct cpu_info cpu_info_store;
     93   1.1    chris 
     94   1.1    chris extern pt_entry_t msgbufpte;
     95   1.1    chris caddr_t	msgbufaddr;
     96   1.1    chris extern paddr_t msgbufphys;
     97   1.1    chris 
     98   1.1    chris int kernel_debug = 0;
     99   1.1    chris 
    100   1.1    chris struct user *proc0paddr;
    101   1.1    chris 
    102  1.12  reinoud /* exported variable to be filled in by the bootloaders */
    103   1.1    chris char *booted_kernel;
    104   1.1    chris 
    105   1.1    chris 
    106   1.1    chris /* Prototypes */
    107   1.1    chris 
    108   1.1    chris u_long strtoul			__P((const char *s, char **ptr, int base));
    109   1.1    chris void data_abort_handler		__P((trapframe_t *frame));
    110   1.1    chris void prefetch_abort_handler	__P((trapframe_t *frame));
    111   1.1    chris void zero_page_readonly		__P((void));
    112   1.1    chris void zero_page_readwrite	__P((void));
    113   1.1    chris extern void configure		__P((void));
    114   1.1    chris 
    115   1.1    chris /*
    116   1.1    chris  * Debug function just to park the CPU
    117   1.1    chris  */
    118   1.1    chris 
    119   1.1    chris void
    120   1.1    chris halt()
    121   1.1    chris {
    122   1.1    chris 	while (1)
    123   1.1    chris 		cpu_sleep(0);
    124   1.1    chris }
    125   1.1    chris 
    126   1.1    chris 
    127   1.1    chris /* Sync the discs and unmount the filesystems */
    128   1.1    chris 
    129   1.1    chris void
    130   1.1    chris bootsync(void)
    131   1.1    chris {
    132   1.1    chris 	static int bootsyncdone = 0;
    133   1.1    chris 
    134   1.1    chris 	if (bootsyncdone) return;
    135   1.1    chris 
    136   1.1    chris 	bootsyncdone = 1;
    137   1.1    chris 
    138   1.1    chris 	/* Make sure we can still manage to do things */
    139   1.1    chris 	if (GetCPSR() & I32_bit) {
    140   1.1    chris 		/*
    141   1.1    chris 		 * If we get here then boot has been called without RB_NOSYNC
    142   1.1    chris 		 * and interrupts were disabled. This means the boot() call
    143   1.1    chris 		 * did not come from a user process e.g. shutdown, but must
    144   1.1    chris 		 * have come from somewhere in the kernel.
    145   1.1    chris 		 */
    146   1.1    chris 		IRQenable;
    147   1.1    chris 		printf("Warning IRQ's disabled during boot()\n");
    148   1.1    chris 	}
    149   1.1    chris 
    150   1.1    chris 	vfs_shutdown();
    151   1.1    chris }
    152   1.1    chris 
    153   1.1    chris /*
    154   1.1    chris  * A few functions that are used to help construct the page tables
    155   1.1    chris  * during the bootstrap process.
    156   1.1    chris  */
    157   1.1    chris 
    158   1.1    chris void
    159   1.1    chris map_pagetable(pagetable, va, pa)
    160   1.1    chris 	vaddr_t pagetable;
    161   1.1    chris 	vaddr_t va;
    162   1.1    chris 	paddr_t pa;
    163   1.1    chris {
    164   1.1    chris #ifdef	DIAGNOSTIC
    165   1.1    chris 	if ((pa & 0xc00) != 0)
    166   1.1    chris 		panic("pagetables should be group allocated on pageboundry");
    167   1.1    chris #endif	/* DIAGNOSTIC */
    168   1.1    chris 
    169   1.1    chris 	((u_int *)pagetable)[(va >> PDSHIFT) + 0] =
    170   1.1    chris 	     L1_PTE((pa & PG_FRAME) + 0x000);
    171   1.1    chris 	((u_int *)pagetable)[(va >> PDSHIFT) + 1] =
    172   1.1    chris 	     L1_PTE((pa & PG_FRAME) + 0x400);
    173   1.1    chris 	((u_int *)pagetable)[(va >> PDSHIFT) + 2] =
    174   1.1    chris 	     L1_PTE((pa & PG_FRAME) + 0x800);
    175   1.1    chris 	((u_int *)pagetable)[(va >> PDSHIFT) + 3] =
    176   1.1    chris 	     L1_PTE((pa & PG_FRAME) + 0xc00);
    177   1.1    chris }
    178   1.1    chris 
    179  1.10    chris /* cats kernels have a 2nd l2 pt, so the range is bigger hence the 0x7ff etc */
    180   1.1    chris vsize_t
    181   1.1    chris map_chunk(pd, pt, va, pa, size, acc, flg)
    182   1.1    chris 	vaddr_t pd;
    183   1.1    chris 	vaddr_t pt;
    184   1.1    chris 	vaddr_t va;
    185   1.1    chris 	paddr_t pa;
    186   1.1    chris 	vsize_t size;
    187   1.1    chris 	u_int acc;
    188   1.1    chris 	u_int flg;
    189   1.1    chris {
    190   1.1    chris 	pd_entry_t *l1pt = (pd_entry_t *)pd;
    191   1.1    chris 	pt_entry_t *l2pt = (pt_entry_t *)pt;
    192   1.1    chris 	vsize_t remain;
    193   1.1    chris 	u_int loop;
    194   1.1    chris 
    195   1.1    chris 	remain = (size + (NBPG - 1)) & ~(NBPG - 1);
    196   1.1    chris #ifdef VERBOSE_INIT_ARM
    197   1.1    chris 	printf("map_chunk: pa=%lx va=%lx sz=%lx rem=%lx acc=%x flg=%x\n",
    198   1.1    chris 	    pa, va, size, remain, acc, flg);
    199   1.1    chris 	printf("map_chunk: ");
    200   1.1    chris #endif
    201   1.1    chris 	size = remain;
    202   1.1    chris 
    203   1.1    chris 	while (remain > 0) {
    204   1.1    chris 		/* Can we do a section mapping ? */
    205   1.1    chris 		if (l1pt && !((pa | va) & (L1_SEC_SIZE - 1))
    206   1.1    chris 		    && remain >= L1_SEC_SIZE) {
    207   1.1    chris #ifdef VERBOSE_INIT_ARM
    208   1.1    chris 			printf("S");
    209   1.1    chris #endif
    210   1.1    chris 			l1pt[(va >> PDSHIFT)] = L1_SECPTE(pa, acc, flg);
    211   1.1    chris 			va += L1_SEC_SIZE;
    212   1.1    chris 			pa += L1_SEC_SIZE;
    213   1.1    chris 			remain -= L1_SEC_SIZE;
    214   1.1    chris 		} else
    215   1.1    chris 		/* Can we do a large page mapping ? */
    216   1.1    chris 		if (!((pa | va) & (L2_LPAGE_SIZE - 1))
    217   1.1    chris 		    && (remain >= L2_LPAGE_SIZE)) {
    218   1.1    chris #ifdef VERBOSE_INIT_ARM
    219   1.1    chris 			printf("L");
    220   1.1    chris #endif
    221   1.1    chris 			for (loop = 0; loop < 16; ++loop)
    222  1.10    chris #ifndef cats
    223   1.1    chris 				l2pt[((va >> PGSHIFT) & 0x3f0) + loop] =
    224   1.1    chris 				    L2_LPTE(pa, acc, flg);
    225  1.10    chris #else
    226  1.10    chris 				l2pt[((va >> PGSHIFT) & 0x7f0) + loop] =
    227  1.10    chris 				    L2_LPTE(pa, acc, flg);
    228  1.10    chris #endif
    229   1.1    chris 			va += L2_LPAGE_SIZE;
    230   1.1    chris 			pa += L2_LPAGE_SIZE;
    231   1.1    chris 			remain -= L2_LPAGE_SIZE;
    232   1.1    chris 		} else
    233   1.1    chris 		/* All we can do is a small page mapping */
    234   1.1    chris 		{
    235   1.1    chris #ifdef VERBOSE_INIT_ARM
    236   1.1    chris 			printf("P");
    237   1.1    chris #endif
    238  1.10    chris #ifndef cats
    239   1.1    chris 			l2pt[((va >> PGSHIFT) & 0x3ff)] = L2_SPTE(pa, acc, flg);
    240  1.10    chris #else
    241  1.10    chris 			l2pt[((va >> PGSHIFT) & 0x7ff)] = L2_SPTE(pa, acc, flg);
    242  1.10    chris #endif
    243   1.1    chris 			va += NBPG;
    244   1.1    chris 			pa += NBPG;
    245   1.1    chris 			remain -= NBPG;
    246   1.1    chris 		}
    247   1.1    chris 	}
    248   1.1    chris #ifdef VERBOSE_INIT_ARM
    249   1.1    chris 	printf("\n");
    250   1.1    chris #endif
    251   1.1    chris 	return(size);
    252   1.1    chris }
    253   1.1    chris 
    254  1.10    chris /* cats versions have larger 2 l2pt's next to each other */
    255   1.1    chris void
    256   1.1    chris map_entry(pagetable, va, pa)
    257   1.1    chris 	vaddr_t pagetable;
    258   1.1    chris 	vaddr_t va;
    259   1.1    chris 	paddr_t pa;
    260   1.1    chris {
    261  1.10    chris #ifndef cats
    262   1.1    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
    263   1.1    chris 	    L2_PTE((pa & PG_FRAME), AP_KRW);
    264  1.10    chris #else
    265  1.10    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000007ff)] =
    266  1.10    chris 	    L2_PTE((pa & PG_FRAME), AP_KRW);
    267  1.10    chris #endif
    268   1.1    chris }
    269   1.1    chris 
    270   1.1    chris 
    271   1.1    chris void
    272   1.1    chris map_entry_nc(pagetable, va, pa)
    273   1.1    chris 	vaddr_t pagetable;
    274   1.1    chris 	vaddr_t va;
    275   1.1    chris 	paddr_t pa;
    276   1.1    chris {
    277  1.10    chris #ifndef cats
    278   1.1    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
    279   1.1    chris 	    L2_PTE_NC_NB((pa & PG_FRAME), AP_KRW);
    280  1.10    chris #else
    281  1.10    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000007ff)] =
    282  1.10    chris 	    L2_PTE_NC_NB((pa & PG_FRAME), AP_KRW);
    283  1.10    chris #endif
    284   1.1    chris }
    285   1.1    chris 
    286   1.1    chris 
    287   1.1    chris void
    288   1.1    chris map_entry_ro(pagetable, va, pa)
    289   1.1    chris 	vaddr_t pagetable;
    290   1.1    chris 	vaddr_t va;
    291   1.1    chris 	paddr_t pa;
    292   1.1    chris {
    293  1.10    chris #ifndef cats
    294   1.1    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000003ff)] =
    295   1.1    chris 	    L2_PTE((pa & PG_FRAME), AP_KR);
    296  1.10    chris #else
    297  1.10    chris 	((pt_entry_t *)pagetable)[((va >> PGSHIFT) & 0x000007ff)] =
    298  1.10    chris 	    L2_PTE((pa & PG_FRAME), AP_KR);
    299  1.10    chris #endif
    300   1.1    chris }
    301   1.1    chris 
    302   1.1    chris 
    303   1.1    chris /*
    304   1.1    chris  * void cpu_startup(void)
    305   1.1    chris  *
    306   1.1    chris  * Machine dependant startup code.
    307   1.1    chris  *
    308   1.1    chris  */
    309   1.1    chris 
    310   1.1    chris void
    311   1.1    chris cpu_startup()
    312   1.1    chris {
    313   1.1    chris 	int loop;
    314   1.1    chris 	paddr_t minaddr;
    315   1.1    chris 	paddr_t maxaddr;
    316   1.1    chris 	caddr_t sysbase;
    317   1.1    chris 	caddr_t size;
    318   1.1    chris 	vsize_t bufsize;
    319   1.1    chris 	int base, residual;
    320   1.1    chris 	char pbuf[9];
    321   1.1    chris 
    322   1.1    chris 	proc0paddr = (struct user *)kernelstack.pv_va;
    323   1.1    chris 	proc0.p_addr = proc0paddr;
    324   1.1    chris 
    325   1.1    chris 	/* Set the cpu control register */
    326   1.1    chris 	cpu_setup(boot_args);
    327   1.1    chris 
    328   1.1    chris 	/* All domains MUST be clients, permissions are VERY important */
    329   1.1    chris 	cpu_domains(DOMAIN_CLIENT);
    330   1.1    chris 
    331   1.1    chris 	/* Lock down zero page */
    332   1.1    chris 	zero_page_readonly();
    333   1.1    chris 
    334   1.1    chris 	/*
    335   1.1    chris 	 * Give pmap a chance to set up a few more things now the vm
    336   1.1    chris 	 * is initialised
    337   1.1    chris 	 */
    338   1.1    chris 	pmap_postinit();
    339   1.1    chris 
    340   1.1    chris 	/*
    341   1.1    chris 	 * Initialize error message buffer (at end of core).
    342   1.1    chris 	 */
    343   1.1    chris 
    344   1.1    chris 	/* msgbufphys was setup during the secondary boot strap */
    345   1.1    chris 	for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
    346   1.3    chris 		pmap_kenter_pa((vaddr_t)msgbufaddr + loop * NBPG,
    347   1.3    chris 		    msgbufphys + loop * NBPG, VM_PROT_READ|VM_PROT_WRITE);
    348   1.5    chris 	pmap_update(pmap_kernel());
    349   1.1    chris 	initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
    350   1.1    chris 
    351   1.1    chris 	/*
    352   1.1    chris 	 * Identify ourselves for the msgbuf (everything printed earlier will
    353   1.1    chris 	 * not be buffered).
    354   1.1    chris 	 */
    355   1.1    chris 	printf(version);
    356   1.1    chris 
    357   1.1    chris 	format_bytes(pbuf, sizeof(pbuf), arm_page_to_byte(physmem));
    358   1.1    chris 	printf("total memory = %s\n", pbuf);
    359   1.1    chris 
    360   1.1    chris 	/*
    361   1.1    chris 	 * Find out how much space we need, allocate it,
    362   1.1    chris 	 * and then give everything true virtual addresses.
    363   1.1    chris 	 */
    364   1.1    chris 	size = allocsys(NULL, NULL);
    365   1.1    chris 	sysbase = (caddr_t)uvm_km_zalloc(kernel_map, round_page((vaddr_t)size));
    366   1.1    chris 	if (sysbase == 0)
    367   1.1    chris 		panic(
    368   1.1    chris 		    "cpu_startup: no room for system tables; %d bytes required",
    369   1.1    chris 		    (u_int)size);
    370   1.1    chris 	if ((caddr_t)((allocsys(sysbase, NULL) - sysbase)) != size)
    371   1.1    chris 		panic("cpu_startup: system table size inconsistency");
    372   1.1    chris 
    373   1.1    chris    	/*
    374   1.1    chris 	 * Now allocate buffers proper.  They are different than the above
    375   1.1    chris 	 * in that they usually occupy more virtual memory than physical.
    376   1.1    chris 	 */
    377   1.1    chris 	bufsize = MAXBSIZE * nbuf;
    378   1.1    chris 	if (uvm_map(kernel_map, (vaddr_t *)&buffers, round_page(bufsize),
    379   1.1    chris 	    NULL, UVM_UNKNOWN_OFFSET, 0,
    380   1.1    chris 	    UVM_MAPFLAG(UVM_PROT_NONE, UVM_PROT_NONE, UVM_INH_NONE,
    381   1.1    chris 	    UVM_ADV_NORMAL, 0)) != 0)
    382   1.1    chris 		panic("cpu_startup: cannot allocate UVM space for buffers");
    383   1.1    chris 	minaddr = (vaddr_t)buffers;
    384   1.1    chris 	if ((bufpages / nbuf) >= btoc(MAXBSIZE)) {
    385   1.1    chris 		/* don't want to alloc more physical mem than needed */
    386   1.1    chris 		bufpages = btoc(MAXBSIZE) * nbuf;
    387   1.1    chris 	}
    388   1.1    chris 
    389   1.1    chris 	base = bufpages / nbuf;
    390   1.1    chris 	residual = bufpages % nbuf;
    391   1.1    chris 	for (loop = 0; loop < nbuf; ++loop) {
    392   1.1    chris 		vsize_t curbufsize;
    393   1.1    chris 		vaddr_t curbuf;
    394   1.1    chris 		struct vm_page *pg;
    395   1.1    chris 
    396   1.3    chris 		/*
    397   1.3    chris 		 * Each buffer has MAXBSIZE bytes of VM space allocated.  Of
    398   1.3    chris 		 * that MAXBSIZE space, we allocate and map (base+1) pages
    399   1.3    chris 		 * for the first "residual" buffers, and then we allocate
    400   1.3    chris 		 * "base" pages for the rest.
    401   1.3    chris 		 */
    402   1.1    chris 		curbuf = (vaddr_t) buffers + (loop * MAXBSIZE);
    403   1.1    chris 		curbufsize = NBPG * ((loop < residual) ? (base+1) : base);
    404   1.1    chris 
    405   1.1    chris 		while (curbufsize) {
    406   1.1    chris 			pg = uvm_pagealloc(NULL, 0, NULL, 0);
    407   1.1    chris 			if (pg == NULL)
    408   1.1    chris 				panic("cpu_startup: not enough memory for buffer cache");
    409   1.3    chris 			pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg),
    410   1.3    chris 				VM_PROT_READ|VM_PROT_WRITE);
    411   1.1    chris 			curbuf += PAGE_SIZE;
    412   1.1    chris 			curbufsize -= PAGE_SIZE;
    413   1.1    chris 		}
    414   1.1    chris 	}
    415   1.5    chris 	pmap_update(pmap_kernel());
    416   1.1    chris 
    417   1.1    chris 	/*
    418   1.1    chris 	 * Allocate a submap for exec arguments.  This map effectively
    419   1.1    chris 	 * limits the number of processes exec'ing at any time.
    420   1.1    chris 	 */
    421   1.1    chris 	exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    422   1.1    chris 				   16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL);
    423   1.1    chris 
    424   1.1    chris 	/*
    425   1.1    chris 	 * Allocate a submap for physio
    426   1.1    chris 	 */
    427   1.1    chris 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    428   1.1    chris 				   VM_PHYS_SIZE, 0, FALSE, NULL);
    429   1.1    chris 
    430   1.1    chris 	/*
    431   1.1    chris 	 * Finally, allocate mbuf cluster submap.
    432   1.1    chris 	 */
    433   1.1    chris 	mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    434   1.1    chris 				 nmbclusters * mclbytes, VM_MAP_INTRSAFE,
    435   1.1    chris 				 FALSE, NULL);
    436   1.1    chris 
    437   1.1    chris 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    438   1.1    chris 	printf("avail memory = %s\n", pbuf);
    439   1.1    chris 	format_bytes(pbuf, sizeof(pbuf), bufpages * NBPG);
    440   1.1    chris 	printf("using %d buffers containing %s of memory\n", nbuf, pbuf);
    441   1.1    chris 
    442   1.1    chris 	/*
    443   1.1    chris 	 * Set up buffers, so they can be used to read disk labels.
    444   1.1    chris 	 */
    445   1.1    chris 	bufinit();
    446   1.1    chris 
    447   1.1    chris 	curpcb = &proc0.p_addr->u_pcb;
    448   1.1    chris 	curpcb->pcb_flags = 0;
    449   1.4   toshii 	curpcb->pcb_un.un_32.pcb32_und_sp = (u_int)proc0.p_addr +
    450   1.4   toshii 	    USPACE_UNDEF_STACK_TOP;
    451   1.4   toshii 	curpcb->pcb_un.un_32.pcb32_sp = (u_int)proc0.p_addr +
    452   1.4   toshii 	    USPACE_SVC_STACK_TOP;
    453   1.2    chris 	(void) pmap_extract(pmap_kernel(), (vaddr_t)(pmap_kernel())->pm_pdir,
    454   1.1    chris 	    (paddr_t *)&curpcb->pcb_pagedir);
    455   1.1    chris 
    456   1.4   toshii         curpcb->pcb_tf = (struct trapframe *)curpcb->pcb_un.un_32.pcb32_sp - 1;
    457   1.1    chris }
    458   1.1    chris 
    459   1.1    chris /*
    460   1.1    chris  * Modify the current mapping for zero page to make it read only
    461   1.1    chris  *
    462   1.1    chris  * This routine is only used until things start forking. Then new
    463   1.1    chris  * system pages are mapped read only in pmap_enter().
    464   1.1    chris  */
    465   1.1    chris 
    466   1.1    chris void
    467   1.1    chris zero_page_readonly()
    468   1.1    chris {
    469   1.1    chris 	WriteWord(PROCESS_PAGE_TBLS_BASE + 0,
    470   1.1    chris 	    L2_PTE((systempage.pv_pa & PG_FRAME), AP_KR));
    471   1.1    chris 	cpu_tlb_flushID_SE(0x00000000);
    472   1.1    chris }
    473   1.1    chris 
    474   1.1    chris 
    475   1.1    chris /*
    476   1.1    chris  * Modify the current mapping for zero page to make it read/write
    477   1.1    chris  *
    478   1.1    chris  * This routine is only used until things start forking. Then system
    479   1.1    chris  * pages belonging to user processes are never made writable.
    480   1.1    chris  */
    481   1.1    chris 
    482   1.1    chris void
    483   1.1    chris zero_page_readwrite()
    484   1.1    chris {
    485   1.1    chris 	WriteWord(PROCESS_PAGE_TBLS_BASE + 0,
    486   1.1    chris 	    L2_PTE((systempage.pv_pa & PG_FRAME), AP_KRW));
    487   1.1    chris 	cpu_tlb_flushID_SE(0x00000000);
    488   1.1    chris }
    489   1.1    chris 
    490   1.1    chris 
    491   1.1    chris /*
    492   1.1    chris  * machine dependent system variables.
    493   1.1    chris  */
    494   1.1    chris 
    495   1.1    chris int
    496   1.1    chris cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    497   1.1    chris 	int *name;
    498   1.1    chris 	u_int namelen;
    499   1.1    chris 	void *oldp;
    500   1.1    chris 	size_t *oldlenp;
    501   1.1    chris 	void *newp;
    502   1.1    chris 	size_t newlen;
    503   1.1    chris 	struct proc *p;
    504   1.1    chris {
    505   1.1    chris 	/* all sysctl names at this level are terminal */
    506   1.1    chris 	if (namelen != 1)
    507   1.1    chris 		return (ENOTDIR);		/* overloaded */
    508   1.1    chris 
    509   1.1    chris 	switch (name[0]) {
    510   1.1    chris 	case CPU_DEBUG:
    511   1.1    chris 		return(sysctl_int(oldp, oldlenp, newp, newlen, &kernel_debug));
    512   1.1    chris 
    513   1.1    chris 	case CPU_BOOTED_DEVICE:
    514   1.1    chris 		if (booted_device != NULL)
    515   1.1    chris 			return (sysctl_rdstring(oldp, oldlenp, newp,
    516   1.1    chris 			    booted_device->dv_xname));
    517   1.1    chris 		return (EOPNOTSUPP);
    518   1.1    chris 
    519   1.1    chris 	case CPU_CONSDEV: {
    520   1.1    chris 		dev_t consdev;
    521   1.1    chris 		if (cn_tab != NULL)
    522   1.1    chris 			consdev = cn_tab->cn_dev;
    523   1.1    chris 		else
    524   1.1    chris 			consdev = NODEV;
    525   1.1    chris 		return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev,
    526   1.1    chris 			sizeof consdev));
    527   1.1    chris 	}
    528   1.1    chris 	case CPU_BOOTED_KERNEL: {
    529   1.1    chris 		if (booted_kernel != NULL && booted_kernel[0] != '\0')
    530   1.1    chris 			return sysctl_rdstring(oldp, oldlenp, newp,
    531   1.1    chris 			    booted_kernel);
    532   1.1    chris 		return (EOPNOTSUPP);
    533   1.1    chris 	}
    534   1.1    chris 
    535   1.1    chris 	default:
    536   1.1    chris 		return (EOPNOTSUPP);
    537   1.1    chris 	}
    538   1.1    chris 	/* NOTREACHED */
    539   1.1    chris }
    540   1.1    chris 
    541   1.1    chris void
    542   1.1    chris parse_mi_bootargs(args)
    543   1.1    chris 	char *args;
    544   1.1    chris {
    545   1.1    chris 	int integer;
    546   1.1    chris 
    547   1.1    chris 	if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
    548   1.1    chris 	    || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
    549   1.1    chris 		if (integer)
    550   1.1    chris 			boothowto |= RB_SINGLE;
    551   1.1    chris 	if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
    552   1.1    chris 	    || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer))
    553   1.1    chris 		if (integer)
    554   1.1    chris 			boothowto |= RB_KDB;
    555   1.1    chris 	if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
    556   1.1    chris 	    || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
    557   1.1    chris 		if (integer)
    558   1.1    chris 			boothowto |= RB_ASKNAME;
    559   1.1    chris 
    560   1.1    chris #ifdef PMAP_DEBUG
    561   1.1    chris 	if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
    562   1.1    chris 		pmap_debug_level = integer;
    563   1.1    chris 		pmap_debug(pmap_debug_level);
    564   1.1    chris 	}
    565   1.1    chris #endif	/* PMAP_DEBUG */
    566   1.1    chris 
    567   1.1    chris /*	if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
    568   1.1    chris 		bufpages = integer;*/
    569   1.1    chris 
    570   1.1    chris #ifndef PMAP_STATIC_L1S
    571   1.1    chris 	if (get_bootconf_option(args, "maxproc", BOOTOPT_TYPE_INT, &integer)) {
    572   1.1    chris 		max_processes = integer;
    573   1.1    chris 		if (max_processes < 16)
    574   1.1    chris 			max_processes = 16;
    575   1.1    chris 		/* Limit is PDSIZE * (max_processes + 1) <= 4MB */
    576   1.1    chris 		if (max_processes > 255)
    577   1.1    chris 			max_processes = 255;
    578   1.1    chris 	}
    579   1.1    chris #endif	/* !PMAP_STATUC_L1S */
    580   1.1    chris #if NMD > 0 && defined(MEMORY_DISK_HOOKS) && !defined(MINIROOTSIZE)
    581   1.1    chris 	if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
    582   1.1    chris 	    || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
    583   1.1    chris 		memory_disc_size = integer;
    584   1.1    chris 		memory_disc_size *= 1024;
    585   1.1    chris 		if (memory_disc_size < 32*1024)
    586   1.1    chris 			memory_disc_size = 32*1024;
    587   1.1    chris 		if (memory_disc_size > 2048*1024)
    588   1.1    chris 			memory_disc_size = 2048*1024;
    589   1.1    chris 	}
    590   1.1    chris #endif	/* NMD && MEMORY_DISK_HOOKS && !MINIROOTSIZE */
    591   1.1    chris 
    592   1.1    chris 	if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
    593   1.1    chris 	    || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
    594   1.1    chris 		if (integer)
    595   1.1    chris 			boothowto |= AB_QUIET;
    596   1.1    chris 	if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
    597   1.1    chris 	    || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
    598   1.1    chris 		if (integer)
    599   1.1    chris 			boothowto |= AB_VERBOSE;
    600   1.1    chris }
    601   1.1    chris 
    602   1.1    chris /* End of machdep.c */
    603