kvm_m68k.c revision 1.11 1 1.11 thorpej /* $NetBSD: kvm_m68k.c,v 1.11 1997/04/09 21:15:50 thorpej 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 * 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.1 cgd */
44 1.1 cgd
45 1.1 cgd #include <sys/param.h>
46 1.10 gwr #include <sys/sysctl.h>
47 1.11 thorpej #include <sys/kcore.h>
48 1.10 gwr
49 1.10 gwr #include <stdio.h>
50 1.10 gwr #include <string.h>
51 1.10 gwr #include <stdlib.h>
52 1.6 leo
53 1.1 cgd #include <unistd.h>
54 1.6 leo #include <limits.h>
55 1.1 cgd #include <nlist.h>
56 1.1 cgd #include <kvm.h>
57 1.1 cgd #include <db.h>
58 1.1 cgd
59 1.11 thorpej #include <machine/kcore.h>
60 1.11 thorpej
61 1.1 cgd #include "kvm_private.h"
62 1.10 gwr #include "kvm_m68k.h"
63 1.1 cgd
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.11 thorpej { "sun3", &_kvm_ops_sun3 },
74 1.11 thorpej { "sun3x", &_kvm_ops_sun3x },
75 1.11 thorpej { NULL, &_kvm_ops_cmn },
76 1.10 gwr };
77 1.1 cgd
78 1.10 gwr /*
79 1.10 gwr * Prepare for translation of kernel virtual addresses into offsets
80 1.10 gwr * into crash dump files. This is where we do the dispatch work.
81 1.10 gwr */
82 1.1 cgd int
83 1.1 cgd _kvm_initvtop(kd)
84 1.1 cgd 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.10 gwr _kvm_freevtop(kd)
131 1.1 cgd kvm_t *kd;
132 1.1 cgd {
133 1.11 thorpej (kd->vmst->ops->freevtop)(kd);
134 1.11 thorpej free(kd->vmst);
135 1.1 cgd }
136 1.1 cgd
137 1.1 cgd int
138 1.10 gwr _kvm_kvatop(kd, va, pap)
139 1.1 cgd kvm_t *kd;
140 1.1 cgd u_long va;
141 1.10 gwr u_long *pap;
142 1.1 cgd {
143 1.11 thorpej return ((kd->vmst->ops->kvatop)(kd, va, pap));
144 1.8 gwr }
145 1.8 gwr
146 1.8 gwr off_t
147 1.8 gwr _kvm_pa2off(kd, pa)
148 1.8 gwr kvm_t *kd;
149 1.8 gwr u_long pa;
150 1.8 gwr {
151 1.11 thorpej return ((kd->vmst->ops->pa2off)(kd, pa));
152 1.1 cgd }
153