1 /* $NetBSD: kvm_alpha.c,v 1.27 2014/02/19 20:21:22 dsl 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>
35 #include <sys/kcore.h>
36 #include <sys/types.h>
41 #include <uvm/uvm_extern.h>
43 #include <machine/kcore.h>
44 #include <machine/pmap.h>
45 #include <machine/vmparam.h>
51 #include "kvm_private.h"
53 __RCSID("$NetBSD: kvm_alpha.c,v 1.27 2014/02/19 20:21:22 dsl Exp $");
57 _kvm_freevtop(kvm_t
*kd
)
64 _kvm_initvtop(kvm_t
*kd
)
70 _kvm_kvatop(kvm_t
*kd
, vaddr_t va
, paddr_t
*pa
)
72 cpu_kcore_hdr_t
*cpu_kh
;
74 u_long pteoff
, page_off
;
78 _kvm_err(kd
, 0, "vatop called in live kernel!");
82 cpu_kh
= kd
->cpu_data
;
83 page_off
= va
& (cpu_kh
->page_size
- 1);
85 if (va
>= ALPHA_K0SEG_BASE
&& va
<= ALPHA_K0SEG_END
) {
87 * Direct-mapped address: just convert it.
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
) {
94 * Real kernel virtual address: do the translation.
97 /* Find and read the L1 PTE. */
98 pteoff
= cpu_kh
->lev1map_pa
+
99 l1pte_index(va
) * sizeof(alpha_pt_entry_t
);
100 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
101 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
102 _kvm_syserr(kd
, 0, "could not read L1 PTE");
106 /* Find and read the L2 PTE. */
107 if ((pte
& ALPHA_PTE_VALID
) == 0) {
108 _kvm_err(kd
, 0, "invalid translation (invalid L1 PTE)");
111 pteoff
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+
112 l2pte_index(va
) * sizeof(alpha_pt_entry_t
);
113 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
114 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
115 _kvm_syserr(kd
, 0, "could not read L2 PTE");
119 /* Find and read the L3 PTE. */
120 if ((pte
& ALPHA_PTE_VALID
) == 0) {
121 _kvm_err(kd
, 0, "invalid translation (invalid L2 PTE)");
124 pteoff
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+
125 l3pte_index(va
) * sizeof(alpha_pt_entry_t
);
126 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
127 _kvm_pa2off(kd
, pteoff
)) != sizeof(pte
)) {
128 _kvm_syserr(kd
, 0, "could not read L3 PTE");
132 /* Fill in the PA. */
133 if ((pte
& ALPHA_PTE_VALID
) == 0) {
134 _kvm_err(kd
, 0, "invalid translation (invalid L3 PTE)");
137 *pa
= ALPHA_PTE_TO_PFN(pte
) * cpu_kh
->page_size
+ page_off
;
138 rv
= cpu_kh
->page_size
- page_off
;
141 * Bogus address (not in KV space): punt.
144 _kvm_err(kd
, 0, "invalid kernel virtual address");
154 * Translate a physical address to a file-offset in the crash dump.
157 _kvm_pa2off(kvm_t
*kd
, paddr_t pa
)
159 cpu_kcore_hdr_t
*cpu_kh
;
160 phys_ram_seg_t
*ramsegs
;
164 cpu_kh
= kd
->cpu_data
;
165 ramsegs
= (phys_ram_seg_t
*)((char *)cpu_kh
+ ALIGN(sizeof *cpu_kh
));
168 for (i
= 0; i
< cpu_kh
->nmemsegs
; i
++) {
169 if (pa
>= ramsegs
[i
].start
&&
170 (pa
- ramsegs
[i
].start
) < ramsegs
[i
].size
) {
171 off
+= (pa
- ramsegs
[i
].start
);
174 off
+= ramsegs
[i
].size
;
177 return (kd
->dump_off
+ off
);
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)
186 _kvm_mdopen(kvm_t
*kd
)
189 kd
->usrstack
= USRSTACK
;
190 kd
->min_uva
= VM_MIN_ADDRESS
;
191 kd
->max_uva
= VM_MAXUSER_ADDRESS
;