Compat linux/linux32 nice(2) fix. The syscall argument is an increment
[netbsd-mini2440.git] / lib / libkvm / kvm_sun3x.c
blob30841f844a8196d8e720913735dfc864a65abc75
1 /* $NetBSD: kvm_sun3x.c,v 1.8 2003/05/16 10:24:56 wiz 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.8 2003/05/16 10:24:56 wiz 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.
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 __P((kvm_t *));
63 void _kvm_sun3x_freevtop __P((kvm_t *));
64 int _kvm_sun3x_kvatop __P((kvm_t *, u_long, u_long *));
65 off_t _kvm_sun3x_pa2off __P((kvm_t *, u_long));
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(kd)
86 kvm_t *kd;
88 return (0);
91 void
92 _kvm_sun3x_freevtop(kd)
93 kvm_t *kd;
98 * Translate a kernel virtual address to a physical address using the
99 * mapping information in kd->vm. Returns the result in pa, and returns
100 * the number of bytes that are contiguously available from this
101 * physical address. This routine is used only for crash dumps.
104 _kvm_sun3x_kvatop(kd, va, pap)
105 kvm_t *kd;
106 u_long va;
107 u_long *pap;
109 cpu_kcore_hdr_t *h = kd->cpu_data;
110 struct sun3x_kcore_hdr *s = &h->un._sun3x;
111 struct vmstate *v = kd->vmst;
112 int idx, len, offset, pte;
113 u_long pteva, pa;
115 if (ISALIVE(kd)) {
116 _kvm_err(kd, 0, "vatop called in live kernel!");
117 return(0);
120 if (va < h->kernbase) {
121 _kvm_err(kd, 0, "not a kernel address");
122 return(0);
126 * If this VA is in the contiguous range, short-cut.
127 * Note that this ends our recursion when we call
128 * kvm_read to access the kernel page table, which
129 * is guaranteed to be in the contiguous range.
131 if (va < s->contig_end) {
132 len = s->contig_end - va;
133 pa = va - h->kernbase;
134 goto done;
138 * The KVA is beyond the contiguous range, so we must
139 * read the PTE for this KVA from the page table.
141 idx = ((va - h->kernbase) >> v->pgshift);
142 pteva = s->kernCbase + (idx * 4);
143 if (kvm_read(kd, pteva, &pte, 4) != 4) {
144 _kvm_err(kd, 0, "can not read PTE!");
145 return (0);
147 if ((pte & s->pg_valid) == 0) {
148 _kvm_err(kd, 0, "page not valid (VA=0x%lx)", va);
149 return (0);
151 offset = va & v->pgofset;
152 len = (h->page_size - offset);
153 pa = _kvm_pg_pa(pte, s) + offset;
155 done:
156 *pap = pa;
157 return (len);
161 * Translate a physical address to a file-offset in the crash dump.
163 off_t
164 _kvm_sun3x_pa2off(kd, pa)
165 kvm_t *kd;
166 u_long pa;
168 off_t off;
169 phys_ram_seg_t *rsp;
170 cpu_kcore_hdr_t *h = kd->cpu_data;
171 struct sun3x_kcore_hdr *s = &h->un._sun3x;
173 off = 0;
174 for (rsp = s->ram_segs; rsp->size; rsp++) {
175 if (pa >= rsp->start && pa < rsp->start + rsp->size) {
176 pa -= rsp->start;
177 break;
179 off += rsp->size;
181 return (kd->dump_off + off + pa);