kvm_amd64.c revision 1603
1228072Sbapt/*- 2228072Sbapt * Copyright (c) 1989, 1992, 1993 3228072Sbapt * The Regents of the University of California. All rights reserved. 4228072Sbapt * 5228072Sbapt * This code is derived from software developed by the Computer Systems 6228072Sbapt * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 7228072Sbapt * BG 91-66 and contributed to Berkeley. 8228072Sbapt * 9228072Sbapt * Redistribution and use in source and binary forms, with or without 10228072Sbapt * modification, are permitted provided that the following conditions 11228072Sbapt * are met: 12228072Sbapt * 1. Redistributions of source code must retain the above copyright 13228072Sbapt * notice, this list of conditions and the following disclaimer. 14228072Sbapt * 2. Redistributions in binary form must reproduce the above copyright 15228072Sbapt * notice, this list of conditions and the following disclaimer in the 16228072Sbapt * documentation and/or other materials provided with the distribution. 17228072Sbapt * 3. All advertising materials mentioning features or use of this software 18228072Sbapt * must display the following acknowledgement: 19228072Sbapt * This product includes software developed by the University of 20228072Sbapt * California, Berkeley and its contributors. 21228072Sbapt * 4. Neither the name of the University nor the names of its contributors 22228072Sbapt * may be used to endorse or promote products derived from this software 23228072Sbapt * without specific prior written permission. 24228072Sbapt * 25228072Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26228072Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27228072Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28228072Sbapt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29228072Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30228072Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31228072Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32228072Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33228072Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34228072Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35228072Sbapt * SUCH DAMAGE. 36228072Sbapt */ 37228072Sbapt 38228072Sbapt#if defined(LIBC_SCCS) && !defined(lint) 39228072Sbaptstatic char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; 40228072Sbapt#endif /* LIBC_SCCS and not lint */ 41228072Sbapt 42228072Sbapt/* 43228072Sbapt * i386 machine dependent routines for kvm. Hopefully, the forthcoming 44228072Sbapt * vm code will one day obsolete this module. 45228072Sbapt */ 46228072Sbapt 47228072Sbapt#include <sys/param.h> 48228072Sbapt#include <sys/user.h> 49228072Sbapt#include <sys/proc.h> 50228072Sbapt#include <sys/stat.h> 51228072Sbapt#include <unistd.h> 52228072Sbapt#include <nlist.h> 53228072Sbapt#include <kvm.h> 54228072Sbapt 55228072Sbapt#include <vm/vm.h> 56228072Sbapt#include <vm/vm_param.h> 57228072Sbapt 58228072Sbapt#include <limits.h> 59228072Sbapt#include <db.h> 60250125Sjkim 61228072Sbapt#include "kvm_private.h" 62228072Sbapt 63228072Sbapt#ifndef btop 64228072Sbapt#define btop(x) (i386_btop(x)) 65228072Sbapt#define ptob(x) (i386_ptob(x)) 66228072Sbapt#endif 67228072Sbapt 68228072Sbaptstruct vmstate { 69228072Sbapt struct pde **IdlePTD; 70228072Sbapt struct pde *PTD; 71228072Sbapt}; 72228072Sbapt 73228072Sbapt#define KREAD(kd, addr, p)\ 74228072Sbapt (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) 75228072Sbapt 76228072Sbaptvoid 77228072Sbapt_kvm_freevtop(kvm_t *kd) { 78228072Sbapt if (kd->vmst->PTD) { 79228072Sbapt free(kd->vmst->PTD); 80228072Sbapt } 81228072Sbapt if (kd->vmst != 0) { 82228072Sbapt free(kd->vmst); 83228072Sbapt } 84228072Sbapt} 85228072Sbapt 86228072Sbaptint 87228072Sbapt_kvm_initvtop(kvm_t *kd) { 88228072Sbapt struct vmstate *vm; 89228072Sbapt struct nlist nlist[2]; 90228072Sbapt 91228072Sbapt vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); 92228072Sbapt if (vm == 0) { 93228072Sbapt _kvm_err(kd, kd->program, "cannot allocate vm"); 94228072Sbapt return (-1); 95228072Sbapt } 96228072Sbapt kd->vmst = vm; 97228072Sbapt 98228072Sbapt nlist[0].n_name = "_IdlePTD"; 99228072Sbapt nlist[1].n_name = 0; 100228072Sbapt 101228072Sbapt if (kvm_nlist(kd, nlist) != 0) { 102228072Sbapt _kvm_err(kd, kd->program, "bad namelist"); 103228072Sbapt return (-1); 104228072Sbapt } 105228072Sbapt vm->IdlePTD = 0; 106228072Sbapt if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { 107228072Sbapt _kvm_err(kd, kd->program, "cannot read IdlePTD"); 108228072Sbapt return (-1); 109228072Sbapt } 110228072Sbapt if ((vm->PTD = _kvm_malloc(kd, NBPG /*sizeof(struct pde)*/)) != 0) { 111228072Sbapt _kvm_err(kd, kd->program, "cannot allocate vm->PTD"); 112228072Sbapt } 113228072Sbapt if (KREAD(kd, (u_long)nlist[1].n_value, &vm->PTD)) { 114228072Sbapt _kvm_err(kd, kd->program, "cannot read PTD"); 115228072Sbapt return (-1); 116228072Sbapt } 117228072Sbapt return (0); 118228072Sbapt} 119228072Sbapt 120228072Sbaptstatic int 121228072Sbapt_kvm_vatop(kvm_t *kd, u_long va, u_long *pa) { 122228072Sbapt 123228072Sbapt if (ISALIVE(kd)) { 124228072Sbapt _kvm_err(kd, 0, "vatop called in live kernel!"); 125228072Sbapt return((off_t)0); 126228072Sbapt } 127228072Sbapt _kvm_err(kd, 0, "invalid address (%x)", va); 128228072Sbapt return ((off_t)0); 129228072Sbapt} 130228072Sbapt 131228072Sbaptint 132228072Sbapt_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa) { 133228072Sbapt return (_kvm_vatop(kd, va, pa)); 134228072Sbapt} 135228072Sbapt 136228072Sbapt/* 137228072Sbapt * Translate a user virtual address to a physical address. 138228072Sbapt */ 139228072Sbaptint 140228072Sbapt_kvm_uvatop(kvm_t *kd, const struct proc *p, u_long va, u_long *pa) { 141228072Sbapt if (ISALIVE(kd)) { 142228072Sbapt /* Not done yet */ 143228072Sbapt } else { 144228072Sbapt /* Not done yet */ 145228072Sbapt } 146228072Sbapt return ((off_t)(0)); 147228072Sbapt} 148228072Sbapt