Remove building with NOCRYPTO option
[minix3.git] / lib / libkvm / kvm_alpha.c
blob03e6378e752f38384a690f900e74101d96298301
1 /* $NetBSD: kvm_alpha.c,v 1.27 2014/02/19 20:21:22 dsl 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/proc.h>
34 #include <sys/stat.h>
35 #include <sys/kcore.h>
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <nlist.h>
39 #include <kvm.h>
41 #include <uvm/uvm_extern.h>
43 #include <machine/kcore.h>
44 #include <machine/pmap.h>
45 #include <machine/vmparam.h>
47 #include <limits.h>
48 #include <db.h>
49 #include <stdlib.h>
51 #include "kvm_private.h"
53 __RCSID("$NetBSD: kvm_alpha.c,v 1.27 2014/02/19 20:21:22 dsl Exp $");
55 /*ARGSUSED*/
56 void
57 _kvm_freevtop(kvm_t *kd)
59 return;
62 /*ARGSUSED*/
63 int
64 _kvm_initvtop(kvm_t *kd)
66 return (0);
69 int
70 _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
72 cpu_kcore_hdr_t *cpu_kh;
73 alpha_pt_entry_t pte;
74 u_long pteoff, page_off;
75 int rv;
77 if (ISALIVE(kd)) {
78 _kvm_err(kd, 0, "vatop called in live kernel!");
79 return(0);
82 cpu_kh = kd->cpu_data;
83 page_off = va & (cpu_kh->page_size - 1);
85 if (va >= ALPHA_K0SEG_BASE && va <= ALPHA_K0SEG_END) {
87 * Direct-mapped address: just convert it.
90 *pa = ALPHA_K0SEG_TO_PHYS(va);
91 rv = cpu_kh->page_size - page_off;
92 } else if (va >= ALPHA_K1SEG_BASE && va <= ALPHA_K1SEG_END) {
94 * Real kernel virtual address: do the translation.
97 /* Find and read the L1 PTE. */
98 pteoff = cpu_kh->lev1map_pa +
99 l1pte_index(va) * sizeof(alpha_pt_entry_t);
100 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
101 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
102 _kvm_syserr(kd, 0, "could not read L1 PTE");
103 goto lose;
106 /* Find and read the L2 PTE. */
107 if ((pte & ALPHA_PTE_VALID) == 0) {
108 _kvm_err(kd, 0, "invalid translation (invalid L1 PTE)");
109 goto lose;
111 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
112 l2pte_index(va) * sizeof(alpha_pt_entry_t);
113 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
114 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
115 _kvm_syserr(kd, 0, "could not read L2 PTE");
116 goto lose;
119 /* Find and read the L3 PTE. */
120 if ((pte & ALPHA_PTE_VALID) == 0) {
121 _kvm_err(kd, 0, "invalid translation (invalid L2 PTE)");
122 goto lose;
124 pteoff = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size +
125 l3pte_index(va) * sizeof(alpha_pt_entry_t);
126 if (_kvm_pread(kd, kd->pmfd, &pte, sizeof(pte),
127 _kvm_pa2off(kd, pteoff)) != sizeof(pte)) {
128 _kvm_syserr(kd, 0, "could not read L3 PTE");
129 goto lose;
132 /* Fill in the PA. */
133 if ((pte & ALPHA_PTE_VALID) == 0) {
134 _kvm_err(kd, 0, "invalid translation (invalid L3 PTE)");
135 goto lose;
137 *pa = ALPHA_PTE_TO_PFN(pte) * cpu_kh->page_size + page_off;
138 rv = cpu_kh->page_size - page_off;
139 } else {
141 * Bogus address (not in KV space): punt.
144 _kvm_err(kd, 0, "invalid kernel virtual address");
145 lose:
146 *pa = -1;
147 rv = 0;
150 return (rv);
154 * Translate a physical address to a file-offset in the crash dump.
156 off_t
157 _kvm_pa2off(kvm_t *kd, paddr_t pa)
159 cpu_kcore_hdr_t *cpu_kh;
160 phys_ram_seg_t *ramsegs;
161 off_t off;
162 int i;
164 cpu_kh = kd->cpu_data;
165 ramsegs = (phys_ram_seg_t *)((char *)cpu_kh + ALIGN(sizeof *cpu_kh));
167 off = 0;
168 for (i = 0; i < cpu_kh->nmemsegs; i++) {
169 if (pa >= ramsegs[i].start &&
170 (pa - ramsegs[i].start) < ramsegs[i].size) {
171 off += (pa - ramsegs[i].start);
172 break;
174 off += ramsegs[i].size;
177 return (kd->dump_off + off);
181 * Machine-dependent initialization for ALL open kvm descriptors,
182 * not just those for a kernel crash dump. Some architectures
183 * have to deal with these NOT being constants! (i.e. m68k)
186 _kvm_mdopen(kvm_t *kd)
189 kd->usrstack = USRSTACK;
190 kd->min_uva = VM_MIN_ADDRESS;
191 kd->max_uva = VM_MAXUSER_ADDRESS;
193 return (0);