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