Home | History | Annotate | Line # | Download | only in arm32
stubs.c revision 1.5.2.7
      1  1.5.2.7  thorpej /*	$NetBSD: stubs.c,v 1.5.2.7 2002/12/29 19:20:07 thorpej 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 
     58  1.5.2.2  nathanw /*
     59  1.5.2.2  nathanw  * These variables are needed by /sbin/savecore
     60  1.5.2.2  nathanw  */
     61  1.5.2.5  nathanw u_int32_t dumpmag = 0x8fca0101;	/* magic number */
     62  1.5.2.2  nathanw int 	dumpsize = 0;		/* pages */
     63  1.5.2.2  nathanw long	dumplo = 0; 		/* blocks */
     64  1.5.2.2  nathanw 
     65  1.5.2.2  nathanw struct pcb dumppcb;
     66  1.5.2.2  nathanw 
     67  1.5.2.2  nathanw /*
     68  1.5.2.2  nathanw  * This is called by main to set dumplo and dumpsize.
     69  1.5.2.2  nathanw  * Dumps always skip the first CLBYTES of disk space
     70  1.5.2.2  nathanw  * in case there might be a disk label stored there.
     71  1.5.2.2  nathanw  * If there is extra space, put dump at the end to
     72  1.5.2.2  nathanw  * reduce the chance that swapping trashes it.
     73  1.5.2.2  nathanw  */
     74  1.5.2.2  nathanw 
     75  1.5.2.2  nathanw void
     76  1.5.2.2  nathanw cpu_dumpconf()
     77  1.5.2.2  nathanw {
     78  1.5.2.6  nathanw 	const struct bdevsw *bdev;
     79  1.5.2.2  nathanw 	int nblks;	/* size of dump area */
     80  1.5.2.2  nathanw 
     81  1.5.2.2  nathanw 	if (dumpdev == NODEV)
     82  1.5.2.2  nathanw 		return;
     83  1.5.2.6  nathanw 	bdev = bdevsw_lookup(dumpdev);
     84  1.5.2.6  nathanw 	if (bdev == NULL)
     85  1.5.2.2  nathanw 		panic("dumpconf: bad dumpdev=0x%x", dumpdev);
     86  1.5.2.6  nathanw 	if (bdev->d_psize == NULL)
     87  1.5.2.2  nathanw 		return;
     88  1.5.2.6  nathanw 	nblks = (*bdev->d_psize)(dumpdev);
     89  1.5.2.2  nathanw 	if (nblks <= ctod(1))
     90  1.5.2.2  nathanw 		return;
     91  1.5.2.2  nathanw 
     92  1.5.2.2  nathanw 	dumpsize = physmem;
     93  1.5.2.2  nathanw 
     94  1.5.2.2  nathanw 	/* Always skip the first CLBYTES, in case there is a label there. */
     95  1.5.2.2  nathanw 	if (dumplo < ctod(1))
     96  1.5.2.2  nathanw 		dumplo = ctod(1);
     97  1.5.2.2  nathanw 
     98  1.5.2.2  nathanw 	/* Put dump at end of partition, and make it fit. */
     99  1.5.2.2  nathanw 	if (dumpsize > dtoc(nblks - dumplo))
    100  1.5.2.2  nathanw 		dumpsize = dtoc(nblks - dumplo);
    101  1.5.2.2  nathanw 	if (dumplo < nblks - ctod(dumpsize))
    102  1.5.2.2  nathanw 		dumplo = nblks - ctod(dumpsize);
    103  1.5.2.2  nathanw }
    104  1.5.2.2  nathanw 
    105  1.5.2.2  nathanw /* This should be moved to machdep.c */
    106  1.5.2.2  nathanw 
    107  1.5.2.5  nathanw extern char *memhook;		/* XXX */
    108  1.5.2.2  nathanw 
    109  1.5.2.2  nathanw /*
    110  1.5.2.2  nathanw  * Doadump comes here after turning off memory management and
    111  1.5.2.2  nathanw  * getting on the dump stack, either when called above, or by
    112  1.5.2.2  nathanw  * the auto-restart code.
    113  1.5.2.2  nathanw  */
    114  1.5.2.2  nathanw 
    115  1.5.2.2  nathanw void
    116  1.5.2.2  nathanw dumpsys()
    117  1.5.2.2  nathanw {
    118  1.5.2.6  nathanw 	const struct bdevsw *bdev;
    119  1.5.2.2  nathanw 	daddr_t blkno;
    120  1.5.2.2  nathanw 	int psize;
    121  1.5.2.2  nathanw 	int error;
    122  1.5.2.2  nathanw 	int addr;
    123  1.5.2.2  nathanw 	int block;
    124  1.5.2.2  nathanw 	int len;
    125  1.5.2.2  nathanw 	vaddr_t dumpspace;
    126  1.5.2.2  nathanw 
    127  1.5.2.2  nathanw 	/* Save registers. */
    128  1.5.2.2  nathanw 	savectx(&dumppcb);
    129  1.5.2.2  nathanw 
    130  1.5.2.2  nathanw 	if (dumpdev == NODEV)
    131  1.5.2.2  nathanw 		return;
    132  1.5.2.2  nathanw 	if (dumpsize == 0) {
    133  1.5.2.2  nathanw 		cpu_dumpconf();
    134  1.5.2.2  nathanw 		if (dumpsize == 0)
    135  1.5.2.2  nathanw 			return;
    136  1.5.2.2  nathanw 	}
    137  1.5.2.2  nathanw 	if (dumplo <= 0) {
    138  1.5.2.2  nathanw 		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
    139  1.5.2.2  nathanw 		    minor(dumpdev));
    140  1.5.2.2  nathanw 		return;
    141  1.5.2.2  nathanw 	}
    142  1.5.2.2  nathanw 	printf("\ndumping to dev %u,%u offset %ld\n", major(dumpdev),
    143  1.5.2.2  nathanw 	    minor(dumpdev), dumplo);
    144  1.5.2.2  nathanw 
    145  1.5.2.2  nathanw 	blkno = dumplo;
    146  1.5.2.5  nathanw 	dumpspace = (vaddr_t) memhook;
    147  1.5.2.2  nathanw 
    148  1.5.2.6  nathanw 	bdev = bdevsw_lookup(dumpdev);
    149  1.5.2.6  nathanw 	if (bdev == NULL || bdev->d_psize == NULL)
    150  1.5.2.6  nathanw 		return;
    151  1.5.2.6  nathanw 	psize = (*bdev->d_psize)(dumpdev);
    152  1.5.2.2  nathanw 	printf("dump ");
    153  1.5.2.2  nathanw 	if (psize == -1) {
    154  1.5.2.2  nathanw 		printf("area unavailable\n");
    155  1.5.2.2  nathanw 		return;
    156  1.5.2.2  nathanw 	}
    157  1.5.2.2  nathanw 
    158  1.5.2.2  nathanw 	error = 0;
    159  1.5.2.2  nathanw 	len = 0;
    160  1.5.2.2  nathanw 
    161  1.5.2.2  nathanw 	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
    162  1.5.2.2  nathanw 		addr = bootconfig.dram[block].address;
    163  1.5.2.2  nathanw 		for (;addr < (bootconfig.dram[block].address
    164  1.5.2.2  nathanw 		    + (bootconfig.dram[block].pages * NBPG)); addr += NBPG) {
    165  1.5.2.2  nathanw 		    	if ((len % (1024*1024)) == 0)
    166  1.5.2.2  nathanw 		    		printf("%d ", len / (1024*1024));
    167  1.5.2.2  nathanw 	                pmap_map(dumpspace, addr, addr + NBPG, VM_PROT_READ);
    168  1.5.2.6  nathanw 			error = (*bdev->d_dump)(dumpdev,
    169  1.5.2.2  nathanw 			    blkno, (caddr_t) dumpspace, NBPG);
    170  1.5.2.2  nathanw 			if (error) break;
    171  1.5.2.2  nathanw 			blkno += btodb(NBPG);
    172  1.5.2.2  nathanw 			len += NBPG;
    173  1.5.2.2  nathanw 		}
    174  1.5.2.2  nathanw 	}
    175  1.5.2.2  nathanw 
    176  1.5.2.2  nathanw 	switch (error) {
    177  1.5.2.2  nathanw 	case ENXIO:
    178  1.5.2.2  nathanw 		printf("device bad\n");
    179  1.5.2.2  nathanw 		break;
    180  1.5.2.2  nathanw 
    181  1.5.2.2  nathanw 	case EFAULT:
    182  1.5.2.2  nathanw 		printf("device not ready\n");
    183  1.5.2.2  nathanw 		break;
    184  1.5.2.2  nathanw 
    185  1.5.2.2  nathanw 	case EINVAL:
    186  1.5.2.2  nathanw 		printf("area improper\n");
    187  1.5.2.2  nathanw 		break;
    188  1.5.2.2  nathanw 
    189  1.5.2.2  nathanw 	case EIO:
    190  1.5.2.2  nathanw 		printf("i/o error\n");
    191  1.5.2.2  nathanw 		break;
    192  1.5.2.2  nathanw 
    193  1.5.2.2  nathanw 	case EINTR:
    194  1.5.2.2  nathanw 		printf("aborted from console\n");
    195  1.5.2.2  nathanw 		break;
    196  1.5.2.2  nathanw 
    197  1.5.2.2  nathanw 	default:
    198  1.5.2.2  nathanw 		printf("succeeded\n");
    199  1.5.2.2  nathanw 		break;
    200  1.5.2.2  nathanw 	}
    201  1.5.2.2  nathanw 	printf("\n\n");
    202  1.5.2.2  nathanw 	delay(1000000);
    203  1.5.2.2  nathanw }
    204  1.5.2.2  nathanw 
    205  1.5.2.2  nathanw /* End of stubs.c */
    206