1 /* $NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
35 static char sccsid
[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
37 __RCSID("$NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos Exp $");
39 #endif /* LIBC_SCCS and not lint */
42 * Sun3x machine dependent routines for kvm.
44 * Note: This file has to build on ALL m68k machines,
45 * so do NOT include any <machine / *.h> files here.
47 #include <sys/param.h>
48 #include <sys/types.h>
49 #include <sys/kcore.h>
57 #include <m68k/kcore.h>
59 #include "kvm_private.h"
62 int _kvm_sun3x_initvtop(kvm_t
*);
63 void _kvm_sun3x_freevtop(kvm_t
*);
64 int _kvm_sun3x_kvatop (kvm_t
*, vaddr_t
, paddr_t
*);
65 off_t
_kvm_sun3x_pa2off (kvm_t
*, paddr_t
);
67 struct kvm_ops _kvm_ops_sun3x
= {
73 #define _kvm_kvas_size(h) \
75 #define _kvm_nkptes(h, v) \
76 (_kvm_kvas_size((h)) >> (v)->pgshift)
77 #define _kvm_pg_pa(pte, h) \
78 ((pte) & (h)->pg_frame)
81 * Prepare for translation of kernel virtual addresses into offsets
82 * into crash dump files. Nothing to do here.
85 _kvm_sun3x_initvtop(kvm_t
*kd
)
91 _kvm_sun3x_freevtop(kvm_t
*kd
)
96 * Translate a kernel virtual address to a physical address using the
97 * mapping information in kd->vm. Returns the result in pa, and returns
98 * the number of bytes that are contiguously available from this
99 * physical address. This routine is used only for crash dumps.
102 _kvm_sun3x_kvatop(kvm_t
*kd
, vaddr_t va
, paddr_t
*pap
)
104 cpu_kcore_hdr_t
*h
= kd
->cpu_data
;
105 struct sun3x_kcore_hdr
*s
= &h
->un
._sun3x
;
106 struct vmstate
*v
= kd
->vmst
;
107 int idx
, len
, offset
, pte
;
111 _kvm_err(kd
, 0, "vatop called in live kernel!");
115 if (va
< h
->kernbase
) {
116 _kvm_err(kd
, 0, "not a kernel address");
121 * If this VA is in the contiguous range, short-cut.
122 * Note that this ends our recursion when we call
123 * kvm_read to access the kernel page table, which
124 * is guaranteed to be in the contiguous range.
126 if (va
< s
->contig_end
) {
127 len
= s
->contig_end
- va
;
128 pa
= va
- h
->kernbase
;
133 * The KVA is beyond the contiguous range, so we must
134 * read the PTE for this KVA from the page table.
136 idx
= ((va
- h
->kernbase
) >> v
->pgshift
);
137 pteva
= s
->kernCbase
+ (idx
* 4);
138 if (kvm_read(kd
, pteva
, &pte
, 4) != 4) {
139 _kvm_err(kd
, 0, "can not read PTE!");
142 if ((pte
& s
->pg_valid
) == 0) {
143 _kvm_err(kd
, 0, "page not valid (VA=0x%lx)", va
);
146 offset
= va
& v
->pgofset
;
147 len
= (h
->page_size
- offset
);
148 pa
= _kvm_pg_pa(pte
, s
) + offset
;
156 * Translate a physical address to a file-offset in the crash dump.
159 _kvm_sun3x_pa2off(kvm_t
*kd
, paddr_t pa
)
163 cpu_kcore_hdr_t
*h
= kd
->cpu_data
;
164 struct sun3x_kcore_hdr
*s
= &h
->un
._sun3x
;
167 for (rsp
= s
->ram_segs
; rsp
->size
; rsp
++) {
168 if (pa
>= rsp
->start
&& pa
< rsp
->start
+ rsp
->size
) {
174 return (kd
->dump_off
+ off
+ pa
);