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