summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1997-02-26 16:46:36 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1997-02-26 16:46:36 +0000
commit27ae0411e3e64c9ed2702ac388005137db53fb76 (patch)
treef3cd2c8ebec671bb1be57bb8576f0041d49e1ef0
parentcb2eb095fa8af44f6bb3cc1179a3e781f2866c3b (diff)
Switch alpha from libkvm.old to libkvm with code from NetBSD.
%x -> %lx format fixes from me.
-rw-r--r--lib/Makefile5
-rw-r--r--lib/libkvm/kvm.c8
-rw-r--r--lib/libkvm/kvm_alpha.c108
-rw-r--r--lib/libkvm/kvm_arm32.c8
-rw-r--r--lib/libkvm/kvm_i386.c6
-rw-r--r--lib/libkvm/kvm_m68k.c6
-rw-r--r--lib/libkvm/kvm_mips.c6
-rw-r--r--lib/libkvm/kvm_ns32k.c6
-rw-r--r--lib/libkvm/kvm_proc.c8
-rw-r--r--lib/libkvm/kvm_sparc.c8
-rw-r--r--lib/libkvm/kvm_vax.c8
11 files changed, 139 insertions, 38 deletions
diff --git a/lib/Makefile b/lib/Makefile
index b9c43c26dd5..c889a8bd5be 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.18 1997/02/26 03:06:48 downsj Exp $
+# $OpenBSD: Makefile,v 1.19 1997/02/26 16:46:25 niklas Exp $
# $NetBSD: Makefile,v 1.20.4.1 1996/06/14 17:22:38 cgd Exp $
SUBDIR= csu libarch libc libcom_err libcompat libcurses libedit \
@@ -7,7 +7,8 @@ SUBDIR= csu libarch libc libcom_err libcompat libcurses libedit \
liby libz
# XXX Temporarely until all ports are able to use libkvm (leo)
-.if (${MACHINE} == "amiga") || \
+.if (${MACHINE} == "alpha") || \
+ (${MACHINE} == "amiga") || \
(${MACHINE} == "atari") || \
(${MACHINE} == "powerpc") || \
(${MACHINE} == "sun3")
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index d18e12b4441..cbe0d571d53 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm.c,v 1.5 1997/01/17 07:11:59 millert Exp $ */
+/* $OpenBSD: kvm.c,v 1.6 1997/02/26 16:46:28 niklas Exp $ */
/* $NetBSD: kvm.c,v 1.43 1996/05/05 04:31:59 gwr Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm.c 8.2 (Berkeley) 2/13/94";
#else
-static char *rcsid = "$OpenBSD: kvm.c,v 1.5 1997/01/17 07:11:59 millert Exp $";
+static char *rcsid = "$OpenBSD: kvm.c,v 1.6 1997/02/26 16:46:28 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -869,7 +869,7 @@ kvm_read(kd, kva, buf, len)
errno = 0;
if (lseek(kd->vmfd, (off_t)kva, SEEK_SET) == -1
&& errno != 0) {
- _kvm_err(kd, 0, "invalid address (%x)", kva);
+ _kvm_err(kd, 0, "invalid address (%lx)", kva);
return (0);
}
cc = read(kd->vmfd, buf, len);
@@ -939,7 +939,7 @@ kvm_write(kd, kva, buf, len)
errno = 0;
if (lseek(kd->vmfd, (off_t)kva, SEEK_SET) == -1
&& errno != 0) {
- _kvm_err(kd, 0, "invalid address (%x)", kva);
+ _kvm_err(kd, 0, "invalid address (%lx)", kva);
return (0);
}
cc = write(kd->vmfd, buf, len);
diff --git a/lib/libkvm/kvm_alpha.c b/lib/libkvm/kvm_alpha.c
index d07681a7f8d..ec8e8cff7ac 100644
--- a/lib/libkvm/kvm_alpha.c
+++ b/lib/libkvm/kvm_alpha.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: kvm_alpha.c,v 1.2 1996/05/05 14:56:50 deraadt Exp $ */
-/* $NetBSD: kvm_alpha.c,v 1.2 1995/09/29 03:57:48 cgd Exp $ */
+/* $OpenBSD: kvm_alpha.c,v 1.3 1997/02/26 16:46:29 niklas Exp $ */
+/* $NetBSD: kvm_alpha.c,v 1.5 1996/10/01 21:12:05 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -32,6 +32,8 @@
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/stat.h>
+#include <sys/kcore.h>
+#include <machine/kcore.h>
#include <unistd.h>
#include <nlist.h>
#include <kvm.h>
@@ -49,6 +51,9 @@ _kvm_freevtop(kd)
kvm_t *kd;
{
+ /* Not actually used for anything right now, but safe. */
+ if (kd->vmst != 0)
+ free(kd->vmst);
}
int
@@ -65,8 +70,103 @@ _kvm_kvatop(kd, va, pa)
u_long va;
u_long *pa;
{
+ cpu_kcore_hdr_t *cpu_kh;
+ int rv, page_off;
+ alpha_pt_entry_t pte;
+ off_t pteoff;
- /* don't forget k0seg translations! */
+ if (ISALIVE(kd)) {
+ _kvm_err(kd, 0, "vatop called in live kernel!");
+ return(0);
+ }
- return (0);
+ cpu_kh = kd->cpu_data;
+ page_off = va & (cpu_kh->page_size - 1);
+
+ if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
+ /*
+ * Direct-mapped address: just convert it.
+ */
+
+ *pa = ALPHA_K0SEG_TO_PHYS(va);
+ rv = cpu_kh->page_size - page_off;
+ } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
+ /*
+ * Real kernel virtual address: do the translation.
+ */
+
+ /* Find and read the L1 PTE. */
+ pteoff = cpu_kh->lev1map_pa +
+ kvtol1pte(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");
+ goto lose;
+ }
+
+ /* Find and read the L2 PTE. */
+ if ((pte & ALPHA_PTE_VALID) == 0) {
+ _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
+ goto lose;
+ }
+ pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
+ vatoste(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");
+ goto lose;
+ }
+
+ /* Find and read the L3 PTE. */
+ if ((pte & ALPHA_PTE_VALID) == 0) {
+ _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
+ goto lose;
+ }
+ pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
+ vatopte(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");
+ goto lose;
+ }
+
+ /* Fill in the PA. */
+ if ((pte & ALPHA_PTE_VALID) == 0) {
+ _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
+ goto lose;
+ }
+ *pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
+ vatopte(va) * sizeof(alpha_pt_entry_t);
+ rv = cpu_kh->page_size - page_off;
+ } else {
+ /*
+ * Bogus address (not in KV space): punt.
+ */
+
+ _kvm_err(kd, 0, "invalid kernel virtual address");
+lose:
+ *pa = -1;
+ rv = 0;
+ }
+
+ return (rv);
+}
+
+/*
+ * Translate a physical address to a file-offset in the crash-dump.
+ */
+off_t
+_kvm_pa2off(kd, pa)
+ kvm_t *kd;
+ u_long pa;
+{
+ off_t off;
+ cpu_kcore_hdr_t *cpu_kh;
+
+ cpu_kh = kd->cpu_data;
+
+ off = 0;
+ pa -= cpu_kh->core_seg.start;
+
+ return (kd->dump_off + off + pa);
}
diff --git a/lib/libkvm/kvm_arm32.c b/lib/libkvm/kvm_arm32.c
index 37a7c19a174..ff2fe048f25 100644
--- a/lib/libkvm/kvm_arm32.c
+++ b/lib/libkvm/kvm_arm32.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_arm32.c,v 1.1 1996/05/05 14:56:52 deraadt Exp $ */
+/* $OpenBSD: kvm_arm32.c,v 1.2 1997/02/26 16:46:29 niklas Exp $ */
/* $NetBSD: kvm_arm32.c,v 1.2 1996/03/18 22:33:16 thorpej Exp $ */
/*
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_arm32.c,v 1.1 1996/05/05 14:56:52 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_arm32.c,v 1.2 1997/02/26 16:46:29 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -151,7 +151,7 @@ _kvm_kvatop(kd, va, pa)
offset = va & PGOFSET;
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
@@ -201,6 +201,6 @@ _kvm_uvatop(kd, p, va, pa)
return (NBPG - offset);
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_i386.c b/lib/libkvm/kvm_i386.c
index 7d1c30e3901..ba3098494b5 100644
--- a/lib/libkvm/kvm_i386.c
+++ b/lib/libkvm/kvm_i386.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_i386.c,v 1.3 1996/05/05 14:57:20 deraadt Exp $ */
+/* $OpenBSD: kvm_i386.c,v 1.4 1997/02/26 16:46:30 niklas Exp $ */
/* $NetBSD: kvm_i386.c,v 1.9 1996/03/18 22:33:38 thorpej Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.3 1996/05/05 14:57:20 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_i386.c,v 1.4 1997/02/26 16:46:30 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -194,6 +194,6 @@ _kvm_kvatop(kd, va, pa)
return (NBPG - offset);
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_m68k.c b/lib/libkvm/kvm_m68k.c
index 983cc724464..42a98c1fa0b 100644
--- a/lib/libkvm/kvm_m68k.c
+++ b/lib/libkvm/kvm_m68k.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_m68k.c,v 1.4 1996/05/10 12:58:31 deraadt Exp $ */
+/* $OpenBSD: kvm_m68k.c,v 1.5 1997/02/26 16:46:31 niklas Exp $ */
/* $NetBSD: kvm_m68k.c,v 1.9 1996/05/07 06:09:11 leo Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.4 1996/05/10 12:58:31 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_m68k.c,v 1.5 1997/02/26 16:46:31 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -193,7 +193,7 @@ _kvm_vatop(kd, sta, va, pa)
return (NBPG - offset);
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_mips.c b/lib/libkvm/kvm_mips.c
index b2a71553459..51b4076918a 100644
--- a/lib/libkvm/kvm_mips.c
+++ b/lib/libkvm/kvm_mips.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_mips.c,v 1.3 1996/06/07 06:50:42 deraadt Exp $ */
+/* $OpenBSD: kvm_mips.c,v 1.4 1997/02/26 16:46:32 niklas Exp $ */
/* $NetBSD: kvm_mips.c,v 1.3 1996/03/18 22:33:44 thorpej Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_mips.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_mips.c,v 1.3 1996/06/07 06:50:42 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_mips.c,v 1.4 1997/02/26 16:46:32 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -165,6 +165,6 @@ _kvm_kvatop(kd, va, pa)
return (NBPG - offset);
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_ns32k.c b/lib/libkvm/kvm_ns32k.c
index 5f363b48677..f8e5e26e424 100644
--- a/lib/libkvm/kvm_ns32k.c
+++ b/lib/libkvm/kvm_ns32k.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_ns32k.c,v 1.2 1996/05/05 14:57:32 deraadt Exp $ */
+/* $OpenBSD: kvm_ns32k.c,v 1.3 1997/02/26 16:46:32 niklas Exp $ */
/* $NetBSD: kvm_ns32k.c,v 1.4 1996/03/18 22:33:50 thorpej Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_ns32k.c,v 1.2 1996/05/05 14:57:32 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_ns32k.c,v 1.3 1997/02/26 16:46:32 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -184,6 +184,6 @@ _kvm_kvatop(kd, va, pa)
return (NBPG - offset);
invalid:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c
index 71488797bf5..e9c63c226cf 100644
--- a/lib/libkvm/kvm_proc.c
+++ b/lib/libkvm/kvm_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_proc.c,v 1.3 1996/10/23 16:43:08 deraadt Exp $ */
+/* $OpenBSD: kvm_proc.c,v 1.4 1997/02/26 16:46:33 niklas Exp $ */
/* $NetBSD: kvm_proc.c,v 1.16 1996/03/18 22:33:57 thorpej Exp $ */
/*-
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
#else
-static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.3 1996/10/23 16:43:08 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.4 1997/02/26 16:46:33 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -779,7 +779,7 @@ kvm_doargv(kd, kp, nchr, info)
* Pointers are stored at the top of the user stack.
*/
if (p->p_stat == SZOMB ||
- kvm_uread(kd, p, ps, (char *)&arginfo,
+ kvm_uread(kd, p, (u_long)ps, (char *)&arginfo,
sizeof(arginfo)) != sizeof(arginfo))
return (0);
@@ -838,7 +838,7 @@ kvm_uread(kd, p, uva, buf, len)
dp = _kvm_uread(kd, p, uva, &cnt);
if (dp == 0) {
- _kvm_err(kd, 0, "invalid address (%x)", uva);
+ _kvm_err(kd, 0, "invalid address (%lx)", uva);
return (0);
}
cc = MIN(cnt, len);
diff --git a/lib/libkvm/kvm_sparc.c b/lib/libkvm/kvm_sparc.c
index d316b37d7ca..7dc5ffa37d2 100644
--- a/lib/libkvm/kvm_sparc.c
+++ b/lib/libkvm/kvm_sparc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_sparc.c,v 1.2 1996/05/05 14:57:50 deraadt Exp $ */
+/* $OpenBSD: kvm_sparc.c,v 1.3 1997/02/26 16:46:34 niklas Exp $ */
/* $NetBSD: kvm_sparc.c,v 1.9 1996/04/01 19:23:03 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
#else
-static char *rcsid = "$OpenBSD: kvm_sparc.c,v 1.2 1996/05/05 14:57:50 deraadt Exp $";
+static char *rcsid = "$OpenBSD: kvm_sparc.c,v 1.3 1997/02/26 16:46:34 niklas Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -299,7 +299,7 @@ _kvm_kvatop44c(kd, va, pa)
return (kd->nbpg - off);
}
err:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
@@ -412,6 +412,6 @@ _kvm_kvatop4m(kd, va, pa)
return (kd->nbpg - off);
}
err:
- _kvm_err(kd, 0, "invalid address (%x)", va);
+ _kvm_err(kd, 0, "invalid address (%lx)", va);
return (0);
}
diff --git a/lib/libkvm/kvm_vax.c b/lib/libkvm/kvm_vax.c
index 9b35a94fbb1..78187013c8c 100644
--- a/lib/libkvm/kvm_vax.c
+++ b/lib/libkvm/kvm_vax.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_vax.c,v 1.2 1996/05/05 14:57:57 deraadt Exp $ */
+/* $OpenBSD: kvm_vax.c,v 1.3 1997/02/26 16:46:35 niklas Exp $ */
/* $NetBSD: kvm_vax.c,v 1.3 1996/03/18 22:34:06 thorpej Exp $ */
/*-
@@ -118,16 +118,16 @@ _kvm_kvatop(kd, va, pa)
u_long va;
u_long *pa;
{
- register int end;
+ register u_long end;
if (va < KERNBASE) {
- _kvm_err(kd, 0, "invalid address (%x<%x)", va, KERNBASE);
+ _kvm_err(kd, 0, "invalid address (%lx<%lx)", va, KERNBASE);
return (0);
}
end = kd->vmst->end;
if (va >= end) {
- _kvm_err(kd, 0, "invalid address (%x>=%x)", va, end);
+ _kvm_err(kd, 0, "invalid address (%lx>=%lx)", va, end);
return (0);
}