|
|
1.1 root 1: /*
2: * adb - routines to read a.out+core at startup
3: * things in struct exec are in vax (!!) byte order
4: */
5: #include "defs.h"
6: #include "space.h"
7: #include "map.h"
8: #include "a.out.h"
9: #include "machine.h"
10:
11: char *symfil = "a.out";
12: char *corfil = "core";
13:
14: MAP symmap[NMAP];
15: MAP cormap[NMAP];
16:
17: int fsym, fcor;
18:
19: static ADDR datbase;
20: ADDR txtsize, datsize, stksize;
21: static ADDR entry;
22: static int magic;
23:
24: setsym()
25: {
26: ADDR loc;
27: struct exec hdr;
28: register MAP *mp;
29: char *malloc();
30:
31: fsym = getfile(symfil, 1);
32: mp = symmap;
33: if (read(fsym, (char *)&hdr, sizeof hdr) != sizeof hdr ||
34: badmagic((int)hdr.a_magic)) {
35: mp->f = mp->b = 0;
36: mp->e = MAXFILE;
37: mp->sp = DATASP;
38: mp->flag = MPINUSE;
39: mp++;
40: mp->flag = 0;
41: return;
42: }
43: magic = hdr.a_magic;
44: entry = hdr.a_entry;
45: loc = hdr.a_text+hdr.a_data;
46: switch (magic) {
47:
48: case A_MAGIC1:
49: txtsize = 0;
50: datbase = 0;
51: datsize = loc;
52: mp->b = 0+hdr.a_unused;
53: mp->e = loc+hdr.a_unused;
54: mp->f = sizeof(hdr);
55: mp->sp = DATASP;
56: mp->flag = MPINUSE;
57: break;
58:
59: case A_MAGIC2:
60: mp->b = 0+hdr.a_unused;
61: mp->e = txtsize = hdr.a_text;
62: mp->e += hdr.a_unused;
63: mp->f = sizeof(hdr);
64: mp->sp = INSTSP;
65: mp->flag = MPINUSE;
66: mp++;
67: mp->b = datbase = round((WORD)hdr.a_text, (WORD)RRND)+hdr.a_unused;
68: mp->e = datsize = datbase + hdr.a_data;
69: mp->e += hdr.a_unused;
70: mp->f = sizeof(hdr) + hdr.a_text;
71: mp->sp = DATASP;
72: mp->flag = MPINUSE;
73: break;
74:
75: case A_MAGIC3:
76: mp->b = 0+hdr.a_unused;
77: mp->e = txtsize = hdr.a_text;
78: mp->e += hdr.a_unused;
79: mp->f = sizeof(hdr);
80: mp->sp = INSTSP;
81: mp->flag = MPINUSE;
82: mp++;
83: mp->b = datbase = 0;
84: mp->b += hdr.a_unused;
85: mp->e = datsize = datbase + hdr.a_data;
86: mp->e += hdr.a_unused;
87: mp->f = sizeof(hdr) + hdr.a_text;
88: mp->sp = DATASP;
89: mp->flag = MPINUSE;
90: break;
91: }
92: mp++;
93: mp->flag = 0;
94: syminit(&hdr);
95: }
96:
97: setcor()
98: {
99: register MAP *mp;
100:
101: fcor = getfile(corfil,2);
102: #if NOTDEF
103: if (fcor < 0
104: || (mapimage() == 0 && mapcore() == 0)) {
105: #endif
106: /* not a core image */
107:
108: mp = cormap;
109: mp->b = 0;
110: mp->e = MAXFILE;
111: mp->f = 0;
112: mp->sp = DATASP;
113: mp->flag = MPINUSE;
114: mp++;
115: mp->flag = 0;
116: return;
117: #if NOTDEF
118: }
119: #endif
120: }
121:
122: mapcore()
123: {
124: #if NOTDEF
125: struct user u;
126: register MAP *mp;
127:
128: lseek(fcor, (off_t)0, 0);
129: if (read(fcor, (char *)&u, sizeof(u)) != sizeof(u)
130: || badmagic(u.u_exdata.ux_mag))
131: return (0);
132: if (magic && magic != u.u_exdata.ux_mag)
133: printf("%s: not from %s\n", corfil, symfil);
134: magic = u.u_exdata.ux_mag;
135: signo = u.u_arg[0];
136: sigcode = u.u_code;
137: txtsize = ctob(u.u_tsize);
138: datsize = ctob(u.u_dsize);
139: stksize = ctob(u.u_ssize);
140: mp = cormap;
141: switch (magic) {
142:
143: case OMAGIC:
144: mp->b = 0;
145: mp->e = txtsize + datsize;
146: mp->f = ctob(UPAGES);
147: mp->sp = DATASP;
148: mp->flag = MPINUSE;
149: mp++;
150: mp->b = MAXSTOR - stksize;
151: mp->e = MAXSTOR;
152: mp->f = txtsize + datsize + ctob(UPAGES);
153: mp->sp = DATASP;
154: mp->flag = MPINUSE;
155: break;
156:
157: case NMAGIC:
158: case ZMAGIC:
159: mp->b = txtsize;
160: mp->e = mp->b + datsize;
161: mp->f = ctob(UPAGES);
162: mp->sp = DATASP;
163: mp->flag = MPINUSE;
164: mp++;
165: mp->b = MAXSTOR - stksize;
166: mp->e = MAXSTOR;
167: mp->f = datsize + ctob(UPAGES);
168: mp->sp = DATASP;
169: mp->flag = MPINUSE;
170: break;
171: }
172: mp++;
173: mp->b = 0;
174: mp->e = ctob(UPAGES);
175: mp->f = 0;
176: mp->sp = UBLKSP;
177: mp->flag = MPINUSE;
178: mp++;
179: mp->flag = 0;
180: rsnarf();
181: return (1);
182: #endif
183: }
184:
185: badmagic(num)
186: int num;
187: {
188:
189: switch (num) {
190: case A_MAGIC1:
191: case A_MAGIC2:
192: case A_MAGIC3:
193: return (0);
194:
195: default:
196: return (1);
197: }
198: }
199:
200: cmdmap(itype, star)
201: register int star, itype;
202: {
203: register MAP *mp;
204: extern char lastc;
205:
206: if (itype & SYMF)
207: mp = symmap;
208: else
209: mp = cormap;
210: if (star) /* UGH */
211: mp++;
212: if (expr(0))
213: mp->b = expv;
214: if (expr(0))
215: mp->e = expv;
216: if (expr(0))
217: mp->f = expv;
218: mp->flag |= MPINUSE;
219: if (rdc()=='?' && (itype&SYMF) == 0) {
220: if (fcor)
221: close(fcor);
222: fcor=fsym;
223: corfil=symfil;
224: } else if (lastc == '/' && itype&SYMF) {
225: if (fsym)
226: close(fsym);
227: fsym=fcor;
228: symfil=corfil;
229: } else
230: reread();
231: }
232:
233: create(f)
234: char *f;
235: {
236: register int fd;
237:
238: fd = creat(f, 0666);
239: if (fd < 0)
240: return (-1);
241: close(fd);
242: return (open(f, wtflag));
243: }
244:
245: getfile(filnam, cnt)
246: char *filnam;
247: {
248: register int fsym;
249:
250: if (strcmp(filnam, "-") == 0)
251: return (-1);
252: fsym = open(filnam, wtflag);
253: if (fsym < 0 && xargc > cnt) {
254: if (wtflag)
255: fsym = create(filnam);
256: if (fsym < 0)
257: printf("cannot open `%s'\n", filnam);
258: }
259: return (fsym);
260: }
261:
262: setvar()
263: {
264:
265: var[varchk('b')] = datbase;
266: var[varchk('d')] = datsize;
267: var[varchk('e')] = entry;
268: var[varchk('m')] = magic;
269: var[varchk('s')] = stksize;
270: var[varchk('t')] = txtsize;
271: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.