kvm_ia64.c revision 85361
1/* $FreeBSD: head/lib/libkvm/kvm_ia64.c 85361 2001-10-23 11:05:35Z dfr $ */ 2/* $NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $ */ 3 4/* 5 * Copyright (c) 1994, 1995 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31#include <sys/param.h> 32#include <sys/lock.h> 33#include <sys/mutex.h> 34#include <sys/user.h> 35#include <sys/proc.h> 36#include <sys/stat.h> 37#include <sys/types.h> 38#include <sys/uio.h> 39#include <unistd.h> 40#include <nlist.h> 41#include <kvm.h> 42 43#include <vm/vm.h> 44#include <vm/vm_param.h> 45 46#include <limits.h> 47#include <stdlib.h> 48#include <machine/pmap.h> 49#include "kvm_private.h" 50 51static off_t _kvm_pa2off(kvm_t *kd, u_long pa); 52 53struct vmstate { 54 u_int64_t lev1map_pa; /* PA of Lev1map */ 55 u_int64_t page_size; /* Page size */ 56 u_int64_t nmemsegs; /* Number of RAM segm */ 57}; 58 59void 60_kvm_freevtop(kd) 61 kvm_t *kd; 62{ 63 64 /* Not actually used for anything right now, but safe. */ 65 if (kd->vmst != 0) 66 free(kd->vmst); 67} 68 69int 70_kvm_initvtop(kd) 71 kvm_t *kd; 72{ 73 struct vmstate *vm; 74 struct nlist nlist[2]; 75 u_long pa; 76 77 vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); 78 if (vm == 0) { 79 _kvm_err(kd, kd->program, "cannot allocate vm"); 80 return (-1); 81 } 82 kd->vmst = vm; 83 vm->page_size = PAGE_SIZE; 84 85 nlist[0].n_name = "_Lev1map"; 86 nlist[1].n_name = 0; 87 88 if (kvm_nlist(kd, nlist) != 0) { 89 _kvm_err(kd, kd->program, "bad namelist"); 90 return (-1); 91 } 92 93 if(!ISALIVE(kd)) { 94 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) { 95 _kvm_err(kd, kd->program, "cannot read Lev1map"); 96 return (-1); 97 } 98 } else 99 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) { 100 _kvm_err(kd, kd->program, "cannot read Lev1map"); 101 return (-1); 102 } 103 vm->lev1map_pa = pa; 104 return (0); 105 106} 107 108int 109_kvm_kvatop(kd, va, pa) 110 kvm_t *kd; 111 u_long va; 112 u_long *pa; 113{ 114 u_int64_t lev1map_pa; /* PA of Lev1map */ 115 u_int64_t page_size; 116 int rv, page_off; 117 pv_entry_t pte; 118 off_t pteoff; 119 struct vmstate *vm; 120 vm = kd->vmst ; 121 122 123 if (ISALIVE(kd)) { 124 _kvm_err(kd, 0, "vatop called in live kernel!"); 125 return(0); 126 } 127 lev1map_pa = vm->lev1map_pa; 128 page_size = vm->page_size; 129 130 page_off = va & (page_size - 1); 131 if (va >= IA64_RR_BASE(6) && va <= IA64_RR_BASE(7) + ((1L<<61)-1)) { 132 /* 133 * Direct-mapped address: just convert it. 134 */ 135 136 *pa = IA64_RR_MASK(va); 137 rv = page_size - page_off; 138 } else if (va >= IA64_RR_BASE(5) && va < IA64_RR_BASE(6)) { 139 /* 140 * Real kernel virtual address: do the translation. 141 */ 142 goto lose; 143 } else { 144 /* 145 * Bogus address (not in KV space): punt. 146 */ 147 148 _kvm_err(kd, 0, "invalid kernel virtual address"); 149lose: 150 *pa = -1; 151 rv = 0; 152 } 153 154 return (rv); 155} 156 157/* 158 * Translate a physical address to a file-offset in the crash-dump. 159 */ 160off_t 161_kvm_pa2off(kd, pa) 162 kvm_t *kd; 163 u_long pa; 164{ 165 return IA64_PHYS_TO_RR7(pa); 166} 167 168