Home | History | Annotate | Line # | Download | only in libkvm
kvm_sun3.c revision 1.11
      1  1.11      wiz /*	$NetBSD: kvm_sun3.c,v 1.11 2003/05/16 10:24:56 wiz 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.7    mikel #include <sys/cdefs.h>
     41   1.4      gwr #if defined(LIBC_SCCS) && !defined(lint)
     42   1.4      gwr #if 0
     43   1.4      gwr static char sccsid[] = "@(#)kvm_sparc.c	8.1 (Berkeley) 6/4/93";
     44   1.4      gwr #else
     45  1.11      wiz __RCSID("$NetBSD: kvm_sun3.c,v 1.11 2003/05/16 10:24:56 wiz Exp $");
     46   1.4      gwr #endif
     47   1.4      gwr #endif /* LIBC_SCCS and not lint */
     48   1.4      gwr 
     49   1.1      gwr /*
     50   1.4      gwr  * Sun3 machine dependent routines for kvm.
     51   1.5      gwr  *
     52   1.5      gwr  * Note: This file has to build on ALL m68k machines,
     53   1.8   briggs  * so do NOT include any <machine / *.h> files here.
     54   1.1      gwr  */
     55   1.1      gwr 
     56   1.5      gwr #include <sys/types.h>
     57   1.4      gwr #include <sys/kcore.h>
     58   1.4      gwr 
     59   1.1      gwr #include <unistd.h>
     60   1.4      gwr #include <limits.h>
     61   1.1      gwr #include <nlist.h>
     62   1.1      gwr #include <kvm.h>
     63   1.4      gwr #include <db.h>
     64   1.1      gwr 
     65   1.6  thorpej #include <m68k/kcore.h>
     66   1.6  thorpej 
     67   1.5      gwr #include "kvm_private.h"
     68   1.5      gwr #include "kvm_m68k.h"
     69   1.5      gwr 
     70   1.5      gwr int   _kvm_sun3_initvtop __P((kvm_t *));
     71   1.5      gwr void  _kvm_sun3_freevtop __P((kvm_t *));
     72   1.5      gwr int	  _kvm_sun3_kvatop   __P((kvm_t *, u_long, u_long *));
     73   1.5      gwr off_t _kvm_sun3_pa2off   __P((kvm_t *, u_long));
     74   1.5      gwr 
     75   1.5      gwr struct kvm_ops _kvm_ops_sun3 = {
     76   1.5      gwr 	_kvm_sun3_initvtop,
     77   1.5      gwr 	_kvm_sun3_freevtop,
     78   1.5      gwr 	_kvm_sun3_kvatop,
     79   1.5      gwr 	_kvm_sun3_pa2off };
     80   1.1      gwr 
     81   1.6  thorpej #define	_kvm_pg_pa(v, s, pte)	\
     82   1.6  thorpej 	(((pte) & (s)->pg_frame) << (v)->pgshift)
     83   1.6  thorpej 
     84   1.6  thorpej #define	_kvm_va_segnum(s, x)	\
     85   1.6  thorpej 	((u_int)(x) >> (s)->segshift)
     86   1.6  thorpej #define	_kvm_pte_num_mask(v)	\
     87   1.6  thorpej 	(0xf << (v)->pgshift)
     88   1.6  thorpej #define	_kvm_va_pte_num(v, va)	\
     89   1.6  thorpej 	(((va) & _kvm_pte_num_mask((v))) >> (v)->pgshift)
     90   1.6  thorpej 
     91   1.5      gwr /*
     92   1.6  thorpej  * XXX Re-define these here, no other place for them.
     93   1.6  thorpej  */
     94   1.6  thorpej #define	NKSEG		256	/* kernel segmap entries */
     95   1.6  thorpej #define	NPAGSEG		16	/* pages per segment */
     96   1.1      gwr 
     97   1.5      gwr /* Finally, our local stuff... */
     98   1.6  thorpej struct private_vmstate {
     99   1.4      gwr 	/* Page Map Entry Group (PMEG) */
    100   1.4      gwr 	int   pmeg[NKSEG][NPAGSEG];
    101   1.1      gwr };
    102   1.1      gwr 
    103   1.4      gwr /*
    104   1.4      gwr  * Prepare for translation of kernel virtual addresses into offsets
    105   1.4      gwr  * into crash dump files. We use the MMU specific goop written at the
    106   1.4      gwr  * beginning of a crash dump by dumpsys()
    107   1.4      gwr  * Note: sun3 MMU specific!
    108   1.4      gwr  */
    109   1.1      gwr int
    110   1.5      gwr _kvm_sun3_initvtop(kd)
    111   1.1      gwr 	kvm_t *kd;
    112   1.1      gwr {
    113   1.6  thorpej 	cpu_kcore_hdr_t *h = kd->cpu_data;
    114   1.6  thorpej 	char *p;
    115   1.4      gwr 
    116   1.4      gwr 	p = kd->cpu_data;
    117   1.6  thorpej 	p += (h->page_size - sizeof(kcore_seg_t));
    118   1.6  thorpej 	kd->vmst->private = p;
    119   1.1      gwr 
    120   1.1      gwr 	return (0);
    121   1.1      gwr }
    122   1.1      gwr 
    123   1.4      gwr void
    124   1.5      gwr _kvm_sun3_freevtop(kd)
    125   1.4      gwr 	kvm_t *kd;
    126   1.4      gwr {
    127   1.4      gwr 	/* This was set by pointer arithmetic, not allocation. */
    128   1.6  thorpej 	kd->vmst->private = (void*)0;
    129   1.4      gwr }
    130   1.1      gwr 
    131   1.1      gwr /*
    132   1.1      gwr  * Translate a kernel virtual address to a physical address using the
    133   1.1      gwr  * mapping information in kd->vm.  Returns the result in pa, and returns
    134   1.9   simonb  * the number of bytes that are contiguously available from this
    135  1.11      wiz  * physical address.  This routine is used only for crash dumps.
    136   1.1      gwr  */
    137   1.1      gwr int
    138   1.5      gwr _kvm_sun3_kvatop(kd, va, pap)
    139   1.1      gwr 	kvm_t *kd;
    140   1.1      gwr 	u_long va;
    141   1.4      gwr 	u_long *pap;
    142   1.1      gwr {
    143   1.6  thorpej 	cpu_kcore_hdr_t *h = kd->cpu_data;
    144   1.6  thorpej 	struct sun3_kcore_hdr *s = &h->un._sun3;
    145   1.6  thorpej 	struct vmstate *v = kd->vmst;
    146   1.6  thorpej 	struct private_vmstate *pv = v->private;
    147   1.6  thorpej 	int pte, offset;
    148   1.4      gwr 	u_int segnum, sme, ptenum;
    149   1.4      gwr 	u_long pa;
    150   1.4      gwr 
    151   1.4      gwr 	if (ISALIVE(kd)) {
    152   1.4      gwr 		_kvm_err(kd, 0, "vatop called in live kernel!");
    153   1.6  thorpej 		return(0);
    154   1.4      gwr 	}
    155   1.1      gwr 
    156   1.6  thorpej 	if (va < h->kernbase) {
    157   1.4      gwr 		_kvm_err(kd, 0, "not a kernel address");
    158   1.6  thorpej 		return(0);
    159   1.1      gwr 	}
    160   1.1      gwr 
    161   1.4      gwr 	/*
    162   1.4      gwr 	 * Get the segmap entry (sme) from the kernel segmap.
    163   1.4      gwr 	 * Note: only have segmap entries from KERNBASE to end.
    164   1.4      gwr 	 */
    165   1.6  thorpej 	segnum = _kvm_va_segnum(s, va - h->kernbase);
    166   1.6  thorpej 	ptenum = _kvm_va_pte_num(v, va);
    167   1.6  thorpej 	offset = va & v->pgofset;
    168   1.4      gwr 
    169   1.4      gwr 	/* The segmap entry selects a PMEG. */
    170   1.6  thorpej 	sme = s->ksegmap[segnum];
    171   1.6  thorpej 	pte = pv->pmeg[sme][ptenum];
    172   1.4      gwr 
    173   1.6  thorpej 	if ((pte & (s)->pg_valid) == 0) {
    174  1.10       he 		_kvm_err(kd, 0, "page not valid (VA=0x%lx)", va);
    175   1.1      gwr 		return (0);
    176   1.1      gwr 	}
    177   1.6  thorpej 	pa = _kvm_pg_pa(v, s, pte) + offset;
    178   1.4      gwr 
    179   1.4      gwr 	*pap = pa;
    180   1.6  thorpej 	return (h->page_size - offset);
    181   1.4      gwr }
    182   1.1      gwr 
    183   1.4      gwr /*
    184  1.11      wiz  * Translate a physical address to a file-offset in the crash dump.
    185   1.4      gwr  */
    186   1.4      gwr off_t
    187   1.5      gwr _kvm_sun3_pa2off(kd, pa)
    188   1.4      gwr 	kvm_t	*kd;
    189   1.4      gwr 	u_long	pa;
    190   1.4      gwr {
    191   1.4      gwr 	return(kd->dump_off + pa);
    192   1.1      gwr }
    193