kvm_m68k.c revision 1.10 1 /* $NetBSD: kvm_m68k.c,v 1.10 1997/03/21 18:44:23 gwr 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.
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/sysctl.h>
50
51 #include <stdio.h>
52 #include <string.h>
53 #include <stdlib.h>
54
55 #include <unistd.h>
56 #include <limits.h>
57 #include <nlist.h>
58 #include <kvm.h>
59 #include <db.h>
60
61 #include "kvm_private.h"
62 #include "kvm_m68k.h"
63
64 /* Could put this in struct vmstate, but this is easier. */
65 static struct kvm_ops *ops;
66
67 struct name_ops {
68 char *name;
69 struct kvm_ops *ops;
70 };
71
72 static struct name_ops optbl[] = {
73 { "amiga", &_kvm_ops_cmn },
74 { "atari", &_kvm_ops_cmn },
75 { "sun3", &_kvm_ops_sun3 },
76 { "sun3x", &_kvm_ops_sun3x },
77 { NULL, NULL },
78 };
79
80
81 /*
82 * Prepare for translation of kernel virtual addresses into offsets
83 * into crash dump files. This is where we do the dispatch work.
84 */
85 int
86 _kvm_initvtop(kd)
87 kvm_t *kd;
88 {
89 char machine[256];
90 int mib[2], len, rval;
91 struct name_ops *nop;
92
93 /* Which set of kvm functions should we use? */
94 mib[0] = CTL_HW;
95 mib[1] = HW_MACHINE;
96 len = sizeof(machine);
97 if (sysctl(mib, 2, machine, &len, NULL, 0) == -1)
98 return (-1);
99
100 for (nop = optbl; nop->name; nop++)
101 if (!strcmp(machine, nop->name))
102 goto found;
103 _kvm_err(kd, 0, "%s: unknown machine!", machine);
104 return (-1);
105
106 found:
107 ops = nop->ops;
108 return ((ops->initvtop)(kd));
109 }
110
111 void
112 _kvm_freevtop(kd)
113 kvm_t *kd;
114 {
115 (ops->freevtop)(kd);
116 }
117
118 int
119 _kvm_kvatop(kd, va, pap)
120 kvm_t *kd;
121 u_long va;
122 u_long *pap;
123 {
124 return ((ops->kvatop)(kd, va, pap));
125 }
126
127 off_t
128 _kvm_pa2off(kd, pa)
129 kvm_t *kd;
130 u_long pa;
131 {
132 return ((ops->pa2off)(kd, pa));
133 }
134