1 /* $NetBSD: kvm_arm.c,v 1.6 2010/09/20 23:23:16 jym Exp $ */
4 * Copyright (C) 1996 Wolfgang Solfrank.
5 * Copyright (C) 1996 TooLs GmbH.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * from: kvm_powerpc.c,v 1.3 1997/09/19 04:00:23 thorpej Exp
37 * arm32 machine dependent routines for kvm.
40 #include <sys/cdefs.h>
41 #if defined(LIBC_SCCS) && !defined(lint)
42 __RCSID("$NetBSD: kvm_arm.c,v 1.6 2010/09/20 23:23:16 jym Exp $");
43 #endif /* LIBC_SCCS and not lint */
45 #include <sys/param.h>
47 #include <sys/kcore.h>
48 #include <sys/types.h>
50 #include <arm/kcore.h>
51 #include <arm/arm32/pte.h>
60 #include "kvm_private.h"
63 _kvm_freevtop(kvm_t
* kd
)
70 _kvm_initvtop(kvm_t
* kd
)
76 _kvm_kvatop(kvm_t
* kd
, vaddr_t va
, paddr_t
*pa
)
78 cpu_kcore_hdr_t
*cpu_kh
;
81 paddr_t pde_pa
, pte_pa
;
84 _kvm_err(kd
, 0, "vatop called in live kernel!");
87 cpu_kh
= kd
->cpu_data
;
89 if (cpu_kh
->version
!= 1) {
90 _kvm_err(kd
, 0, "unsupported kcore structure version");
93 if (cpu_kh
->flags
!= 0) {
94 _kvm_err(kd
, 0, "kcore flags not supported");
98 * work out which L1 table we need
100 if (va
>= (cpu_kh
->UserL1TableSize
<< 17))
101 pde_pa
= cpu_kh
->PAKernelL1Table
;
103 pde_pa
= cpu_kh
->PAUserL1Table
;
106 * work out the offset into the L1 Table
108 pde_pa
+= ((va
>> 20) * sizeof(pd_entry_t
));
110 if (_kvm_pread(kd
, kd
->pmfd
, (void *) &pde
, sizeof(pd_entry_t
),
111 _kvm_pa2off(kd
, pde_pa
)) != sizeof(pd_entry_t
)) {
112 _kvm_syserr(kd
, 0, "could not read L1 entry");
116 * next work out what kind of record it is
118 switch (pde
& L1_TYPE_MASK
) {
120 *pa
= (pde
& L1_S_FRAME
) | (va
& L1_S_OFFSET
);
121 return L1_S_SIZE
- (va
& L1_S_OFFSET
);
123 pte_pa
= (pde
& L1_C_ADDR_MASK
)
124 | ((va
& 0xff000) >> 10);
127 pte_pa
= (pde
& L1_S_ADDR_MASK
)
128 | ((va
& 0xffc00) >> 8);
131 _kvm_syserr(kd
, 0, "L1 entry is invalid");
136 * locate the pte and load it
138 if (_kvm_pread(kd
, kd
->pmfd
, (void *) &pte
, sizeof(pt_entry_t
),
139 _kvm_pa2off(kd
, pte_pa
)) != sizeof(pt_entry_t
)) {
140 _kvm_syserr(kd
, 0, "could not read L2 entry");
143 switch (pte
& L2_TYPE_MASK
) {
145 *pa
= (pte
& L2_L_FRAME
) | (va
& L2_L_OFFSET
);
146 return (L2_L_SIZE
- (va
& L2_L_OFFSET
));
148 *pa
= (pte
& L2_S_FRAME
) | (va
& L2_S_OFFSET
);
149 return (L2_S_SIZE
- (va
& L2_S_OFFSET
));
151 *pa
= (pte
& L2_T_FRAME
) | (va
& L2_T_OFFSET
);
152 return (L2_T_SIZE
- (va
& L2_T_OFFSET
));
154 _kvm_syserr(kd
, 0, "L2 entry is invalid");
158 _kvm_err(kd
, 0, "vatop not yet implemented!");
163 _kvm_pa2off(kvm_t
* kd
, u_long pa
)
165 cpu_kcore_hdr_t
*cpu_kh
;
166 phys_ram_seg_t
*ramsegs
;
170 cpu_kh
= kd
->cpu_data
;
171 ramsegs
= (void *) ((char *) (void *) cpu_kh
+ cpu_kh
->omemsegs
);
174 for (i
= 0; i
< cpu_kh
->nmemsegs
; i
++) {
175 if (pa
>= ramsegs
[i
].start
&&
176 (pa
- ramsegs
[i
].start
) < ramsegs
[i
].size
) {
177 off
+= (pa
- ramsegs
[i
].start
);
180 off
+= ramsegs
[i
].size
;
182 return (kd
->dump_off
+ off
);
186 * Machine-dependent initialization for ALL open kvm descriptors,
187 * not just those for a kernel crash dump. Some architectures
188 * have to deal with these NOT being constants! (i.e. arm)
191 _kvm_mdopen(kvm_t
* kd
)
194 extern struct ps_strings
*__ps_strings
;
196 #if 0 /* XXX - These vary across arm machines... */
197 kd
->usrstack
= USRSTACK
;
198 kd
->min_uva
= VM_MIN_ADDRESS
;
199 kd
->max_uva
= VM_MAXUSER_ADDRESS
;
201 /* This is somewhat hack-ish, but it works. */
202 max_uva
= (uintptr_t) (__ps_strings
+ 1);
203 kd
->usrstack
= max_uva
;
204 kd
->max_uva
= max_uva
;