1*104ea677Schristos /* $NetBSD: kvm_vax.c,v 1.21 2022/01/10 19:51:30 christos Exp $ */
2346e67f8Sthorpej
3460abf61Sragge /*-
4460abf61Sragge * Copyright (c) 1992, 1993
5460abf61Sragge * The Regents of the University of California. All rights reserved.
6460abf61Sragge *
7460abf61Sragge * This code is derived from software developed by the Computer Systems
8460abf61Sragge * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9460abf61Sragge * BG 91-66 and contributed to Berkeley.
10460abf61Sragge *
11460abf61Sragge * Redistribution and use in source and binary forms, with or without
12460abf61Sragge * modification, are permitted provided that the following conditions
13460abf61Sragge * are met:
14460abf61Sragge * 1. Redistributions of source code must retain the above copyright
15460abf61Sragge * notice, this list of conditions and the following disclaimer.
16460abf61Sragge * 2. Redistributions in binary form must reproduce the above copyright
17460abf61Sragge * notice, this list of conditions and the following disclaimer in the
18460abf61Sragge * documentation and/or other materials provided with the distribution.
19eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
20460abf61Sragge * may be used to endorse or promote products derived from this software
21460abf61Sragge * without specific prior written permission.
22460abf61Sragge *
23460abf61Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24460abf61Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25460abf61Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26460abf61Sragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27460abf61Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28460abf61Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29460abf61Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30460abf61Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31460abf61Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32460abf61Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33460abf61Sragge * SUCH DAMAGE.
34460abf61Sragge */
35460abf61Sragge
36460abf61Sragge /*
37460abf61Sragge * VAX machine dependent routines for kvm. Hopefully, the forthcoming
38460abf61Sragge * vm code will one day obsolete this module. Furthermore, I hope it
39460abf61Sragge * gets here soon, because this basically is an error stub! (sorry)
40460abf61Sragge * This code may not work anyway.
41460abf61Sragge */
42460abf61Sragge
43460abf61Sragge #include <sys/param.h>
44460abf61Sragge #include <sys/proc.h>
45460abf61Sragge #include <sys/stat.h>
46962a341dSjym #include <sys/types.h>
47962a341dSjym
48460abf61Sragge #include <unistd.h>
49460abf61Sragge #include <nlist.h>
5041d776abSragge #include <stdlib.h>
51460abf61Sragge #include <kvm.h>
52460abf61Sragge
533b8ac18dSmrg #include <uvm/uvm_extern.h>
54460abf61Sragge
55a089eadaSchuck #include <machine/vmparam.h>
56a089eadaSchuck
57460abf61Sragge #include <limits.h>
58460abf61Sragge #include <db.h>
59460abf61Sragge
60460abf61Sragge #include "kvm_private.h"
61460abf61Sragge
62*104ea677Schristos __RCSID("$NetBSD: kvm_vax.c,v 1.21 2022/01/10 19:51:30 christos Exp $");
63a089eadaSchuck
64460abf61Sragge struct vmstate {
65460abf61Sragge u_long end;
66460abf61Sragge };
67460abf61Sragge
68460abf61Sragge void
_kvm_freevtop(kvm_t * kd)696dc46b92Sjym _kvm_freevtop(kvm_t *kd)
70460abf61Sragge {
71460abf61Sragge if (kd->vmst != 0)
72460abf61Sragge free(kd->vmst);
73460abf61Sragge }
74460abf61Sragge
75460abf61Sragge int
_kvm_initvtop(kvm_t * kd)766dc46b92Sjym _kvm_initvtop(kvm_t *kd)
77460abf61Sragge {
780b7831a3Sperry struct vmstate *vm;
79460abf61Sragge struct stat st;
802c6ba846Sthorpej struct nlist nl[2];
81460abf61Sragge
82460abf61Sragge vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
83460abf61Sragge if (vm == 0)
84460abf61Sragge return (-1);
85460abf61Sragge
86460abf61Sragge kd->vmst = vm;
87460abf61Sragge
88460abf61Sragge if (fstat(kd->pmfd, &st) < 0)
89460abf61Sragge return (-1);
90460abf61Sragge
91460abf61Sragge /* Get end of kernel address */
922c6ba846Sthorpej nl[0].n_name = "_end";
932c6ba846Sthorpej nl[1].n_name = 0;
942c6ba846Sthorpej if (kvm_nlist(kd, nl) != 0) {
95460abf61Sragge _kvm_err(kd, kd->program, "pmap_stod: no such symbol");
96460abf61Sragge return (-1);
97460abf61Sragge }
982c6ba846Sthorpej vm->end = (u_long)nl[0].n_value;
99460abf61Sragge
100460abf61Sragge return (0);
101460abf61Sragge }
102460abf61Sragge
103460abf61Sragge #define VA_OFF(va) (va & (NBPG - 1))
104460abf61Sragge
105460abf61Sragge /*
106460abf61Sragge * Translate a kernel virtual address to a physical address using the
107460abf61Sragge * mapping information in kd->vm. Returns the result in pa, and returns
108460abf61Sragge * the number of bytes that are contiguously available from this
109460abf61Sragge * physical address. This routine is used only for crash dumps.
110460abf61Sragge */
111460abf61Sragge int
_kvm_kvatop(kvm_t * kd,vaddr_t va,paddr_t * pa)112962a341dSjym _kvm_kvatop(kvm_t *kd, vaddr_t va, paddr_t *pa)
113460abf61Sragge {
1146ea94941Smatt u_long end;
115460abf61Sragge
1166ea94941Smatt if (va < (u_long) KERNBASE) {
117962a341dSjym _kvm_err(kd, 0, "invalid address (%#"PRIxVADDR"<%lx)", va,
118962a341dSjym (u_long)KERNBASE);
119460abf61Sragge return (0);
120460abf61Sragge }
121460abf61Sragge
122460abf61Sragge end = kd->vmst->end;
123460abf61Sragge if (va >= end) {
124962a341dSjym _kvm_err(kd, 0, "invalid address (%#"PRIxVADDR"<%lx)", va,
125962a341dSjym end);
126460abf61Sragge return (0);
127460abf61Sragge }
128460abf61Sragge
1296ea94941Smatt *pa = (va - (u_long) KERNBASE);
130460abf61Sragge return (end - va);
131460abf61Sragge }
1325c3223d4Sragge
1335c3223d4Sragge /*
134b976c559Swiz * Translate a physical address to a file-offset in the crash dump.
135b976c559Swiz * XXX - crash dump doesn't work anyway.
1365c3223d4Sragge */
1375c3223d4Sragge off_t
_kvm_pa2off(kvm_t * kd,paddr_t pa)138962a341dSjym _kvm_pa2off(kvm_t *kd, paddr_t pa)
1395c3223d4Sragge {
1405c3223d4Sragge return(kd->dump_off + pa);
1415c3223d4Sragge }
1425c3223d4Sragge
143f6385749Sgwr
144f6385749Sgwr /*
145f6385749Sgwr * Machine-dependent initialization for ALL open kvm descriptors,
146f6385749Sgwr * not just those for a kernel crash dump. Some architectures
147f6385749Sgwr * have to deal with these NOT being constants! (i.e. m68k)
148f6385749Sgwr */
149f6385749Sgwr int
_kvm_mdopen(kvm_t * kd)1506dc46b92Sjym _kvm_mdopen(kvm_t *kd)
151f6385749Sgwr {
152f6385749Sgwr
153f6385749Sgwr kd->min_uva = VM_MIN_ADDRESS;
154f6385749Sgwr kd->max_uva = VM_MAXUSER_ADDRESS;
155f6385749Sgwr
156f6385749Sgwr return (0);
157f6385749Sgwr }
158