diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-05 14:58:01 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-05 14:58:01 +0000 |
commit | 54dfec2daf1be7e2dd1c8d054a99f43305e87e19 (patch) | |
tree | ea4c23c0d494b1d01b4878c4544a0e989649ad3b /lib/libkvm/kvm_ns32k.c | |
parent | 69eb3008fd7c3ef1de34f9de181036c0e4610954 (diff) |
sync with 0430
Diffstat (limited to 'lib/libkvm/kvm_ns32k.c')
-rw-r--r-- | lib/libkvm/kvm_ns32k.c | 77 |
1 files changed, 60 insertions, 17 deletions
diff --git a/lib/libkvm/kvm_ns32k.c b/lib/libkvm/kvm_ns32k.c index 9b15b96d31a..5f363b48677 100644 --- a/lib/libkvm/kvm_ns32k.c +++ b/lib/libkvm/kvm_ns32k.c @@ -1,3 +1,6 @@ +/* $OpenBSD: kvm_ns32k.c,v 1.2 1996/05/05 14:57:32 deraadt Exp $ */ +/* $NetBSD: kvm_ns32k.c,v 1.4 1996/03/18 22:33:50 thorpej Exp $ */ + /*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -36,19 +39,23 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -/* from: static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: kvm_ns32k.c,v 1.1 1995/10/18 08:42:44 deraadt Exp $"; +#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 $"; +#endif #endif /* LIBC_SCCS and not lint */ /* - * pc532 machine dependent routines for kvm. Hopefully, the forthcoming - * vm code will one day obsolete this module. (copy from kvm_i386.c) + * ns32k machine dependent routines for kvm. Hopefully, the forthcoming + * vm code will one day obsolete this module. */ #include <sys/param.h> #include <sys/user.h> #include <sys/proc.h> #include <sys/stat.h> +#include <stdlib.h> #include <unistd.h> #include <nlist.h> #include <kvm.h> @@ -61,8 +68,7 @@ static char *rcsid = "$Id: kvm_ns32k.c,v 1.1 1995/10/18 08:42:44 deraadt Exp $"; #include "kvm_private.h" -#include <machine/pmap.h> -#define PDSHIFT 22 +#include <machine/pte.h> #ifndef btop #define btop(x) (((unsigned)(x)) >> PGSHIFT) /* XXX */ @@ -70,8 +76,8 @@ static char *rcsid = "$Id: kvm_ns32k.c,v 1.1 1995/10/18 08:42:44 deraadt Exp $"; #endif struct vmstate { - struct pde **IdlePTD; - struct pde *PTD; + pd_entry_t **PTDpaddr; + pd_entry_t *PTD; }; #define KREAD(kd, addr, p)\ @@ -81,11 +87,12 @@ void _kvm_freevtop(kd) kvm_t *kd; { - if (kd->vmst->PTD != 0) - free(kd->vmst->PTD); + if (kd->vmst != 0) { + if (kd->vmst->PTD != 0) + free(kd->vmst->PTD); - if (kd->vmst != 0) free(kd->vmst); + } } int @@ -94,30 +101,35 @@ _kvm_initvtop(kd) { struct vmstate *vm; struct nlist nlist[2]; + pt_entry_t *tmpPTD; vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); if (vm == 0) return (-1); kd->vmst = vm; - nlist[0].n_name = "_IdlePTD"; + nlist[0].n_name = "_PTDpaddr"; nlist[1].n_name = 0; if (kvm_nlist(kd, nlist) != 0) { _kvm_err(kd, kd->program, "bad namelist"); return (-1); } - vm->IdlePTD = 0; + + vm->PTDpaddr = 0; vm->PTD = 0; - if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { - _kvm_err(kd, kd->program, "cannot read IdlePTD"); + if (KREAD(kd, (u_long)nlist[0].n_value - KERNBASE, &vm->PTDpaddr)) { + _kvm_err(kd, kd->program, "cannot read PTDpaddr"); return (-1); } - vm->PTD = (struct pde *)_kvm_malloc(kd, NBPG); - if ((kvm_read(kd, (u_long)vm->IdlePTD, &vm->PTD, NBPG)) != NBPG) { + + tmpPTD = (pd_entry_t *)_kvm_malloc(kd, NBPG); + if ((kvm_read(kd, (u_long)vm->PTDpaddr, tmpPTD, NBPG)) != NBPG) { + free(tmpPTD); _kvm_err(kd, kd->program, "cannot read PTD"); return (-1); } + vm->PTD = tmpPTD; return (0); } @@ -132,14 +144,45 @@ _kvm_kvatop(kd, va, pa) { struct vmstate *vm; u_long offset; + u_long pte_pa; + pt_entry_t pte; if (ISALIVE(kd)) { _kvm_err(kd, 0, "vatop called in live kernel!"); return(0); } + vm = kd->vmst; offset = va & PGOFSET; + /* + * If we are initializing (kernel page table descriptor pointer + * not yet set) * then return pa == va to avoid infinite recursion. + */ + if (vm->PTD == 0) { + *pa = va; + return (NBPG - offset); + } + if ((vm->PTD[pdei(va)] & PG_V) == 0) + goto invalid; + + pte_pa = (vm->PTD[pdei(va)] & PG_FRAME) + + (ptei(va) * sizeof(pt_entry_t)); + /* XXX READ PHYSICAL XXX */ + { + if (lseek(kd->pmfd, (off_t)pte_pa, 0) == -1 && errno != 0) { + _kvm_syserr(kd, 0, "kvm_lseek"); + goto invalid; + } + if (read(kd->pmfd, &pte, sizeof pte) != sizeof pte) { + _kvm_syserr(kd, kd->program, "kvm_read"); + goto invalid; + } + } + + *pa = (pte & PG_FRAME) + offset; + return (NBPG - offset); + invalid: _kvm_err(kd, 0, "invalid address (%x)", va); return (0); |