kvm_i386.c revision 1603
14Srgrimes/*- 24Srgrimes * Copyright (c) 1989, 1992, 1993 34Srgrimes * The Regents of the University of California. All rights reserved. 44Srgrimes * 54Srgrimes * This code is derived from software developed by the Computer Systems 64Srgrimes * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 74Srgrimes * BG 91-66 and contributed to Berkeley. 84Srgrimes * 94Srgrimes * Redistribution and use in source and binary forms, with or without 104Srgrimes * modification, are permitted provided that the following conditions 114Srgrimes * are met: 124Srgrimes * 1. Redistributions of source code must retain the above copyright 134Srgrimes * notice, this list of conditions and the following disclaimer. 144Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 154Srgrimes * notice, this list of conditions and the following disclaimer in the 164Srgrimes * documentation and/or other materials provided with the distribution. 174Srgrimes * 3. All advertising materials mentioning features or use of this software 184Srgrimes * must display the following acknowledgement: 194Srgrimes * This product includes software developed by the University of 204Srgrimes * California, Berkeley and its contributors. 214Srgrimes * 4. Neither the name of the University nor the names of its contributors 224Srgrimes * may be used to endorse or promote products derived from this software 234Srgrimes * without specific prior written permission. 244Srgrimes * 254Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 264Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 274Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 284Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 294Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 304Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 314Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 324Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 334Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 344Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 354Srgrimes * SUCH DAMAGE. 364Srgrimes */ 374Srgrimes 38620Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 3948104Syokotastatic char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; 404Srgrimes#endif /* LIBC_SCCS and not lint */ 414Srgrimes 4232726Seivind/* 4332726Seivind * i386 machine dependent routines for kvm. Hopefully, the forthcoming 442056Swollman * vm code will one day obsolete this module. 4512675Sjulian */ 4612675Sjulian 4712675Sjulian#include <sys/param.h> 481549Srgrimes#include <sys/user.h> 495764Sbde#include <sys/proc.h> 5012675Sjulian#include <sys/stat.h> 5118951Sjulian#include <unistd.h> 5212701Sphk#include <nlist.h> 532056Swollman#include <kvm.h> 542056Swollman 5534924Sbde#include <vm/vm.h> 564Srgrimes#include <vm/vm_param.h> 5712701Sphk 582056Swollman#include <limits.h> 594Srgrimes#include <db.h> 6012675Sjulian 6112675Sjulian#include "kvm_private.h" 6212675Sjulian 6312675Sjulian#ifndef btop 6412675Sjulian#define btop(x) (i386_btop(x)) 6529368Speter#define ptob(x) (i386_ptob(x)) 6612675Sjulian#endif 6738485Sbde 6847625Sphkstruct vmstate { 6947625Sphk struct pde **IdlePTD; 7047625Sphk struct pde *PTD; 7147625Sphk}; 7247625Sphk 7347625Sphk#define KREAD(kd, addr, p)\ 7447625Sphk (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) 7547625Sphk 7647625Sphkvoid 7747625Sphk_kvm_freevtop(kvm_t *kd) { 7847625Sphk if (kd->vmst->PTD) { 7947625Sphk free(kd->vmst->PTD); 8047625Sphk } 8147625Sphk if (kd->vmst != 0) { 8247625Sphk free(kd->vmst); 8347625Sphk } 8447625Sphk} 8547625Sphk 8647625Sphkint 8747625Sphk_kvm_initvtop(kvm_t *kd) { 8838485Sbde struct vmstate *vm; 8912675Sjulian struct nlist nlist[2]; 9027982Sjulian 9141612Seivind vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); 9212701Sphk if (vm == 0) { 9327982Sjulian _kvm_err(kd, kd->program, "cannot allocate vm"); 9418951Sjulian return (-1); 9512701Sphk } 967680Sjoerg kd->vmst = vm; 977680Sjoerg 987680Sjoerg nlist[0].n_name = "_IdlePTD"; 997680Sjoerg nlist[1].n_name = 0; 1004Srgrimes 10127982Sjulian if (kvm_nlist(kd, nlist) != 0) { 10227982Sjulian _kvm_err(kd, kd->program, "bad namelist"); 10327982Sjulian return (-1); 1045764Sbde } 10527982Sjulian vm->IdlePTD = 0; 10627982Sjulian if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { 10727982Sjulian _kvm_err(kd, kd->program, "cannot read IdlePTD"); 10812675Sjulian return (-1); 10927982Sjulian } 11012675Sjulian if ((vm->PTD = _kvm_malloc(kd, NBPG /*sizeof(struct pde)*/)) != 0) { 1115764Sbde _kvm_err(kd, kd->program, "cannot allocate vm->PTD"); 11248104Syokota } 11342373Syokota if (KREAD(kd, (u_long)nlist[1].n_value, &vm->PTD)) { 114798Swollman _kvm_err(kd, kd->program, "cannot read PTD"); 1154Srgrimes return (-1); 1164Srgrimes } 11710665Sbde return (0); 11848104Syokota} 1194Srgrimes 1204Srgrimesstatic int 12110665Sbde_kvm_vatop(kvm_t *kd, u_long va, u_long *pa) { 1224Srgrimes 12310665Sbde if (ISALIVE(kd)) { 12448104Syokota _kvm_err(kd, 0, "vatop called in live kernel!"); 12542373Syokota return((off_t)0); 12642373Syokota } 12742373Syokota _kvm_err(kd, 0, "invalid address (%x)", va); 1284Srgrimes return ((off_t)0); 1294Srgrimes} 13010665Sbde 13110665Sbdeint 1324Srgrimes_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa) { 13310665Sbde return (_kvm_vatop(kd, va, pa)); 1344Srgrimes} 13518951Sjulian 13618951Sjulian/* 13718951Sjulian * Translate a user virtual address to a physical address. 13818951Sjulian */ 13918951Sjulianint 14018951Sjulian_kvm_uvatop(kvm_t *kd, const struct proc *p, u_long va, u_long *pa) { 14118951Sjulian if (ISALIVE(kd)) { 14218951Sjulian /* Not done yet */ 14318951Sjulian } else { 14418951Sjulian /* Not done yet */ 14518951Sjulian } 14618951Sjulian return ((off_t)(0)); 14710665Sbde} 1484Srgrimes