1 /* $NetBSD: kvm_sun3.c,v 1.4 1996/05/05 04:32:18 gwr Exp $ */ 2 3 /*- 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software developed by the Computer Systems 8 * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 9 * BG 91-66 and contributed to Berkeley. 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 the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 * OR 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 40 #if defined(LIBC_SCCS) && !defined(lint) 41 #if 0 42 static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93"; 43 #else 44 static char *rcsid = "$NetBSD: kvm_sun3.c,v 1.4 1996/05/05 04:32:18 gwr Exp $"; 45 #endif 46 #endif /* LIBC_SCCS and not lint */ 47 48 /* 49 * Sun3 machine dependent routines for kvm. 50 */ 51 52 #include <sys/param.h> 53 #include <sys/user.h> 54 #include <sys/proc.h> 55 #include <sys/stat.h> 56 57 #include <sys/core.h> 58 #include <sys/exec_aout.h> 59 #include <sys/kcore.h> 60 61 #include <unistd.h> 62 #include <limits.h> 63 #include <nlist.h> 64 #include <kvm.h> 65 #include <db.h> 66 67 #include <vm/vm.h> 68 #include <vm/vm_param.h> 69 70 #include <machine/kcore.h> 71 #include <machine/pte.h> 72 73 #include "kvm_private.h" 74 75 #define NKSEG (NSEGMAP/8) /* kernel segmap entries */ 76 struct vmstate { 77 /* Page Map Entry Group (PMEG) */ 78 int pmeg[NKSEG][NPAGSEG]; 79 }; 80 81 /* 82 * Prepare for translation of kernel virtual addresses into offsets 83 * into crash dump files. We use the MMU specific goop written at the 84 * beginning of a crash dump by dumpsys() 85 * Note: sun3 MMU specific! 86 */ 87 int 88 _kvm_initvtop(kd) 89 kvm_t *kd; 90 { 91 register char *p; 92 93 p = kd->cpu_data; 94 p += (NBPG - sizeof(kcore_seg_t)); 95 kd->vmst = (struct vmstate *)p; 96 97 return (0); 98 } 99 100 void 101 _kvm_freevtop(kd) 102 kvm_t *kd; 103 { 104 /* This was set by pointer arithmetic, not allocation. */ 105 kd->vmst = (void*)0; 106 } 107 108 /* 109 * Translate a kernel virtual address to a physical address using the 110 * mapping information in kd->vm. Returns the result in pa, and returns 111 * the number of bytes that are contiguously available from this 112 * physical address. This routine is used only for crashdumps. 113 */ 114 int 115 _kvm_kvatop(kd, va, pap) 116 kvm_t *kd; 117 u_long va; 118 u_long *pap; 119 { 120 register cpu_kcore_hdr_t *ckh; 121 u_int segnum, sme, ptenum; 122 int pte, offset; 123 u_long pa; 124 125 if (ISALIVE(kd)) { 126 _kvm_err(kd, 0, "vatop called in live kernel!"); 127 return((off_t)0); 128 } 129 ckh = kd->cpu_data; 130 131 if (va < KERNBASE) { 132 _kvm_err(kd, 0, "not a kernel address"); 133 return((off_t)0); 134 } 135 136 /* 137 * Get the segmap entry (sme) from the kernel segmap. 138 * Note: only have segmap entries from KERNBASE to end. 139 */ 140 segnum = VA_SEGNUM(va - KERNBASE); 141 ptenum = VA_PTE_NUM(va); 142 offset = va & PGOFSET; 143 144 /* The segmap entry selects a PMEG. */ 145 sme = ckh->ksegmap[segnum]; 146 pte = kd->vmst->pmeg[sme][ptenum]; 147 148 if ((pte & PG_VALID) == 0) { 149 _kvm_err(kd, 0, "page not valid (VA=0x%x)", va); 150 return (0); 151 } 152 pa = PG_PA(pte) + offset; 153 154 *pap = pa; 155 return (NBPG - offset); 156 } 157 158 /* 159 * Translate a physical address to a file-offset in the crash-dump. 160 */ 161 off_t 162 _kvm_pa2off(kd, pa) 163 kvm_t *kd; 164 u_long pa; 165 { 166 return(kd->dump_off + pa); 167 } 168