2 /* $NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $ */
5 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
8 * Author: Chris G. Demetriou
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
20 * Carnegie Mellon requests users of this software to return to
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
31 #include <sys/param.h>
33 #include <sys/mutex.h>
37 #include <sys/types.h>
44 #include <vm/vm_param.h>
48 #include <machine/pmap.h>
49 #include "kvm_private.h"
51 static off_t _kvm_pa2off(kvm_t *kd, u_long pa);
54 u_int64_t lev1map_pa; /* PA of Lev1map */
55 u_int64_t page_size; /* Page size */
56 u_int64_t nmemsegs; /* Number of RAM segm */
64 /* Not actually used for anything right now, but safe. */
74 struct nlist nlist[2];
77 vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
79 _kvm_err(kd, kd->program, "cannot allocate vm");
83 vm->page_size = ALPHA_PGBYTES;
85 nlist[0].n_name = "_Lev1map";
88 if (kvm_nlist(kd, nlist) != 0) {
89 _kvm_err(kd, kd->program, "bad namelist");
94 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
95 _kvm_err(kd, kd->program, "cannot read Lev1map");
99 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
100 _kvm_err(kd, kd->program, "cannot read Lev1map");
109 _kvm_kvatop(kd, va, pa)
114 u_int64_t lev1map_pa; /* PA of Lev1map */
117 alpha_pt_entry_t pte;
124 _kvm_err(kd, 0, "vatop called in live kernel!");
127 lev1map_pa = vm->lev1map_pa;
128 page_size = vm->page_size;
130 page_off = va & (page_size - 1);
131 if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
133 * Direct-mapped address: just convert it.
136 *pa = ALPHA_K0SEG_TO_PHYS(va);
137 rv = page_size - page_off;
138 } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
140 * Real kernel virtual address: do the translation.
142 #define PTMASK ((1 << ALPHA_PTSHIFT) - 1)
143 #define pmap_lev1_index(va) (((va) >> ALPHA_L1SHIFT) & PTMASK)
144 #define pmap_lev2_index(va) (((va) >> ALPHA_L2SHIFT) & PTMASK)
145 #define pmap_lev3_index(va) (((va) >> ALPHA_L3SHIFT) & PTMASK)
147 /* Find and read the L1 PTE. */
148 pteoff = lev1map_pa +
149 pmap_lev1_index(va) * sizeof(alpha_pt_entry_t);
150 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
151 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
152 _kvm_syserr(kd, 0, "could not read L1 PTE");
156 /* Find and read the L2 PTE. */
157 if ((pte & ALPHA_PTE_VALID) == 0) {
158 _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
161 pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
162 pmap_lev2_index(va) * sizeof(alpha_pt_entry_t);
163 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
164 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
165 _kvm_syserr(kd, 0, "could not read L2 PTE");
169 /* Find and read the L3 PTE. */
170 if ((pte & ALPHA_PTE_VALID) == 0) {
171 _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
174 pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
175 pmap_lev3_index(va) * sizeof(alpha_pt_entry_t);
176 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
177 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
178 _kvm_syserr(kd, 0, "could not read L3 PTE");
182 /* Fill in the PA. */
183 if ((pte & ALPHA_PTE_VALID) == 0) {
184 _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
187 *pa = ALPHA_PTE_TO_PFN(pte) * page_size + page_off;
188 rv = page_size - page_off;
191 * Bogus address (not in KV space): punt.
194 _kvm_err(kd, 0, "invalid kernel virtual address");
204 * Translate a physical address to a file-offset in the crash-dump.
211 return ALPHA_K0SEG_TO_PHYS(pa);