1 /* $NetBSD: kvm_sun3.c,v 1.6 1997/04/09 21:15:58 thorpej 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.6 1997/04/09 21:15:58 thorpej Exp $"; 45 #endif 46 #endif /* LIBC_SCCS and not lint */ 47 48 /* 49 * Sun3 machine dependent routines for kvm. 50 * 51 * Note: This file has to build on ALL m68k machines, 52 * so do NOT include any <machine/*.h> files here. 53 */ 54 55 #include <sys/types.h> 56 #include <sys/kcore.h> 57 58 #include <unistd.h> 59 #include <limits.h> 60 #include <nlist.h> 61 #include <kvm.h> 62 #include <db.h> 63 64 #include <m68k/kcore.h> 65 66 #include "kvm_private.h" 67 #include "kvm_m68k.h" 68 69 int _kvm_sun3_initvtop __P((kvm_t *)); 70 void _kvm_sun3_freevtop __P((kvm_t *)); 71 int _kvm_sun3_kvatop __P((kvm_t *, u_long, u_long *)); 72 off_t _kvm_sun3_pa2off __P((kvm_t *, u_long)); 73 74 struct kvm_ops _kvm_ops_sun3 = { 75 _kvm_sun3_initvtop, 76 _kvm_sun3_freevtop, 77 _kvm_sun3_kvatop, 78 _kvm_sun3_pa2off }; 79 80 #define _kvm_pg_pa(v, s, pte) \ 81 (((pte) & (s)->pg_frame) << (v)->pgshift) 82 83 #define _kvm_va_segnum(s, x) \ 84 ((u_int)(x) >> (s)->segshift) 85 #define _kvm_pte_num_mask(v) \ 86 (0xf << (v)->pgshift) 87 #define _kvm_va_pte_num(v, va) \ 88 (((va) & _kvm_pte_num_mask((v))) >> (v)->pgshift) 89 90 /* 91 * XXX Re-define these here, no other place for them. 92 */ 93 #define NKSEG 256 /* kernel segmap entries */ 94 #define NPAGSEG 16 /* pages per segment */ 95 96 /* Finally, our local stuff... */ 97 struct private_vmstate { 98 /* Page Map Entry Group (PMEG) */ 99 int pmeg[NKSEG][NPAGSEG]; 100 }; 101 102 /* 103 * Prepare for translation of kernel virtual addresses into offsets 104 * into crash dump files. We use the MMU specific goop written at the 105 * beginning of a crash dump by dumpsys() 106 * Note: sun3 MMU specific! 107 */ 108 int 109 _kvm_sun3_initvtop(kd) 110 kvm_t *kd; 111 { 112 cpu_kcore_hdr_t *h = kd->cpu_data; 113 char *p; 114 115 p = kd->cpu_data; 116 p += (h->page_size - sizeof(kcore_seg_t)); 117 kd->vmst->private = p; 118 119 return (0); 120 } 121 122 void 123 _kvm_sun3_freevtop(kd) 124 kvm_t *kd; 125 { 126 /* This was set by pointer arithmetic, not allocation. */ 127 kd->vmst->private = (void*)0; 128 } 129 130 /* 131 * Translate a kernel virtual address to a physical address using the 132 * mapping information in kd->vm. Returns the result in pa, and returns 133 * the number of bytes that are contiguously available from this 134 * physical address. This routine is used only for crashdumps. 135 */ 136 int 137 _kvm_sun3_kvatop(kd, va, pap) 138 kvm_t *kd; 139 u_long va; 140 u_long *pap; 141 { 142 cpu_kcore_hdr_t *h = kd->cpu_data; 143 struct sun3_kcore_hdr *s = &h->un._sun3; 144 struct vmstate *v = kd->vmst; 145 struct private_vmstate *pv = v->private; 146 int pte, offset; 147 u_int segnum, sme, ptenum; 148 u_long pa; 149 150 if (ISALIVE(kd)) { 151 _kvm_err(kd, 0, "vatop called in live kernel!"); 152 return(0); 153 } 154 155 if (va < h->kernbase) { 156 _kvm_err(kd, 0, "not a kernel address"); 157 return(0); 158 } 159 160 /* 161 * Get the segmap entry (sme) from the kernel segmap. 162 * Note: only have segmap entries from KERNBASE to end. 163 */ 164 segnum = _kvm_va_segnum(s, va - h->kernbase); 165 ptenum = _kvm_va_pte_num(v, va); 166 offset = va & v->pgofset; 167 168 /* The segmap entry selects a PMEG. */ 169 sme = s->ksegmap[segnum]; 170 pte = pv->pmeg[sme][ptenum]; 171 172 if ((pte & (s)->pg_valid) == 0) { 173 _kvm_err(kd, 0, "page not valid (VA=0x%x)", va); 174 return (0); 175 } 176 pa = _kvm_pg_pa(v, s, pte) + offset; 177 178 *pap = pa; 179 return (h->page_size - offset); 180 } 181 182 /* 183 * Translate a physical address to a file-offset in the crash-dump. 184 */ 185 off_t 186 _kvm_sun3_pa2off(kd, pa) 187 kvm_t *kd; 188 u_long pa; 189 { 190 return(kd->dump_off + pa); 191 } 192