kvm_i386.c revision 15533
16735Samurai/*- 26735Samurai * Copyright (c) 1989, 1992, 1993 36735Samurai * The Regents of the University of California. All rights reserved. 46735Samurai * 56735Samurai * This code is derived from software developed by the Computer Systems 66735Samurai * Engineering group at Lawrence Berkeley Laboratory under DARPA contract 76735Samurai * BG 91-66 and contributed to Berkeley. 86735Samurai * 96735Samurai * Redistribution and use in source and binary forms, with or without 106735Samurai * modification, are permitted provided that the following conditions 116735Samurai * are met: 126735Samurai * 1. Redistributions of source code must retain the above copyright 136735Samurai * notice, this list of conditions and the following disclaimer. 146735Samurai * 2. Redistributions in binary form must reproduce the above copyright 156735Samurai * notice, this list of conditions and the following disclaimer in the 166735Samurai * documentation and/or other materials provided with the distribution. 176735Samurai * 3. All advertising materials mentioning features or use of this software 186735Samurai * must display the following acknowledgement: 198857Srgrimes * This product includes software developed by the University of 2050479Speter * California, Berkeley and its contributors. 218857Srgrimes * 4. Neither the name of the University nor the names of its contributors 226735Samurai * may be used to endorse or promote products derived from this software 236735Samurai * without specific prior written permission. 246735Samurai * 256735Samurai * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 266735Samurai * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 276735Samurai * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2843313Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 296735Samurai * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 306735Samurai * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 316735Samurai * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 326735Samurai * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 336735Samurai * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 346735Samurai * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3532721Sbrian * SUCH DAMAGE. 3636285Sbrian */ 3736285Sbrian 3836285Sbrian#if defined(LIBC_SCCS) && !defined(lint) 3930715Sbrianstatic char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; 4046085Sbrian#endif /* LIBC_SCCS and not lint */ 4130715Sbrian 4232616Sbrian/* 4330715Sbrian * i386 machine dependent routines for kvm. Hopefully, the forthcoming 4432616Sbrian * vm code will one day obsolete this module. 4546686Sbrian */ 4630715Sbrian 4730715Sbrian#include <sys/param.h> 4846686Sbrian#include <sys/user.h> 4930715Sbrian#include <sys/proc.h> 5029265Sbrian#include <sys/stat.h> 5131061Sbrian#include <unistd.h> 5236285Sbrian#include <nlist.h> 5336285Sbrian#include <kvm.h> 5436285Sbrian 5536285Sbrian#include <vm/vm.h> 5636285Sbrian#include <vm/vm_param.h> 5736285Sbrian 5838557Sbrian#include <limits.h> 5938557Sbrian#include <db.h> 6036285Sbrian 6136285Sbrian#include "kvm_private.h" 6236285Sbrian 6336285Sbrian#ifndef btop 6436285Sbrian#define btop(x) (i386_btop(x)) 6536285Sbrian#define ptob(x) (i386_ptob(x)) 6636285Sbrian#endif 6743313Sbrian 6843313Sbrianstruct vmstate { 6943313Sbrian struct pde **IdlePTD; 7036285Sbrian struct pde *PTD; 7158032Sbrian}; 7230715Sbrian 736735Samurai#define KREAD(kd, addr, p)\ 7432616Sbrian (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) 756735Samurai 766735Samuraivoid 776735Samurai_kvm_freevtop(kvm_t *kd) { 786735Samurai if (kd->vmst->PTD) { 7930715Sbrian free(kd->vmst->PTD); 806735Samurai } 816735Samurai if (kd->vmst != 0) { 826735Samurai free(kd->vmst); 836735Samurai } 846735Samurai} 856735Samurai 866735Samuraiint 8736285Sbrian_kvm_initvtop(kvm_t *kd) { 886735Samurai struct vmstate *vm; 896735Samurai struct nlist nlist[2]; 9028679Sbrian 9128679Sbrian vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm)); 9228679Sbrian if (vm == 0) { 9328679Sbrian _kvm_err(kd, kd->program, "cannot allocate vm"); 9430715Sbrian return (-1); 956735Samurai } 9640665Sbrian kd->vmst = vm; 9740665Sbrian 986735Samurai nlist[0].n_name = "_IdlePTD"; 9928679Sbrian nlist[1].n_name = 0; 1006735Samurai 10128679Sbrian if (kvm_nlist(kd, nlist) != 0) { 10228679Sbrian _kvm_err(kd, kd->program, "bad namelist"); 10328679Sbrian return (-1); 10428679Sbrian } 10540665Sbrian vm->PTD = 0; 10631962Sbrian vm->IdlePTD = 0; 10780730Sbrian if (KREAD(kd, (u_long)nlist[0].n_value, &vm->IdlePTD)) { 10840665Sbrian _kvm_err(kd, kd->program, "cannot read IdlePTD"); 10940665Sbrian return (-1); 11028679Sbrian } 11128679Sbrian if ((vm->PTD = _kvm_malloc(kd, PAGE_SIZE /*sizeof(struct pde)*/)) != 0) { 11231061Sbrian _kvm_err(kd, kd->program, "cannot allocate vm->PTD"); 11331061Sbrian } 11436285Sbrian if (KREAD(kd, (u_long)nlist[1].n_value, &vm->PTD)) { 11528679Sbrian _kvm_err(kd, kd->program, "cannot read PTD"); 11628679Sbrian return (-1); 11728679Sbrian } 11840665Sbrian return (0); 11928679Sbrian} 12028679Sbrian 12136285Sbrianstatic int 12228679Sbrian_kvm_vatop(kvm_t *kd, u_long va, u_long *pa) { 12328679Sbrian 12428679Sbrian if (ISALIVE(kd)) { 12528679Sbrian _kvm_err(kd, 0, "vatop called in live kernel!"); 12636285Sbrian return((off_t)0); 12728679Sbrian } 1286735Samurai _kvm_err(kd, 0, "invalid address (%x)", va); 12928679Sbrian return ((off_t)0); 13028679Sbrian} 13140665Sbrian 13240665Sbrianint 13340665Sbrian_kvm_kvatop(kvm_t *kd, u_long va, u_long *pa) { 13440665Sbrian return (_kvm_vatop(kd, va, pa)); 13540665Sbrian} 13640665Sbrian