Home | History | Annotate | Line # | Download | only in arm32
stubs.c revision 1.14
      1 /*	$NetBSD: stubs.c,v 1.14 2003/07/15 00:24:42 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994-1998 Mark Brinicombe.
      5  * Copyright (c) 1994 Brini.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software written for Brini by Mark Brinicombe
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by Mark Brinicombe
     21  *	for the NetBSD Project.
     22  * 4. The name of the company nor the name of the author may be used to
     23  *    endorse or promote products derived from this software without specific
     24  *    prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     27  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     28  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     30  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     32  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  *
     38  * Routines that are temporary or do not have a home yet.
     39  *
     40  * Created      : 17/09/94
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: stubs.c,v 1.14 2003/07/15 00:24:42 lukem Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/errno.h>
     49 #include <sys/proc.h>
     50 #include <sys/conf.h>
     51 #include <sys/msgbuf.h>
     52 #include <uvm/uvm_extern.h>
     53 #include <machine/cpu.h>
     54 #include <machine/intr.h>
     55 #include <machine/bootconfig.h>
     56 #include <machine/pcb.h>
     57 #include <arm/arm32/machdep.h>
     58 
     59 extern dev_t dumpdev;
     60 
     61 /*
     62  * These variables are needed by /sbin/savecore
     63  */
     64 u_int32_t dumpmag = 0x8fca0101;	/* magic number */
     65 int 	dumpsize = 0;		/* pages */
     66 long	dumplo = 0; 		/* blocks */
     67 
     68 struct pcb dumppcb;
     69 
     70 /*
     71  * This is called by main to set dumplo and dumpsize.
     72  * Dumps always skip the first CLBYTES of disk space
     73  * in case there might be a disk label stored there.
     74  * If there is extra space, put dump at the end to
     75  * reduce the chance that swapping trashes it.
     76  */
     77 
     78 void
     79 cpu_dumpconf()
     80 {
     81 	const struct bdevsw *bdev;
     82 	int nblks;	/* size of dump area */
     83 
     84 	if (dumpdev == NODEV)
     85 		return;
     86 	bdev = bdevsw_lookup(dumpdev);
     87 	if (bdev == NULL)
     88 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
     89 	if (bdev->d_psize == NULL)
     90 		return;
     91 	nblks = (*bdev->d_psize)(dumpdev);
     92 	if (nblks <= ctod(1))
     93 		return;
     94 
     95 	dumpsize = physmem;
     96 
     97 	/* Always skip the first CLBYTES, in case there is a label there. */
     98 	if (dumplo < ctod(1))
     99 		dumplo = ctod(1);
    100 
    101 	/* Put dump at end of partition, and make it fit. */
    102 	if (dumpsize > dtoc(nblks - dumplo))
    103 		dumpsize = dtoc(nblks - dumplo);
    104 	if (dumplo < nblks - ctod(dumpsize))
    105 		dumplo = nblks - ctod(dumpsize);
    106 }
    107 
    108 /* This should be moved to machdep.c */
    109 
    110 extern char *memhook;		/* XXX */
    111 
    112 /*
    113  * Doadump comes here after turning off memory management and
    114  * getting on the dump stack, either when called above, or by
    115  * the auto-restart code.
    116  */
    117 
    118 void
    119 dumpsys()
    120 {
    121 	const struct bdevsw *bdev;
    122 	daddr_t blkno;
    123 	int psize;
    124 	int error;
    125 	int addr;
    126 	int block;
    127 	int len;
    128 	vaddr_t dumpspace;
    129 
    130 	/* Save registers. */
    131 	savectx(&dumppcb);
    132 	/* flush everything out of caches */
    133 	cpu_dcache_wbinv_all();
    134 
    135 	if (dumpdev == NODEV)
    136 		return;
    137 	if (dumpsize == 0) {
    138 		cpu_dumpconf();
    139 		if (dumpsize == 0)
    140 			return;
    141 	}
    142 	if (dumplo <= 0) {
    143 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    144 		    minor(dumpdev));
    145 		return;
    146 	}
    147 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    148 	    minor(dumpdev), dumplo);
    149 
    150 	blkno = dumplo;
    151 	dumpspace = (vaddr_t) memhook;
    152 
    153 	bdev = bdevsw_lookup(dumpdev);
    154 	if (bdev == NULL || bdev->d_psize == NULL)
    155 		return;
    156 	psize = (*bdev->d_psize)(dumpdev);
    157 	printf("dump ");
    158 	if (psize == -1) {
    159 		printf("area unavailable\n");
    160 		return;
    161 	}
    162 
    163 	error = 0;
    164 	len = 0;
    165 
    166 	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
    167 		addr = bootconfig.dram[block].address;
    168 		for (;addr < (bootconfig.dram[block].address
    169 		    + (bootconfig.dram[block].pages * PAGE_SIZE));
    170 		     addr += PAGE_SIZE) {
    171 		    	if ((len % (1024*1024)) == 0)
    172 		    		printf("%d ", len / (1024*1024));
    173 			pmap_kenter_pa(dumpspace, addr, VM_PROT_READ);
    174 			pmap_update(pmap_kernel());
    175 
    176 			error = (*bdev->d_dump)(dumpdev,
    177 			    blkno, (caddr_t) dumpspace, PAGE_SIZE);
    178 			pmap_kremove(dumpspace, PAGE_SIZE);
    179 			pmap_update(pmap_kernel());
    180 			if (error) break;
    181 			blkno += btodb(PAGE_SIZE);
    182 			len += PAGE_SIZE;
    183 		}
    184 	}
    185 
    186 	switch (error) {
    187 	case ENXIO:
    188 		printf("device bad\n");
    189 		break;
    190 
    191 	case EFAULT:
    192 		printf("device not ready\n");
    193 		break;
    194 
    195 	case EINVAL:
    196 		printf("area improper\n");
    197 		break;
    198 
    199 	case EIO:
    200 		printf("i/o error\n");
    201 		break;
    202 
    203 	case EINTR:
    204 		printf("aborted from console\n");
    205 		break;
    206 
    207 	default:
    208 		printf("succeeded\n");
    209 		break;
    210 	}
    211 	printf("\n\n");
    212 	delay(1000000);
    213 }
    214 
    215 /* End of stubs.c */
    216