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