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