Home | History | Annotate | Line # | Download | only in libkvm
kvm_vax.c revision 1.1
      1  1.1  ragge /*-
      2  1.1  ragge  * Copyright (c) 1992, 1993
      3  1.1  ragge  *	The Regents of the University of California.  All rights reserved.
      4  1.1  ragge  *
      5  1.1  ragge  * This code is derived from software developed by the Computer Systems
      6  1.1  ragge  * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
      7  1.1  ragge  * BG 91-66 and contributed to Berkeley.
      8  1.1  ragge  *
      9  1.1  ragge  * Redistribution and use in source and binary forms, with or without
     10  1.1  ragge  * modification, are permitted provided that the following conditions
     11  1.1  ragge  * are met:
     12  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     13  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     14  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     17  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     18  1.1  ragge  *    must display the following acknowledgement:
     19  1.1  ragge  *	This product includes software developed by the University of
     20  1.1  ragge  *	California, Berkeley and its contributors.
     21  1.1  ragge  * 4. Neither the name of the University nor the names of its contributors
     22  1.1  ragge  *    may be used to endorse or promote products derived from this software
     23  1.1  ragge  *    without specific prior written permission.
     24  1.1  ragge  *
     25  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1  ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1  ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1  ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1  ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1  ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1  ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1  ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1  ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1  ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1  ragge  * SUCH DAMAGE.
     36  1.1  ragge  */
     37  1.1  ragge 
     38  1.1  ragge /*
     39  1.1  ragge  * VAX machine dependent routines for kvm.  Hopefully, the forthcoming
     40  1.1  ragge  * vm code will one day obsolete this module.  Furthermore, I hope it
     41  1.1  ragge  * gets here soon, because this basically is an error stub! (sorry)
     42  1.1  ragge  * This code may not work anyway.
     43  1.1  ragge  */
     44  1.1  ragge 
     45  1.1  ragge #include <sys/param.h>
     46  1.1  ragge #include <sys/user.h>
     47  1.1  ragge #include <sys/proc.h>
     48  1.1  ragge #include <sys/stat.h>
     49  1.1  ragge #include <unistd.h>
     50  1.1  ragge #include <nlist.h>
     51  1.1  ragge #include <kvm.h>
     52  1.1  ragge 
     53  1.1  ragge #include <vm/vm.h>
     54  1.1  ragge #include <vm/vm_param.h>
     55  1.1  ragge 
     56  1.1  ragge #include <limits.h>
     57  1.1  ragge #include <db.h>
     58  1.1  ragge 
     59  1.1  ragge #include "kvm_private.h"
     60  1.1  ragge 
     61  1.1  ragge struct vmstate {
     62  1.1  ragge 	u_long end;
     63  1.1  ragge };
     64  1.1  ragge 
     65  1.1  ragge void
     66  1.1  ragge _kvm_freevtop(kd)
     67  1.1  ragge 	kvm_t *kd;
     68  1.1  ragge {
     69  1.1  ragge 	if (kd->vmst != 0)
     70  1.1  ragge 		free(kd->vmst);
     71  1.1  ragge }
     72  1.1  ragge 
     73  1.1  ragge int
     74  1.1  ragge _kvm_initvtop(kd)
     75  1.1  ragge 	kvm_t *kd;
     76  1.1  ragge {
     77  1.1  ragge 	register int i;
     78  1.1  ragge 	register int off;
     79  1.1  ragge 	register struct vmstate *vm;
     80  1.1  ragge 	struct stat st;
     81  1.1  ragge 	struct nlist nlist[2];
     82  1.1  ragge 
     83  1.1  ragge 	vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
     84  1.1  ragge 	if (vm == 0)
     85  1.1  ragge 		return (-1);
     86  1.1  ragge 
     87  1.1  ragge 	kd->vmst = vm;
     88  1.1  ragge 
     89  1.1  ragge 	if (fstat(kd->pmfd, &st) < 0)
     90  1.1  ragge 		return (-1);
     91  1.1  ragge 
     92  1.1  ragge 	/* Get end of kernel address */
     93  1.1  ragge 	nlist[0].n_name = "_end";
     94  1.1  ragge 	nlist[1].n_name = 0;
     95  1.1  ragge 	if (kvm_nlist(kd, nlist) != 0) {
     96  1.1  ragge 		_kvm_err(kd, kd->program, "pmap_stod: no such symbol");
     97  1.1  ragge 		return (-1);
     98  1.1  ragge 	}
     99  1.1  ragge 	vm->end = (u_long)nlist[0].n_value;
    100  1.1  ragge 
    101  1.1  ragge 	return (0);
    102  1.1  ragge }
    103  1.1  ragge 
    104  1.1  ragge #define VA_OFF(va) (va & (NBPG - 1))
    105  1.1  ragge 
    106  1.1  ragge /*
    107  1.1  ragge  * Translate a kernel virtual address to a physical address using the
    108  1.1  ragge  * mapping information in kd->vm.  Returns the result in pa, and returns
    109  1.1  ragge  * the number of bytes that are contiguously available from this
    110  1.1  ragge  * physical address.  This routine is used only for crashdumps.
    111  1.1  ragge  */
    112  1.1  ragge int
    113  1.1  ragge _kvm_kvatop(kd, va, pa)
    114  1.1  ragge 	kvm_t *kd;
    115  1.1  ragge 	u_long va;
    116  1.1  ragge 	u_long *pa;
    117  1.1  ragge {
    118  1.1  ragge 	register int end;
    119  1.1  ragge 
    120  1.1  ragge 	if (va < KERNBASE) {
    121  1.1  ragge 		_kvm_err(kd, 0, "invalid address (%x<%x)", va, KERNBASE);
    122  1.1  ragge 		return (0);
    123  1.1  ragge 	}
    124  1.1  ragge 
    125  1.1  ragge 	end = kd->vmst->end;
    126  1.1  ragge 	if (va >= end) {
    127  1.1  ragge 		_kvm_err(kd, 0, "invalid address (%x>=%x)", va, end);
    128  1.1  ragge 		return (0);
    129  1.1  ragge 	}
    130  1.1  ragge 
    131  1.1  ragge 	*pa = (va - KERNBASE);
    132  1.1  ragge 	return (end - va);
    133  1.1  ragge }
    134