kvm_sun3x.c revision 1.3 1 1.3 gwr /* $NetBSD: kvm_sun3x.c,v 1.3 1997/07/17 22:42:00 gwr 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.1 gwr #if defined(LIBC_SCCS) && !defined(lint)
40 1.1 gwr #if 0
41 1.1 gwr static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
42 1.1 gwr #else
43 1.3 gwr static char *rcsid = "$NetBSD: kvm_sun3x.c,v 1.3 1997/07/17 22:42:00 gwr Exp $";
44 1.1 gwr #endif
45 1.1 gwr #endif /* LIBC_SCCS and not lint */
46 1.1 gwr
47 1.1 gwr /*
48 1.1 gwr * Sun3x machine dependent routines for kvm.
49 1.1 gwr *
50 1.1 gwr * Note: This file has to build on ALL m68k machines,
51 1.1 gwr * so do NOT include any <machine/*.h> files here.
52 1.1 gwr */
53 1.1 gwr
54 1.1 gwr #include <sys/types.h>
55 1.1 gwr #include <sys/kcore.h>
56 1.1 gwr
57 1.1 gwr #include <unistd.h>
58 1.1 gwr #include <limits.h>
59 1.1 gwr #include <nlist.h>
60 1.1 gwr #include <kvm.h>
61 1.1 gwr #include <db.h>
62 1.1 gwr
63 1.2 thorpej #include <m68k/kcore.h>
64 1.2 thorpej
65 1.1 gwr #include "kvm_private.h"
66 1.1 gwr #include "kvm_m68k.h"
67 1.1 gwr
68 1.1 gwr int _kvm_sun3x_initvtop __P((kvm_t *));
69 1.1 gwr void _kvm_sun3x_freevtop __P((kvm_t *));
70 1.1 gwr int _kvm_sun3x_kvatop __P((kvm_t *, u_long, u_long *));
71 1.1 gwr off_t _kvm_sun3x_pa2off __P((kvm_t *, u_long));
72 1.1 gwr
73 1.1 gwr struct kvm_ops _kvm_ops_sun3x = {
74 1.1 gwr _kvm_sun3x_initvtop,
75 1.1 gwr _kvm_sun3x_freevtop,
76 1.1 gwr _kvm_sun3x_kvatop,
77 1.1 gwr _kvm_sun3x_pa2off };
78 1.1 gwr
79 1.2 thorpej #define _kvm_kvas_size(h) \
80 1.2 thorpej (-((h)->kernbase))
81 1.2 thorpej #define _kvm_nkptes(h, v) \
82 1.2 thorpej (_kvm_kvas_size((h)) >> (v)->pgshift)
83 1.2 thorpej #define _kvm_pg_pa(pte, h) \
84 1.2 thorpej ((pte) & (h)->pg_frame)
85 1.1 gwr
86 1.1 gwr /*
87 1.1 gwr * Prepare for translation of kernel virtual addresses into offsets
88 1.1 gwr * into crash dump files. Nothing to do here.
89 1.1 gwr */
90 1.1 gwr int
91 1.1 gwr _kvm_sun3x_initvtop(kd)
92 1.1 gwr kvm_t *kd;
93 1.1 gwr {
94 1.1 gwr return (0);
95 1.1 gwr }
96 1.1 gwr
97 1.1 gwr void
98 1.1 gwr _kvm_sun3x_freevtop(kd)
99 1.1 gwr kvm_t *kd;
100 1.1 gwr {
101 1.1 gwr }
102 1.1 gwr
103 1.1 gwr /*
104 1.1 gwr * Translate a kernel virtual address to a physical address using the
105 1.1 gwr * mapping information in kd->vm. Returns the result in pa, and returns
106 1.1 gwr * the number of bytes that are contiguously available from this
107 1.1 gwr * physical address. This routine is used only for crashdumps.
108 1.1 gwr */
109 1.1 gwr int
110 1.1 gwr _kvm_sun3x_kvatop(kd, va, pap)
111 1.1 gwr kvm_t *kd;
112 1.1 gwr u_long va;
113 1.1 gwr u_long *pap;
114 1.1 gwr {
115 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
116 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
117 1.2 thorpej struct vmstate *v = kd->vmst;
118 1.1 gwr int idx, len, offset, pte;
119 1.1 gwr u_long pteva, pa;
120 1.1 gwr
121 1.1 gwr if (ISALIVE(kd)) {
122 1.1 gwr _kvm_err(kd, 0, "vatop called in live kernel!");
123 1.2 thorpej return(0);
124 1.1 gwr }
125 1.1 gwr
126 1.2 thorpej if (va < h->kernbase) {
127 1.1 gwr _kvm_err(kd, 0, "not a kernel address");
128 1.1 gwr return(0);
129 1.1 gwr }
130 1.1 gwr
131 1.1 gwr /*
132 1.1 gwr * If this VA is in the contiguous range, short-cut.
133 1.1 gwr * Note that this ends our recursion when we call
134 1.1 gwr * kvm_read to access the kernel page table, which
135 1.1 gwr * is guaranteed to be in the contiguous range.
136 1.1 gwr */
137 1.2 thorpej if (va < s->contig_end) {
138 1.3 gwr len = s->contig_end - va;
139 1.2 thorpej pa = va - h->kernbase;
140 1.1 gwr goto done;
141 1.1 gwr }
142 1.1 gwr
143 1.1 gwr /*
144 1.1 gwr * The KVA is beyond the contiguous range, so we must
145 1.1 gwr * read the PTE for this KVA from the page table.
146 1.1 gwr */
147 1.2 thorpej idx = ((va - h->kernbase) >> v->pgshift);
148 1.2 thorpej pteva = s->kernCbase + (idx * 4);
149 1.1 gwr if (kvm_read(kd, pteva, &pte, 4) != 4) {
150 1.1 gwr _kvm_err(kd, 0, "can not read PTE!");
151 1.1 gwr return (0);
152 1.1 gwr }
153 1.2 thorpej if ((pte & s->pg_valid) == 0) {
154 1.1 gwr _kvm_err(kd, 0, "page not valid (VA=0x%x)", va);
155 1.1 gwr return (0);
156 1.1 gwr }
157 1.2 thorpej offset = va & v->pgofset;
158 1.2 thorpej len = (h->page_size - offset);
159 1.2 thorpej pa = _kvm_pg_pa(pte, s) + offset;
160 1.1 gwr
161 1.1 gwr done:
162 1.1 gwr *pap = pa;
163 1.1 gwr return (len);
164 1.1 gwr }
165 1.1 gwr
166 1.1 gwr /*
167 1.1 gwr * Translate a physical address to a file-offset in the crash-dump.
168 1.1 gwr */
169 1.1 gwr off_t
170 1.1 gwr _kvm_sun3x_pa2off(kd, pa)
171 1.1 gwr kvm_t *kd;
172 1.1 gwr u_long pa;
173 1.1 gwr {
174 1.1 gwr off_t off;
175 1.2 thorpej phys_ram_seg_t *rsp;
176 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
177 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
178 1.1 gwr
179 1.1 gwr off = 0;
180 1.2 thorpej for (rsp = s->ram_segs; rsp->size; rsp++) {
181 1.1 gwr if (pa >= rsp->start && pa < rsp->start + rsp->size) {
182 1.1 gwr pa -= rsp->start;
183 1.1 gwr break;
184 1.1 gwr }
185 1.1 gwr off += rsp->size;
186 1.1 gwr }
187 1.2 thorpej return (kd->dump_off + off + pa);
188 1.1 gwr }
189 1.1 gwr
190