kvm_sun3.c revision 1.3 1 1.3 thorpej /* $NetBSD: kvm_sun3.c,v 1.3 1996/03/18 22:34:04 thorpej Exp $ */
2 1.3 thorpej
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1992, 1993
5 1.1 gwr * The Regents of the University of California. All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software developed by the Computer Systems
8 1.1 gwr * Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9 1.1 gwr * BG 91-66 and contributed to Berkeley.
10 1.1 gwr *
11 1.1 gwr * Redistribution and use in source and binary forms, with or without
12 1.1 gwr * modification, are permitted provided that the following conditions
13 1.1 gwr * are met:
14 1.1 gwr * 1. Redistributions of source code must retain the above copyright
15 1.1 gwr * notice, this list of conditions and the following disclaimer.
16 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 gwr * notice, this list of conditions and the following disclaimer in the
18 1.1 gwr * documentation and/or other materials provided with the distribution.
19 1.1 gwr * 3. All advertising materials mentioning features or use of this software
20 1.1 gwr * must display the following acknowledgement:
21 1.1 gwr * This product includes software developed by the University of
22 1.1 gwr * California, Berkeley and its contributors.
23 1.1 gwr * 4. Neither the name of the University nor the names of its contributors
24 1.1 gwr * may be used to endorse or promote products derived from this software
25 1.1 gwr * without specific prior written permission.
26 1.1 gwr *
27 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 gwr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 gwr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 gwr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 gwr * SUCH DAMAGE.
38 1.1 gwr */
39 1.1 gwr
40 1.1 gwr /*
41 1.1 gwr * Sun3 machine dependent routines for kvm. Hopefully, the forthcoming
42 1.1 gwr * vm code will one day obsolete this module. Furthermore, I hope it
43 1.1 gwr * gets here soon, because this basically is an error stub! (sorry)
44 1.1 gwr */
45 1.1 gwr
46 1.1 gwr #include <sys/param.h>
47 1.1 gwr #include <sys/user.h>
48 1.1 gwr #include <sys/proc.h>
49 1.1 gwr #include <sys/stat.h>
50 1.1 gwr #include <unistd.h>
51 1.1 gwr #include <nlist.h>
52 1.1 gwr #include <kvm.h>
53 1.1 gwr
54 1.1 gwr #include <vm/vm.h>
55 1.1 gwr #include <vm/vm_param.h>
56 1.1 gwr
57 1.1 gwr #include <limits.h>
58 1.1 gwr #include <db.h>
59 1.1 gwr
60 1.1 gwr #include "kvm_private.h"
61 1.1 gwr
62 1.1 gwr struct vmstate {
63 1.1 gwr u_long end;
64 1.1 gwr };
65 1.1 gwr
66 1.1 gwr void
67 1.1 gwr _kvm_freevtop(kd)
68 1.1 gwr kvm_t *kd;
69 1.1 gwr {
70 1.1 gwr if (kd->vmst != 0)
71 1.1 gwr free(kd->vmst);
72 1.1 gwr }
73 1.1 gwr
74 1.1 gwr int
75 1.1 gwr _kvm_initvtop(kd)
76 1.1 gwr kvm_t *kd;
77 1.1 gwr {
78 1.1 gwr register int i;
79 1.1 gwr register int off;
80 1.1 gwr register struct vmstate *vm;
81 1.1 gwr struct stat st;
82 1.1 gwr struct nlist nlist[2];
83 1.1 gwr
84 1.1 gwr vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
85 1.1 gwr if (vm == 0)
86 1.1 gwr return (-1);
87 1.1 gwr
88 1.1 gwr kd->vmst = vm;
89 1.1 gwr
90 1.1 gwr if (fstat(kd->pmfd, &st) < 0)
91 1.1 gwr return (-1);
92 1.1 gwr
93 1.1 gwr /* Get end of kernel address */
94 1.1 gwr nlist[0].n_name = "_end";
95 1.1 gwr nlist[1].n_name = 0;
96 1.1 gwr if (kvm_nlist(kd, nlist) != 0) {
97 1.1 gwr _kvm_err(kd, kd->program, "pmap_stod: no such symbol");
98 1.1 gwr return (-1);
99 1.1 gwr }
100 1.1 gwr vm->end = (u_long)nlist[0].n_value;
101 1.1 gwr
102 1.1 gwr return (0);
103 1.1 gwr }
104 1.1 gwr
105 1.1 gwr #define VA_OFF(va) (va & (NBPG - 1))
106 1.1 gwr
107 1.1 gwr /*
108 1.1 gwr * Translate a kernel virtual address to a physical address using the
109 1.1 gwr * mapping information in kd->vm. Returns the result in pa, and returns
110 1.1 gwr * the number of bytes that are contiguously available from this
111 1.1 gwr * physical address. This routine is used only for crashdumps.
112 1.1 gwr */
113 1.1 gwr int
114 1.1 gwr _kvm_kvatop(kd, va, pa)
115 1.1 gwr kvm_t *kd;
116 1.1 gwr u_long va;
117 1.1 gwr u_long *pa;
118 1.1 gwr {
119 1.1 gwr register int end;
120 1.1 gwr
121 1.1 gwr if (va < KERNBASE) {
122 1.1 gwr _kvm_err(kd, 0, "invalid address (%x<%x)", va, KERNBASE);
123 1.1 gwr return (0);
124 1.1 gwr }
125 1.1 gwr
126 1.1 gwr end = kd->vmst->end;
127 1.1 gwr if (va >= end) {
128 1.1 gwr _kvm_err(kd, 0, "invalid address (%x>=%x)", va, end);
129 1.1 gwr return (0);
130 1.1 gwr }
131 1.1 gwr
132 1.1 gwr *pa = (va - KERNBASE);
133 1.1 gwr return (end - va);
134 1.1 gwr }
135