Home | History | Annotate | Line # | Download | only in arm32
stubs.c revision 1.17
      1  1.17  christos /*	$NetBSD: stubs.c,v 1.17 2007/03/04 05:59:37 christos 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  * Routines that are temporary or do not have a home yet.
     39   1.1     chris  *
     40   1.1     chris  * Created      : 17/09/94
     41   1.1     chris  */
     42  1.14     lukem 
     43  1.14     lukem #include <sys/cdefs.h>
     44  1.17  christos __KERNEL_RCSID(0, "$NetBSD: stubs.c,v 1.17 2007/03/04 05:59:37 christos Exp $");
     45   1.1     chris 
     46   1.1     chris #include <sys/param.h>
     47   1.1     chris #include <sys/systm.h>
     48   1.1     chris #include <sys/errno.h>
     49   1.1     chris #include <sys/proc.h>
     50   1.1     chris #include <sys/conf.h>
     51   1.1     chris #include <sys/msgbuf.h>
     52   1.1     chris #include <uvm/uvm_extern.h>
     53   1.1     chris #include <machine/cpu.h>
     54   1.3      matt #include <machine/intr.h>
     55   1.1     chris #include <machine/bootconfig.h>
     56   1.1     chris #include <machine/pcb.h>
     57   1.7     chris #include <arm/arm32/machdep.h>
     58   1.1     chris 
     59   1.1     chris extern dev_t dumpdev;
     60   1.1     chris 
     61   1.1     chris /*
     62   1.1     chris  * These variables are needed by /sbin/savecore
     63   1.1     chris  */
     64   1.8   tsutsui u_int32_t dumpmag = 0x8fca0101;	/* magic number */
     65   1.1     chris int 	dumpsize = 0;		/* pages */
     66   1.1     chris long	dumplo = 0; 		/* blocks */
     67   1.1     chris 
     68   1.1     chris struct pcb dumppcb;
     69   1.1     chris 
     70   1.1     chris /*
     71   1.1     chris  * This is called by main to set dumplo and dumpsize.
     72   1.1     chris  * Dumps always skip the first CLBYTES of disk space
     73   1.1     chris  * in case there might be a disk label stored there.
     74   1.1     chris  * If there is extra space, put dump at the end to
     75   1.1     chris  * reduce the chance that swapping trashes it.
     76   1.1     chris  */
     77   1.1     chris 
     78   1.1     chris void
     79   1.1     chris cpu_dumpconf()
     80   1.1     chris {
     81  1.10   gehenna 	const struct bdevsw *bdev;
     82   1.1     chris 	int nblks;	/* size of dump area */
     83   1.1     chris 
     84   1.1     chris 	if (dumpdev == NODEV)
     85   1.1     chris 		return;
     86  1.10   gehenna 	bdev = bdevsw_lookup(dumpdev);
     87  1.16       mrg 	if (bdev == NULL) {
     88  1.16       mrg 		dumpdev = NODEV;
     89  1.16       mrg 		return;
     90  1.16       mrg 	}
     91  1.10   gehenna 	if (bdev->d_psize == NULL)
     92   1.1     chris 		return;
     93  1.10   gehenna 	nblks = (*bdev->d_psize)(dumpdev);
     94   1.1     chris 	if (nblks <= ctod(1))
     95   1.1     chris 		return;
     96   1.1     chris 
     97   1.1     chris 	dumpsize = physmem;
     98   1.1     chris 
     99   1.1     chris 	/* Always skip the first CLBYTES, in case there is a label there. */
    100   1.1     chris 	if (dumplo < ctod(1))
    101   1.1     chris 		dumplo = ctod(1);
    102   1.1     chris 
    103   1.1     chris 	/* Put dump at end of partition, and make it fit. */
    104   1.1     chris 	if (dumpsize > dtoc(nblks - dumplo))
    105   1.1     chris 		dumpsize = dtoc(nblks - dumplo);
    106   1.1     chris 	if (dumplo < nblks - ctod(dumpsize))
    107   1.1     chris 		dumplo = nblks - ctod(dumpsize);
    108   1.1     chris }
    109   1.1     chris 
    110   1.1     chris /* This should be moved to machdep.c */
    111   1.1     chris 
    112   1.9   thorpej extern char *memhook;		/* XXX */
    113   1.1     chris 
    114   1.1     chris /*
    115   1.1     chris  * Doadump comes here after turning off memory management and
    116   1.1     chris  * getting on the dump stack, either when called above, or by
    117   1.1     chris  * the auto-restart code.
    118   1.1     chris  */
    119   1.1     chris 
    120   1.1     chris void
    121   1.1     chris dumpsys()
    122   1.1     chris {
    123  1.10   gehenna 	const struct bdevsw *bdev;
    124   1.1     chris 	daddr_t blkno;
    125   1.1     chris 	int psize;
    126   1.1     chris 	int error;
    127   1.1     chris 	int addr;
    128   1.1     chris 	int block;
    129   1.1     chris 	int len;
    130   1.1     chris 	vaddr_t dumpspace;
    131   1.1     chris 
    132   1.1     chris 	/* Save registers. */
    133   1.1     chris 	savectx(&dumppcb);
    134  1.12     chris 	/* flush everything out of caches */
    135  1.12     chris 	cpu_dcache_wbinv_all();
    136   1.1     chris 
    137   1.1     chris 	if (dumpdev == NODEV)
    138   1.1     chris 		return;
    139   1.1     chris 	if (dumpsize == 0) {
    140   1.1     chris 		cpu_dumpconf();
    141   1.1     chris 		if (dumpsize == 0)
    142   1.1     chris 			return;
    143   1.1     chris 	}
    144   1.1     chris 	if (dumplo <= 0) {
    145   1.1     chris 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    146   1.1     chris 		    minor(dumpdev));
    147   1.1     chris 		return;
    148   1.1     chris 	}
    149   1.1     chris 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    150   1.1     chris 	    minor(dumpdev), dumplo);
    151   1.1     chris 
    152   1.1     chris 	blkno = dumplo;
    153   1.9   thorpej 	dumpspace = (vaddr_t) memhook;
    154   1.1     chris 
    155  1.10   gehenna 	bdev = bdevsw_lookup(dumpdev);
    156  1.10   gehenna 	if (bdev == NULL || bdev->d_psize == NULL)
    157  1.10   gehenna 		return;
    158  1.10   gehenna 	psize = (*bdev->d_psize)(dumpdev);
    159   1.1     chris 	printf("dump ");
    160   1.1     chris 	if (psize == -1) {
    161   1.1     chris 		printf("area unavailable\n");
    162   1.1     chris 		return;
    163   1.1     chris 	}
    164   1.1     chris 
    165   1.1     chris 	error = 0;
    166   1.1     chris 	len = 0;
    167   1.1     chris 
    168   1.1     chris 	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
    169   1.1     chris 		addr = bootconfig.dram[block].address;
    170   1.1     chris 		for (;addr < (bootconfig.dram[block].address
    171  1.13   thorpej 		    + (bootconfig.dram[block].pages * PAGE_SIZE));
    172  1.13   thorpej 		     addr += PAGE_SIZE) {
    173   1.1     chris 		    	if ((len % (1024*1024)) == 0)
    174   1.1     chris 		    		printf("%d ", len / (1024*1024));
    175  1.12     chris 			pmap_kenter_pa(dumpspace, addr, VM_PROT_READ);
    176  1.12     chris 			pmap_update(pmap_kernel());
    177  1.12     chris 
    178  1.10   gehenna 			error = (*bdev->d_dump)(dumpdev,
    179  1.17  christos 			    blkno, (void *) dumpspace, PAGE_SIZE);
    180  1.13   thorpej 			pmap_kremove(dumpspace, PAGE_SIZE);
    181  1.12     chris 			pmap_update(pmap_kernel());
    182   1.1     chris 			if (error) break;
    183  1.13   thorpej 			blkno += btodb(PAGE_SIZE);
    184  1.13   thorpej 			len += PAGE_SIZE;
    185   1.1     chris 		}
    186   1.1     chris 	}
    187   1.1     chris 
    188   1.1     chris 	switch (error) {
    189   1.1     chris 	case ENXIO:
    190   1.1     chris 		printf("device bad\n");
    191   1.1     chris 		break;
    192   1.1     chris 
    193   1.1     chris 	case EFAULT:
    194   1.1     chris 		printf("device not ready\n");
    195   1.1     chris 		break;
    196   1.1     chris 
    197   1.1     chris 	case EINVAL:
    198   1.1     chris 		printf("area improper\n");
    199   1.1     chris 		break;
    200   1.1     chris 
    201   1.1     chris 	case EIO:
    202   1.1     chris 		printf("i/o error\n");
    203   1.1     chris 		break;
    204   1.1     chris 
    205   1.1     chris 	case EINTR:
    206   1.1     chris 		printf("aborted from console\n");
    207   1.1     chris 		break;
    208   1.1     chris 
    209   1.1     chris 	default:
    210   1.1     chris 		printf("succeeded\n");
    211   1.1     chris 		break;
    212   1.1     chris 	}
    213   1.1     chris 	printf("\n\n");
    214   1.1     chris 	delay(1000000);
    215   1.1     chris }
    216   1.1     chris 
    217   1.1     chris /* End of stubs.c */
    218