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