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