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