|
|
1.1 root 1: #include "stdio.h"
2: #include "sys/param.h"
3: #include <sys/dir.h>
4: #include <sys/psl.h>
5: #include <sys/pte.h>
6: #include <sys/user.h>
7: #include <ctype.h>
8: #include <a.out.h>
9: #include "sys/vm.h"
10:
11: struct pcb pcb;
12: int kernel;
13: int kcore;
14: struct pte *sbr;
15: int slr;
16: int masterpcbb;
17: int fcor, ffil;
18:
19: struct nlist *cursym;
20: char *sysnam;
21:
22: lookup(s)
23: char *s;
24: { static struct nlist nl[2];
25: nl[0].n_un.n_name = s;
26: nlist(sysnam, nl);
27: cursym = nl;
28: if(nl[0].n_value == 0)
29: fatal("lookup of %s failed\n", s);
30: else
31: printf("lookup of %s is 0x%x\n", s, cursym->n_value);
32: }
33:
34: vtophys(addr)
35: off_t addr;
36: {
37: int oldaddr = addr;
38: int v;
39: struct pte pte;
40:
41: addr &= ~0xc0000000;
42: v = btop(addr);
43: switch (oldaddr&0xc0000000) {
44:
45: case 0xc0000000:
46: case 0x80000000:
47: /*
48: * In system space get system pte. If
49: * valid or reclaimable then physical address
50: * is combination of its page number and the page
51: * offset of the original address.
52: */
53: if (v >= slr)
54: goto oor;
55: addr = ((long)(sbr+v)) &~ 0x80000000;
56: goto simple;
57:
58: case 0x40000000:
59: /*
60: * In p1 space must not be in shadow region.
61: */
62: if (v < pcb.pcb_p1lr)
63: goto oor;
64: addr = (off_t) (pcb.pcb_p1br+v);
65: break;
66:
67: case 0x00000000:
68: /*
69: * In p0 space must not be off end of region.
70: */
71: if (v >= pcb.pcb_p0lr)
72: goto oor;
73: addr = (off_t) (pcb.pcb_p0br+v);
74: break;
75: oor:
76: return (-1);
77: }
78: /*
79: * For p0/p1 address, user-level page table should
80: * be in kernel vm. Do second-level indirect by recursing.
81: */
82: if ((addr & 0x80000000) == 0) {
83: return (-1);
84: }
85: addr = vtophys(addr);
86: simple:
87: /*
88: * Addr is now address of the pte of the page we
89: * are interested in; get the pte and paste up the
90: * physical address.
91: */
92: if(lseek(fcor, addr, 0) < 0 || read(fcor, (char *)&pte, sizeof(char *)) <= 0) {
93: return (-1);
94: }
95: /* SHOULD CHECK NOT I/O ADDRESS; NEED CPU TYPE! */
96: if (pte.pg_v == 0 && (pte.pg_fod || pte.pg_pfnum == 0)) {
97: return (-1);
98: }
99: return (ptob(pte.pg_pfnum) + (oldaddr & PGOFSET));
100: }
101:
102: main(argc, argv)
103: char **argv;
104: {
105: if(argc == 1) {
106: sysnam = "/vmunix";
107: fcor = open("core", 0);
108: }
109: else if(argc != 3) {
110: fprintf(stderr, "usage: %s [core system]\n", argv[0]);
111: exit(1);
112: }
113: else {
114: sysnam = argv[2];
115: fcor = open(argv[1], 0);
116: }
117: lookup("_Sysmap");
118: sbr = cursym->n_value;
119: lookup("_Syssize");
120: slr = cursym->n_value;
121: printf("sbr %X slr %X\n", sbr, slr);
122: lookup("_masterpaddr");
123: lseek(fcor, cursym->n_value & 0x7fffffff, 0);
124: read(fcor, (char *)&masterpcbb, sizeof(char *));
125: masterpcbb = (masterpcbb&PG_PFNUM)*512;
126: getpcb();
127: go();
128: exit(0);
129: }
130:
131: getpcb()
132: {
133:
134: lseek(fcor, masterpcbb&~0x80000000, 0);
135: read(fcor, &pcb, sizeof (struct pcb));
136: pcb.pcb_p0lr &= ~AST_CLR;
137: printf("p0br %X p0lr %X p1br %X p1lr %X\n",
138: pcb.pcb_p0br, pcb.pcb_p0lr, pcb.pcb_p1br, pcb.pcb_p1lr);
139: }
140:
141: struct rec {
142: long len;
143: struct rec *next;
144: char *fname;
145: } proFptr;
146: FILE *outfd;
147: struct rec *x;
148: char buf[256];
149: long foo[1024];
150: int fd;
151:
152: go()
153: {
154: if(fcor < 0) {
155: perror("/dev/kmem");
156: exit(1);
157: }
158: outfd = fopen("prof.out", "w");
159: if(outfd == 0) {
160: perror("prof.out");
161: exit(1);
162: }
163: lookup("_proFptr");
164: if(vseek(fcor, cursym->n_value, 0) == -1) {
165: fprintf(stderr, "vseek failed seeking to x%x\n", cursym->n_value);
166: exit(1);
167: }
168: if(read(fcor, (char *)&x, sizeof(long)) != sizeof(long)) {
169: fprintf(stderr, "read failed\n");
170: exit(1);;
171: }
172: for(;;) {
173: readit();
174: if(proFptr.next == 0 || proFptr.next == x)
175: break;
176: x = proFptr.next;
177: }
178: }
179:
180: readit()
181: { int i;
182: i = vseek(fcor, (char *)x, 0);
183: if(i == -1)
184: fatal("first vseek in readit, seeking to x%x\n", x);
185: i = read(fcor, (char *)&proFptr, sizeof(proFptr));
186: if(i != sizeof(proFptr))
187: fatal("reading proFptr in readit\n");
188: i = read(fcor, (char *)foo, sizeof(long) * proFptr.len);
189: if(i != sizeof(long) * proFptr.len)
190: fatal("read %d instead of %d\n", i, sizeof(long) * proFptr.len);
191: i = vseek(fcor, proFptr.fname, 0);
192: if(i == -1)
193: fatal("seeking to x%x\n", proFptr.fname);
194: i = read(fcor, buf, sizeof(buf));
195: fprintf(outfd, "%s\n", buf);
196: fflush(outfd);
197: for(i = 3; i < proFptr.len; i++)
198: fprintf(outfd, "%d\n", foo[i-3]);
199: }
200:
201: fatal(s, a, b, c, d, e, f, g)
202: char *s;
203: {
204: fprintf(stderr, s, a, b, c, d, e, f, g);
205: exit(1);
206: }
207:
208: vseek(fd, loc, flag)
209: long loc;
210: { long addr;
211: addr = vtophys(loc);
212: return(lseek(fd, addr, flag));
213: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.