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