1: /*
2: * fix system image for I/D space
3: * Move data down to 0; move text to 4K.
4: * Also put the data at the start of the
5: * file and the text after it.
6: */
7:
8: int tbuf[259];
9: int rbuf[259];
10: int obuf[259];
11: int txtsiz;
12: int datsiz;
13: int bsssiz;
14: int symsiz;
15:
16: int txtrel 8192;
17: int datrel;
18:
19:
20: main(argc, argv)
21: char **argv;
22: {
23: register word, rel, s;
24:
25: if (argc<3) {
26: printf("Arg count\n");
27: exit(1);
28: }
29: if ((tbuf[0] = open(argv[1], 0)) < 0) {
30: printf("Input file\n");
31: exit(1);
32: }
33: rbuf[0] = open(argv[1], 0);
34: if ((fcreat(argv[2], obuf)) < 0) {
35: printf("Output file\n");
36: exit(1);
37: }
38: if (getw(tbuf) != 0407) {
39: printf("Bad input format\n");
40: exit(1);
41: }
42: putw(0407, obuf);
43: txtsiz = getw(tbuf);
44: datsiz = getw(tbuf);
45: bsssiz = getw(tbuf);
46: symsiz = getw(tbuf);
47: getw(tbuf);
48: getw(tbuf);
49: if (getw(tbuf) != 0) {
50: printf("No relocation bits\n");
51: exit(1);
52: }
53: putw(txtsiz, obuf);
54: putw(datsiz, obuf);
55: putw(bsssiz, obuf);
56: putw(symsiz, obuf);
57: putw(0, obuf);
58: putw(0, obuf);
59: putw(1, obuf);
60: datrel = -txtsiz;
61: /*
62: * Copy out data first
63: */
64: tbuf[1] = 0;
65: seek(tbuf[0], 020+txtsiz, 0);
66: seek(rbuf[0], 020+txtsiz, 0);
67: seek(rbuf[0], txtsiz, 1);
68: seek(rbuf[0], datsiz, 1);
69: s = datsiz >> 1;
70: while (s--) {
71: word = getw(tbuf);
72: rel = getw(rbuf);
73: if (rel&01)
74: word =- datrel;
75: word =+ getrel(rel);
76: putw(word, obuf);
77: }
78: /*
79: * Now to the text.
80: */
81: rbuf[1] = 0;
82: tbuf[1] = 0;
83: seek(rbuf[0], 020+txtsiz, 0);
84: seek(rbuf[0], datsiz, 1);
85: seek(tbuf[0], 020, 0);
86: s = txtsiz >> 1;
87: while(s--) {
88: rel = getw(rbuf);
89: word = getw(tbuf);
90: if (rel&01)
91: word =- txtrel;
92: word =+ getrel(rel);
93: putw(word, obuf);
94: }
95: /*
96: * The symbol table.
97: */
98: tbuf[1] = 0;
99: seek(tbuf[0], 020+txtsiz, 0);
100: seek(tbuf[0], txtsiz, 1);
101: seek(tbuf[0], datsiz, 1);
102: seek(tbuf[0], datsiz, 1);
103: s = symsiz;
104: while ((s =- 12) >= 0) {
105: putw(getw(tbuf), obuf);
106: putw(getw(tbuf), obuf);
107: putw(getw(tbuf), obuf);
108: putw(getw(tbuf), obuf);
109: rel = getw(tbuf);
110: putw(rel, obuf);
111: word = getw(tbuf);
112: switch(rel&07) {
113: case 2:
114: word =+ txtrel;
115: break;
116:
117: case 3:
118: case 4:
119: word =+ datrel;
120: }
121: putw(word, obuf);
122: }
123: fflush(obuf);
124: close(obuf[0]);
125: exit(0);
126: }
127:
128: getrel(r)
129: {
130: switch (r&016) {
131:
132: case 02: /* ref to text */
133: return(txtrel);
134:
135: case 04: /* ref to data */
136: case 06: /* ref to bss */
137: return(datrel);
138:
139: case 0:
140: return(0);
141:
142: default:
143: printf("Bad relocation %o\n", r);
144: return(0);
145: }
146: }
Defined functions
main
defined in line
20;
never used
Defined variables
obuf
defined in line
10; used 19 times
rbuf
defined in line
9; used 9 times
tbuf
defined in line
8; used 26 times
txtsiz
defined in line
11; used 10 times