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