Remove building with NOCRYPTO option
[minix3.git] / lib / libkvm / kvm_sun3x.c
blobc7539d15247bce19538d1ca05d89e0896da059eb
1 /* $NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos Exp $ */
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 #if 0
35 static char sccsid[] = "@(#)kvm_sparc.c 8.1 (Berkeley) 6/4/93";
36 #else
37 __RCSID("$NetBSD: kvm_sun3x.c,v 1.12 2011/09/14 12:37:55 christos Exp $");
38 #endif
39 #endif /* LIBC_SCCS and not lint */
42 * Sun3x machine dependent routines for kvm.
44 * Note: This file has to build on ALL m68k machines,
45 * so do NOT include any <machine / *.h> files here.
47 #include <sys/param.h>
48 #include <sys/types.h>
49 #include <sys/kcore.h>
51 #include <unistd.h>
52 #include <limits.h>
53 #include <nlist.h>
54 #include <kvm.h>
55 #include <db.h>
57 #include <m68k/kcore.h>
59 #include "kvm_private.h"
60 #include "kvm_m68k.h"
62 int _kvm_sun3x_initvtop(kvm_t *);
63 void _kvm_sun3x_freevtop(kvm_t *);
64 int _kvm_sun3x_kvatop (kvm_t *, vaddr_t, paddr_t *);
65 off_t _kvm_sun3x_pa2off (kvm_t *, paddr_t);
67 struct kvm_ops _kvm_ops_sun3x = {
68 _kvm_sun3x_initvtop,
69 _kvm_sun3x_freevtop,
70 _kvm_sun3x_kvatop,
71 _kvm_sun3x_pa2off };
73 #define _kvm_kvas_size(h) \
74 (-((h)->kernbase))
75 #define _kvm_nkptes(h, v) \
76 (_kvm_kvas_size((h)) >> (v)->pgshift)
77 #define _kvm_pg_pa(pte, h) \
78 ((pte) & (h)->pg_frame)
81 * Prepare for translation of kernel virtual addresses into offsets
82 * into crash dump files. Nothing to do here.
84 int
85 _kvm_sun3x_initvtop(kvm_t *kd)
87 return 0;
90 void
91 _kvm_sun3x_freevtop(kvm_t *kd)
96 * Translate a kernel virtual address to a physical address using the
97 * mapping information in kd->vm. Returns the result in pa, and returns
98 * the number of bytes that are contiguously available from this
99 * physical address. This routine is used only for crash dumps.
102 _kvm_sun3x_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pap)
104 cpu_kcore_hdr_t *h = kd->cpu_data;
105 struct sun3x_kcore_hdr *s = &h->un._sun3x;
106 struct vmstate *v = kd->vmst;
107 int idx, len, offset, pte;
108 u_long pteva, pa;
110 if (ISALIVE(kd)) {
111 _kvm_err(kd, 0, "vatop called in live kernel!");
112 return(0);
115 if (va < h->kernbase) {
116 _kvm_err(kd, 0, "not a kernel address");
117 return(0);
121 * If this VA is in the contiguous range, short-cut.
122 * Note that this ends our recursion when we call
123 * kvm_read to access the kernel page table, which
124 * is guaranteed to be in the contiguous range.
126 if (va < s->contig_end) {
127 len = s->contig_end - va;
128 pa = va - h->kernbase;
129 goto done;
133 * The KVA is beyond the contiguous range, so we must
134 * read the PTE for this KVA from the page table.
136 idx = ((va - h->kernbase) >> v->pgshift);
137 pteva = s->kernCbase + (idx * 4);
138 if (kvm_read(kd, pteva, &pte, 4) != 4) {
139 _kvm_err(kd, 0, "can not read PTE!");
140 return (0);
142 if ((pte & s->pg_valid) == 0) {
143 _kvm_err(kd, 0, "page not valid (VA=0x%lx)", va);
144 return (0);
146 offset = va & v->pgofset;
147 len = (h->page_size - offset);
148 pa = _kvm_pg_pa(pte, s) + offset;
150 done:
151 *pap = pa;
152 return (len);
156 * Translate a physical address to a file-offset in the crash dump.
158 off_t
159 _kvm_sun3x_pa2off(kvm_t *kd, paddr_t pa)
161 off_t off;
162 phys_ram_seg_t *rsp;
163 cpu_kcore_hdr_t *h = kd->cpu_data;
164 struct sun3x_kcore_hdr *s = &h->un._sun3x;
166 off = 0;
167 for (rsp = s->ram_segs; rsp->size; rsp++) {
168 if (pa >= rsp->start && pa < rsp->start + rsp->size) {
169 pa -= rsp->start;
170 break;
172 off += rsp->size;
174 return (kd->dump_off + off + pa);