2 * Copyright (c) 1989, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software developed by the Computer Systems
6 * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
7 * BG 91-66 and contributed to Berkeley.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * from: FreeBSD: src/lib/libkvm/kvm_i386.c,v 1.15 2001/10/10 17:48:43
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
43 #if defined(LIBC_SCCS) && !defined(lint)
45 static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
47 #endif /* LIBC_SCCS and not lint */
50 * sparc64 machine dependent routines for kvm.
53 #include <sys/param.h>
63 #include <vm/vm_param.h>
65 #include <machine/kerneldump.h>
66 #include <machine/tte.h>
67 #include <machine/tlb.h>
68 #include <machine/tsb.h>
72 #include "kvm_private.h"
75 #define btop(x) (sparc64_btop(x))
76 #define ptob(x) (sparc64_ptob(x))
81 vm_size_t vm_tsb_mask;
83 struct sparc64_dump_reg *vm_regions;
87 _kvm_freevtop(kvm_t *kd)
90 free(kd->vmst->vm_regions);
96 _kvm_read_phys(kvm_t *kd, off_t pos, void *buf, size_t size)
99 /* XXX This has to be a raw file read, kvm_read is virtual. */
100 if (lseek(kd->pmfd, pos, SEEK_SET) == -1) {
101 _kvm_syserr(kd, kd->program, "_kvm_read_phys: lseek");
104 if (read(kd->pmfd, buf, size) != size) {
105 _kvm_syserr(kd, kd->program, "_kvm_read_phys: read");
112 _kvm_reg_cmp(const void *a, const void *b)
114 const struct sparc64_dump_reg *ra, *rb;
118 if (ra->dr_pa < rb->dr_pa)
120 else if (ra->dr_pa >= rb->dr_pa + rb->dr_size)
126 #define KVM_OFF_NOTFOUND 0
129 _kvm_find_off(struct vmstate *vm, vm_offset_t pa, vm_size_t size)
131 struct sparc64_dump_reg *reg, key;
135 reg = bsearch(&key, vm->vm_regions, vm->vm_nregions,
136 sizeof(*vm->vm_regions), _kvm_reg_cmp);
138 return (KVM_OFF_NOTFOUND);
140 if (o + size > reg->dr_size)
141 return (KVM_OFF_NOTFOUND);
142 return (reg->dr_offs + o);
146 _kvm_initvtop(kvm_t *kd)
148 struct sparc64_dump_hdr hdr;
149 struct sparc64_dump_reg *regs;
155 vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
157 _kvm_err(kd, kd->program, "cannot allocate vm");
162 if (!_kvm_read_phys(kd, 0, &hdr, sizeof(hdr)))
166 regsz = hdr.dh_nregions * sizeof(*regs);
167 regs = _kvm_malloc(kd, regsz);
169 _kvm_err(kd, kd->program, "cannot allocate regions");
172 if (!_kvm_read_phys(kd, sizeof(hdr), regs, regsz))
174 qsort(regs, hdr.dh_nregions, sizeof(*regs), _kvm_reg_cmp);
176 vm->vm_tsb_mask = hdr.dh_tsb_mask;
177 vm->vm_regions = regs;
178 vm->vm_nregions = hdr.dh_nregions;
179 vm->vm_tsb_off = _kvm_find_off(vm, hdr.dh_tsb_pa, hdr.dh_tsb_size);
180 if (vm->vm_tsb_off == KVM_OFF_NOTFOUND) {
181 _kvm_err(kd, kd->program, "tsb not found in dump");
194 _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa)
198 off_t tte_off, pa_off;
202 pg_off = va & PAGE_MASK;
203 if (va >= VM_MIN_DIRECT_ADDRESS)
204 pa_off = TLB_DIRECT_TO_PHYS(va) & ~PAGE_MASK;
207 tte_off = kd->vmst->vm_tsb_off +
208 ((vpn & kd->vmst->vm_tsb_mask) << TTE_SHIFT);
209 if (!_kvm_read_phys(kd, tte_off, &tte, sizeof(tte)))
211 if (!tte_match(&tte, va))
213 pa_off = TTE_GET_PA(&tte);
215 rest = PAGE_SIZE - pg_off;
216 pa_off = _kvm_find_off(kd->vmst, pa_off, rest);
217 if (pa_off == KVM_OFF_NOTFOUND)
219 *pa = pa_off + pg_off;
223 _kvm_err(kd, 0, "invalid address (%x)", va);