1 /* $NetBSD: kvm_arm.c,v 1.3 2008/01/01 14:10:37 chris 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.3 2008/01/01 14:10:37 chris Exp $");
43 #endif /* LIBC_SCCS and not lint */
45 #include <sys/param.h>
47 #include <sys/kcore.h>
48 #include <arm/kcore.h>
49 #include <arm/arm32/pte.h>
58 #include "kvm_private.h"
61 _kvm_freevtop(kvm_t
* kd
)
68 _kvm_initvtop(kvm_t
* kd
)
74 _kvm_kvatop(kvm_t
* kd
, u_long va
, u_long
* pa
)
76 cpu_kcore_hdr_t
*cpu_kh
;
79 uint32_t pde_pa
, pte_pa
;
82 _kvm_err(kd
, 0, "vatop called in live kernel!");
85 cpu_kh
= kd
->cpu_data
;
87 if (cpu_kh
->version
!= 1) {
88 _kvm_err(kd
, 0, "unsupported kcore structure version");
91 if (cpu_kh
->flags
!= 0) {
92 _kvm_err(kd
, 0, "kcore flags not supported");
96 * work out which L1 table we need
98 if (va
>= (cpu_kh
->UserL1TableSize
<< 17))
99 pde_pa
= cpu_kh
->PAKernelL1Table
;
101 pde_pa
= cpu_kh
->PAUserL1Table
;
104 * work out the offset into the L1 Table
106 pde_pa
+= ((va
>> 20) * sizeof(pd_entry_t
));
108 if (_kvm_pread(kd
, kd
->pmfd
, (void *) &pde
, sizeof(pd_entry_t
),
109 _kvm_pa2off(kd
, pde_pa
)) != sizeof(pd_entry_t
)) {
110 _kvm_syserr(kd
, 0, "could not read L1 entry");
114 * next work out what kind of record it is
116 switch (pde
& L1_TYPE_MASK
) {
118 *pa
= (pde
& L1_S_FRAME
) | (va
& L1_S_OFFSET
);
119 return L1_S_SIZE
- (va
& L1_S_OFFSET
);
121 pte_pa
= (pde
& L1_C_ADDR_MASK
)
122 | ((va
& 0xff000) >> 10);
125 pte_pa
= (pde
& L1_S_ADDR_MASK
)
126 | ((va
& 0xffc00) >> 8);
129 _kvm_syserr(kd
, 0, "L1 entry is invalid");
134 * locate the pte and load it
136 if (_kvm_pread(kd
, kd
->pmfd
, (void *) &pte
, sizeof(pt_entry_t
),
137 _kvm_pa2off(kd
, pte_pa
)) != sizeof(pt_entry_t
)) {
138 _kvm_syserr(kd
, 0, "could not read L2 entry");
141 switch (pte
& L2_TYPE_MASK
) {
143 *pa
= (pte
& L2_L_FRAME
) | (va
& L2_L_OFFSET
);
144 return (L2_L_SIZE
- (va
& L2_L_OFFSET
));
146 *pa
= (pte
& L2_S_FRAME
) | (va
& L2_S_OFFSET
);
147 return (L2_S_SIZE
- (va
& L2_S_OFFSET
));
149 *pa
= (pte
& L2_T_FRAME
) | (va
& L2_T_OFFSET
);
150 return (L2_T_SIZE
- (va
& L2_T_OFFSET
));
152 _kvm_syserr(kd
, 0, "L2 entry is invalid");
156 _kvm_err(kd
, 0, "vatop not yet implemented!");
161 _kvm_pa2off(kvm_t
* kd
, u_long pa
)
163 cpu_kcore_hdr_t
*cpu_kh
;
164 phys_ram_seg_t
*ramsegs
;
168 cpu_kh
= kd
->cpu_data
;
169 ramsegs
= (void *) ((char *) (void *) cpu_kh
+ cpu_kh
->omemsegs
);
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
;
180 return (kd
->dump_off
+ off
);
184 * Machine-dependent initialization for ALL open kvm descriptors,
185 * not just those for a kernel crash dump. Some architectures
186 * have to deal with these NOT being constants! (i.e. arm)
189 _kvm_mdopen(kvm_t
* kd
)
192 extern struct ps_strings
*__ps_strings
;
194 #if 0 /* XXX - These vary across arm machines... */
195 kd
->usrstack
= USRSTACK
;
196 kd
->min_uva
= VM_MIN_ADDRESS
;
197 kd
->max_uva
= VM_MAXUSER_ADDRESS
;
199 /* This is somewhat hack-ish, but it works. */
200 max_uva
= (uintptr_t) (__ps_strings
+ 1);
201 kd
->usrstack
= max_uva
;
202 kd
->max_uva
= max_uva
;