kvm_sparc64.c revision 1.4 1 1.4 mrg /* $NetBSD: kvm_sparc64.c,v 1.4 2000/06/29 06:34:26 mrg Exp $ */
2 1.1 eeh
3 1.1 eeh /*-
4 1.1 eeh * Copyright (c) 1992, 1993
5 1.1 eeh * The Regents of the University of California. All rights reserved.
6 1.1 eeh *
7 1.1 eeh * This code is derived from software developed by the Computer Systems
8 1.1 eeh * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9 1.1 eeh * BG 91-66 and contributed to Berkeley.
10 1.1 eeh *
11 1.1 eeh * Redistribution and use in source and binary forms, with or without
12 1.1 eeh * modification, are permitted provided that the following conditions
13 1.1 eeh * are met:
14 1.1 eeh * 1. Redistributions of source code must retain the above copyright
15 1.1 eeh * notice, this list of conditions and the following disclaimer.
16 1.1 eeh * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 eeh * notice, this list of conditions and the following disclaimer in the
18 1.1 eeh * documentation and/or other materials provided with the distribution.
19 1.1 eeh * 3. All advertising materials mentioning features or use of this software
20 1.1 eeh * must display the following acknowledgement:
21 1.1 eeh * This product includes software developed by the University of
22 1.1 eeh * California, Berkeley and its contributors.
23 1.1 eeh * 4. Neither the name of the University nor the names of its contributors
24 1.1 eeh * may be used to endorse or promote products derived from this software
25 1.1 eeh * without specific prior written permission.
26 1.1 eeh *
27 1.1 eeh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 eeh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 eeh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 eeh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 eeh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 eeh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 eeh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 eeh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 eeh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 eeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 eeh * SUCH DAMAGE.
38 1.1 eeh */
39 1.1 eeh
40 1.1 eeh #include <sys/cdefs.h>
41 1.1 eeh #if defined(LIBC_SCCS) && !defined(lint)
42 1.1 eeh #if 0
43 1.1 eeh static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
44 1.1 eeh #else
45 1.4 mrg __RCSID("$NetBSD: kvm_sparc64.c,v 1.4 2000/06/29 06:34:26 mrg Exp $");
46 1.1 eeh #endif
47 1.1 eeh #endif /* LIBC_SCCS and not lint */
48 1.1 eeh
49 1.1 eeh /*
50 1.2 simonb * Sparc machine dependent routines for kvm. Hopefully, the forthcoming
51 1.1 eeh * vm code will one day obsolete this module.
52 1.1 eeh */
53 1.1 eeh
54 1.1 eeh #include <sys/param.h>
55 1.1 eeh #include <sys/exec.h>
56 1.1 eeh #include <sys/user.h>
57 1.1 eeh #include <sys/proc.h>
58 1.1 eeh #include <sys/stat.h>
59 1.1 eeh #include <sys/core.h>
60 1.1 eeh #include <sys/kcore.h>
61 1.1 eeh #include <unistd.h>
62 1.1 eeh #include <nlist.h>
63 1.1 eeh #include <kvm.h>
64 1.1 eeh
65 1.4 mrg #include <uvm/uvm_extern.h>
66 1.3 mrg
67 1.1 eeh #include <machine/kcore.h>
68 1.1 eeh
69 1.1 eeh #include <limits.h>
70 1.1 eeh #include <db.h>
71 1.1 eeh
72 1.1 eeh #include "kvm_private.h"
73 1.1 eeh
74 1.1 eeh int _kvm_kvatop __P((kvm_t *, u_long, u_long *));
75 1.1 eeh
76 1.1 eeh void
77 1.1 eeh _kvm_freevtop(kd)
78 1.1 eeh kvm_t *kd;
79 1.1 eeh {
80 1.1 eeh if (kd->vmst != 0) {
81 1.1 eeh _kvm_err(kd, kd->program, "_kvm_freevtop: internal error");
82 1.1 eeh kd->vmst = 0;
83 1.1 eeh }
84 1.1 eeh }
85 1.1 eeh
86 1.1 eeh /*
87 1.1 eeh * Prepare for translation of kernel virtual addresses into offsets
88 1.1 eeh * into crash dump files. We use the MMU specific goop written at the
89 1.1 eeh * front of the crash dump by pmap_dumpmmu().
90 1.1 eeh */
91 1.1 eeh int
92 1.1 eeh _kvm_initvtop(kd)
93 1.1 eeh kvm_t *kd;
94 1.1 eeh {
95 1.1 eeh kd->nbpg = 8196;
96 1.1 eeh return (0);
97 1.1 eeh }
98 1.1 eeh
99 1.1 eeh /*
100 1.1 eeh * Translate a kernel virtual address to a physical address using the
101 1.1 eeh * mapping information in kd->vm. Returns the result in pa, and returns
102 1.2 simonb * the number of bytes that are contiguously available from this
103 1.1 eeh * physical address. This routine is used only for crashdumps.
104 1.1 eeh */
105 1.1 eeh int
106 1.1 eeh _kvm_kvatop(kd, va, pa)
107 1.1 eeh kvm_t *kd;
108 1.1 eeh u_long va;
109 1.1 eeh u_long *pa;
110 1.1 eeh {
111 1.1 eeh cpu_kcore_hdr_t *cpup = kd->cpu_data;
112 1.1 eeh u_long kernbase = cpup->kernbase;
113 1.1 eeh
114 1.1 eeh if (va < kernbase)
115 1.1 eeh goto err;
116 1.1 eeh
117 1.1 eeh /* Handle the wired 4MB TTE */
118 1.1 eeh if (va > cpup->kernbase && va < cpup->kernbase + 4*1024*1024) {
119 1.1 eeh u_long vaddr;
120 1.1 eeh
121 1.1 eeh vaddr = va - cpup->kernbase;
122 1.1 eeh *pa = cpup->kphys + va;
123 1.1 eeh return (4*1024*1024 - va);
124 1.2 simonb }
125 1.1 eeh #if 0
126 1.1 eeh /*
127 1.1 eeh * Layout of CPU segment:
128 1.1 eeh * cpu_kcore_hdr_t;
129 1.1 eeh * [alignment]
130 1.1 eeh * phys_ram_seg_t[cpup->nmemseg];
131 1.1 eeh * segmap[cpup->nsegmap];
132 1.1 eeh * ptes[cpup->npmegs];
133 1.1 eeh */
134 1.1 eeh segmaps = (struct segmap *)((long)kd->cpu_data + cpup->segmapoffset);
135 1.1 eeh ptes = (int *)((int)kd->cpu_data + cpup->pmegoffset);
136 1.1 eeh nkreg = ((int)((-(unsigned)kernbase) / NBPRG));
137 1.1 eeh nureg = 256 - nkreg;
138 1.1 eeh
139 1.1 eeh vr = VA_VREG(va);
140 1.1 eeh vs = VA_VSEG(va);
141 1.1 eeh
142 1.1 eeh sp = &segmaps[(vr-nureg)*NSEGRG + vs];
143 1.1 eeh if (sp->sg_npte == 0)
144 1.1 eeh goto err;
145 1.1 eeh if (sp->sg_pmeg == cpup->npmeg - 1) /* =seginval */
146 1.1 eeh goto err;
147 1.1 eeh pte = ptes[sp->sg_pmeg * nptesg + VA_VPG(va)];
148 1.1 eeh if ((pte & PG_V) != 0) {
149 1.1 eeh long p, off = VA_OFF(va);
150 1.1 eeh
151 1.1 eeh p = (pte & PG_PFNUM) << pgshift;
152 1.1 eeh *pa = p + off;
153 1.1 eeh return (kd->nbpg - off);
154 1.1 eeh }
155 1.1 eeh #endif
156 1.1 eeh err:
157 1.1 eeh _kvm_err(kd, 0, "invalid address (%x)", va);
158 1.1 eeh return (0);
159 1.1 eeh }
160 1.1 eeh
161 1.1 eeh
162 1.2 simonb /*
163 1.1 eeh * Translate a physical address to a file-offset in the crash-dump.
164 1.2 simonb */
165 1.1 eeh off_t
166 1.1 eeh _kvm_pa2off(kd, pa)
167 1.1 eeh kvm_t *kd;
168 1.1 eeh u_long pa;
169 1.1 eeh {
170 1.1 eeh cpu_kcore_hdr_t *cpup = kd->cpu_data;
171 1.1 eeh phys_ram_seg_t *mp;
172 1.1 eeh off_t off;
173 1.1 eeh int nmem;
174 1.1 eeh
175 1.1 eeh /*
176 1.1 eeh * Layout of CPU segment:
177 1.1 eeh * cpu_kcore_hdr_t;
178 1.1 eeh * [alignment]
179 1.1 eeh * phys_ram_seg_t[cpup->nmemseg];
180 1.1 eeh */
181 1.1 eeh mp = (phys_ram_seg_t *)((long)kd->cpu_data + cpup->memsegoffset);
182 1.1 eeh off = 0;
183 1.1 eeh
184 1.1 eeh /* Translate (sparse) pfnum to (packed) dump offset */
185 1.1 eeh for (nmem = cpup->nmemseg; --nmem >= 0; mp++) {
186 1.1 eeh if (mp->start <= pa && pa < mp->start + mp->size)
187 1.1 eeh break;
188 1.1 eeh off += mp->size;
189 1.1 eeh }
190 1.1 eeh if (nmem < 0) {
191 1.1 eeh _kvm_err(kd, 0, "invalid address (%x)", pa);
192 1.1 eeh return (-1);
193 1.1 eeh }
194 1.1 eeh
195 1.1 eeh return (kd->dump_off + off + pa - mp->start);
196 1.1 eeh }
197 1.1 eeh
198 1.1 eeh /*
199 1.1 eeh * Machine-dependent initialization for ALL open kvm descriptors,
200 1.1 eeh * not just those for a kernel crash dump. Some architectures
201 1.1 eeh * have to deal with these NOT being constants! (i.e. m68k)
202 1.1 eeh */
203 1.1 eeh int
204 1.1 eeh _kvm_mdopen(kd)
205 1.1 eeh kvm_t *kd;
206 1.1 eeh {
207 1.1 eeh u_long max_uva;
208 1.1 eeh extern struct ps_strings *__ps_strings;
209 1.1 eeh
210 1.1 eeh max_uva = (u_long) (__ps_strings + 1);
211 1.1 eeh kd->usrstack = max_uva;
212 1.1 eeh kd->max_uva = max_uva;
213 1.1 eeh kd->min_uva = 0;
214 1.1 eeh
215 1.1 eeh return (0);
216 1.1 eeh }
217