2000-06-29 10:34:22 +04:00
|
|
|
/* $NetBSD: kvm_mips.c,v 1.15 2000/06/29 06:34:24 mrg Exp $ */
|
1996-03-19 01:33:07 +03:00
|
|
|
|
1998-02-20 02:32:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
1994-05-09 07:15:36 +04:00
|
|
|
*
|
1998-02-20 02:32:35 +03:00
|
|
|
* Author: Chris G. Demetriou
|
1994-05-09 07:15:36 +04:00
|
|
|
*
|
1998-02-20 02:32:35 +03:00
|
|
|
* 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.
|
1999-07-02 19:28:49 +04:00
|
|
|
*
|
1998-02-20 02:32:35 +03:00
|
|
|
* 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.
|
1999-07-02 19:28:49 +04:00
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
1998-02-20 02:32:35 +03:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1994-05-09 07:15:36 +04:00
|
|
|
*
|
1998-02-20 02:32:35 +03:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
1999-07-02 19:28:49 +04:00
|
|
|
*/
|
1998-02-20 02:32:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified for NetBSD/mips by Jason R. Thorpe, Numerical Aerospace
|
|
|
|
* Simulation Facility, NASA Ames Research Center.
|
1994-05-09 07:15:36 +04:00
|
|
|
*/
|
|
|
|
|
1997-08-15 06:21:56 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-09 07:15:36 +04:00
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2000-06-29 10:34:22 +04:00
|
|
|
__RCSID("$NetBSD: kvm_mips.c,v 1.15 2000/06/29 06:34:24 mrg Exp $");
|
1994-05-09 07:15:36 +04:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
1996-03-19 01:33:07 +03:00
|
|
|
|
1994-05-09 07:15:36 +04:00
|
|
|
/*
|
1998-02-20 02:32:35 +03:00
|
|
|
* MIPS machine dependent routines for kvm.
|
1994-05-09 07:15:36 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
1998-02-20 02:32:35 +03:00
|
|
|
#include <sys/kcore.h>
|
|
|
|
#include <machine/kcore.h>
|
1997-10-20 23:43:26 +04:00
|
|
|
#include <stdlib.h>
|
1994-05-09 07:15:36 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
|
2000-06-29 10:34:22 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
1994-05-09 07:15:36 +04:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <db.h>
|
|
|
|
|
|
|
|
#include "kvm_private.h"
|
|
|
|
|
1997-06-18 05:41:31 +04:00
|
|
|
#include <mips/cpuregs.h>
|
1994-05-09 07:15:36 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
_kvm_freevtop(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
1998-02-20 02:32:35 +03:00
|
|
|
|
|
|
|
/* Not actually used for anything right now, but safe. */
|
1994-05-09 07:15:36 +04:00
|
|
|
if (kd->vmst != 0)
|
|
|
|
free(kd->vmst);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_kvm_initvtop(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
1998-02-20 02:32:35 +03:00
|
|
|
|
1994-05-09 07:15:36 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate a kernel virtual address to a physical address.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
_kvm_kvatop(kd, va, pa)
|
|
|
|
kvm_t *kd;
|
|
|
|
u_long va;
|
|
|
|
u_long *pa;
|
|
|
|
{
|
1998-02-20 02:32:35 +03:00
|
|
|
cpu_kcore_hdr_t *cpu_kh;
|
|
|
|
int page_off;
|
|
|
|
u_int pte;
|
|
|
|
u_long pte_pa;
|
1997-06-18 05:41:31 +04:00
|
|
|
|
1994-05-09 07:15:36 +04:00
|
|
|
if (ISALIVE(kd)) {
|
|
|
|
_kvm_err(kd, 0, "vatop called in live kernel!");
|
|
|
|
return((off_t)0);
|
|
|
|
}
|
1997-06-18 05:41:31 +04:00
|
|
|
|
1998-02-20 02:32:35 +03:00
|
|
|
cpu_kh = kd->cpu_data;
|
|
|
|
page_off = va & PGOFSET;
|
|
|
|
|
|
|
|
if (va < MIPS_KSEG0_START) {
|
|
|
|
/*
|
|
|
|
* KUSEG (user virtual address space) - invalid.
|
|
|
|
*/
|
|
|
|
_kvm_err(kd, 0, "invalid kernel virtual address");
|
|
|
|
goto lose;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (va >= MIPS_KSEG0_START && va < MIPS_KSEG1_START) {
|
|
|
|
/*
|
|
|
|
* Direct-mapped cached address: just convert it.
|
|
|
|
*/
|
|
|
|
*pa = MIPS_KSEG0_TO_PHYS(va);
|
|
|
|
return (NBPG - page_off);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (va >= MIPS_KSEG1_START && va < MIPS_KSEG2_START) {
|
|
|
|
/*
|
|
|
|
* Direct-mapped uncached address: just convert it.
|
|
|
|
*/
|
|
|
|
*pa = MIPS_KSEG1_TO_PHYS(va);
|
|
|
|
return (NBPG - page_off);
|
1997-06-18 05:41:31 +04:00
|
|
|
}
|
1998-02-20 02:32:35 +03:00
|
|
|
|
1994-05-09 07:15:36 +04:00
|
|
|
/*
|
1998-02-20 02:32:35 +03:00
|
|
|
* We now know that we're a KSEG2 (kernel virtually mapped)
|
|
|
|
* address. Translate the address using the pmap's kernel
|
|
|
|
* page table.
|
1994-05-09 07:15:36 +04:00
|
|
|
*/
|
1998-02-20 02:32:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 1: Make sure the kernel page table has a translation
|
|
|
|
* for the address.
|
|
|
|
*/
|
|
|
|
if (va >= (MIPS_KSEG2_START + (cpu_kh->sysmapsize * NBPG))) {
|
|
|
|
_kvm_err(kd, 0, "invalid KSEG2 address");
|
|
|
|
goto lose;
|
1994-05-09 07:15:36 +04:00
|
|
|
}
|
1998-02-20 02:32:35 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 2: Locate and read the PTE.
|
|
|
|
*/
|
|
|
|
pte_pa = cpu_kh->sysmappa +
|
|
|
|
(((va - MIPS_KSEG2_START) >> PGSHIFT) * sizeof(u_int));
|
1998-07-01 00:29:39 +04:00
|
|
|
if (pread(kd->pmfd, &pte, sizeof(pte), _kvm_pa2off(kd, pte_pa)) !=
|
|
|
|
sizeof(pte)) {
|
1998-02-20 02:32:35 +03:00
|
|
|
_kvm_syserr(kd, 0, "could not read PTE");
|
|
|
|
goto lose;
|
1994-05-09 07:15:36 +04:00
|
|
|
}
|
1997-06-18 05:41:31 +04:00
|
|
|
|
1994-05-09 07:15:36 +04:00
|
|
|
/*
|
1998-02-20 02:32:35 +03:00
|
|
|
* Step 3: Validate the PTE and return the physical address.
|
1994-05-09 07:15:36 +04:00
|
|
|
*/
|
1998-02-20 02:32:35 +03:00
|
|
|
if ((pte & cpu_kh->pg_v) == 0) {
|
|
|
|
_kvm_err(kd, 0, "invalid translation (invalid PTE)");
|
|
|
|
goto lose;
|
|
|
|
}
|
|
|
|
*pa = (((pte & cpu_kh->pg_frame) >> cpu_kh->pg_shift) << PGSHIFT) +
|
|
|
|
page_off;
|
|
|
|
return (NBPG - page_off);
|
|
|
|
|
|
|
|
lose:
|
|
|
|
*pa = -1;
|
1994-05-09 07:15:36 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1997-08-14 20:05:21 +04:00
|
|
|
|
1998-02-20 02:32:35 +03: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;
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1997-08-14 20:05:21 +04:00
|
|
|
/*
|
|
|
|
* Machine-dependent initialization for ALL open kvm descriptors,
|
|
|
|
* not just those for a kernel crash dump. Some architectures
|
|
|
|
* have to deal with these NOT being constants! (i.e. m68k)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
_kvm_mdopen(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
|
|
|
|
|
|
|
kd->usrstack = USRSTACK;
|
|
|
|
kd->min_uva = VM_MIN_ADDRESS;
|
|
|
|
kd->max_uva = VM_MAXUSER_ADDRESS;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|