1 /* $NetBSD: kvm_mips.c,v 1.17 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.
31 * Modified for NetBSD/mips by Jason R. Thorpe, Numerical Aerospace
32 * Simulation Facility, NASA Ames Research Center.
35 #include <sys/cdefs.h>
36 #if defined(LIBC_SCCS) && !defined(lint)
37 __RCSID("$NetBSD: kvm_mips.c,v 1.17 2003/05/16 10:24:55 wiz Exp $");
38 #endif /* LIBC_SCCS and not lint */
41 * MIPS machine dependent routines for kvm.
44 #include <sys/param.h>
48 #include <sys/kcore.h>
49 #include <machine/kcore.h>
55 #include <uvm/uvm_extern.h>
60 #include "kvm_private.h"
62 #include <mips/cpuregs.h>
63 #include <mips/vmparam.h>
70 /* Not actually used for anything right now, but safe. */
84 * Translate a kernel virtual address to a physical address.
87 _kvm_kvatop(kd
, va
, pa
)
92 cpu_kcore_hdr_t
*cpu_kh
;
98 _kvm_err(kd
, 0, "vatop called in live kernel!");
102 cpu_kh
= kd
->cpu_data
;
103 page_off
= va
& PGOFSET
;
105 if (va
< MIPS_KSEG0_START
) {
107 * KUSEG (user virtual address space) - invalid.
109 _kvm_err(kd
, 0, "invalid kernel virtual address");
113 if (va
>= MIPS_KSEG0_START
&& va
< MIPS_KSEG1_START
) {
115 * Direct-mapped cached address: just convert it.
117 *pa
= MIPS_KSEG0_TO_PHYS(va
);
118 return (NBPG
- page_off
);
121 if (va
>= MIPS_KSEG1_START
&& va
< MIPS_KSEG2_START
) {
123 * Direct-mapped uncached address: just convert it.
125 *pa
= MIPS_KSEG1_TO_PHYS(va
);
126 return (NBPG
- page_off
);
130 * We now know that we're a KSEG2 (kernel virtually mapped)
131 * address. Translate the address using the pmap's kernel
136 * Step 1: Make sure the kernel page table has a translation
139 if (va
>= (MIPS_KSEG2_START
+ (cpu_kh
->sysmapsize
* NBPG
))) {
140 _kvm_err(kd
, 0, "invalid KSEG2 address");
145 * Step 2: Locate and read the PTE.
147 pte_pa
= cpu_kh
->sysmappa
+
148 (((va
- MIPS_KSEG2_START
) >> PGSHIFT
) * sizeof(u_int
));
149 if (_kvm_pread(kd
, kd
->pmfd
, &pte
, sizeof(pte
),
150 _kvm_pa2off(kd
, pte_pa
)) != sizeof(pte
)) {
151 _kvm_syserr(kd
, 0, "could not read PTE");
156 * Step 3: Validate the PTE and return the physical address.
158 if ((pte
& cpu_kh
->pg_v
) == 0) {
159 _kvm_err(kd
, 0, "invalid translation (invalid PTE)");
162 *pa
= (((pte
& cpu_kh
->pg_frame
) >> cpu_kh
->pg_shift
) << PGSHIFT
) +
164 return (NBPG
- page_off
);
172 * Translate a physical address to a file-offset in the crash dump.
179 cpu_kcore_hdr_t
*cpu_kh
;
180 phys_ram_seg_t
*ramsegs
;
184 cpu_kh
= kd
->cpu_data
;
185 ramsegs
= (phys_ram_seg_t
*)((char *)cpu_kh
+ ALIGN(sizeof *cpu_kh
));
188 for (i
= 0; i
< cpu_kh
->nmemsegs
; i
++) {
189 if (pa
>= ramsegs
[i
].start
&&
190 (pa
- ramsegs
[i
].start
) < ramsegs
[i
].size
) {
191 off
+= (pa
- ramsegs
[i
].start
);
194 off
+= ramsegs
[i
].size
;
197 return (kd
->dump_off
+ off
);
201 * Machine-dependent initialization for ALL open kvm descriptors,
202 * not just those for a kernel crash dump. Some architectures
203 * have to deal with these NOT being constants! (i.e. m68k)
210 kd
->usrstack
= USRSTACK
;
211 kd
->min_uva
= VM_MIN_ADDRESS
;
212 kd
->max_uva
= VM_MAXUSER_ADDRESS
;