Home | History | Annotate | Line # | Download | only in libkvm
kvm_sun3x.c revision 1.1
      1  1.1  gwr /*	$NetBSD: kvm_sun3x.c,v 1.1 1997/03/21 18:44:26 gwr Exp $	*/
      2  1.1  gwr 
      3  1.1  gwr /*-
      4  1.1  gwr  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  1.1  gwr  * All rights reserved.
      6  1.1  gwr  *
      7  1.1  gwr  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  gwr  * by Gordon W. Ross.
      9  1.1  gwr  *
     10  1.1  gwr  * Redistribution and use in source and binary forms, with or without
     11  1.1  gwr  * modification, are permitted provided that the following conditions
     12  1.1  gwr  * are met:
     13  1.1  gwr  * 1. Redistributions of source code must retain the above copyright
     14  1.1  gwr  *    notice, this list of conditions and the following disclaimer.
     15  1.1  gwr  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  gwr  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  gwr  *    documentation and/or other materials provided with the distribution.
     18  1.1  gwr  * 3. All advertising materials mentioning features or use of this software
     19  1.1  gwr  *    must display the following acknowledgement:
     20  1.1  gwr  *        This product includes software developed by the NetBSD
     21  1.1  gwr  *        Foundation, Inc. and its contributors.
     22  1.1  gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  gwr  *    contributors may be used to endorse or promote products derived
     24  1.1  gwr  *    from this software without specific prior written permission.
     25  1.1  gwr  *
     26  1.1  gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  gwr  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  gwr  */
     38  1.1  gwr 
     39  1.1  gwr #if defined(LIBC_SCCS) && !defined(lint)
     40  1.1  gwr #if 0
     41  1.1  gwr static char sccsid[] = "@(#)kvm_sparc.c	8.1 (Berkeley) 6/4/93";
     42  1.1  gwr #else
     43  1.1  gwr static char *rcsid = "$NetBSD: kvm_sun3x.c,v 1.1 1997/03/21 18:44:26 gwr Exp $";
     44  1.1  gwr #endif
     45  1.1  gwr #endif /* LIBC_SCCS and not lint */
     46  1.1  gwr 
     47  1.1  gwr /*
     48  1.1  gwr  * Sun3x machine dependent routines for kvm.
     49  1.1  gwr  *
     50  1.1  gwr  * Note: This file has to build on ALL m68k machines,
     51  1.1  gwr  * so do NOT include any <machine/*.h> files here.
     52  1.1  gwr  */
     53  1.1  gwr 
     54  1.1  gwr #include <sys/types.h>
     55  1.1  gwr #include <sys/kcore.h>
     56  1.1  gwr 
     57  1.1  gwr #include <unistd.h>
     58  1.1  gwr #include <limits.h>
     59  1.1  gwr #include <nlist.h>
     60  1.1  gwr #include <kvm.h>
     61  1.1  gwr #include <db.h>
     62  1.1  gwr 
     63  1.1  gwr #include "kvm_private.h"
     64  1.1  gwr #include "kvm_m68k.h"
     65  1.1  gwr 
     66  1.1  gwr int   _kvm_sun3x_initvtop __P((kvm_t *));
     67  1.1  gwr void  _kvm_sun3x_freevtop __P((kvm_t *));
     68  1.1  gwr int	  _kvm_sun3x_kvatop   __P((kvm_t *, u_long, u_long *));
     69  1.1  gwr off_t _kvm_sun3x_pa2off   __P((kvm_t *, u_long));
     70  1.1  gwr 
     71  1.1  gwr struct kvm_ops _kvm_ops_sun3x = {
     72  1.1  gwr 	_kvm_sun3x_initvtop,
     73  1.1  gwr 	_kvm_sun3x_freevtop,
     74  1.1  gwr 	_kvm_sun3x_kvatop,
     75  1.1  gwr 	_kvm_sun3x_pa2off };
     76  1.1  gwr 
     77  1.1  gwr /*
     78  1.1  gwr  * XXX: I don't like this, but until all arch/.../include files
     79  1.1  gwr  * are exported into some user-accessable place, there is no
     80  1.1  gwr  * convenient alternative to copying these definitions here.
     81  1.1  gwr  */
     82  1.1  gwr 
     83  1.1  gwr /* sun3x/include/param.h */
     84  1.1  gwr #define PGSHIFT 	13
     85  1.1  gwr #define NBPG		8192
     86  1.1  gwr #define PGOFSET 	(NBPG-1)
     87  1.1  gwr #define KERNBASE	0xF8000000
     88  1.1  gwr 
     89  1.1  gwr /* sun3x/sun3x/pmap.c */
     90  1.1  gwr #define	KVAS_SIZE	(-KERNBASE)
     91  1.1  gwr #define	NKPTES		(KVAS_SIZE >> PGSHIFT)
     92  1.1  gwr 
     93  1.1  gwr #define PG_FRAME	0xffffff00
     94  1.1  gwr #define PG_VALID 	0x00000001
     95  1.1  gwr 
     96  1.1  gwr #define PG_PA(pte)	(pte & PG_FRAME)
     97  1.1  gwr 
     98  1.1  gwr /* sun3x/include/kcore.h */
     99  1.1  gwr #define NPHYS_RAM_SEGS 4
    100  1.1  gwr typedef struct {
    101  1.1  gwr 	u_long	start;		/* Physical start address	*/
    102  1.1  gwr 	u_long	size;		/* Size in bytes		*/
    103  1.1  gwr } cpu_ram_seg_t;
    104  1.1  gwr typedef struct cpu_kcore_hdr {
    105  1.1  gwr 	u_long ckh_contig_end;
    106  1.1  gwr 	u_long ckh_kernCbase;
    107  1.1  gwr 	cpu_ram_seg_t	ram_segs[NPHYS_RAM_SEGS];
    108  1.1  gwr } cpu_kcore_hdr_t;
    109  1.1  gwr 
    110  1.1  gwr /* Finally, our local stuff... */
    111  1.1  gwr 
    112  1.1  gwr /*
    113  1.1  gwr  * Prepare for translation of kernel virtual addresses into offsets
    114  1.1  gwr  * into crash dump files.  Nothing to do here.
    115  1.1  gwr  */
    116  1.1  gwr int
    117  1.1  gwr _kvm_sun3x_initvtop(kd)
    118  1.1  gwr 	kvm_t *kd;
    119  1.1  gwr {
    120  1.1  gwr 	return (0);
    121  1.1  gwr }
    122  1.1  gwr 
    123  1.1  gwr void
    124  1.1  gwr _kvm_sun3x_freevtop(kd)
    125  1.1  gwr 	kvm_t *kd;
    126  1.1  gwr {
    127  1.1  gwr }
    128  1.1  gwr 
    129  1.1  gwr /*
    130  1.1  gwr  * Translate a kernel virtual address to a physical address using the
    131  1.1  gwr  * mapping information in kd->vm.  Returns the result in pa, and returns
    132  1.1  gwr  * the number of bytes that are contiguously available from this
    133  1.1  gwr  * physical address.  This routine is used only for crashdumps.
    134  1.1  gwr  */
    135  1.1  gwr int
    136  1.1  gwr _kvm_sun3x_kvatop(kd, va, pap)
    137  1.1  gwr 	kvm_t *kd;
    138  1.1  gwr 	u_long va;
    139  1.1  gwr 	u_long *pap;
    140  1.1  gwr {
    141  1.1  gwr 	register cpu_kcore_hdr_t *ckh;
    142  1.1  gwr 	int idx, len, offset, pte;
    143  1.1  gwr 	u_long pteva, pa;
    144  1.1  gwr 
    145  1.1  gwr 	if (ISALIVE(kd)) {
    146  1.1  gwr 		_kvm_err(kd, 0, "vatop called in live kernel!");
    147  1.1  gwr 		return((off_t)0);
    148  1.1  gwr 	}
    149  1.1  gwr 	ckh = kd->cpu_data;
    150  1.1  gwr 
    151  1.1  gwr 	if (va < KERNBASE) {
    152  1.1  gwr 		_kvm_err(kd, 0, "not a kernel address");
    153  1.1  gwr 		return(0);
    154  1.1  gwr 	}
    155  1.1  gwr 
    156  1.1  gwr 	/*
    157  1.1  gwr 	 * If this VA is in the contiguous range, short-cut.
    158  1.1  gwr 	 * Note that this ends our recursion when we call
    159  1.1  gwr 	 * kvm_read to access the kernel page table, which
    160  1.1  gwr 	 * is guaranteed to be in the contiguous range.
    161  1.1  gwr 	 */
    162  1.1  gwr 	if (va < ckh->ckh_contig_end) {
    163  1.1  gwr 		len = va - ckh->ckh_contig_end;
    164  1.1  gwr 		pa = va - KERNBASE;
    165  1.1  gwr 		goto done;
    166  1.1  gwr 	}
    167  1.1  gwr 
    168  1.1  gwr 	/*
    169  1.1  gwr 	 * The KVA is beyond the contiguous range, so we must
    170  1.1  gwr 	 * read the PTE for this KVA from the page table.
    171  1.1  gwr 	 */
    172  1.1  gwr 	idx = ((va - KERNBASE) >> PGSHIFT);
    173  1.1  gwr 	pteva = ckh->ckh_kernCbase + (idx * 4);
    174  1.1  gwr 	if (kvm_read(kd, pteva, &pte, 4) != 4) {
    175  1.1  gwr 		_kvm_err(kd, 0, "can not read PTE!");
    176  1.1  gwr 		return (0);
    177  1.1  gwr 	}
    178  1.1  gwr 	if ((pte & PG_VALID) == 0) {
    179  1.1  gwr 		_kvm_err(kd, 0, "page not valid (VA=0x%x)", va);
    180  1.1  gwr 		return (0);
    181  1.1  gwr 	}
    182  1.1  gwr 	offset = va & PGOFSET;
    183  1.1  gwr 	len = (NBPG - offset);
    184  1.1  gwr 	pa = PG_PA(pte) + offset;
    185  1.1  gwr 
    186  1.1  gwr done:
    187  1.1  gwr 	*pap = pa;
    188  1.1  gwr 	return (len);
    189  1.1  gwr }
    190  1.1  gwr 
    191  1.1  gwr /*
    192  1.1  gwr  * Translate a physical address to a file-offset in the crash-dump.
    193  1.1  gwr  */
    194  1.1  gwr off_t
    195  1.1  gwr _kvm_sun3x_pa2off(kd, pa)
    196  1.1  gwr 	kvm_t	*kd;
    197  1.1  gwr 	u_long	pa;
    198  1.1  gwr {
    199  1.1  gwr 	off_t		off;
    200  1.1  gwr 	cpu_ram_seg_t	*rsp;
    201  1.1  gwr 	register cpu_kcore_hdr_t *cpu_kh;
    202  1.1  gwr 
    203  1.1  gwr 	cpu_kh = kd->cpu_data;
    204  1.1  gwr 	off = 0;
    205  1.1  gwr 	for (rsp = cpu_kh->ram_segs; rsp->size; rsp++) {
    206  1.1  gwr 		if (pa >= rsp->start && pa < rsp->start + rsp->size) {
    207  1.1  gwr 			pa -= rsp->start;
    208  1.1  gwr 			break;
    209  1.1  gwr 		}
    210  1.1  gwr 		off += rsp->size;
    211  1.1  gwr 	}
    212  1.1  gwr 	return(kd->dump_off + off + pa);
    213  1.1  gwr }
    214  1.1  gwr 
    215