summaryrefslogtreecommitdiff
path: root/lib/libkvm
diff options
context:
space:
mode:
authorEric Jackson <ericj@cvs.openbsd.org>2000-11-08 18:40:49 +0000
committerEric Jackson <ericj@cvs.openbsd.org>2000-11-08 18:40:49 +0000
commitfaccf98b9f52e4311f730c37ba93f1b0646b0c8d (patch)
tree4818cba232e05dfc76267a61700424b46539061f /lib/libkvm
parent9d2c7b44d39473e225e3229baec13c127ff2e69c (diff)
adjust for changes to kcore, and dynamically compute page shift.
from NetBSD. art@ OK
Diffstat (limited to 'lib/libkvm')
-rw-r--r--lib/libkvm/kvm_alpha.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/lib/libkvm/kvm_alpha.c b/lib/libkvm/kvm_alpha.c
index 54ffa5efbc0..ee7b749a50e 100644
--- a/lib/libkvm/kvm_alpha.c
+++ b/lib/libkvm/kvm_alpha.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_alpha.c,v 1.4 2000/06/09 04:01:50 ericj Exp $ */
+/* $OpenBSD: kvm_alpha.c,v 1.5 2000/11/08 18:40:48 ericj Exp $ */
/* $NetBSD: kvm_alpha.c,v 1.5 1996/10/01 21:12:05 cgd Exp $ */
/*
@@ -28,6 +28,8 @@
* rights to redistribute these changes.
*/
+#define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
+
#include <sys/param.h>
#include <sys/user.h>
#include <sys/proc.h>
@@ -46,6 +48,10 @@
#include "kvm_private.h"
+struct vmstate {
+ vsize_t page_shift;
+};
+
void
_kvm_freevtop(kd)
kvm_t *kd;
@@ -60,7 +66,25 @@ int
_kvm_initvtop(kd)
kvm_t *kd;
{
+ cpu_kcore_hdr_t *cpu_kh;
+ struct vmstate *vm;
+
+ vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
+ if (vm == NULL)
+ return (-1);
+
+ cpu_kh = kd->cpu_data;
+
+ /* Compute page_shift. */
+ for (vm->page_shift = 0; (1L << vm->page_shift) < cpu_kh->page_size;
+ vm->page_shift++)
+ /* nothing */ ;
+ if ((1L << vm->page_shift) != cpu_kh->page_size) {
+ free(vm);
+ return (-1);
+ }
+ kd->vmst = vm;
return (0);
}
@@ -71,6 +95,7 @@ _kvm_kvatop(kd, va, pa)
u_long *pa;
{
cpu_kcore_hdr_t *cpu_kh;
+ struct vmstate *vm;
int rv, page_off;
alpha_pt_entry_t pte;
off_t pteoff;
@@ -81,8 +106,11 @@ _kvm_kvatop(kd, va, pa)
}
cpu_kh = kd->cpu_data;
+ vm = kd->vmst;
page_off = va & (cpu_kh->page_size - 1);
+#define PAGE_SHIFT vm->page_shift
+
if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
/*
* Direct-mapped address: just convert it.
@@ -97,7 +125,7 @@ _kvm_kvatop(kd, va, pa)
/* Find and read the L1 PTE. */
pteoff = cpu_kh->lev1map_pa +
- kvtol1pte(va) * sizeof(alpha_pt_entry_t);
+ l1pte_index(va) * sizeof(alpha_pt_entry_t);
if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L1 PTE");
@@ -110,7 +138,7 @@ _kvm_kvatop(kd, va, pa)
goto lose;
}
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
- vatoste(va) * sizeof(alpha_pt_entry_t);
+ l2pte_index(va) * sizeof(alpha_pt_entry_t);
if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L2 PTE");
@@ -123,7 +151,7 @@ _kvm_kvatop(kd, va, pa)
goto lose;
}
pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
- vatopte(va) * sizeof(alpha_pt_entry_t);
+ l3pte_index(va) * sizeof(alpha_pt_entry_t);
if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
_kvm_syserr(kd, 0, "could not read L3 PTE");
@@ -159,13 +187,22 @@ _kvm_pa2off(kd, pa)
kvm_t *kd;
u_long pa;
{
- off_t off;
cpu_kcore_hdr_t *cpu_kh;
+ phys_ram_seg_t *ramsegs;
+ off_t off;
+ int i;
cpu_kh = kd->cpu_data;
+ ramsegs = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
off = 0;
- pa -= cpu_kh->core_seg.start;
-
- return (kd->dump_off + off + pa);
+ for (i = 0; i < cpu_kh->nmemsegs; i++) {
+ if (pa >= ramsegs[i].start &&
+ (pa - ramsegs[i].start) < ramsegs[i].size) {
+ off += (pa - ramsegs[i].start);
+ break;
+ }
+ off += ramsegs[i].size;
+ }
+ return (kd->dump_off + off);
}