1 /* $FreeBSD: src/lib/libkvm/kvm_alpha.c,v 1.4 1999/12/27 07:14:56 peter Exp $ */
2 /* $DragonFly: src/lib/libkvm/Attic/kvm_alpha.c,v 1.3 2004/04/11 21:28:03 cpressey Exp $ */
3 /* $NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $ */
6 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
9 * Author: Chris G. Demetriou
11 * Permission to use, copy, modify and distribute this software and
12 * its documentation is hereby granted, provided that both the copyright
13 * notice and this permission notice appear in all copies of the
14 * software, derivative works or modified versions, and any portions
15 * thereof, and that both notices appear in supporting documentation.
17 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
18 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
19 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
21 * Carnegie Mellon requests users of this software to return to
23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
24 * School of Computer Science
25 * Carnegie Mellon University
26 * Pittsburgh PA 15213-3890
28 * any improvements or extensions that they make and grant Carnegie the
29 * rights to redistribute these changes.
32 #include <sys/param.h>
36 #include <sys/types.h>
43 #include <vm/vm_param.h>
47 #include <machine/pmap.h>
48 #include "kvm_private.h"
50 static off_t _kvm_pa2off(kvm_t *kd, u_long pa);
53 u_int64_t lev1map_pa; /* PA of Lev1map */
54 u_int64_t page_size; /* Page size */
55 u_int64_t nmemsegs; /* Number of RAM segm */
59 _kvm_freevtop(kvm_t *kd)
61 /* Not actually used for anything right now, but safe. */
67 _kvm_initvtop(kvm_t *kd)
70 struct nlist nlist[2];
73 vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
75 _kvm_err(kd, kd->program, "cannot allocate vm");
79 vm->page_size = ALPHA_PGBYTES;
81 nlist[0].n_name = "_Lev1map";
84 if (kvm_nlist(kd, nlist) != 0) {
85 _kvm_err(kd, kd->program, "bad namelist");
90 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
91 _kvm_err(kd, kd->program, "cannot read Lev1map");
95 if (kvm_read(kd, (nlist[0].n_value), &pa, sizeof(pa)) != sizeof(pa)) {
96 _kvm_err(kd, kd->program, "cannot read Lev1map");
105 _kvm_kvatop(kvm_t *kd, u_long va, u_long *pa)
107 u_int64_t lev1map_pa; /* PA of Lev1map */
110 alpha_pt_entry_t pte;
117 _kvm_err(kd, 0, "vatop called in live kernel!");
120 lev1map_pa = vm->lev1map_pa;
121 page_size = vm->page_size;
123 page_off = va & (page_size - 1);
124 if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
126 * Direct-mapped address: just convert it.
129 *pa = ALPHA_K0SEG_TO_PHYS(va);
130 rv = page_size - page_off;
131 } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
133 * Real kernel virtual address: do the translation.
135 #define PTMASK ((1 << ALPHA_PTSHIFT) - 1)
136 #define pmap_lev1_index(va) (((va) >> ALPHA_L1SHIFT) & PTMASK)
137 #define pmap_lev2_index(va) (((va) >> ALPHA_L2SHIFT) & PTMASK)
138 #define pmap_lev3_index(va) (((va) >> ALPHA_L3SHIFT) & PTMASK)
140 /* Find and read the L1 PTE. */
141 pteoff = lev1map_pa +
142 pmap_lev1_index(va) * sizeof(alpha_pt_entry_t);
143 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
144 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
145 _kvm_syserr(kd, 0, "could not read L1 PTE");
149 /* Find and read the L2 PTE. */
150 if ((pte & ALPHA_PTE_VALID) == 0) {
151 _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
154 pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
155 pmap_lev2_index(va) * sizeof(alpha_pt_entry_t);
156 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
157 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
158 _kvm_syserr(kd, 0, "could not read L2 PTE");
162 /* Find and read the L3 PTE. */
163 if ((pte & ALPHA_PTE_VALID) == 0) {
164 _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
167 pteoff = ALPHA_PTE_TO_PFN(pte) * page_size +
168 pmap_lev3_index(va) * sizeof(alpha_pt_entry_t);
169 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
170 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
171 _kvm_syserr(kd, 0, "could not read L3 PTE");
175 /* Fill in the PA. */
176 if ((pte & ALPHA_PTE_VALID) == 0) {
177 _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
180 *pa = ALPHA_PTE_TO_PFN(pte) * page_size + page_off;
181 rv = page_size - page_off;
184 * Bogus address (not in KV space): punt.
187 _kvm_err(kd, 0, "invalid kernel virtual address");
197 * Translate a physical address to a file-offset in the crash-dump.
200 _kvm_pa2off(kvm_t *kd, u_long pa)
202 return ALPHA_K0SEG_TO_PHYS(pa);