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