kvm_sun3x.c revision 1.1 1 /* $NetBSD: kvm_sun3x.c,v 1.1 1997/03/21 18:44:26 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 #if defined(LIBC_SCCS) && !defined(lint)
40 #if 0
41 static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
42 #else
43 static char *rcsid = "$NetBSD: kvm_sun3x.c,v 1.1 1997/03/21 18:44:26 gwr Exp $";
44 #endif
45 #endif /* LIBC_SCCS and not lint */
46
47 /*
48 * Sun3x machine dependent routines for kvm.
49 *
50 * Note: This file has to build on ALL m68k machines,
51 * so do NOT include any <machine/*.h> files here.
52 */
53
54 #include <sys/types.h>
55 #include <sys/kcore.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 "kvm_private.h"
64 #include "kvm_m68k.h"
65
66 int _kvm_sun3x_initvtop __P((kvm_t *));
67 void _kvm_sun3x_freevtop __P((kvm_t *));
68 int _kvm_sun3x_kvatop __P((kvm_t *, u_long, u_long *));
69 off_t _kvm_sun3x_pa2off __P((kvm_t *, u_long));
70
71 struct kvm_ops _kvm_ops_sun3x = {
72 _kvm_sun3x_initvtop,
73 _kvm_sun3x_freevtop,
74 _kvm_sun3x_kvatop,
75 _kvm_sun3x_pa2off };
76
77 /*
78 * XXX: I don't like this, but until all arch/.../include files
79 * are exported into some user-accessable place, there is no
80 * convenient alternative to copying these definitions here.
81 */
82
83 /* sun3x/include/param.h */
84 #define PGSHIFT 13
85 #define NBPG 8192
86 #define PGOFSET (NBPG-1)
87 #define KERNBASE 0xF8000000
88
89 /* sun3x/sun3x/pmap.c */
90 #define KVAS_SIZE (-KERNBASE)
91 #define NKPTES (KVAS_SIZE >> PGSHIFT)
92
93 #define PG_FRAME 0xffffff00
94 #define PG_VALID 0x00000001
95
96 #define PG_PA(pte) (pte & PG_FRAME)
97
98 /* sun3x/include/kcore.h */
99 #define NPHYS_RAM_SEGS 4
100 typedef struct {
101 u_long start; /* Physical start address */
102 u_long size; /* Size in bytes */
103 } cpu_ram_seg_t;
104 typedef struct cpu_kcore_hdr {
105 u_long ckh_contig_end;
106 u_long ckh_kernCbase;
107 cpu_ram_seg_t ram_segs[NPHYS_RAM_SEGS];
108 } cpu_kcore_hdr_t;
109
110 /* Finally, our local stuff... */
111
112 /*
113 * Prepare for translation of kernel virtual addresses into offsets
114 * into crash dump files. Nothing to do here.
115 */
116 int
117 _kvm_sun3x_initvtop(kd)
118 kvm_t *kd;
119 {
120 return (0);
121 }
122
123 void
124 _kvm_sun3x_freevtop(kd)
125 kvm_t *kd;
126 {
127 }
128
129 /*
130 * Translate a kernel virtual address to a physical address using the
131 * mapping information in kd->vm. Returns the result in pa, and returns
132 * the number of bytes that are contiguously available from this
133 * physical address. This routine is used only for crashdumps.
134 */
135 int
136 _kvm_sun3x_kvatop(kd, va, pap)
137 kvm_t *kd;
138 u_long va;
139 u_long *pap;
140 {
141 register cpu_kcore_hdr_t *ckh;
142 int idx, len, offset, pte;
143 u_long pteva, pa;
144
145 if (ISALIVE(kd)) {
146 _kvm_err(kd, 0, "vatop called in live kernel!");
147 return((off_t)0);
148 }
149 ckh = kd->cpu_data;
150
151 if (va < KERNBASE) {
152 _kvm_err(kd, 0, "not a kernel address");
153 return(0);
154 }
155
156 /*
157 * If this VA is in the contiguous range, short-cut.
158 * Note that this ends our recursion when we call
159 * kvm_read to access the kernel page table, which
160 * is guaranteed to be in the contiguous range.
161 */
162 if (va < ckh->ckh_contig_end) {
163 len = va - ckh->ckh_contig_end;
164 pa = va - KERNBASE;
165 goto done;
166 }
167
168 /*
169 * The KVA is beyond the contiguous range, so we must
170 * read the PTE for this KVA from the page table.
171 */
172 idx = ((va - KERNBASE) >> PGSHIFT);
173 pteva = ckh->ckh_kernCbase + (idx * 4);
174 if (kvm_read(kd, pteva, &pte, 4) != 4) {
175 _kvm_err(kd, 0, "can not read PTE!");
176 return (0);
177 }
178 if ((pte & PG_VALID) == 0) {
179 _kvm_err(kd, 0, "page not valid (VA=0x%x)", va);
180 return (0);
181 }
182 offset = va & PGOFSET;
183 len = (NBPG - offset);
184 pa = PG_PA(pte) + offset;
185
186 done:
187 *pap = pa;
188 return (len);
189 }
190
191 /*
192 * Translate a physical address to a file-offset in the crash-dump.
193 */
194 off_t
195 _kvm_sun3x_pa2off(kd, pa)
196 kvm_t *kd;
197 u_long pa;
198 {
199 off_t off;
200 cpu_ram_seg_t *rsp;
201 register cpu_kcore_hdr_t *cpu_kh;
202
203 cpu_kh = kd->cpu_data;
204 off = 0;
205 for (rsp = cpu_kh->ram_segs; rsp->size; rsp++) {
206 if (pa >= rsp->start && pa < rsp->start + rsp->size) {
207 pa -= rsp->start;
208 break;
209 }
210 off += rsp->size;
211 }
212 return(kd->dump_off + off + pa);
213 }
214
215