Home | History | Annotate | Line # | Download | only in libkvm
kvm_sun3.c revision 1.4
      1  1.4      gwr /*	$NetBSD: kvm_sun3.c,v 1.4 1996/05/05 04:32:18 gwr Exp $	*/
      2  1.3  thorpej 
      3  1.1      gwr /*-
      4  1.1      gwr  * Copyright (c) 1992, 1993
      5  1.1      gwr  *	The Regents of the University of California.  All rights reserved.
      6  1.1      gwr  *
      7  1.1      gwr  * This code is derived from software developed by the Computer Systems
      8  1.1      gwr  * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
      9  1.1      gwr  * BG 91-66 and contributed to Berkeley.
     10  1.1      gwr  *
     11  1.1      gwr  * Redistribution and use in source and binary forms, with or without
     12  1.1      gwr  * modification, are permitted provided that the following conditions
     13  1.1      gwr  * are met:
     14  1.1      gwr  * 1. Redistributions of source code must retain the above copyright
     15  1.1      gwr  *    notice, this list of conditions and the following disclaimer.
     16  1.1      gwr  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1      gwr  *    notice, this list of conditions and the following disclaimer in the
     18  1.1      gwr  *    documentation and/or other materials provided with the distribution.
     19  1.1      gwr  * 3. All advertising materials mentioning features or use of this software
     20  1.1      gwr  *    must display the following acknowledgement:
     21  1.1      gwr  *	This product includes software developed by the University of
     22  1.1      gwr  *	California, Berkeley and its contributors.
     23  1.1      gwr  * 4. Neither the name of the University nor the names of its contributors
     24  1.1      gwr  *    may be used to endorse or promote products derived from this software
     25  1.1      gwr  *    without specific prior written permission.
     26  1.1      gwr  *
     27  1.1      gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.1      gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.1      gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.1      gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.1      gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.1      gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.1      gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.1      gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.1      gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.1      gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.1      gwr  * SUCH DAMAGE.
     38  1.1      gwr  */
     39  1.1      gwr 
     40  1.4      gwr #if defined(LIBC_SCCS) && !defined(lint)
     41  1.4      gwr #if 0
     42  1.4      gwr static char sccsid[] = "@(#)kvm_sparc.c	8.1 (Berkeley) 6/4/93";
     43  1.4      gwr #else
     44  1.4      gwr static char *rcsid = "$NetBSD: kvm_sun3.c,v 1.4 1996/05/05 04:32:18 gwr Exp $";
     45  1.4      gwr #endif
     46  1.4      gwr #endif /* LIBC_SCCS and not lint */
     47  1.4      gwr 
     48  1.1      gwr /*
     49  1.4      gwr  * Sun3 machine dependent routines for kvm.
     50  1.1      gwr  */
     51  1.1      gwr 
     52  1.1      gwr #include <sys/param.h>
     53  1.1      gwr #include <sys/user.h>
     54  1.1      gwr #include <sys/proc.h>
     55  1.1      gwr #include <sys/stat.h>
     56  1.4      gwr 
     57  1.4      gwr #include <sys/core.h>
     58  1.4      gwr #include <sys/exec_aout.h>
     59  1.4      gwr #include <sys/kcore.h>
     60  1.4      gwr 
     61  1.1      gwr #include <unistd.h>
     62  1.4      gwr #include <limits.h>
     63  1.1      gwr #include <nlist.h>
     64  1.1      gwr #include <kvm.h>
     65  1.4      gwr #include <db.h>
     66  1.1      gwr 
     67  1.1      gwr #include <vm/vm.h>
     68  1.1      gwr #include <vm/vm_param.h>
     69  1.1      gwr 
     70  1.4      gwr #include <machine/kcore.h>
     71  1.4      gwr #include <machine/pte.h>
     72  1.1      gwr 
     73  1.1      gwr #include "kvm_private.h"
     74  1.1      gwr 
     75  1.4      gwr #define NKSEG (NSEGMAP/8)	/* kernel segmap entries */
     76  1.1      gwr struct vmstate {
     77  1.4      gwr 	/* Page Map Entry Group (PMEG) */
     78  1.4      gwr 	int   pmeg[NKSEG][NPAGSEG];
     79  1.1      gwr };
     80  1.1      gwr 
     81  1.4      gwr /*
     82  1.4      gwr  * Prepare for translation of kernel virtual addresses into offsets
     83  1.4      gwr  * into crash dump files. We use the MMU specific goop written at the
     84  1.4      gwr  * beginning of a crash dump by dumpsys()
     85  1.4      gwr  * Note: sun3 MMU specific!
     86  1.4      gwr  */
     87  1.1      gwr int
     88  1.1      gwr _kvm_initvtop(kd)
     89  1.1      gwr 	kvm_t *kd;
     90  1.1      gwr {
     91  1.4      gwr 	register char *p;
     92  1.4      gwr 
     93  1.4      gwr 	p = kd->cpu_data;
     94  1.4      gwr 	p += (NBPG - sizeof(kcore_seg_t));
     95  1.4      gwr 	kd->vmst = (struct vmstate *)p;
     96  1.1      gwr 
     97  1.1      gwr 	return (0);
     98  1.1      gwr }
     99  1.1      gwr 
    100  1.4      gwr void
    101  1.4      gwr _kvm_freevtop(kd)
    102  1.4      gwr 	kvm_t *kd;
    103  1.4      gwr {
    104  1.4      gwr 	/* This was set by pointer arithmetic, not allocation. */
    105  1.4      gwr 	kd->vmst = (void*)0;
    106  1.4      gwr }
    107  1.1      gwr 
    108  1.1      gwr /*
    109  1.1      gwr  * Translate a kernel virtual address to a physical address using the
    110  1.1      gwr  * mapping information in kd->vm.  Returns the result in pa, and returns
    111  1.1      gwr  * the number of bytes that are contiguously available from this
    112  1.1      gwr  * physical address.  This routine is used only for crashdumps.
    113  1.1      gwr  */
    114  1.1      gwr int
    115  1.4      gwr _kvm_kvatop(kd, va, pap)
    116  1.1      gwr 	kvm_t *kd;
    117  1.1      gwr 	u_long va;
    118  1.4      gwr 	u_long *pap;
    119  1.1      gwr {
    120  1.4      gwr 	register cpu_kcore_hdr_t *ckh;
    121  1.4      gwr 	u_int segnum, sme, ptenum;
    122  1.4      gwr 	int pte, offset;
    123  1.4      gwr 	u_long pa;
    124  1.4      gwr 
    125  1.4      gwr 	if (ISALIVE(kd)) {
    126  1.4      gwr 		_kvm_err(kd, 0, "vatop called in live kernel!");
    127  1.4      gwr 		return((off_t)0);
    128  1.4      gwr 	}
    129  1.4      gwr 	ckh = kd->cpu_data;
    130  1.1      gwr 
    131  1.1      gwr 	if (va < KERNBASE) {
    132  1.4      gwr 		_kvm_err(kd, 0, "not a kernel address");
    133  1.4      gwr 		return((off_t)0);
    134  1.1      gwr 	}
    135  1.1      gwr 
    136  1.4      gwr 	/*
    137  1.4      gwr 	 * Get the segmap entry (sme) from the kernel segmap.
    138  1.4      gwr 	 * Note: only have segmap entries from KERNBASE to end.
    139  1.4      gwr 	 */
    140  1.4      gwr 	segnum = VA_SEGNUM(va - KERNBASE);
    141  1.4      gwr 	ptenum = VA_PTE_NUM(va);
    142  1.4      gwr 	offset = va & PGOFSET;
    143  1.4      gwr 
    144  1.4      gwr 	/* The segmap entry selects a PMEG. */
    145  1.4      gwr 	sme = ckh->ksegmap[segnum];
    146  1.4      gwr 	pte = kd->vmst->pmeg[sme][ptenum];
    147  1.4      gwr 
    148  1.4      gwr 	if ((pte & PG_VALID) == 0) {
    149  1.4      gwr 		_kvm_err(kd, 0, "page not valid (VA=0x%x)", va);
    150  1.1      gwr 		return (0);
    151  1.1      gwr 	}
    152  1.4      gwr 	pa = PG_PA(pte) + offset;
    153  1.4      gwr 
    154  1.4      gwr 	*pap = pa;
    155  1.4      gwr 	return (NBPG - offset);
    156  1.4      gwr }
    157  1.1      gwr 
    158  1.4      gwr /*
    159  1.4      gwr  * Translate a physical address to a file-offset in the crash-dump.
    160  1.4      gwr  */
    161  1.4      gwr off_t
    162  1.4      gwr _kvm_pa2off(kd, pa)
    163  1.4      gwr 	kvm_t	*kd;
    164  1.4      gwr 	u_long	pa;
    165  1.4      gwr {
    166  1.4      gwr 	return(kd->dump_off + pa);
    167  1.1      gwr }
    168