[BACK]Return to stubs.c CVS log [TXT][DIR] Up to [local] / sys / arch / arm / arm

Annotation of sys/arch/arm/arm/stubs.c, Revision 1.1.1.1

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

CVSweb