xref: /csrg-svn/lib/libkvm/kvm_mips.c (revision 57862)
1*57862Sralph /*-
2*57862Sralph  * Copyright (c) 1989, 1992 The Regents of the University of California.
3*57862Sralph  * All rights reserved.
4*57862Sralph  *
5*57862Sralph  * This code is derived from software developed by the Computer Systems
6*57862Sralph  * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
7*57862Sralph  * BG 91-66 and contributed to Berkeley. Modified for MIPS by Ralph Campbell.
8*57862Sralph  *
9*57862Sralph  * %sccs.include.redist.c%
10*57862Sralph  */
11*57862Sralph 
12*57862Sralph #if defined(LIBC_SCCS) && !defined(lint)
13*57862Sralph static char sccsid[] = "@(#)kvm_mips.c	1.1 (Berkeley) 02/04/93";
14*57862Sralph #endif /* LIBC_SCCS and not lint */
15*57862Sralph /*
16*57862Sralph  * MIPS machine dependent routines for kvm.  Hopefully, the forthcoming
17*57862Sralph  * vm code will one day obsolete this module.
18*57862Sralph  */
19*57862Sralph 
20*57862Sralph #include <sys/param.h>
21*57862Sralph #include <sys/user.h>
22*57862Sralph #include <sys/proc.h>
23*57862Sralph #include <sys/stat.h>
24*57862Sralph #include <unistd.h>
25*57862Sralph #include <nlist.h>
26*57862Sralph #include <kvm.h>
27*57862Sralph 
28*57862Sralph #include <vm/vm.h>
29*57862Sralph #include <vm/vm_param.h>
30*57862Sralph 
31*57862Sralph #include <limits.h>
32*57862Sralph #include <db.h>
33*57862Sralph 
34*57862Sralph #include "kvm_private.h"
35*57862Sralph 
36*57862Sralph #include <machine/machConst.h>
37*57862Sralph #include <machine/pte.h>
38*57862Sralph #include <machine/pmap.h>
39*57862Sralph 
40*57862Sralph #define KREAD(kd, addr, p)\
41*57862Sralph 	(kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p)))
42*57862Sralph 
43*57862Sralph void
44*57862Sralph _kvm_freevtop(kd)
45*57862Sralph 	kvm_t *kd;
46*57862Sralph {
47*57862Sralph }
48*57862Sralph 
49*57862Sralph int
50*57862Sralph _kvm_initvtop(kd)
51*57862Sralph 	kvm_t *kd;
52*57862Sralph {
53*57862Sralph 
54*57862Sralph 	return (0);
55*57862Sralph }
56*57862Sralph 
57*57862Sralph /*
58*57862Sralph  * Translate a kernel virtual address to a physical address.
59*57862Sralph  */
60*57862Sralph int
61*57862Sralph _kvm_kvatop(kd, va, pa)
62*57862Sralph 	kvm_t *kd;
63*57862Sralph 	u_long va;
64*57862Sralph 	u_long *pa;
65*57862Sralph {
66*57862Sralph 	u_long pte, addr, offset;
67*57862Sralph 
68*57862Sralph 	if (va < KERNBASE ||
69*57862Sralph 	    va >= VM_MIN_KERNEL_ADDRESS + PMAP_HASH_KPAGES * NPTEPG * NBPG)
70*57862Sralph 		goto invalid;
71*57862Sralph 	if (va < VM_MIN_KERNEL_ADDRESS) {
72*57862Sralph 		*pa = MACH_CACHED_TO_PHYS(va);
73*57862Sralph 		return (NBPG - (va & PGOFSET));
74*57862Sralph 	}
75*57862Sralph 	addr = PMAP_HASH_KADDR + ((va - VM_MIN_KERNEL_ADDRESS) >> PGSHIFT);
76*57862Sralph 	/*
77*57862Sralph 	 * Can't use KREAD to read kernel segment table entries.
78*57862Sralph 	 * Fortunately it is 1-to-1 mapped so we don't have to.
79*57862Sralph 	 */
80*57862Sralph 	if (lseek(kd->pmfd, (off_t)addr, 0) < 0 ||
81*57862Sralph 	    read(kd->pmfd, (char *)&pte, sizeof(pte)) < 0)
82*57862Sralph 		goto invalid;
83*57862Sralph 	offset = va & PGOFSET;
84*57862Sralph 	*pa = (pte & PG_FRAME) | offset;
85*57862Sralph 	return (NBPG - offset);
86*57862Sralph 
87*57862Sralph invalid:
88*57862Sralph 	_kvm_err(kd, 0, "invalid address (%x)", va);
89*57862Sralph 	return (0);
90*57862Sralph }
91*57862Sralph 
92*57862Sralph /*
93*57862Sralph  * Translate a user virtual address to a physical address.
94*57862Sralph  */
95*57862Sralph int
96*57862Sralph _kvm_uvatop(kd, p, va, pa)
97*57862Sralph 	kvm_t *kd;
98*57862Sralph 	const struct proc *p;
99*57862Sralph 	u_long va;
100*57862Sralph 	u_long *pa;
101*57862Sralph {
102*57862Sralph #if 0
103*57862Sralph 	register struct vmspace *vms = p->p_vmspace;
104*57862Sralph 	u_long stab_kva, kva;
105*57862Sralph 
106*57862Sralph 	kva = (u_long)&vms->vm_pmap.pm_stab;
107*57862Sralph 	if (kvm_read(kd, kva, (char *)&kva, 4) != 4) {
108*57862Sralph 		_kvm_err(kd, 0, "invalid address (%x)", va);
109*57862Sralph 		return (0);
110*57862Sralph 	}
111*57862Sralph 	return (_kvm_vatop(kd, kva, va, pa));
112*57862Sralph #else
113*57862Sralph 	_kvm_err(kd, 0, "invalid address (%x)", va);
114*57862Sralph 	return (0);
115*57862Sralph #endif
116*57862Sralph }
117