|
|
1.1 root 1: /*
2: * mjm: modified to run on VAX
3: * added short data type to some variables
4: * relocate command--
5: * 11reloc file [-]octal [ - ]
6: *
7: * relocate object or 11a.out file up in core
8: * by the possibly negated octal number.
9: *
10: * if optional 3rd arg is given,
11: * replace "setd" at start by "nop"
12: */
13:
14: short tbuf[256]; /* mjm */
15: short rbuf[256]; /* mjm */
16: int fin;
17: int fout;
18: short *txtp; /* mjm */
19: short *relp; /* mjm */
20: long relloc;
21: long txtloc;
22: int dotdot;
23: long txtsiz;
24: unsigned short t1; /* mjm */
25: unsigned short t2; /* mjm */
26: unsigned short t4; /* mjm */
27: unsigned short t7; /* mjm */
28: int txtw;
29:
30: main(argc, argv)
31: char *argv[];
32: {
33: int sign, c;
34:
35: if (argc<3) {
36: usage:
37: write(1, "11reloc file [-]octal\n", 22);
38: exit(1);
39: }
40: dotdot = 0;
41: if (*argv[2] == '-') {
42: sign = -1;
43: argv[2]++;
44: } else
45: sign = 1;
46: while (*argv[2]) {
47: c = *argv[2]++ - '0';
48: if (c<0 || c>7)
49: goto usage;
50: dotdot = (dotdot<<3) + c;
51: }
52: dotdot *= sign;
53: if ((fin = open(argv[1], 0)) < 0) {
54: write(1, "File not readable\n", 18);
55: exit(1);
56: }
57: if ((fout = open(argv[1], 1)) < 0) {
58: write(1, "File not writable\n", 18);
59: exit(1);
60: }
61: txtw = read(fin, (char *)tbuf, 512);
62: if (tbuf[0]!=0411 && tbuf[0]!=0410 && tbuf[0]!=0407) { /* magic */
63: write(1, "Bad format\n", 11);
64: exit(1);
65: }
66: if (tbuf[7] != 0) { /* relocation? */
67: write (1, "No relocation bits\n", 19);
68: exit(1);
69: }
70: t1 = tbuf[1];
71: t2 = tbuf[2];
72: t4 = tbuf[4];
73: txtloc = 020;
74: if (argc>3 && argv[3][1]=='o') {
75: dotdot += 020;
76: tbuf[0] = 0405; /* old magic */
77: tbuf[1] += tbuf[2];
78: tbuf[2] = 0;
79: tbuf[4] = tbuf[3];
80: tbuf[3] = 0;
81: tbuf[6] = 0240;
82: tbuf[7] = t7 = 0240;
83: }
84: txtsiz = (unsigned)tbuf[1];
85: txtsiz += (unsigned)tbuf[2];
86: relloc = txtloc + txtsiz;
87: txtsiz /= 2;
88: lseek(fin, relloc & ~0777, 0);
89: read(fin, (char *)rbuf, 512);
90: txtp = &tbuf[8];
91: relp = &rbuf[(relloc&0777) >> 1];
92: if (argc>3) /* nop out "setd" at start */
93: if (tbuf[8] == 0170011)
94: tbuf[8] = 0240;
95: while(txtsiz--) {
96: switch (*relp & 017) {
97:
98: case 01: /* pc ref to abs */
99: *txtp -= dotdot;
100: break;
101:
102: case 02: /* ref to text */
103: case 04: /* ref to data */
104: case 06: /* ref to bss */
105: *txtp += dotdot;
106:
107: }
108: advance();
109: }
110: if (txtp != &tbuf[0])
111: write(fout, (char *)&tbuf[0], txtw);
112:
113:
114: txtsiz = t4 / 2;
115: relloc = 020;
116: relloc += t1;
117: relloc += t1;
118: relloc += t2;
119: relloc += t2;
120: lseek(fin, relloc & ~0777, 0);
121: lseek(fout, relloc & ~0777, 0);
122: txtw = read(fin, (char *)tbuf, 512);
123: txtp = &tbuf[(relloc&0777) >> 1] + 4;
124: while((txtsiz -= 6) > 0) {
125: switch(*txtp & 77) {
126:
127: case 2:
128: case 3:
129: case 4:
130: *(txtp + 1) += dotdot;
131: }
132: adv6();
133: }
134: if(txtp != &tbuf[0])
135: write(fout, (char *)&tbuf[0], txtw);
136: exit(0);
137: }
138:
139: advance()
140: {
141:
142: relp++;
143: relloc += 2;
144: if (relp == &rbuf[256]) {
145: lseek(fin, relloc, 0);
146: read(fin, (char *)&rbuf[0], 512);
147: relp = &rbuf[0];
148: }
149: txtp++;
150: txtloc += 2;
151: if (txtp >= &tbuf[256]) {
152: write(fout, (char *)&tbuf[0], txtw);
153: lseek(fin, txtloc, 0);
154: txtw = read(fin, (char *)&tbuf[0], 512);
155: txtp = &tbuf[0];
156: }
157: }
158:
159: adv6()
160: {
161: txtp += 6;
162: if(txtp >= &tbuf[256]) {
163: write(fout, (char *)tbuf, txtw);
164: txtw = read(fin, (char *)tbuf, 512);
165: txtp -= 256;
166: }
167: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.