Home | History | Annotate | Line # | Download | only in libkvm
kvm_m68k.c revision 1.6
      1  1.1      cgd /*-
      2  1.1      cgd  * Copyright (c) 1989, 1992, 1993
      3  1.1      cgd  *	The Regents of the University of California.  All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * This code is derived from software developed by the Computer Systems
      6  1.1      cgd  * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
      7  1.1      cgd  * BG 91-66 and contributed to Berkeley.
      8  1.1      cgd  *
      9  1.1      cgd  * Redistribution and use in source and binary forms, with or without
     10  1.1      cgd  * modification, are permitted provided that the following conditions
     11  1.1      cgd  * are met:
     12  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     13  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     14  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     16  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     17  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     18  1.1      cgd  *    must display the following acknowledgement:
     19  1.1      cgd  *	This product includes software developed by the University of
     20  1.1      cgd  *	California, Berkeley and its contributors.
     21  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     22  1.1      cgd  *    may be used to endorse or promote products derived from this software
     23  1.1      cgd  *    without specific prior written permission.
     24  1.1      cgd  *
     25  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1      cgd  * SUCH DAMAGE.
     36  1.1      cgd  */
     37  1.1      cgd 
     38  1.1      cgd #if defined(LIBC_SCCS) && !defined(lint)
     39  1.1      cgd /* from: static char sccsid[] = "@(#)kvm_hp300.c	8.1 (Berkeley) 6/4/93"; */
     40  1.6      leo static char *rcsid = "$Id: kvm_m68k.c,v 1.6 1996/03/16 10:23:51 leo Exp $";
     41  1.1      cgd #endif /* LIBC_SCCS and not lint */
     42  1.1      cgd 
     43  1.1      cgd /*
     44  1.1      cgd  * m68k machine dependent routines for kvm.  Hopefully, the forthcoming
     45  1.1      cgd  * vm code will one day obsolete this module.
     46  1.1      cgd  */
     47  1.1      cgd 
     48  1.1      cgd #include <sys/param.h>
     49  1.1      cgd #include <sys/user.h>
     50  1.1      cgd #include <sys/proc.h>
     51  1.1      cgd #include <sys/stat.h>
     52  1.6      leo 
     53  1.6      leo #include <sys/core.h>
     54  1.6      leo #include <sys/exec_aout.h>
     55  1.6      leo #include <sys/kcore.h>
     56  1.6      leo 
     57  1.1      cgd #include <unistd.h>
     58  1.6      leo #include <limits.h>
     59  1.1      cgd #include <nlist.h>
     60  1.1      cgd #include <kvm.h>
     61  1.1      cgd 
     62  1.1      cgd #include <vm/vm.h>
     63  1.1      cgd #include <vm/vm_param.h>
     64  1.1      cgd 
     65  1.1      cgd #include <db.h>
     66  1.1      cgd 
     67  1.1      cgd #include "kvm_private.h"
     68  1.1      cgd 
     69  1.1      cgd #include <machine/pte.h>
     70  1.6      leo #include <machine/kcore.h>
     71  1.1      cgd 
     72  1.1      cgd #ifndef btop
     73  1.1      cgd #define	btop(x)		(((unsigned)(x)) >> PGSHIFT)	/* XXX */
     74  1.1      cgd #define	ptob(x)		((caddr_t)((x) << PGSHIFT))	/* XXX */
     75  1.1      cgd #endif
     76  1.1      cgd 
     77  1.1      cgd #define KREAD(kd, addr, p)\
     78  1.1      cgd 	(kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p)))
     79  1.1      cgd 
     80  1.1      cgd void
     81  1.1      cgd _kvm_freevtop(kd)
     82  1.1      cgd 	kvm_t *kd;
     83  1.1      cgd {
     84  1.1      cgd 	if (kd->vmst != 0)
     85  1.1      cgd 		free(kd->vmst);
     86  1.1      cgd }
     87  1.1      cgd 
     88  1.1      cgd int
     89  1.1      cgd _kvm_initvtop(kd)
     90  1.1      cgd 	kvm_t *kd;
     91  1.1      cgd {
     92  1.1      cgd 	return (0);
     93  1.1      cgd }
     94  1.1      cgd 
     95  1.1      cgd static int
     96  1.1      cgd _kvm_vatop(kd, sta, va, pa)
     97  1.1      cgd 	kvm_t *kd;
     98  1.2  mycroft 	st_entry_t *sta;
     99  1.1      cgd 	u_long va;
    100  1.1      cgd 	u_long *pa;
    101  1.1      cgd {
    102  1.6      leo 	register cpu_kcore_hdr_t *cpu_kh;
    103  1.1      cgd 	register u_long addr;
    104  1.1      cgd 	int p, ste, pte;
    105  1.1      cgd 	int offset;
    106  1.1      cgd 
    107  1.1      cgd 	if (ISALIVE(kd)) {
    108  1.1      cgd 		_kvm_err(kd, 0, "vatop called in live kernel!");
    109  1.1      cgd 		return((off_t)0);
    110  1.1      cgd 	}
    111  1.1      cgd 	offset = va & PGOFSET;
    112  1.6      leo 	cpu_kh = kd->cpu_hdr;
    113  1.1      cgd 	/*
    114  1.1      cgd 	 * If we are initializing (kernel segment table pointer not yet set)
    115  1.1      cgd 	 * then return pa == va to avoid infinite recursion.
    116  1.1      cgd 	 */
    117  1.6      leo 	if (cpu_kh->sysseg_pa == 0) {
    118  1.6      leo 		*pa = va + cpu_kh->kernel_pa;
    119  1.1      cgd 		return (NBPG - offset);
    120  1.1      cgd 	}
    121  1.6      leo 	if (cpu_kh->mmutype == -2) {
    122  1.2  mycroft 		st_entry_t *sta2;
    123  1.1      cgd 
    124  1.1      cgd 		addr = (u_long)&sta[va >> SG4_SHIFT1];
    125  1.1      cgd 		/*
    126  1.1      cgd 		 * Can't use KREAD to read kernel segment table entries.
    127  1.1      cgd 		 * Fortunately it is 1-to-1 mapped so we don't have to.
    128  1.1      cgd 		 */
    129  1.6      leo 		if (sta == cpu_kh->sysseg_pa) {
    130  1.6      leo 			if (lseek(kd->pmfd, _kvm_pa2off(kd, addr), 0) == -1 ||
    131  1.1      cgd 			    read(kd->pmfd, (char *)&ste, sizeof(ste)) < 0)
    132  1.1      cgd 				goto invalid;
    133  1.1      cgd 		} else if (KREAD(kd, addr, &ste))
    134  1.1      cgd 			goto invalid;
    135  1.1      cgd 		if ((ste & SG_V) == 0) {
    136  1.1      cgd 			_kvm_err(kd, 0, "invalid level 1 descriptor (%x)",
    137  1.1      cgd 				 ste);
    138  1.1      cgd 			return((off_t)0);
    139  1.1      cgd 		}
    140  1.2  mycroft 		sta2 = (st_entry_t *)(ste & SG4_ADDR1);
    141  1.1      cgd 		addr = (u_long)&sta2[(va & SG4_MASK2) >> SG4_SHIFT2];
    142  1.1      cgd 		/*
    143  1.1      cgd 		 * Address from level 1 STE is a physical address,
    144  1.1      cgd 		 * so don't use kvm_read.
    145  1.1      cgd 		 */
    146  1.6      leo 		if (lseek(kd->pmfd, _kvm_pa2off(kd, addr), 0) == -1 ||
    147  1.1      cgd 		    read(kd->pmfd, (char *)&ste, sizeof(ste)) < 0)
    148  1.1      cgd 			goto invalid;
    149  1.1      cgd 		if ((ste & SG_V) == 0) {
    150  1.1      cgd 			_kvm_err(kd, 0, "invalid level 2 descriptor (%x)",
    151  1.1      cgd 				 ste);
    152  1.1      cgd 			return((off_t)0);
    153  1.1      cgd 		}
    154  1.2  mycroft 		sta2 = (st_entry_t *)(ste & SG4_ADDR2);
    155  1.1      cgd 		addr = (u_long)&sta2[(va & SG4_MASK3) >> SG4_SHIFT3];
    156  1.1      cgd 	} else {
    157  1.1      cgd 		addr = (u_long)&sta[va >> SEGSHIFT];
    158  1.1      cgd 		/*
    159  1.1      cgd 		 * Can't use KREAD to read kernel segment table entries.
    160  1.1      cgd 		 * Fortunately it is 1-to-1 mapped so we don't have to.
    161  1.1      cgd 		 */
    162  1.6      leo 		if (sta == cpu_kh->sysseg_pa) {
    163  1.6      leo 			if (lseek(kd->pmfd, _kvm_pa2off(kd, addr), 0) == -1 ||
    164  1.1      cgd 			    read(kd->pmfd, (char *)&ste, sizeof(ste)) < 0)
    165  1.1      cgd 				goto invalid;
    166  1.1      cgd 		} else if (KREAD(kd, addr, &ste))
    167  1.1      cgd 			goto invalid;
    168  1.1      cgd 		if ((ste & SG_V) == 0) {
    169  1.1      cgd 			_kvm_err(kd, 0, "invalid segment (%x)", ste);
    170  1.1      cgd 			return((off_t)0);
    171  1.1      cgd 		}
    172  1.1      cgd 		p = btop(va & SG_PMASK);
    173  1.2  mycroft 		addr = (ste & SG_FRAME) + (p * sizeof(pt_entry_t));
    174  1.1      cgd 	}
    175  1.1      cgd 	/*
    176  1.1      cgd 	 * Address from STE is a physical address so don't use kvm_read.
    177  1.1      cgd 	 */
    178  1.6      leo 	if (lseek(kd->pmfd, _kvm_pa2off(kd, addr), 0) == -1 ||
    179  1.1      cgd 	    read(kd->pmfd, (char *)&pte, sizeof(pte)) < 0)
    180  1.1      cgd 		goto invalid;
    181  1.1      cgd 	addr = pte & PG_FRAME;
    182  1.1      cgd 	if (pte == PG_NV) {
    183  1.1      cgd 		_kvm_err(kd, 0, "page not valid");
    184  1.1      cgd 		return (0);
    185  1.1      cgd 	}
    186  1.6      leo 	*pa = addr + offset;
    187  1.1      cgd 
    188  1.1      cgd 	return (NBPG - offset);
    189  1.1      cgd invalid:
    190  1.1      cgd 	_kvm_err(kd, 0, "invalid address (%x)", va);
    191  1.1      cgd 	return (0);
    192  1.1      cgd }
    193  1.1      cgd 
    194  1.1      cgd int
    195  1.1      cgd _kvm_kvatop(kd, va, pa)
    196  1.1      cgd 	kvm_t *kd;
    197  1.1      cgd 	u_long va;
    198  1.1      cgd 	u_long *pa;
    199  1.1      cgd {
    200  1.6      leo 	return (_kvm_vatop(kd, (u_long)kd->cpu_hdr->sysseg_pa, va, pa));
    201  1.1      cgd }
    202