1 /* $NetBSD: kvm_m68k.c,v 1.15 2001/05/21 14:56:29 fredette Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Gordon W. Ross and Jason R. Thorpe. 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 the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Run-time kvm dispatcher for m68k machines. 41 * The actual MD code is in the files: 42 * kvm_m68k_cmn.c kvm_sun3.c ... 43 * 44 * Note: This file has to build on ALL m68k machines, 45 * so do NOT include any <machine/[*].h> files here. 46 */ 47 48 #include <sys/param.h> 49 #include <sys/exec.h> 50 #include <sys/kcore.h> 51 #include <sys/sysctl.h> 52 53 #include <stdio.h> 54 #include <string.h> 55 #include <stdlib.h> 56 57 #include <unistd.h> 58 #include <limits.h> 59 #include <nlist.h> 60 #include <kvm.h> 61 #include <db.h> 62 63 #include <m68k/kcore.h> 64 65 #include "kvm_private.h" 66 #include "kvm_m68k.h" 67 68 struct name_ops { 69 const char *name; 70 struct kvm_ops *ops; 71 }; 72 73 /* 74 * Match specific kcore types first, falling into a default. 75 */ 76 static struct name_ops optbl[] = { 77 { "sun2", &_kvm_ops_sun2 }, 78 { "sun3", &_kvm_ops_sun3 }, 79 { "sun3x", &_kvm_ops_sun3x }, 80 { NULL, &_kvm_ops_cmn }, 81 }; 82 83 /* 84 * Prepare for translation of kernel virtual addresses into offsets 85 * into crash dump files. This is where we do the dispatch work. 86 */ 87 int 88 _kvm_initvtop(kd) 89 kvm_t *kd; 90 { 91 cpu_kcore_hdr_t *h; 92 struct name_ops *nop; 93 struct vmstate *vm; 94 95 vm = (struct vmstate *)_kvm_malloc(kd, sizeof (*vm)); 96 if (vm == 0) 97 return (-1); 98 99 kd->vmst = vm; 100 101 /* 102 * Use the machine name in the kcore header to determine 103 * our ops vector. When we reach an ops vector with 104 * no name, we've found a default. 105 */ 106 h = kd->cpu_data; 107 h->name[sizeof(h->name) - 1] = '\0'; /* sanity */ 108 for (nop = optbl; nop->name != NULL; nop++) 109 if (strcmp(nop->name, h->name) == 0) 110 break; 111 112 vm->ops = nop->ops; 113 114 /* 115 * Compute pgshift and pgofset. 116 */ 117 for (vm->pgshift = 0; (1 << vm->pgshift) < h->page_size; vm->pgshift++) 118 /* nothing */ ; 119 if ((1 << vm->pgshift) != h->page_size) 120 goto bad; 121 vm->pgofset = h->page_size - 1; 122 123 if ((vm->ops->initvtop)(kd) < 0) 124 goto bad; 125 126 return (0); 127 128 bad: 129 kd->vmst = NULL; 130 free(vm); 131 return (-1); 132 } 133 134 void 135 _kvm_freevtop(kd) 136 kvm_t *kd; 137 { 138 (kd->vmst->ops->freevtop)(kd); 139 free(kd->vmst); 140 } 141 142 int 143 _kvm_kvatop(kd, va, pap) 144 kvm_t *kd; 145 u_long va; 146 u_long *pap; 147 { 148 return ((kd->vmst->ops->kvatop)(kd, va, pap)); 149 } 150 151 off_t 152 _kvm_pa2off(kd, pa) 153 kvm_t *kd; 154 u_long pa; 155 { 156 return ((kd->vmst->ops->pa2off)(kd, pa)); 157 } 158 159 /* 160 * Machine-dependent initialization for ALL open kvm descriptors, 161 * not just those for a kernel crash dump. Some architectures 162 * have to deal with these NOT being constants! (i.e. m68k) 163 */ 164 int 165 _kvm_mdopen(kd) 166 kvm_t *kd; 167 { 168 u_long max_uva; 169 extern struct ps_strings *__ps_strings; 170 171 #if 0 /* XXX - These vary across m68k machines... */ 172 kd->usrstack = USRSTACK; 173 kd->min_uva = VM_MIN_ADDRESS; 174 kd->max_uva = VM_MAXUSER_ADDRESS; 175 #endif 176 /* This is somewhat hack-ish, but it works. */ 177 max_uva = (u_long) (__ps_strings + 1); 178 kd->usrstack = max_uva; 179 kd->max_uva = max_uva; 180 kd->min_uva = 0; 181 182 return (0); 183 } 184