kvm_sun3x.c revision 1.8 1 1.8 wiz /* $NetBSD: kvm_sun3x.c,v 1.8 2003/05/16 10:24:56 wiz Exp $ */
2 1.1 gwr
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gwr * by Gordon W. Ross.
9 1.1 gwr *
10 1.1 gwr * Redistribution and use in source and binary forms, with or without
11 1.1 gwr * modification, are permitted provided that the following conditions
12 1.1 gwr * are met:
13 1.1 gwr * 1. Redistributions of source code must retain the above copyright
14 1.1 gwr * notice, this list of conditions and the following disclaimer.
15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer in the
17 1.1 gwr * documentation and/or other materials provided with the distribution.
18 1.1 gwr * 3. All advertising materials mentioning features or use of this software
19 1.1 gwr * must display the following acknowledgement:
20 1.1 gwr * This product includes software developed by the NetBSD
21 1.1 gwr * Foundation, Inc. and its contributors.
22 1.1 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 gwr * contributors may be used to endorse or promote products derived
24 1.1 gwr * from this software without specific prior written permission.
25 1.1 gwr *
26 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 gwr */
38 1.1 gwr
39 1.4 mikel #include <sys/cdefs.h>
40 1.1 gwr #if defined(LIBC_SCCS) && !defined(lint)
41 1.1 gwr #if 0
42 1.1 gwr static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
43 1.1 gwr #else
44 1.8 wiz __RCSID("$NetBSD: kvm_sun3x.c,v 1.8 2003/05/16 10:24:56 wiz Exp $");
45 1.1 gwr #endif
46 1.1 gwr #endif /* LIBC_SCCS and not lint */
47 1.1 gwr
48 1.1 gwr /*
49 1.1 gwr * Sun3x machine dependent routines for kvm.
50 1.1 gwr *
51 1.1 gwr * Note: This file has to build on ALL m68k machines,
52 1.5 briggs * so do NOT include any <machine / *.h> files here.
53 1.1 gwr */
54 1.1 gwr
55 1.1 gwr #include <sys/types.h>
56 1.1 gwr #include <sys/kcore.h>
57 1.1 gwr
58 1.1 gwr #include <unistd.h>
59 1.1 gwr #include <limits.h>
60 1.1 gwr #include <nlist.h>
61 1.1 gwr #include <kvm.h>
62 1.1 gwr #include <db.h>
63 1.1 gwr
64 1.2 thorpej #include <m68k/kcore.h>
65 1.2 thorpej
66 1.1 gwr #include "kvm_private.h"
67 1.1 gwr #include "kvm_m68k.h"
68 1.1 gwr
69 1.1 gwr int _kvm_sun3x_initvtop __P((kvm_t *));
70 1.1 gwr void _kvm_sun3x_freevtop __P((kvm_t *));
71 1.1 gwr int _kvm_sun3x_kvatop __P((kvm_t *, u_long, u_long *));
72 1.1 gwr off_t _kvm_sun3x_pa2off __P((kvm_t *, u_long));
73 1.1 gwr
74 1.1 gwr struct kvm_ops _kvm_ops_sun3x = {
75 1.1 gwr _kvm_sun3x_initvtop,
76 1.1 gwr _kvm_sun3x_freevtop,
77 1.1 gwr _kvm_sun3x_kvatop,
78 1.1 gwr _kvm_sun3x_pa2off };
79 1.1 gwr
80 1.2 thorpej #define _kvm_kvas_size(h) \
81 1.2 thorpej (-((h)->kernbase))
82 1.2 thorpej #define _kvm_nkptes(h, v) \
83 1.2 thorpej (_kvm_kvas_size((h)) >> (v)->pgshift)
84 1.2 thorpej #define _kvm_pg_pa(pte, h) \
85 1.2 thorpej ((pte) & (h)->pg_frame)
86 1.1 gwr
87 1.1 gwr /*
88 1.1 gwr * Prepare for translation of kernel virtual addresses into offsets
89 1.1 gwr * into crash dump files. Nothing to do here.
90 1.1 gwr */
91 1.1 gwr int
92 1.1 gwr _kvm_sun3x_initvtop(kd)
93 1.1 gwr kvm_t *kd;
94 1.1 gwr {
95 1.1 gwr return (0);
96 1.1 gwr }
97 1.1 gwr
98 1.1 gwr void
99 1.1 gwr _kvm_sun3x_freevtop(kd)
100 1.1 gwr kvm_t *kd;
101 1.1 gwr {
102 1.1 gwr }
103 1.1 gwr
104 1.1 gwr /*
105 1.1 gwr * Translate a kernel virtual address to a physical address using the
106 1.1 gwr * mapping information in kd->vm. Returns the result in pa, and returns
107 1.6 simonb * the number of bytes that are contiguously available from this
108 1.8 wiz * physical address. This routine is used only for crash dumps.
109 1.1 gwr */
110 1.1 gwr int
111 1.1 gwr _kvm_sun3x_kvatop(kd, va, pap)
112 1.1 gwr kvm_t *kd;
113 1.1 gwr u_long va;
114 1.1 gwr u_long *pap;
115 1.1 gwr {
116 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
117 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
118 1.2 thorpej struct vmstate *v = kd->vmst;
119 1.1 gwr int idx, len, offset, pte;
120 1.1 gwr u_long pteva, pa;
121 1.1 gwr
122 1.1 gwr if (ISALIVE(kd)) {
123 1.1 gwr _kvm_err(kd, 0, "vatop called in live kernel!");
124 1.2 thorpej return(0);
125 1.1 gwr }
126 1.1 gwr
127 1.2 thorpej if (va < h->kernbase) {
128 1.1 gwr _kvm_err(kd, 0, "not a kernel address");
129 1.1 gwr return(0);
130 1.1 gwr }
131 1.1 gwr
132 1.1 gwr /*
133 1.1 gwr * If this VA is in the contiguous range, short-cut.
134 1.1 gwr * Note that this ends our recursion when we call
135 1.1 gwr * kvm_read to access the kernel page table, which
136 1.1 gwr * is guaranteed to be in the contiguous range.
137 1.1 gwr */
138 1.2 thorpej if (va < s->contig_end) {
139 1.3 gwr len = s->contig_end - va;
140 1.2 thorpej pa = va - h->kernbase;
141 1.1 gwr goto done;
142 1.1 gwr }
143 1.1 gwr
144 1.1 gwr /*
145 1.1 gwr * The KVA is beyond the contiguous range, so we must
146 1.1 gwr * read the PTE for this KVA from the page table.
147 1.1 gwr */
148 1.2 thorpej idx = ((va - h->kernbase) >> v->pgshift);
149 1.2 thorpej pteva = s->kernCbase + (idx * 4);
150 1.1 gwr if (kvm_read(kd, pteva, &pte, 4) != 4) {
151 1.1 gwr _kvm_err(kd, 0, "can not read PTE!");
152 1.1 gwr return (0);
153 1.1 gwr }
154 1.2 thorpej if ((pte & s->pg_valid) == 0) {
155 1.7 he _kvm_err(kd, 0, "page not valid (VA=0x%lx)", va);
156 1.1 gwr return (0);
157 1.1 gwr }
158 1.2 thorpej offset = va & v->pgofset;
159 1.2 thorpej len = (h->page_size - offset);
160 1.2 thorpej pa = _kvm_pg_pa(pte, s) + offset;
161 1.1 gwr
162 1.1 gwr done:
163 1.1 gwr *pap = pa;
164 1.1 gwr return (len);
165 1.1 gwr }
166 1.1 gwr
167 1.1 gwr /*
168 1.8 wiz * Translate a physical address to a file-offset in the crash dump.
169 1.1 gwr */
170 1.1 gwr off_t
171 1.1 gwr _kvm_sun3x_pa2off(kd, pa)
172 1.1 gwr kvm_t *kd;
173 1.1 gwr u_long pa;
174 1.1 gwr {
175 1.1 gwr off_t off;
176 1.2 thorpej phys_ram_seg_t *rsp;
177 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
178 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
179 1.1 gwr
180 1.1 gwr off = 0;
181 1.2 thorpej for (rsp = s->ram_segs; rsp->size; rsp++) {
182 1.1 gwr if (pa >= rsp->start && pa < rsp->start + rsp->size) {
183 1.1 gwr pa -= rsp->start;
184 1.1 gwr break;
185 1.1 gwr }
186 1.1 gwr off += rsp->size;
187 1.1 gwr }
188 1.2 thorpej return (kd->dump_off + off + pa);
189 1.1 gwr }
190 1.1 gwr
191