1 /* $NetBSD: kvm_alpha.c,v 1.22 2003/05/16 10:24:55 wiz Exp $ */
4 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
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.
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.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
32 #include <sys/param.h>
36 #include <sys/kcore.h>
37 #include <machine/kcore.h>
42 #include <uvm/uvm_extern.h>
43 #include <machine/pmap.h>
44 #include <machine/vmparam.h>
50 #include "kvm_private.h"
69 _kvm_kvatop(kd
, va
, pa
)
74 cpu_kcore_hdr_t
*cpu_kh
;
76 u_long pteoff
, page_off
;
80 _kvm_err(kd
, 0, "vatop called in live kernel!");
84 cpu_kh
= kd
->cpu_data
;
85 page_off
= va
& (cpu_kh
->page_size
- 1);
87 if (va
>= ALPHA_K0SEG_BASE
&& va
<= ALPHA_K0SEG_END
) {
89 * Direct-mapped address: just convert it.
92 *pa
= ALPHA_K0SEG_TO_PHYS(va
);
93 rv
= cpu_kh
->page_size
- page_off
;
94 } else if (va
>= ALPHA_K1SEG_BASE
&& va
<= ALPHA_K1SEG_END
) {
96 * Real kernel virtual address: do the translation.
99 /* Find and read the L1 PTE. */
100 pteoff
= cpu_kh
->lev1map_pa
+
101 l1pte_index(va
) * sizeof(alpha_pt_entry_t
);
102 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
103 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
104 _kvm_syserr(kd
, 0, "could not read L1 PTE");
108 /* Find and read the L2 PTE. */
109 if ((pte
& ALPHA_PTE_VALID
) == 0) {
110 _kvm_err(kd
, 0, "invalid translation (invalid L1 PTE)");
113 pteoff
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+
114 l2pte_index(va
) * sizeof(alpha_pt_entry_t
);
115 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
116 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
117 _kvm_syserr(kd
, 0, "could not read L2 PTE");
121 /* Find and read the L3 PTE. */
122 if ((pte
& ALPHA_PTE_VALID
) == 0) {
123 _kvm_err(kd
, 0, "invalid translation (invalid L2 PTE)");
126 pteoff
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+
127 l3pte_index(va
) * sizeof(alpha_pt_entry_t
);
128 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
129 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
130 _kvm_syserr(kd
, 0, "could not read L3 PTE");
134 /* Fill in the PA. */
135 if ((pte
& ALPHA_PTE_VALID
) == 0) {
136 _kvm_err(kd
, 0, "invalid translation (invalid L3 PTE)");
139 *pa
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+ page_off
;
140 rv
= cpu_kh
->page_size
- page_off
;
143 * Bogus address (not in KV space): punt.
146 _kvm_err(kd
, 0, "invalid kernel virtual address");
156 * Translate a physical address to a file-offset in the crash dump.
163 cpu_kcore_hdr_t
*cpu_kh
;
164 phys_ram_seg_t
*ramsegs
;
168 cpu_kh
= kd
->cpu_data
;
169 ramsegs
= (phys_ram_seg_t
*)((char *)cpu_kh
+ ALIGN(sizeof *cpu_kh
));
172 for (i
= 0; i
< cpu_kh
->nmemsegs
; i
++) {
173 if (pa
>= ramsegs
[i
].start
&&
174 (pa
- ramsegs
[i
].start
) < ramsegs
[i
].size
) {
175 off
+= (pa
- ramsegs
[i
].start
);
178 off
+= ramsegs
[i
].size
;
181 return (kd
->dump_off
+ off
);
185 * Machine-dependent initialization for ALL open kvm descriptors,
186 * not just those for a kernel crash dump. Some architectures
187 * have to deal with these NOT being constants! (i.e. m68k)
194 kd
->usrstack
= USRSTACK
;
195 kd
->min_uva
= VM_MIN_ADDRESS
;
196 kd
->max_uva
= VM_MAXUSER_ADDRESS
;