Home | History | Annotate | Line # | Download | only in libkvm
kvm_alpha.c revision 1.10
      1  1.10  thorpej /*	$NetBSD: kvm_alpha.c,v 1.10 1998/03/03 00:07:30 thorpej Exp $	*/
      2   1.1      cgd 
      3   1.1      cgd /*
      4   1.1      cgd  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
      5   1.1      cgd  * All rights reserved.
      6   1.1      cgd  *
      7   1.1      cgd  * Author: Chris G. Demetriou
      8   1.1      cgd  *
      9   1.1      cgd  * Permission to use, copy, modify and distribute this software and
     10   1.1      cgd  * its documentation is hereby granted, provided that both the copyright
     11   1.1      cgd  * notice and this permission notice appear in all copies of the
     12   1.1      cgd  * software, derivative works or modified versions, and any portions
     13   1.1      cgd  * thereof, and that both notices appear in supporting documentation.
     14   1.1      cgd  *
     15   1.1      cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16   1.1      cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17   1.1      cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18   1.1      cgd  *
     19   1.1      cgd  * Carnegie Mellon requests users of this software to return to
     20   1.1      cgd  *
     21   1.1      cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22   1.1      cgd  *  School of Computer Science
     23   1.1      cgd  *  Carnegie Mellon University
     24   1.1      cgd  *  Pittsburgh PA 15213-3890
     25   1.1      cgd  *
     26   1.1      cgd  * any improvements or extensions that they make and grant Carnegie the
     27   1.1      cgd  * rights to redistribute these changes.
     28   1.1      cgd  */
     29   1.1      cgd 
     30   1.1      cgd #include <sys/param.h>
     31   1.1      cgd #include <sys/user.h>
     32   1.1      cgd #include <sys/proc.h>
     33   1.1      cgd #include <sys/stat.h>
     34   1.4      cgd #include <sys/kcore.h>
     35   1.4      cgd #include <machine/kcore.h>
     36   1.1      cgd #include <unistd.h>
     37   1.1      cgd #include <nlist.h>
     38   1.1      cgd #include <kvm.h>
     39   1.1      cgd 
     40   1.1      cgd #include <vm/vm.h>
     41   1.1      cgd #include <vm/vm_param.h>
     42   1.1      cgd 
     43   1.1      cgd #include <limits.h>
     44   1.1      cgd #include <db.h>
     45   1.7      mrg #include <stdlib.h>
     46   1.1      cgd 
     47   1.1      cgd #include "kvm_private.h"
     48   1.1      cgd 
     49   1.1      cgd void
     50   1.1      cgd _kvm_freevtop(kd)
     51   1.1      cgd 	kvm_t *kd;
     52   1.1      cgd {
     53   1.1      cgd 
     54   1.5      cgd 	/* Not actually used for anything right now, but safe. */
     55   1.5      cgd 	if (kd->vmst != 0)
     56   1.5      cgd 		free(kd->vmst);
     57   1.1      cgd }
     58   1.1      cgd 
     59   1.1      cgd int
     60   1.1      cgd _kvm_initvtop(kd)
     61   1.1      cgd 	kvm_t *kd;
     62   1.1      cgd {
     63   1.1      cgd 
     64   1.1      cgd 	return (0);
     65   1.1      cgd }
     66   1.1      cgd 
     67   1.1      cgd int
     68   1.1      cgd _kvm_kvatop(kd, va, pa)
     69   1.1      cgd 	kvm_t *kd;
     70   1.1      cgd 	u_long va;
     71   1.1      cgd 	u_long *pa;
     72   1.1      cgd {
     73   1.4      cgd 	cpu_kcore_hdr_t *cpu_kh;
     74   1.4      cgd 	int rv, page_off;
     75   1.5      cgd 	alpha_pt_entry_t pte;
     76   1.5      cgd 	off_t pteoff;
     77   1.2      cgd 
     78   1.4      cgd         if (ISALIVE(kd)) {
     79   1.4      cgd                 _kvm_err(kd, 0, "vatop called in live kernel!");
     80   1.4      cgd                 return(0);
     81   1.4      cgd         }
     82   1.4      cgd 
     83   1.4      cgd 	cpu_kh = kd->cpu_data;
     84   1.4      cgd 	page_off = va & (cpu_kh->page_size - 1);
     85   1.4      cgd 
     86   1.4      cgd 	if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
     87   1.4      cgd 		/*
     88   1.5      cgd 		 * Direct-mapped address: just convert it.
     89   1.4      cgd 		 */
     90   1.5      cgd 
     91   1.4      cgd 		*pa = ALPHA_K0SEG_TO_PHYS(va);
     92   1.4      cgd 		rv = cpu_kh->page_size - page_off;
     93   1.4      cgd 	} else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
     94   1.4      cgd 		/*
     95   1.5      cgd 		 * Real kernel virtual address: do the translation.
     96   1.4      cgd 		 */
     97   1.5      cgd 
     98   1.5      cgd 		/* Find and read the L1 PTE. */
     99   1.5      cgd 		pteoff = cpu_kh->lev1map_pa +
    100  1.10  thorpej 		    l1pte_index(va) * sizeof(alpha_pt_entry_t);
    101   1.5      cgd 		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
    102   1.5      cgd 		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
    103   1.5      cgd 			_kvm_syserr(kd, 0, "could not read L1 PTE");
    104   1.5      cgd 			goto lose;
    105   1.5      cgd 		}
    106   1.5      cgd 
    107   1.5      cgd 		/* Find and read the L2 PTE. */
    108   1.5      cgd 		if ((pte & ALPHA_PTE_VALID) == 0) {
    109   1.5      cgd 			_kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
    110   1.5      cgd 			goto lose;
    111   1.5      cgd 		}
    112   1.5      cgd 		pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
    113  1.10  thorpej 		    l2pte_index(va) * sizeof(alpha_pt_entry_t);
    114   1.5      cgd 		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
    115   1.5      cgd 		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
    116   1.5      cgd 			_kvm_syserr(kd, 0, "could not read L2 PTE");
    117   1.5      cgd 			goto lose;
    118   1.5      cgd 		}
    119   1.5      cgd 
    120   1.5      cgd 		/* Find and read the L3 PTE. */
    121   1.5      cgd 		if ((pte & ALPHA_PTE_VALID) == 0) {
    122   1.5      cgd 			_kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
    123   1.5      cgd 			goto lose;
    124   1.5      cgd 		}
    125   1.5      cgd 		pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
    126  1.10  thorpej 		    l3pte_index(va) * sizeof(alpha_pt_entry_t);
    127   1.5      cgd 		if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
    128   1.5      cgd 		    read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
    129   1.5      cgd 			_kvm_syserr(kd, 0, "could not read L3 PTE");
    130   1.5      cgd 			goto lose;
    131   1.5      cgd 		}
    132   1.5      cgd 
    133   1.5      cgd 		/* Fill in the PA. */
    134   1.5      cgd 		if ((pte & ALPHA_PTE_VALID) == 0) {
    135   1.5      cgd 			_kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
    136   1.5      cgd 			goto lose;
    137   1.5      cgd 		}
    138   1.8     ross 		*pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
    139   1.5      cgd 		rv = cpu_kh->page_size - page_off;
    140   1.4      cgd 	} else {
    141   1.4      cgd 		/*
    142   1.5      cgd 		 * Bogus address (not in KV space): punt.
    143   1.4      cgd 		 */
    144   1.5      cgd 
    145   1.5      cgd 		_kvm_err(kd, 0, "invalid kernel virtual address");
    146   1.5      cgd lose:
    147   1.4      cgd 		*pa = -1;
    148   1.4      cgd 		rv = 0;
    149   1.4      cgd 	}
    150   1.1      cgd 
    151   1.4      cgd 	return (rv);
    152   1.3      cgd }
    153   1.3      cgd 
    154   1.3      cgd /*
    155   1.3      cgd  * Translate a physical address to a file-offset in the crash-dump.
    156   1.3      cgd  */
    157   1.3      cgd off_t
    158   1.3      cgd _kvm_pa2off(kd, pa)
    159   1.3      cgd 	kvm_t *kd;
    160   1.3      cgd 	u_long pa;
    161   1.3      cgd {
    162   1.9      cgd 	cpu_kcore_hdr_t *cpu_kh;
    163   1.9      cgd 	phys_ram_seg_t *ramsegs;
    164   1.4      cgd 	off_t off;
    165   1.9      cgd 	int i;
    166   1.4      cgd 
    167   1.4      cgd 	cpu_kh = kd->cpu_data;
    168   1.9      cgd 	ramsegs = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
    169   1.4      cgd 
    170   1.4      cgd 	off = 0;
    171   1.9      cgd 	for (i = 0; i < cpu_kh->nmemsegs; i++) {
    172   1.9      cgd 		if (pa >= ramsegs[i].start &&
    173   1.9      cgd 		    (pa - ramsegs[i].start) < ramsegs[i].size) {
    174   1.9      cgd 			off += (pa - ramsegs[i].start);
    175   1.9      cgd 			break;
    176   1.9      cgd 		}
    177   1.9      cgd 		off += ramsegs[i].size;
    178   1.9      cgd 	}
    179   1.3      cgd 
    180   1.9      cgd 	return (kd->dump_off + off);
    181   1.6      gwr }
    182   1.6      gwr 
    183   1.6      gwr /*
    184   1.6      gwr  * Machine-dependent initialization for ALL open kvm descriptors,
    185   1.6      gwr  * not just those for a kernel crash dump.  Some architectures
    186   1.6      gwr  * have to deal with these NOT being constants!  (i.e. m68k)
    187   1.6      gwr  */
    188   1.6      gwr int
    189   1.6      gwr _kvm_mdopen(kd)
    190   1.6      gwr 	kvm_t	*kd;
    191   1.6      gwr {
    192   1.6      gwr 
    193   1.6      gwr 	kd->usrstack = USRSTACK;
    194   1.6      gwr 	kd->min_uva = VM_MIN_ADDRESS;
    195   1.6      gwr 	kd->max_uva = VM_MAXUSER_ADDRESS;
    196   1.6      gwr 
    197   1.6      gwr 	return (0);
    198   1.1      cgd }
    199