Fix mdoc(7)/man(7) mix up.
[netbsd-mini2440.git] / lib / libkvm / kvm_arm.c
blob336089fdf657a30dff356f454b4b473c41074cc5
1 /* $NetBSD: kvm_arm.c,v 1.3 2008/01/01 14:10:37 chris Exp $ */
3 /*-
4 * Copyright (C) 1996 Wolfgang Solfrank.
5 * Copyright (C) 1996 TooLs GmbH.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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>
46 #include <sys/exec.h>
47 #include <sys/kcore.h>
48 #include <arm/kcore.h>
49 #include <arm/arm32/pte.h>
51 #include <stdlib.h>
52 #include <db.h>
53 #include <limits.h>
54 #include <kvm.h>
56 #include <unistd.h>
58 #include "kvm_private.h"
60 void
61 _kvm_freevtop(kvm_t * kd)
63 if (kd->vmst != 0)
64 free(kd->vmst);
67 int
68 _kvm_initvtop(kvm_t * kd)
70 return 0;
73 int
74 _kvm_kvatop(kvm_t * kd, u_long va, u_long * pa)
76 cpu_kcore_hdr_t *cpu_kh;
77 pd_entry_t pde;
78 pt_entry_t pte;
79 uint32_t pde_pa, pte_pa;
81 if (ISALIVE(kd)) {
82 _kvm_err(kd, 0, "vatop called in live kernel!");
83 return (0);
85 cpu_kh = kd->cpu_data;
87 if (cpu_kh->version != 1) {
88 _kvm_err(kd, 0, "unsupported kcore structure version");
89 return 0;
91 if (cpu_kh->flags != 0) {
92 _kvm_err(kd, 0, "kcore flags not supported");
93 return 0;
96 * work out which L1 table we need
98 if (va >= (cpu_kh->UserL1TableSize << 17))
99 pde_pa = cpu_kh->PAKernelL1Table;
100 else
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");
111 return (0);
114 * next work out what kind of record it is
116 switch (pde & L1_TYPE_MASK) {
117 case L1_TYPE_S:
118 *pa = (pde & L1_S_FRAME) | (va & L1_S_OFFSET);
119 return L1_S_SIZE - (va & L1_S_OFFSET);
120 case L1_TYPE_C:
121 pte_pa = (pde & L1_C_ADDR_MASK)
122 | ((va & 0xff000) >> 10);
123 break;
124 case L1_TYPE_F:
125 pte_pa = (pde & L1_S_ADDR_MASK)
126 | ((va & 0xffc00) >> 8);
127 break;
128 default:
129 _kvm_syserr(kd, 0, "L1 entry is invalid");
130 return (0);
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");
139 return (0);
141 switch (pte & L2_TYPE_MASK) {
142 case L2_TYPE_L:
143 *pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET);
144 return (L2_L_SIZE - (va & L2_L_OFFSET));
145 case L2_TYPE_S:
146 *pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET);
147 return (L2_S_SIZE - (va & L2_S_OFFSET));
148 case L2_TYPE_T:
149 *pa = (pte & L2_T_FRAME) | (va & L2_T_OFFSET);
150 return (L2_T_SIZE - (va & L2_T_OFFSET));
151 default:
152 _kvm_syserr(kd, 0, "L2 entry is invalid");
153 return (0);
156 _kvm_err(kd, 0, "vatop not yet implemented!");
157 return 0;
160 off_t
161 _kvm_pa2off(kvm_t * kd, u_long pa)
163 cpu_kcore_hdr_t *cpu_kh;
164 phys_ram_seg_t *ramsegs;
165 off_t off;
166 int i;
168 cpu_kh = kd->cpu_data;
169 ramsegs = (void *) ((char *) (void *) cpu_kh + cpu_kh->omemsegs);
171 off = 0;
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);
176 break;
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)
191 uintptr_t max_uva;
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;
198 #endif
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;
203 kd->min_uva = 0;
205 return (0);