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>
40 #include <vm/vm_param.h>
46 #include "kvm_private.h"
53 /* Not actually used for anything right now, but safe. */
67 _kvm_kvatop(kd, va, pa)
73 cpu_kcore_hdr_t *cpu_kh;
79 _kvm_err(kd, 0, "vatop called in live kernel!");
83 cpu_kh = kd->cpu_data;
84 page_off = va & (cpu_kh->page_size - 1);
86 if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
88 * Direct-mapped address: just convert it.
91 *pa = ALPHA_K0SEG_TO_PHYS(va);
92 rv = cpu_kh->page_size - page_off;
93 } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
95 * Real kernel virtual address: do the translation.
98 /* Find and read the L1 PTE. */
99 pteoff = cpu_kh->lev1map_pa +
100 kvtol1pte(va) * sizeof(alpha_pt_entry_t);
101 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
102 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
103 _kvm_syserr(kd, 0, "could not read L1 PTE");
107 /* Find and read the L2 PTE. */
108 if ((pte & ALPHA_PTE_VALID) == 0) {
109 _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
112 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
113 vatoste(va) * sizeof(alpha_pt_entry_t);
114 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
115 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
116 _kvm_syserr(kd, 0, "could not read L2 PTE");
120 /* Find and read the L3 PTE. */
121 if ((pte & ALPHA_PTE_VALID) == 0) {
122 _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
125 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
126 vatopte(va) * sizeof(alpha_pt_entry_t);
127 if (lseek(kd->pmfd, _kvm_pa2off(kd, pteoff), 0) == -1 ||
128 read(kd->pmfd, (char *)&pte, sizeof(pte)) != sizeof(pte)) {
129 _kvm_syserr(kd, 0, "could not read L3 PTE");
133 /* Fill in the PA. */
134 if ((pte & ALPHA_PTE_VALID) == 0) {
135 _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
138 *pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
139 rv = cpu_kh->page_size - page_off;
142 * Bogus address (not in KV space): punt.
145 _kvm_err(kd, 0, "invalid kernel virtual address");
158 * Translate a physical address to a file-offset in the crash-dump.
167 cpu_kcore_hdr_t *cpu_kh;
169 cpu_kh = kd->cpu_data;
172 pa -= cpu_kh->core_seg.start;
174 return (kd->dump_off + off + pa);
176 return 0; /* XXX fixme */
181 * Machine-dependent initialization for ALL open kvm descriptors,
182 * not just those for a kernel crash dump. Some architectures
183 * have to deal with these NOT being constants! (i.e. m68k)
190 #if 0 /* XXX fixme */
191 kd->usrstack = USRSTACK;
192 kd->min_uva = VM_MIN_ADDRESS;
193 kd->max_uva = VM_MAXUSER_ADDRESS;