Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):
-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);
Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.
For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.
Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.
The change was compile tested for all arches, as it impacts all of them.
See also:
http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
2010-09-21 03:23:16 +04:00
|
|
|
/* $NetBSD: kvm_alpha.c,v 1.25 2010/09/20 23:23:16 jym Exp $ */
|
1995-02-10 20:51:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
1999-07-02 19:28:49 +04:00
|
|
|
*
|
1995-02-10 20:51:56 +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
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
1995-02-10 20:51:56 +03:00
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1999-07-02 19:28:49 +04:00
|
|
|
*
|
1995-02-10 20:51:56 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1998-03-25 03:47:20 +03:00
|
|
|
#define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
|
|
|
|
|
1995-02-10 20:51:56 +03:00
|
|
|
#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>
|
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):
-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);
Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.
For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.
Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.
The change was compile tested for all arches, as it impacts all of them.
See also:
http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
2010-09-21 03:23:16 +04:00
|
|
|
#include <sys/types.h>
|
1995-02-10 20:51:56 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
|
2000-06-29 10:34:22 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):
-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);
Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.
For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.
Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.
The change was compile tested for all arches, as it impacts all of them.
See also:
http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
2010-09-21 03:23:16 +04:00
|
|
|
|
|
|
|
#include <machine/kcore.h>
|
2001-08-05 07:33:15 +04:00
|
|
|
#include <machine/pmap.h>
|
2001-08-05 21:51:40 +04:00
|
|
|
#include <machine/vmparam.h>
|
1995-02-10 20:51:56 +03:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <db.h>
|
1997-10-10 12:45:29 +04:00
|
|
|
#include <stdlib.h>
|
1995-02-10 20:51:56 +03:00
|
|
|
|
|
|
|
#include "kvm_private.h"
|
|
|
|
|
2003-04-10 02:46:39 +04:00
|
|
|
/*ARGSUSED*/
|
1995-02-10 20:51:56 +03:00
|
|
|
void
|
2010-09-19 06:07:00 +04:00
|
|
|
_kvm_freevtop(kvm_t *kd)
|
1995-02-10 20:51:56 +03:00
|
|
|
{
|
2003-04-10 02:46:39 +04:00
|
|
|
return;
|
1995-02-10 20:51:56 +03:00
|
|
|
}
|
|
|
|
|
2003-04-10 02:46:39 +04:00
|
|
|
/*ARGSUSED*/
|
1995-02-10 20:51:56 +03:00
|
|
|
int
|
2010-09-19 06:07:00 +04:00
|
|
|
_kvm_initvtop(kvm_t *kd)
|
1995-02-10 20:51:56 +03:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):
-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);
Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.
For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.
Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.
The change was compile tested for all arches, as it impacts all of them.
See also:
http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
2010-09-21 03:23:16 +04:00
|
|
|
_kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
|
1995-02-10 20:51:56 +03:00
|
|
|
{
|
1996-10-01 23:04:02 +04:00
|
|
|
cpu_kcore_hdr_t *cpu_kh;
|
1996-10-02 01:12:05 +04:00
|
|
|
alpha_pt_entry_t pte;
|
1998-08-02 01:12:32 +04:00
|
|
|
u_long pteoff, page_off;
|
|
|
|
int rv;
|
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 +
|
1998-03-03 03:07:30 +03:00
|
|
|
l1pte_index(va) * sizeof(alpha_pt_entry_t);
|
2008-01-15 16:57:41 +03:00
|
|
|
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
1998-07-01 00:29:39 +04:00
|
|
|
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
1996-10-02 01:12:05 +04:00
|
|
|
_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 +
|
1998-03-03 03:07:30 +03:00
|
|
|
l2pte_index(va) * sizeof(alpha_pt_entry_t);
|
2008-01-15 16:57:41 +03:00
|
|
|
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
1998-07-01 00:29:39 +04:00
|
|
|
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
1996-10-02 01:12:05 +04:00
|
|
|
_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 +
|
1998-03-03 03:07:30 +03:00
|
|
|
l3pte_index(va) * sizeof(alpha_pt_entry_t);
|
2008-01-15 16:57:41 +03:00
|
|
|
if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
|
1998-07-01 00:29:39 +04:00
|
|
|
_kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
|
1996-10-02 01:12:05 +04:00
|
|
|
_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;
|
|
|
|
}
|
1997-11-02 11:35:08 +03:00
|
|
|
*pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
|
1996-10-02 01:12:05 +04:00
|
|
|
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
|
|
|
|
|
|
|
/*
|
2003-05-16 14:24:55 +04:00
|
|
|
* Translate a physical address to a file-offset in the crash dump.
|
1996-10-01 18:37:00 +04:00
|
|
|
*/
|
1999-07-02 19:28:49 +04:00
|
|
|
off_t
|
Change kvm_pa2off() and kvm_kvatop() prototypes (private to kvm(3)):
-int _kvm_kvatop(kvm_t *, u_long, u_long *);
-off_t _kvm_pa2off(kvm_t *, u_long);
+int _kvm_kvatop(kvm_t *, vaddr_t, paddr_t *);
+off_t _kvm_pa2off(kvm_t *, paddr_t);
Basically, use vaddr_t for VA and paddr_t for PA. In addition, for variables
representing addresses, use paddr_t or vaddr_t, depending on the context.
For most arches, vaddr_t and paddr_t are equivalent to unsigned long. However,
the change was needed for exotic situations, like i386 PAE, were unsigned long
is not suitable for PA which are 64 bits long. As this required a complete
change of the function prototypes, all arches had to be adapted accordingly.
Core files from before this commit should still work with the new code; I did
not see any direct dependency between core's structure and kvatop/pa2off.
The change was compile tested for all arches, as it impacts all of them.
See also:
http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html
2010-09-21 03:23:16 +04:00
|
|
|
_kvm_pa2off(kvm_t *kd, paddr_t pa)
|
1996-10-01 18:37:00 +04:00
|
|
|
{
|
1996-10-01 23:04:02 +04:00
|
|
|
cpu_kcore_hdr_t *cpu_kh;
|
1998-02-14 04:00:49 +03:00
|
|
|
phys_ram_seg_t *ramsegs;
|
|
|
|
off_t off;
|
|
|
|
int i;
|
1996-10-01 23:04:02 +04:00
|
|
|
|
|
|
|
cpu_kh = kd->cpu_data;
|
1998-02-14 04:00:49 +03:00
|
|
|
ramsegs = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
|
1996-10-01 23:04:02 +04:00
|
|
|
|
|
|
|
off = 0;
|
1998-02-14 04:00:49 +03:00
|
|
|
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;
|
|
|
|
}
|
1996-10-01 18:37:00 +04:00
|
|
|
|
1998-02-14 04:00:49 +03:00
|
|
|
return (kd->dump_off + off);
|
1996-10-01 18:37:00 +04:00
|
|
|
}
|
1997-08-12 20:34:07 +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
|
2010-09-19 06:07:00 +04:00
|
|
|
_kvm_mdopen(kvm_t *kd)
|
1997-08-12 20:34:07 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
kd->usrstack = USRSTACK;
|
|
|
|
kd->min_uva = VM_MIN_ADDRESS;
|
|
|
|
kd->max_uva = VM_MAXUSER_ADDRESS;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|