kvm_amd64.c revision 4231
1139749Simp/*- 2119853Scg * Copyright (c) 1989, 1992, 1993 350724Scg * The Regents of the University of California. All rights reserved. 450724Scg * 550724Scg * This code is derived from software developed by the Computer Systems 650724Scg * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 750724Scg * BG 91-66 and contributed to Berkeley. 850724Scg * 950724Scg * Redistribution and use in source and binary forms, with or without 1050724Scg * modification, are permitted provided that the following conditions 1150724Scg * are met: 1250724Scg * 1. Redistributions of source code must retain the above copyright 1350724Scg * notice, this list of conditions and the following disclaimer. 1450724Scg * 2. Redistributions in binary form must reproduce the above copyright 1550724Scg * notice, this list of conditions and the following disclaimer in the 1650724Scg * documentation and/or other materials provided with the distribution. 1750724Scg * 3. All advertising materials mentioning features or use of this software 1850724Scg * must display the following acknowledgement: 1950724Scg * This product includes software developed by the University of 2050724Scg * California, Berkeley and its contributors. 2150724Scg * 4. Neither the name of the University nor the names of its contributors 2250724Scg * may be used to endorse or promote products derived from this software 2350724Scg * without specific prior written permission. 2450724Scg * 2550724Scg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2650733Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2750724Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2850724Scg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2950724Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3050724Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3150724Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3250724Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3350724Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3450724Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3550724Scg * SUCH DAMAGE. 3650724Scg */ 3750724Scg 3850724Scg#if defined(LIBC_SCCS) && !defined(lint) 3950724Scgstatic char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; 4050724Scg#endif /* LIBC_SCCS and not lint */ 4150724Scg 4250724Scg/* 4350724Scg * i386 machine dependent routines for kvm. Hopefully, the forthcoming 4450724Scg * vm code will one day obsolete this module. 4550724Scg */ 4650724Scg 4750724Scg#include <sys/param.h> 4850724Scg#include <sys/user.h> 4950724Scg#include <sys/proc.h> 5050724Scg#include <sys/stat.h> 5150724Scg#include <unistd.h> 5250724Scg#include <nlist.h> 5350724Scg#include <kvm.h> 5450724Scg 5550724Scg#include <vm/vm.h> 5650724Scg#include <vm/vm_param.h> 5750724Scg 5850724Scg#include <limits.h> 5950724Scg#include <db.h> 6050724Scg 6150724Scg#include "kvm_private.h" 6250724Scg 6350724Scg#ifndef btop 6450724Scg#define btop(x) (i386_btop(x)) 6550724Scg#define ptob(x) (i386_ptob(x)) 6650724Scg#endif 6750724Scg 6850724Scgstruct vmstate { 6950724Scg struct pde **IdlePTD; 7050724Scg struct pde *PTD; 7150724Scg}; 7250724Scg 7350724Scg#define KREAD(kd, addr, p)\ 7450724Scg (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) 7550724Scg 7650724Scgvoid 7750724Scg_kvm_freevtop(kvm_t *kd) { 7850724Scg if (kd->vmst->PTD) { 7950724Scg free(kd->vmst->PTD); 8050724Scg } 8150724Scg if (kd->vmst != 0) { 8250724Scg free(kd->vmst); 8350724Scg } 8450724Scg} 8550724Scg 8650724Scgint 8750724Scg_kvm_initvtop(kvm_t *kd) { 8850724Scg struct vmstate *vm; 8950724Scg struct nlist nlist[2]; 9050724Scg 9150724Scg vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); 9250724Scg if (vm == 0) { 9350724Scg _kvm_err(kd, kd->program, "cannot allocate vm"); 9450724Scg return (-1); 9550724Scg } 9650724Scg kd->vmst = vm; 9750724Scg 9850724Scg nlist[0].n_name = "_IdlePTD"; 9950724Scg nlist[1].n_name = 0; 100 101 if (kvm_nlist(kd, nlist) != 0) { 102 _kvm_err(kd, kd->program, "bad namelist"); 103 return (-1); 104 } 105 vm->PTD = 0 106 vm->IdlePTD = 0; 107 if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { 108 _kvm_err(kd, kd->program, "cannot read IdlePTD"); 109 return (-1); 110 } 111 if ((vm->PTD = _kvm_malloc(kd, NBPG /*sizeof(struct pde)*/)) != 0) { 112 _kvm_err(kd, kd->program, "cannot allocate vm->PTD"); 113 } 114 if (KREAD(kd, (u_long)nlist[1].n_value, &vm->PTD)) { 115 _kvm_err(kd, kd->program, "cannot read PTD"); 116 return (-1); 117 } 118 return (0); 119} 120 121static int 122_kvm_vatop(kvm_t *kd, u_long va, u_long *pa) { 123 124 if (ISALIVE(kd)) { 125 _kvm_err(kd, 0, "vatop called in live kernel!"); 126 return((off_t)0); 127 } 128 _kvm_err(kd, 0, "invalid address (%x)", va); 129 return ((off_t)0); 130} 131 132int 133_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa) { 134 return (_kvm_vatop(kd, va, pa)); 135} 136