1 /* $NetBSD: kvm_sparc64.c,v 1.12 2008/01/15 13:57:42 ad Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software developed by the Computer Systems
8 * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9 * BG 91-66 and contributed to Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
37 #if defined(LIBC_SCCS) && !defined(lint)
39 static char sccsid
[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
41 __RCSID("$NetBSD: kvm_sparc64.c,v 1.12 2008/01/15 13:57:42 ad Exp $");
43 #endif /* LIBC_SCCS and not lint */
46 * Sparc machine dependent routines for kvm. Hopefully, the forthcoming
47 * vm code will one day obsolete this module.
50 #include <sys/param.h>
56 #include <sys/kcore.h>
61 #include <uvm/uvm_extern.h>
63 #include <machine/pmap.h>
64 #include <machine/kcore.h>
65 #include <machine/vmparam.h>
70 #include "kvm_private.h"
72 int _kvm_kvatop
__P((kvm_t
*, u_long
, u_long
*));
79 _kvm_err(kd
, kd
->program
, "_kvm_freevtop: internal error");
85 * Prepare for translation of kernel virtual addresses into offsets
86 * into crash dump files. We use the MMU specific goop written at the
87 * front of the crash dump by pmap_dumpmmu().
89 * We should read in and cache the ksegs here to speed up operations...
101 * Translate a kernel virtual address to a physical address using the
102 * mapping information in kd->vm. Returns the result in pa, and returns
103 * the number of bytes that are contiguously available from this
104 * physical address. This routine is used only for crash dumps.
107 _kvm_kvatop(kd
, va
, pa
)
112 cpu_kcore_hdr_t
*cpup
= kd
->cpu_data
;
113 u_long kernbase
= cpup
->kernbase
;
114 uint64_t *pseg
, *pdir
, *ptbl
;
115 struct cpu_kcore_4mbseg
*ktlb
;
122 /* Handle the wired 4MB TTEs and per-CPU mappings */
123 if (cpup
->memsegoffset
> sizeof(cpu_kcore_hdr_t
) &&
124 cpup
->newmagic
== SPARC64_KCORE_NEWMAGIC
) {
126 * new format: we have a list of 4 MB mappings
128 ktlb
= (struct cpu_kcore_4mbseg
*)
129 ((uintptr_t)kd
->cpu_data
+ cpup
->off4mbsegs
);
130 for (i
= 0; i
< cpup
->num4mbsegs
; i
++) {
131 uint64_t start
= ktlb
[i
].va
;
132 if (va
< start
|| va
>= start
+PAGE_SIZE_4M
)
134 *pa
= ktlb
[i
].pa
+ va
- start
;
135 return (int)(start
+PAGE_SIZE_4M
- va
);
138 if (cpup
->numcpuinfos
> 0) {
139 /* we have per-CPU mapping info */
140 uint64_t start
, base
;
142 base
= cpup
->cpubase
- 32*1024;
143 if (va
>= base
&& va
< (base
+ cpup
->percpusz
)) {
146 + cpup
->thiscpu
*cpup
->percpusz
148 return cpup
->percpusz
- start
;
153 * old format: just a textbase/size and database/size
155 if (va
> cpup
->ktextbase
&& va
<
156 (cpup
->ktextbase
+ cpup
->ktextsz
)) {
159 vaddr
= va
- cpup
->ktextbase
;
160 *pa
= cpup
->ktextp
+ vaddr
;
161 return (int)(cpup
->ktextsz
- vaddr
);
163 if (va
> cpup
->kdatabase
&& va
<
164 (cpup
->kdatabase
+ cpup
->kdatasz
)) {
167 vaddr
= va
- cpup
->kdatabase
;
168 *pa
= cpup
->kdatap
+ vaddr
;
169 return (int)(cpup
->kdatasz
- vaddr
);
174 * Parse kernel page table.
176 pseg
= (uint64_t *)(u_long
)cpup
->segmapoffset
;
177 if (_kvm_pread(kd
, kd
->pmfd
, &pdir
, sizeof(pdir
),
178 _kvm_pa2off(kd
, (u_long
)&pseg
[va_to_seg(va
)]))
180 _kvm_syserr(kd
, 0, "could not read L1 PTE");
185 _kvm_err(kd
, 0, "invalid L1 PTE");
189 if (_kvm_pread(kd
, kd
->pmfd
, &ptbl
, sizeof(ptbl
),
190 _kvm_pa2off(kd
, (u_long
)&pdir
[va_to_dir(va
)]))
192 _kvm_syserr(kd
, 0, "could not read L2 PTE");
197 _kvm_err(kd
, 0, "invalid L2 PTE");
201 if (_kvm_pread(kd
, kd
->pmfd
, &data
, sizeof(data
),
202 _kvm_pa2off(kd
, (u_long
)&ptbl
[va_to_pte(va
)]))
204 _kvm_syserr(kd
, 0, "could not read TTE");
209 _kvm_err(kd
, 0, "invalid L2 TTE");
214 * Calculate page offsets and things.
216 * XXXX -- We could support multiple page sizes.
218 va
= va
& (kd
->nbpg
- 1);
223 * Parse and trnslate our TTE.
226 return (int)(kd
->nbpg
- va
);
230 _kvm_err(kd
, 0, "invalid address (%lx)", va
);
236 * Translate a physical address to a file-offset in the crash dump.
243 cpu_kcore_hdr_t
*cpup
= kd
->cpu_data
;
249 * Layout of CPU segment:
252 * phys_ram_seg_t[cpup->nmemseg];
254 mp
= (phys_ram_seg_t
*)((long)kd
->cpu_data
+ cpup
->memsegoffset
);
257 /* Translate (sparse) pfnum to (packed) dump offset */
258 for (nmem
= cpup
->nmemseg
; --nmem
>= 0; mp
++) {
259 if (mp
->start
<= pa
&& pa
< mp
->start
+ mp
->size
)
264 _kvm_err(kd
, 0, "invalid address (%lx)", pa
);
268 return (kd
->dump_off
+ off
+ pa
- mp
->start
);
272 * Machine-dependent initialization for ALL open kvm descriptors,
273 * not just those for a kernel crash dump. Some architectures
274 * have to deal with these NOT being constants! (i.e. m68k)
281 extern struct ps_strings
*__ps_strings
;
283 max_uva
= (u_long
) (__ps_strings
+ 1);
284 kd
->usrstack
= max_uva
;
285 kd
->max_uva
= max_uva
;