Home | History | Annotate | Line # | Download | only in arm32
stubs.c revision 1.18.18.2
      1  1.18.18.2     skrll /*	$NetBSD: stubs.c,v 1.18.18.2 2009/03/03 18:28:51 skrll 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.18.18.2     skrll __KERNEL_RCSID(0, "$NetBSD: stubs.c,v 1.18.18.2 2009/03/03 18:28:51 skrll 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.18     chris #include <arm/kcore.h>
     59       1.18     chris #include <sys/kcore.h>
     60       1.18     chris #include <sys/core.h>
     61       1.18     chris #include <sys/exec_aout.h>
     62        1.1     chris 
     63        1.1     chris extern dev_t dumpdev;
     64        1.1     chris 
     65       1.18     chris int	cpu_dump(void);
     66       1.18     chris int	cpu_dumpsize(void);
     67       1.18     chris u_long	cpu_dump_mempagecnt(void);
     68       1.18     chris 
     69        1.1     chris /*
     70        1.1     chris  * These variables are needed by /sbin/savecore
     71        1.1     chris  */
     72        1.8   tsutsui u_int32_t dumpmag = 0x8fca0101;	/* magic number */
     73        1.1     chris int 	dumpsize = 0;		/* pages */
     74        1.1     chris long	dumplo = 0; 		/* blocks */
     75        1.1     chris 
     76        1.1     chris struct pcb dumppcb;
     77        1.1     chris 
     78        1.1     chris /*
     79        1.1     chris  * This is called by main to set dumplo and dumpsize.
     80       1.18     chris  * Dumps always skip the first PAGE_SIZE of disk space
     81        1.1     chris  * in case there might be a disk label stored there.
     82        1.1     chris  * If there is extra space, put dump at the end to
     83        1.1     chris  * reduce the chance that swapping trashes it.
     84        1.1     chris  */
     85        1.1     chris 
     86        1.1     chris void
     87        1.1     chris cpu_dumpconf()
     88        1.1     chris {
     89       1.10   gehenna 	const struct bdevsw *bdev;
     90       1.18     chris 	int nblks, dumpblks;	/* size of dump area */
     91        1.1     chris 
     92        1.1     chris 	if (dumpdev == NODEV)
     93        1.1     chris 		return;
     94       1.10   gehenna 	bdev = bdevsw_lookup(dumpdev);
     95       1.18     chris 	if (bdev == NULL)
     96  1.18.18.1     skrll 		panic("dumpconf: bad dumpdev=0x%"PRIx64"", dumpdev);
     97       1.10   gehenna 	if (bdev->d_psize == NULL)
     98        1.1     chris 		return;
     99       1.10   gehenna 	nblks = (*bdev->d_psize)(dumpdev);
    100        1.1     chris 	if (nblks <= ctod(1))
    101        1.1     chris 		return;
    102        1.1     chris 
    103       1.18     chris 	dumpblks = cpu_dumpsize();
    104       1.18     chris 	if (dumpblks < 0)
    105       1.18     chris 		goto bad;
    106       1.18     chris 	dumpblks += ctod(cpu_dump_mempagecnt());
    107       1.18     chris 
    108       1.18     chris 	/* If dump won't fit (incl. room for possible label), punt. */
    109       1.18     chris 	if (dumpblks > (nblks - ctod(1)))
    110       1.18     chris 		goto bad;
    111       1.18     chris 
    112       1.18     chris 	/* Put dump at end of partition */
    113       1.18     chris 	dumplo = nblks - dumpblks;
    114       1.18     chris 
    115       1.18     chris 	/* dumpsize is in page units, and doesn't include headers. */
    116       1.18     chris 	dumpsize = cpu_dump_mempagecnt();
    117       1.18     chris 	return;
    118       1.18     chris 
    119       1.18     chris  bad:
    120       1.18     chris 	dumpsize = 0;
    121       1.18     chris }
    122       1.18     chris 
    123       1.18     chris /*
    124       1.18     chris  * cpu_dump: dump the machine-dependent kernel core dump headers.
    125       1.18     chris  */
    126       1.18     chris int
    127       1.18     chris cpu_dump()
    128       1.18     chris {
    129       1.18     chris 	int (*dump)(dev_t, daddr_t, void *, size_t);
    130       1.18     chris 	char bf[dbtob(1)];
    131       1.18     chris 	kcore_seg_t *segp;
    132       1.18     chris 	cpu_kcore_hdr_t *cpuhdrp;
    133       1.18     chris 	phys_ram_seg_t *memsegp;
    134       1.18     chris 	const struct bdevsw *bdev;
    135       1.18     chris 	int i;
    136       1.18     chris 
    137       1.18     chris 	bdev = bdevsw_lookup(dumpdev);
    138       1.18     chris 	if (bdev == NULL)
    139       1.18     chris 		return (ENXIO);
    140       1.18     chris 	dump = bdev->d_dump;
    141       1.18     chris 
    142       1.18     chris 	memset(bf, 0, sizeof bf);
    143       1.18     chris 	segp = (kcore_seg_t *)bf;
    144       1.18     chris 	cpuhdrp = (cpu_kcore_hdr_t *)&bf[ALIGN(sizeof(*segp))];
    145       1.18     chris 	memsegp = (phys_ram_seg_t *)&bf[ ALIGN(sizeof(*segp)) +
    146       1.18     chris 	    ALIGN(sizeof(*cpuhdrp))];
    147       1.18     chris 
    148       1.18     chris 	/*
    149       1.18     chris 	 * Generate a segment header.
    150       1.18     chris 	 */
    151       1.18     chris 	CORE_SETMAGIC(*segp, KCORE_MAGIC, MID_MACHINE, CORE_CPU);
    152       1.18     chris 	segp->c_size = dbtob(1) - ALIGN(sizeof(*segp));
    153       1.18     chris 
    154       1.18     chris 	/*
    155       1.18     chris 	 * Add the machine-dependent header info.
    156       1.18     chris 	 */
    157       1.18     chris 	cpuhdrp->version = 1;
    158       1.18     chris 	cpuhdrp->PAKernelL1Table = pmap_kernel_L1_addr();
    159       1.18     chris 	cpuhdrp->UserL1TableSize = 0;
    160       1.18     chris 	cpuhdrp->nmemsegs = bootconfig.dramblocks;
    161       1.18     chris 	cpuhdrp->omemsegs = ALIGN(sizeof(*cpuhdrp));
    162       1.18     chris 
    163       1.18     chris 	/*
    164       1.18     chris 	 * Fill in the memory segment descriptors.
    165       1.18     chris 	 */
    166       1.18     chris 	for (i = 0; i < bootconfig.dramblocks; i++) {
    167       1.18     chris 		memsegp[i].start = bootconfig.dram[i].address;
    168       1.18     chris 		memsegp[i].size = bootconfig.dram[i].pages * PAGE_SIZE;
    169       1.18     chris 	}
    170       1.18     chris 
    171       1.18     chris 	return (dump(dumpdev, dumplo, bf, dbtob(1)));
    172       1.18     chris }
    173       1.18     chris 
    174       1.18     chris /*
    175       1.18     chris  * cpu_dumpsize: calculate size of machine-dependent kernel core dump headers.
    176       1.18     chris  */
    177       1.18     chris int
    178       1.18     chris cpu_dumpsize()
    179       1.18     chris {
    180       1.18     chris 	int size;
    181       1.18     chris 
    182       1.18     chris 	size = ALIGN(sizeof(kcore_seg_t)) + ALIGN(sizeof(cpu_kcore_hdr_t)) +
    183       1.18     chris 	    ALIGN( bootconfig.dramblocks * sizeof(phys_ram_seg_t));
    184       1.18     chris 	if (roundup(size, dbtob(1)) != dbtob(1))
    185       1.18     chris 		return (-1);
    186        1.1     chris 
    187       1.18     chris 	return (1);
    188       1.18     chris }
    189       1.18     chris 
    190       1.18     chris 
    191       1.18     chris /*
    192       1.18     chris  * cpu_dump_mempagecnt: calculate the size of RAM (in pages) to be dumped.
    193       1.18     chris  */
    194       1.18     chris u_long
    195       1.18     chris cpu_dump_mempagecnt()
    196       1.18     chris {
    197       1.18     chris 	u_long i, n;
    198       1.18     chris 
    199       1.18     chris 	n = 0;
    200       1.18     chris 	for (i = 0; i < bootconfig.dramblocks; i++) {
    201       1.18     chris 		n += bootconfig.dram[i].pages;
    202       1.18     chris 	}
    203       1.18     chris 
    204       1.18     chris 	return (n);
    205        1.1     chris }
    206        1.1     chris 
    207        1.1     chris /* This should be moved to machdep.c */
    208        1.1     chris 
    209       1.18     chris extern vaddr_t memhook;		/* XXX */
    210        1.1     chris 
    211        1.1     chris /*
    212        1.1     chris  * Doadump comes here after turning off memory management and
    213        1.1     chris  * getting on the dump stack, either when called above, or by
    214        1.1     chris  * the auto-restart code.
    215        1.1     chris  */
    216       1.18     chris void dodumpsys(void);
    217        1.1     chris 
    218        1.1     chris void
    219       1.18     chris dodumpsys()
    220        1.1     chris {
    221       1.10   gehenna 	const struct bdevsw *bdev;
    222        1.1     chris 	daddr_t blkno;
    223        1.1     chris 	int psize;
    224        1.1     chris 	int error;
    225        1.1     chris 	int addr;
    226        1.1     chris 	int block;
    227        1.1     chris 	int len;
    228        1.1     chris 	vaddr_t dumpspace;
    229        1.1     chris 
    230       1.12     chris 	/* flush everything out of caches */
    231       1.12     chris 	cpu_dcache_wbinv_all();
    232        1.1     chris 
    233        1.1     chris 	if (dumpdev == NODEV)
    234        1.1     chris 		return;
    235        1.1     chris 	if (dumpsize == 0) {
    236        1.1     chris 		cpu_dumpconf();
    237        1.1     chris 	}
    238       1.18     chris 	if (dumplo <= 0 || dumpsize == 0) {
    239  1.18.18.2     skrll 		printf("\ndump to dev %u,%u not possible\n",
    240  1.18.18.1     skrll 		    major(dumpdev), minor(dumpdev));
    241       1.18     chris 		delay(5000000);
    242        1.1     chris 		return;
    243        1.1     chris 	}
    244  1.18.18.2     skrll 	printf("\ndumping to dev %u,%u offset %ld\n",
    245  1.18.18.1     skrll 	    major(dumpdev), minor(dumpdev), dumplo);
    246        1.1     chris 
    247        1.1     chris 
    248       1.10   gehenna 	bdev = bdevsw_lookup(dumpdev);
    249       1.10   gehenna 	if (bdev == NULL || bdev->d_psize == NULL)
    250       1.10   gehenna 		return;
    251       1.10   gehenna 	psize = (*bdev->d_psize)(dumpdev);
    252        1.1     chris 	printf("dump ");
    253        1.1     chris 	if (psize == -1) {
    254        1.1     chris 		printf("area unavailable\n");
    255        1.1     chris 		return;
    256        1.1     chris 	}
    257        1.1     chris 
    258       1.18     chris 	if ((error = cpu_dump()) != 0)
    259       1.18     chris 		goto err;
    260       1.18     chris 
    261       1.18     chris 	blkno = dumplo + cpu_dumpsize();
    262       1.18     chris 	dumpspace = memhook;
    263        1.1     chris 	error = 0;
    264        1.1     chris 	len = 0;
    265        1.1     chris 
    266        1.1     chris 	for (block = 0; block < bootconfig.dramblocks && error == 0; ++block) {
    267        1.1     chris 		addr = bootconfig.dram[block].address;
    268        1.1     chris 		for (;addr < (bootconfig.dram[block].address
    269       1.13   thorpej 		    + (bootconfig.dram[block].pages * PAGE_SIZE));
    270       1.13   thorpej 		     addr += PAGE_SIZE) {
    271        1.1     chris 		    	if ((len % (1024*1024)) == 0)
    272        1.1     chris 		    		printf("%d ", len / (1024*1024));
    273       1.18     chris 
    274       1.12     chris 			pmap_kenter_pa(dumpspace, addr, VM_PROT_READ);
    275       1.12     chris 			pmap_update(pmap_kernel());
    276       1.10   gehenna 			error = (*bdev->d_dump)(dumpdev,
    277       1.17  christos 			    blkno, (void *) dumpspace, PAGE_SIZE);
    278       1.18     chris 
    279       1.18     chris 			if (error) goto err;
    280       1.13   thorpej 			blkno += btodb(PAGE_SIZE);
    281       1.13   thorpej 			len += PAGE_SIZE;
    282        1.1     chris 		}
    283        1.1     chris 	}
    284       1.18     chris err:
    285        1.1     chris 	switch (error) {
    286        1.1     chris 	case ENXIO:
    287        1.1     chris 		printf("device bad\n");
    288        1.1     chris 		break;
    289        1.1     chris 
    290        1.1     chris 	case EFAULT:
    291        1.1     chris 		printf("device not ready\n");
    292        1.1     chris 		break;
    293        1.1     chris 
    294        1.1     chris 	case EINVAL:
    295        1.1     chris 		printf("area improper\n");
    296        1.1     chris 		break;
    297        1.1     chris 
    298        1.1     chris 	case EIO:
    299        1.1     chris 		printf("i/o error\n");
    300        1.1     chris 		break;
    301        1.1     chris 
    302        1.1     chris 	case EINTR:
    303        1.1     chris 		printf("aborted from console\n");
    304        1.1     chris 		break;
    305        1.1     chris 
    306       1.18     chris 	case 0:
    307       1.18     chris 		printf("succeeded\n");
    308       1.18     chris 		break;
    309       1.18     chris 
    310        1.1     chris 	default:
    311       1.18     chris 		printf("error %d\n", error);
    312        1.1     chris 		break;
    313        1.1     chris 	}
    314        1.1     chris 	printf("\n\n");
    315       1.18     chris 	delay(5000000);
    316        1.1     chris }
    317        1.1     chris 
    318        1.1     chris /* End of stubs.c */
    319