kvm_vax.c revision 1.19 1 1.19 matt /* $NetBSD: kvm_vax.c,v 1.19 2014/01/27 21:00:01 matt Exp $ */
2 1.3 thorpej
3 1.1 ragge /*-
4 1.1 ragge * Copyright (c) 1992, 1993
5 1.1 ragge * The Regents of the University of California. All rights reserved.
6 1.1 ragge *
7 1.1 ragge * This code is derived from software developed by the Computer Systems
8 1.1 ragge * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9 1.1 ragge * BG 91-66 and contributed to Berkeley.
10 1.1 ragge *
11 1.1 ragge * Redistribution and use in source and binary forms, with or without
12 1.1 ragge * modification, are permitted provided that the following conditions
13 1.1 ragge * are met:
14 1.1 ragge * 1. Redistributions of source code must retain the above copyright
15 1.1 ragge * notice, this list of conditions and the following disclaimer.
16 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 ragge * notice, this list of conditions and the following disclaimer in the
18 1.1 ragge * documentation and/or other materials provided with the distribution.
19 1.16 agc * 3. Neither the name of the University nor the names of its contributors
20 1.1 ragge * may be used to endorse or promote products derived from this software
21 1.1 ragge * without specific prior written permission.
22 1.1 ragge *
23 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 ragge * SUCH DAMAGE.
34 1.1 ragge */
35 1.1 ragge
36 1.1 ragge /*
37 1.1 ragge * VAX machine dependent routines for kvm. Hopefully, the forthcoming
38 1.1 ragge * vm code will one day obsolete this module. Furthermore, I hope it
39 1.1 ragge * gets here soon, because this basically is an error stub! (sorry)
40 1.1 ragge * This code may not work anyway.
41 1.1 ragge */
42 1.1 ragge
43 1.1 ragge #include <sys/param.h>
44 1.1 ragge #include <sys/user.h>
45 1.1 ragge #include <sys/proc.h>
46 1.1 ragge #include <sys/stat.h>
47 1.18 jym #include <sys/types.h>
48 1.18 jym
49 1.1 ragge #include <unistd.h>
50 1.1 ragge #include <nlist.h>
51 1.6 ragge #include <stdlib.h>
52 1.1 ragge #include <kvm.h>
53 1.1 ragge
54 1.10 mrg #include <uvm/uvm_extern.h>
55 1.1 ragge
56 1.13 chuck #include <machine/vmparam.h>
57 1.13 chuck
58 1.1 ragge #include <limits.h>
59 1.1 ragge #include <db.h>
60 1.1 ragge
61 1.1 ragge #include "kvm_private.h"
62 1.13 chuck
63 1.19 matt __RCSID("$NetBSD: kvm_vax.c,v 1.19 2014/01/27 21:00:01 matt Exp $");
64 1.1 ragge
65 1.1 ragge struct vmstate {
66 1.1 ragge u_long end;
67 1.1 ragge };
68 1.1 ragge
69 1.1 ragge void
70 1.17 jym _kvm_freevtop(kvm_t *kd)
71 1.1 ragge {
72 1.1 ragge if (kd->vmst != 0)
73 1.1 ragge free(kd->vmst);
74 1.1 ragge }
75 1.1 ragge
76 1.1 ragge int
77 1.17 jym _kvm_initvtop(kvm_t *kd)
78 1.1 ragge {
79 1.7 perry struct vmstate *vm;
80 1.1 ragge struct stat st;
81 1.14 thorpej struct nlist nl[2];
82 1.1 ragge
83 1.1 ragge vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
84 1.1 ragge if (vm == 0)
85 1.1 ragge return (-1);
86 1.1 ragge
87 1.1 ragge kd->vmst = vm;
88 1.1 ragge
89 1.1 ragge if (fstat(kd->pmfd, &st) < 0)
90 1.1 ragge return (-1);
91 1.1 ragge
92 1.1 ragge /* Get end of kernel address */
93 1.14 thorpej nl[0].n_name = "_end";
94 1.14 thorpej nl[1].n_name = 0;
95 1.14 thorpej if (kvm_nlist(kd, nl) != 0) {
96 1.1 ragge _kvm_err(kd, kd->program, "pmap_stod: no such symbol");
97 1.1 ragge return (-1);
98 1.1 ragge }
99 1.14 thorpej vm->end = (u_long)nl[0].n_value;
100 1.1 ragge
101 1.1 ragge return (0);
102 1.1 ragge }
103 1.1 ragge
104 1.1 ragge #define VA_OFF(va) (va & (NBPG - 1))
105 1.1 ragge
106 1.1 ragge /*
107 1.1 ragge * Translate a kernel virtual address to a physical address using the
108 1.1 ragge * mapping information in kd->vm. Returns the result in pa, and returns
109 1.8 simonb * the number of bytes that are contiguously available from this
110 1.15 wiz * physical address. This routine is used only for crash dumps.
111 1.1 ragge */
112 1.1 ragge int
113 1.18 jym _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
114 1.1 ragge {
115 1.12 matt u_long end;
116 1.1 ragge
117 1.12 matt if (va < (u_long) KERNBASE) {
118 1.18 jym _kvm_err(kd, 0, "invalid address (%#"PRIxVADDR"<%lx)", va,
119 1.18 jym (u_long)KERNBASE);
120 1.1 ragge return (0);
121 1.1 ragge }
122 1.1 ragge
123 1.1 ragge end = kd->vmst->end;
124 1.1 ragge if (va >= end) {
125 1.18 jym _kvm_err(kd, 0, "invalid address (%#"PRIxVADDR"<%lx)", va,
126 1.18 jym end);
127 1.1 ragge return (0);
128 1.1 ragge }
129 1.1 ragge
130 1.12 matt *pa = (va - (u_long) KERNBASE);
131 1.1 ragge return (end - va);
132 1.1 ragge }
133 1.4 ragge
134 1.8 simonb /*
135 1.15 wiz * Translate a physical address to a file-offset in the crash dump.
136 1.15 wiz * XXX - crash dump doesn't work anyway.
137 1.4 ragge */
138 1.4 ragge off_t
139 1.18 jym _kvm_pa2off(kvm_t *kd, paddr_t pa)
140 1.4 ragge {
141 1.4 ragge return(kd->dump_off + pa);
142 1.4 ragge }
143 1.4 ragge
144 1.5 gwr
145 1.5 gwr /*
146 1.5 gwr * Machine-dependent initialization for ALL open kvm descriptors,
147 1.5 gwr * not just those for a kernel crash dump. Some architectures
148 1.5 gwr * have to deal with these NOT being constants! (i.e. m68k)
149 1.5 gwr */
150 1.5 gwr int
151 1.17 jym _kvm_mdopen(kvm_t *kd)
152 1.5 gwr {
153 1.5 gwr
154 1.5 gwr kd->usrstack = USRSTACK;
155 1.5 gwr kd->min_uva = VM_MIN_ADDRESS;
156 1.5 gwr kd->max_uva = VM_MAXUSER_ADDRESS;
157 1.5 gwr
158 1.5 gwr return (0);
159 1.5 gwr }
160