kvm_m68k.c revision 1.10 1 1.10 gwr /* $NetBSD: kvm_m68k.c,v 1.10 1997/03/21 18:44:23 gwr 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.10 gwr * by Gordon W. Ross.
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 * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.10 gwr * This product includes software developed by the NetBSD
21 1.10 gwr * Foundation, Inc. and its contributors.
22 1.10 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.10 gwr * contributors may be used to endorse or promote products derived
24 1.10 gwr * from this software without specific prior written permission.
25 1.1 cgd *
26 1.10 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.10 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.10 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.10 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.10 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.10 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.10 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.10 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.10 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.10 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.10 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.1 cgd /*
40 1.10 gwr * Run-time kvm dispatcher for m68k machines.
41 1.10 gwr * The actual MD code is in the files:
42 1.10 gwr * kvm_m68k_cmn.c kvm_sun3.c ...
43 1.10 gwr *
44 1.10 gwr * Note: This file has to build on ALL m68k machines,
45 1.10 gwr * so do NOT include any <machine/*.h> files here.
46 1.1 cgd */
47 1.1 cgd
48 1.1 cgd #include <sys/param.h>
49 1.10 gwr #include <sys/sysctl.h>
50 1.10 gwr
51 1.10 gwr #include <stdio.h>
52 1.10 gwr #include <string.h>
53 1.10 gwr #include <stdlib.h>
54 1.6 leo
55 1.1 cgd #include <unistd.h>
56 1.6 leo #include <limits.h>
57 1.1 cgd #include <nlist.h>
58 1.1 cgd #include <kvm.h>
59 1.1 cgd #include <db.h>
60 1.1 cgd
61 1.1 cgd #include "kvm_private.h"
62 1.10 gwr #include "kvm_m68k.h"
63 1.1 cgd
64 1.10 gwr /* Could put this in struct vmstate, but this is easier. */
65 1.10 gwr static struct kvm_ops *ops;
66 1.1 cgd
67 1.10 gwr struct name_ops {
68 1.10 gwr char *name;
69 1.10 gwr struct kvm_ops *ops;
70 1.10 gwr };
71 1.10 gwr
72 1.10 gwr static struct name_ops optbl[] = {
73 1.10 gwr { "amiga", &_kvm_ops_cmn },
74 1.10 gwr { "atari", &_kvm_ops_cmn },
75 1.10 gwr { "sun3", &_kvm_ops_sun3 },
76 1.10 gwr { "sun3x", &_kvm_ops_sun3x },
77 1.10 gwr { NULL, NULL },
78 1.10 gwr };
79 1.1 cgd
80 1.1 cgd
81 1.10 gwr /*
82 1.10 gwr * Prepare for translation of kernel virtual addresses into offsets
83 1.10 gwr * into crash dump files. This is where we do the dispatch work.
84 1.10 gwr */
85 1.1 cgd int
86 1.1 cgd _kvm_initvtop(kd)
87 1.1 cgd kvm_t *kd;
88 1.1 cgd {
89 1.10 gwr char machine[256];
90 1.10 gwr int mib[2], len, rval;
91 1.10 gwr struct name_ops *nop;
92 1.10 gwr
93 1.10 gwr /* Which set of kvm functions should we use? */
94 1.10 gwr mib[0] = CTL_HW;
95 1.10 gwr mib[1] = HW_MACHINE;
96 1.10 gwr len = sizeof(machine);
97 1.10 gwr if (sysctl(mib, 2, machine, &len, NULL, 0) == -1)
98 1.10 gwr return (-1);
99 1.10 gwr
100 1.10 gwr for (nop = optbl; nop->name; nop++)
101 1.10 gwr if (!strcmp(machine, nop->name))
102 1.10 gwr goto found;
103 1.10 gwr _kvm_err(kd, 0, "%s: unknown machine!", machine);
104 1.10 gwr return (-1);
105 1.10 gwr
106 1.10 gwr found:
107 1.10 gwr ops = nop->ops;
108 1.10 gwr return ((ops->initvtop)(kd));
109 1.1 cgd }
110 1.1 cgd
111 1.10 gwr void
112 1.10 gwr _kvm_freevtop(kd)
113 1.1 cgd kvm_t *kd;
114 1.1 cgd {
115 1.10 gwr (ops->freevtop)(kd);
116 1.1 cgd }
117 1.1 cgd
118 1.1 cgd int
119 1.10 gwr _kvm_kvatop(kd, va, pap)
120 1.1 cgd kvm_t *kd;
121 1.1 cgd u_long va;
122 1.10 gwr u_long *pap;
123 1.1 cgd {
124 1.10 gwr return ((ops->kvatop)(kd, va, pap));
125 1.8 gwr }
126 1.8 gwr
127 1.8 gwr off_t
128 1.8 gwr _kvm_pa2off(kd, pa)
129 1.8 gwr kvm_t *kd;
130 1.8 gwr u_long pa;
131 1.8 gwr {
132 1.10 gwr return ((ops->pa2off)(kd, pa));
133 1.1 cgd }
134