Do not run mandoc for lintmanpages if MANPAGES is empty.
[netbsd-mini2440.git] / lib / libkvm / kvm_alpha.c
blob34cd568a12b803d560f9f4e7c5a0a4b651ec34e8
1 /* $NetBSD: kvm_alpha.c,v 1.22 2003/05/16 10:24:55 wiz Exp $ */
3 /*
4 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5 * All rights reserved.
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.
30 #define __KVM_ALPHA_PRIVATE /* see <machine/pte.h> */
32 #include <sys/param.h>
33 #include <sys/user.h>
34 #include <sys/proc.h>
35 #include <sys/stat.h>
36 #include <sys/kcore.h>
37 #include <machine/kcore.h>
38 #include <unistd.h>
39 #include <nlist.h>
40 #include <kvm.h>
42 #include <uvm/uvm_extern.h>
43 #include <machine/pmap.h>
44 #include <machine/vmparam.h>
46 #include <limits.h>
47 #include <db.h>
48 #include <stdlib.h>
50 #include "kvm_private.h"
52 /*ARGSUSED*/
53 void
54 _kvm_freevtop(kd)
55 kvm_t *kd;
57 return;
60 /*ARGSUSED*/
61 int
62 _kvm_initvtop(kd)
63 kvm_t *kd;
65 return (0);
68 int
69 _kvm_kvatop(kd, va, pa)
70 kvm_t *kd;
71 u_long va;
72 u_long *pa;
74 cpu_kcore_hdr_t *cpu_kh;
75 alpha_pt_entry_t pte;
76 u_long pteoff, page_off;
77 int rv;
79 if (ISALIVE(kd)) {
80 _kvm_err(kd, 0, "vatop called in live kernel!");
81 return(0);
84 cpu_kh = kd->cpu_data;
85 page_off = va & (cpu_kh->page_size - 1);
87 if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
89 * Direct-mapped address: just convert it.
92 *pa = ALPHA_K0SEG_TO_PHYS(va);
93 rv = cpu_kh->page_size - page_off;
94 } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
96 * Real kernel virtual address: do the translation.
99 /* Find and read the L1 PTE. */
100 pteoff = cpu_kh->lev1map_pa +
101 l1pte_index(va) * sizeof(alpha_pt_entry_t);
102 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
103 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
104 _kvm_syserr(kd, 0, "could not read L1 PTE");
105 goto lose;
108 /* Find and read the L2 PTE. */
109 if ((pte & ALPHA_PTE_VALID) == 0) {
110 _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
111 goto lose;
113 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
114 l2pte_index(va) * sizeof(alpha_pt_entry_t);
115 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
116 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
117 _kvm_syserr(kd, 0, "could not read L2 PTE");
118 goto lose;
121 /* Find and read the L3 PTE. */
122 if ((pte & ALPHA_PTE_VALID) == 0) {
123 _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
124 goto lose;
126 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
127 l3pte_index(va) * sizeof(alpha_pt_entry_t);
128 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
129 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
130 _kvm_syserr(kd, 0, "could not read L3 PTE");
131 goto lose;
134 /* Fill in the PA. */
135 if ((pte & ALPHA_PTE_VALID) == 0) {
136 _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
137 goto lose;
139 *pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
140 rv = cpu_kh->page_size - page_off;
141 } else {
143 * Bogus address (not in KV space): punt.
146 _kvm_err(kd, 0, "invalid kernel virtual address");
147 lose:
148 *pa = -1;
149 rv = 0;
152 return (rv);
156 * Translate a physical address to a file-offset in the crash dump.
158 off_t
159 _kvm_pa2off(kd, pa)
160 kvm_t *kd;
161 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 = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
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;
181 return (kd->dump_off + off);
185 * Machine-dependent initialization for ALL open kvm descriptors,
186 * not just those for a kernel crash dump. Some architectures
187 * have to deal with these NOT being constants! (i.e. m68k)
190 _kvm_mdopen(kd)
191 kvm_t *kd;
194 kd->usrstack = USRSTACK;
195 kd->min_uva = VM_MIN_ADDRESS;
196 kd->max_uva = VM_MAXUSER_ADDRESS;
198 return (0);