kvm_hppa.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: kvm_hppa.c,v 1.1.2.2 2002/12/19 02:26:19 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (c) 1989, 1992, 1993
5 1.1.2.2 thorpej * The Regents of the University of California. All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * This code is derived from software developed by the Computer Systems
8 1.1.2.2 thorpej * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9 1.1.2.2 thorpej * BG 91-66 and contributed to Berkeley.
10 1.1.2.2 thorpej *
11 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
13 1.1.2.2 thorpej * are met:
14 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
19 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1.2.2 thorpej * must display the following acknowledgement:
21 1.1.2.2 thorpej * This product includes software developed by the University of
22 1.1.2.2 thorpej * California, Berkeley and its contributors.
23 1.1.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
24 1.1.2.2 thorpej * may be used to endorse or promote products derived from this software
25 1.1.2.2 thorpej * without specific prior written permission.
26 1.1.2.2 thorpej *
27 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1.2.2 thorpej * SUCH DAMAGE.
38 1.1.2.2 thorpej */
39 1.1.2.2 thorpej
40 1.1.2.2 thorpej #include <sys/cdefs.h>
41 1.1.2.2 thorpej #if defined(LIBC_SCCS) && !defined(lint)
42 1.1.2.2 thorpej #if 0
43 1.1.2.2 thorpej static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93";
44 1.1.2.2 thorpej #else
45 1.1.2.2 thorpej __RCSID("$NetBSD: kvm_hppa.c,v 1.1.2.2 2002/12/19 02:26:19 thorpej Exp $");
46 1.1.2.2 thorpej #endif
47 1.1.2.2 thorpej #endif /* LIBC_SCCS and not lint */
48 1.1.2.2 thorpej
49 1.1.2.2 thorpej /*
50 1.1.2.2 thorpej * hppa machine dependent routines for kvm.
51 1.1.2.2 thorpej * XXX fredette - largely unimplemented so far. what is here
52 1.1.2.2 thorpej * is lifted and disabled.
53 1.1.2.2 thorpej */
54 1.1.2.2 thorpej
55 1.1.2.2 thorpej #include <sys/param.h>
56 1.1.2.2 thorpej #include <sys/user.h>
57 1.1.2.2 thorpej #include <sys/proc.h>
58 1.1.2.2 thorpej #include <sys/stat.h>
59 1.1.2.2 thorpej #include <sys/kcore.h>
60 1.1.2.2 thorpej #include <machine/kcore.h>
61 1.1.2.2 thorpej #include <stdlib.h>
62 1.1.2.2 thorpej #include <unistd.h>
63 1.1.2.2 thorpej #include <nlist.h>
64 1.1.2.2 thorpej #include <kvm.h>
65 1.1.2.2 thorpej
66 1.1.2.2 thorpej #include <uvm/uvm_extern.h>
67 1.1.2.2 thorpej
68 1.1.2.2 thorpej #include <limits.h>
69 1.1.2.2 thorpej #include <db.h>
70 1.1.2.2 thorpej
71 1.1.2.2 thorpej #include "kvm_private.h"
72 1.1.2.2 thorpej
73 1.1.2.2 thorpej #include <machine/pmap.h>
74 1.1.2.2 thorpej #include <machine/pte.h>
75 1.1.2.2 thorpej #include <machine/vmparam.h>
76 1.1.2.2 thorpej
77 1.1.2.2 thorpej #ifndef btop
78 1.1.2.2 thorpej #define btop(x) (((unsigned)(x)) >> PGSHIFT) /* XXX */
79 1.1.2.2 thorpej #define ptob(x) ((caddr_t)((x) << PGSHIFT)) /* XXX */
80 1.1.2.2 thorpej #endif
81 1.1.2.2 thorpej
82 1.1.2.2 thorpej void
83 1.1.2.2 thorpej _kvm_freevtop(kd)
84 1.1.2.2 thorpej kvm_t *kd;
85 1.1.2.2 thorpej {
86 1.1.2.2 thorpej
87 1.1.2.2 thorpej /* Not actually used for anything right now, but safe. */
88 1.1.2.2 thorpej if (kd->vmst != 0)
89 1.1.2.2 thorpej free(kd->vmst);
90 1.1.2.2 thorpej }
91 1.1.2.2 thorpej
92 1.1.2.2 thorpej /*ARGSUSED*/
93 1.1.2.2 thorpej int
94 1.1.2.2 thorpej _kvm_initvtop(kd)
95 1.1.2.2 thorpej kvm_t *kd;
96 1.1.2.2 thorpej {
97 1.1.2.2 thorpej
98 1.1.2.2 thorpej return (0);
99 1.1.2.2 thorpej }
100 1.1.2.2 thorpej
101 1.1.2.2 thorpej /*
102 1.1.2.2 thorpej * Translate a kernel virtual address to a physical address.
103 1.1.2.2 thorpej */
104 1.1.2.2 thorpej int
105 1.1.2.2 thorpej _kvm_kvatop(kd, va, pa)
106 1.1.2.2 thorpej kvm_t *kd;
107 1.1.2.2 thorpej u_long va;
108 1.1.2.2 thorpej u_long *pa;
109 1.1.2.2 thorpej {
110 1.1.2.2 thorpej #if 0
111 1.1.2.2 thorpej cpu_kcore_hdr_t *cpu_kh;
112 1.1.2.2 thorpej u_long page_off;
113 1.1.2.2 thorpej pd_entry_t pde;
114 1.1.2.2 thorpej pt_entry_t pte;
115 1.1.2.2 thorpej u_long pde_pa, pte_pa;
116 1.1.2.2 thorpej #endif
117 1.1.2.2 thorpej
118 1.1.2.2 thorpej if (ISALIVE(kd)) {
119 1.1.2.2 thorpej _kvm_err(kd, 0, "vatop called in live kernel!");
120 1.1.2.2 thorpej return (0);
121 1.1.2.2 thorpej }
122 1.1.2.2 thorpej
123 1.1.2.2 thorpej _kvm_syserr(kd, 0, "could not read PTE");
124 1.1.2.2 thorpej
125 1.1.2.2 thorpej #if 0
126 1.1.2.2 thorpej cpu_kh = kd->cpu_data;
127 1.1.2.2 thorpej page_off = va & PGOFSET;
128 1.1.2.2 thorpej
129 1.1.2.2 thorpej /*
130 1.1.2.2 thorpej * Find and read the page directory entry.
131 1.1.2.2 thorpej */
132 1.1.2.2 thorpej pde_pa = cpu_kh->ptdpaddr + (pdei(va) * sizeof(pd_entry_t));
133 1.1.2.2 thorpej if (pread(kd->pmfd, (void *)&pde, sizeof(pde),
134 1.1.2.2 thorpej _kvm_pa2off(kd, pde_pa)) != sizeof(pde)) {
135 1.1.2.2 thorpej _kvm_syserr(kd, 0, "could not read PDE");
136 1.1.2.2 thorpej goto lose;
137 1.1.2.2 thorpej }
138 1.1.2.2 thorpej
139 1.1.2.2 thorpej /*
140 1.1.2.2 thorpej * Find and read the page table entry.
141 1.1.2.2 thorpej */
142 1.1.2.2 thorpej if ((pde & PG_V) == 0) {
143 1.1.2.2 thorpej _kvm_err(kd, 0, "invalid translation (invalid PDE)");
144 1.1.2.2 thorpej goto lose;
145 1.1.2.2 thorpej }
146 1.1.2.2 thorpej pte_pa = (pde & PG_FRAME) + (ptei(va) * sizeof(pt_entry_t));
147 1.1.2.2 thorpej if (pread(kd->pmfd, (void *) &pte, sizeof(pte),
148 1.1.2.2 thorpej _kvm_pa2off(kd, pte_pa)) != sizeof(pte)) {
149 1.1.2.2 thorpej _kvm_syserr(kd, 0, "could not read PTE");
150 1.1.2.2 thorpej goto lose;
151 1.1.2.2 thorpej }
152 1.1.2.2 thorpej
153 1.1.2.2 thorpej /*
154 1.1.2.2 thorpej * Validate the PTE and return the physical address.
155 1.1.2.2 thorpej */
156 1.1.2.2 thorpej if ((pte & PG_V) == 0) {
157 1.1.2.2 thorpej _kvm_err(kd, 0, "invalid translation (invalid PTE)");
158 1.1.2.2 thorpej goto lose;
159 1.1.2.2 thorpej }
160 1.1.2.2 thorpej *pa = (pte & PG_FRAME) + page_off;
161 1.1.2.2 thorpej return (int)(NBPG - page_off);
162 1.1.2.2 thorpej
163 1.1.2.2 thorpej lose:
164 1.1.2.2 thorpej #endif
165 1.1.2.2 thorpej *pa = (u_long)~0L;
166 1.1.2.2 thorpej return (0);
167 1.1.2.2 thorpej }
168 1.1.2.2 thorpej
169 1.1.2.2 thorpej /*
170 1.1.2.2 thorpej * Translate a physical address to a file-offset in the crash dump.
171 1.1.2.2 thorpej */
172 1.1.2.2 thorpej off_t
173 1.1.2.2 thorpej _kvm_pa2off(kd, pa)
174 1.1.2.2 thorpej kvm_t *kd;
175 1.1.2.2 thorpej u_long pa;
176 1.1.2.2 thorpej {
177 1.1.2.2 thorpej #if 0
178 1.1.2.2 thorpej cpu_kcore_hdr_t *cpu_kh;
179 1.1.2.2 thorpej phys_ram_seg_t *ramsegs;
180 1.1.2.2 thorpej off_t off;
181 1.1.2.2 thorpej int i;
182 1.1.2.2 thorpej
183 1.1.2.2 thorpej cpu_kh = kd->cpu_data;
184 1.1.2.2 thorpej ramsegs = (void *)((char *)(void *)cpu_kh + ALIGN(sizeof *cpu_kh));
185 1.1.2.2 thorpej
186 1.1.2.2 thorpej off = 0;
187 1.1.2.2 thorpej for (i = 0; i < cpu_kh->nmemsegs; i++) {
188 1.1.2.2 thorpej if (pa >= ramsegs[i].start &&
189 1.1.2.2 thorpej (pa - ramsegs[i].start) < ramsegs[i].size) {
190 1.1.2.2 thorpej off += (pa - ramsegs[i].start);
191 1.1.2.2 thorpej break;
192 1.1.2.2 thorpej }
193 1.1.2.2 thorpej off += ramsegs[i].size;
194 1.1.2.2 thorpej }
195 1.1.2.2 thorpej
196 1.1.2.2 thorpej return (kd->dump_off + off);
197 1.1.2.2 thorpej #endif
198 1.1.2.2 thorpej return 0;
199 1.1.2.2 thorpej }
200 1.1.2.2 thorpej
201 1.1.2.2 thorpej /*
202 1.1.2.2 thorpej * Machine-dependent initialization for ALL open kvm descriptors,
203 1.1.2.2 thorpej * not just those for a kernel crash dump. Some architectures
204 1.1.2.2 thorpej * have to deal with these NOT being constants! (i.e. m68k)
205 1.1.2.2 thorpej */
206 1.1.2.2 thorpej int
207 1.1.2.2 thorpej _kvm_mdopen(kd)
208 1.1.2.2 thorpej kvm_t *kd;
209 1.1.2.2 thorpej {
210 1.1.2.2 thorpej
211 1.1.2.2 thorpej kd->usrstack = USRSTACK;
212 1.1.2.2 thorpej kd->min_uva = VM_MIN_ADDRESS;
213 1.1.2.2 thorpej kd->max_uva = VM_MAXUSER_ADDRESS;
214 1.1.2.2 thorpej
215 1.1.2.2 thorpej return (0);
216 1.1.2.2 thorpej }
217