kvm_sun3x.c revision 1.12 1 1.12 christos /* $NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos 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.12 christos __RCSID("$NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos 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.12 christos #include <sys/param.h>
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.10 jym int _kvm_sun3x_initvtop(kvm_t *);
63 1.10 jym void _kvm_sun3x_freevtop(kvm_t *);
64 1.11 jym int _kvm_sun3x_kvatop (kvm_t *, vaddr_t, paddr_t *);
65 1.11 jym off_t _kvm_sun3x_pa2off (kvm_t *, paddr_t);
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.10 jym _kvm_sun3x_initvtop(kvm_t *kd)
86 1.1 gwr {
87 1.10 jym return 0;
88 1.1 gwr }
89 1.1 gwr
90 1.1 gwr void
91 1.10 jym _kvm_sun3x_freevtop(kvm_t *kd)
92 1.1 gwr {
93 1.1 gwr }
94 1.1 gwr
95 1.1 gwr /*
96 1.1 gwr * Translate a kernel virtual address to a physical address using the
97 1.1 gwr * mapping information in kd->vm. Returns the result in pa, and returns
98 1.6 simonb * the number of bytes that are contiguously available from this
99 1.8 wiz * physical address. This routine is used only for crash dumps.
100 1.1 gwr */
101 1.1 gwr int
102 1.11 jym _kvm_sun3x_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pap)
103 1.1 gwr {
104 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
105 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
106 1.2 thorpej struct vmstate *v = kd->vmst;
107 1.1 gwr int idx, len, offset, pte;
108 1.1 gwr u_long pteva, pa;
109 1.1 gwr
110 1.1 gwr if (ISALIVE(kd)) {
111 1.1 gwr _kvm_err(kd, 0, "vatop called in live kernel!");
112 1.2 thorpej return(0);
113 1.1 gwr }
114 1.1 gwr
115 1.2 thorpej if (va < h->kernbase) {
116 1.1 gwr _kvm_err(kd, 0, "not a kernel address");
117 1.1 gwr return(0);
118 1.1 gwr }
119 1.1 gwr
120 1.1 gwr /*
121 1.1 gwr * If this VA is in the contiguous range, short-cut.
122 1.1 gwr * Note that this ends our recursion when we call
123 1.1 gwr * kvm_read to access the kernel page table, which
124 1.1 gwr * is guaranteed to be in the contiguous range.
125 1.1 gwr */
126 1.2 thorpej if (va < s->contig_end) {
127 1.3 gwr len = s->contig_end - va;
128 1.2 thorpej pa = va - h->kernbase;
129 1.1 gwr goto done;
130 1.1 gwr }
131 1.1 gwr
132 1.1 gwr /*
133 1.1 gwr * The KVA is beyond the contiguous range, so we must
134 1.1 gwr * read the PTE for this KVA from the page table.
135 1.1 gwr */
136 1.2 thorpej idx = ((va - h->kernbase) >> v->pgshift);
137 1.2 thorpej pteva = s->kernCbase + (idx * 4);
138 1.1 gwr if (kvm_read(kd, pteva, &pte, 4) != 4) {
139 1.1 gwr _kvm_err(kd, 0, "can not read PTE!");
140 1.1 gwr return (0);
141 1.1 gwr }
142 1.2 thorpej if ((pte & s->pg_valid) == 0) {
143 1.7 he _kvm_err(kd, 0, "page not valid (VA=0x%lx)", va);
144 1.1 gwr return (0);
145 1.1 gwr }
146 1.2 thorpej offset = va & v->pgofset;
147 1.2 thorpej len = (h->page_size - offset);
148 1.2 thorpej pa = _kvm_pg_pa(pte, s) + offset;
149 1.1 gwr
150 1.1 gwr done:
151 1.1 gwr *pap = pa;
152 1.1 gwr return (len);
153 1.1 gwr }
154 1.1 gwr
155 1.1 gwr /*
156 1.8 wiz * Translate a physical address to a file-offset in the crash dump.
157 1.1 gwr */
158 1.1 gwr off_t
159 1.11 jym _kvm_sun3x_pa2off(kvm_t *kd, paddr_t pa)
160 1.1 gwr {
161 1.1 gwr off_t off;
162 1.2 thorpej phys_ram_seg_t *rsp;
163 1.2 thorpej cpu_kcore_hdr_t *h = kd->cpu_data;
164 1.2 thorpej struct sun3x_kcore_hdr *s = &h->un._sun3x;
165 1.1 gwr
166 1.1 gwr off = 0;
167 1.2 thorpej for (rsp = s->ram_segs; rsp->size; rsp++) {
168 1.1 gwr if (pa >= rsp->start && pa < rsp->start + rsp->size) {
169 1.1 gwr pa -= rsp->start;
170 1.1 gwr break;
171 1.1 gwr }
172 1.1 gwr off += rsp->size;
173 1.1 gwr }
174 1.2 thorpej return (kd->dump_off + off + pa);
175 1.1 gwr }
176 1.1 gwr
177