1996-10-02 01:12:05 +04:00
|
|
|
/* $NetBSD: kvm_alpha.c,v 1.5 1996/10/01 21:12:05 cgd Exp $ */
|
1995-02-10 20:51:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
1996-10-01 23:04:02 +04:00
|
|
|
#include <sys/kcore.h>
|
|
|
|
#include <machine/kcore.h>
|
1995-02-10 20:51:56 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <db.h>
|
|
|
|
|
|
|
|
#include "kvm_private.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
_kvm_freevtop(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
|
|
|
|
1996-10-02 01:12:05 +04:00
|
|
|
/* Not actually used for anything right now, but safe. */
|
|
|
|
if (kd->vmst != 0)
|
|
|
|
free(kd->vmst);
|
1995-02-10 20:51:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_kvm_initvtop(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_kvm_kvatop(kd, va, pa)
|
|
|
|
kvm_t *kd;
|
|
|
|
u_long va;
|
|
|
|
u_long *pa;
|
|
|
|
{
|
1996-10-01 23:04:02 +04:00
|
|
|
cpu_kcore_hdr_t *cpu_kh;
|
|
|
|
int rv, page_off;
|
1996-10-02 01:12:05 +04:00
|
|
|
alpha_pt_entry_t pte;
|
|
|
|
off_t pteoff;
|
1995-02-10 20:51:56 +03:00
|
|
|
|
1996-10-01 23:04:02 +04:00
|
|
|
if (ISALIVE(kd)) {
|
|
|
|
_kvm_err(kd, 0, "vatop called in live kernel!");
|
|
|
|
return(0);
|
|
|
|
}
|
1995-09-29 06:57:48 +03:00
|
|
|
|
1996-10-01 23:04:02 +04:00
|
|
|
cpu_kh = kd->cpu_data;
|
|
|
|
page_off = va & (cpu_kh->page_size - 1);
|
|
|
|
|
|
|
|
if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
|
|
|
|
/*
|
1996-10-02 01:12:05 +04:00
|
|
|
* Direct-mapped address: just convert it.
|
1996-10-01 23:04:02 +04:00
|
|
|
*/
|
1996-10-02 01:12:05 +04:00
|
|
|
|
1996-10-01 23:04:02 +04:00
|
|
|
*pa = ALPHA_K0SEG_TO_PHYS(va);
|
|
|
|
rv = cpu_kh->page_size - page_off;
|
|
|
|
} else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
|
|
|
|
/*
|
1996-10-02 01:12:05 +04:00
|
|
|
* Real kernel virtual address: do the translation.
|
1996-10-01 23:04:02 +04:00
|
|
|
*/
|
1996-10-02 01:12:05 +04:00
|
|
|
|
|
|
|
/* 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;
|
1996-10-01 23:04:02 +04:00
|
|
|
} else {
|
|
|
|
/*
|
1996-10-02 01:12:05 +04:00
|
|
|
* Bogus address (not in KV space): punt.
|
1996-10-01 23:04:02 +04:00
|
|
|
*/
|
1996-10-02 01:12:05 +04:00
|
|
|
|
|
|
|
_kvm_err(kd, 0, "invalid kernel virtual address");
|
|
|
|
lose:
|
1996-10-01 23:04:02 +04:00
|
|
|
*pa = -1;
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
1995-02-10 20:51:56 +03:00
|
|
|
}
|
1996-10-01 18:37:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a physical address to a file-offset in the crash-dump.
|
|
|
|
*/
|
|
|
|
off_t
|
|
|
|
_kvm_pa2off(kd, pa)
|
|
|
|
kvm_t *kd;
|
|
|
|
u_long pa;
|
|
|
|
{
|
1996-10-01 23:04:02 +04:00
|
|
|
off_t off;
|
|
|
|
cpu_kcore_hdr_t *cpu_kh;
|
|
|
|
|
|
|
|
cpu_kh = kd->cpu_data;
|
|
|
|
|
|
|
|
off = 0;
|
|
|
|
pa -= cpu_kh->core_seg.start;
|
1996-10-01 18:37:00 +04:00
|
|
|
|
1996-10-01 23:04:02 +04:00
|
|
|
return (kd->dump_off + off + pa);
|
1996-10-01 18:37:00 +04:00
|
|
|
}
|