annotate old-trunk/lwlink/objdump.c @ 348:11a95c6414b4

Added third func to instab to split resolve and emit logic
author lost@starbug
date Sat, 27 Mar 2010 22:15:07 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 objdump.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWLINK
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 A standalone program to dump an object file in a text form to stdout
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #ifdef HAVE_CONFIG_H
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "config.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #endif
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 void read_lwobj16v0(unsigned char *filedata, long filesize);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 char *program_name;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 The logic of reading the entire file into memory is simple. All the symbol
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 names in the file are NUL terminated strings and can be used directly without
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 making additional copies.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 int main(int argc, char **argv)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 long size;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 FILE *f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 long bread;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 unsigned char *filedata;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 program_name = argv[0];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 if (argc != 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 fprintf(stderr, "Must specify exactly one input file.\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 f = fopen(argv[1], "rb");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 if (!f)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 fprintf(stderr, "Can't open file %s:", argv[1]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 fseek(f, 0, SEEK_END);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 size = ftell(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 rewind(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 filedata = lw_malloc(size);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 bread = fread(filedata, 1, size, f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 if (bread < size)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 fprintf(stderr, "Short read on file %s (%ld/%ld):", argv[1], bread, size);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 fclose(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 if (!memcmp(filedata, "LWOBJ16", 8))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 // read v0 LWOBJ16 file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 read_lwobj16v0(filedata, size);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 fprintf(stderr, "%s: unknown file format\n", argv[1]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 exit(0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 // this macro is used to bail out if we run off the end of the file data
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 // while parsing - it keeps the code below cleaner
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 #define NEXTBYTE() do { cc++; if (cc > filesize) { fprintf(stderr, "***invalid file format\n"); exit(1); } } while (0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 // this macro is used to refer to the current byte in the stream
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 #define CURBYTE() (filedata[cc < filesize ? cc : filesize - 1])
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 // this one will leave the input pointer past the trailing NUL
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 #define CURSTR() read_lwobj16v0_str(&cc, &filedata, filesize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 unsigned char *read_lwobj16v0_str(long *cc1, unsigned char **filedata1, long filesize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 int cc = *cc1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 unsigned char *filedata = *filedata1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 unsigned char *fp;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 fp = &CURBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 *cc1 = cc;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 *filedata1 = filedata;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 return fp;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 // the function below can be switched to dealing with data coming from a
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 // source other than an in-memory byte pool by adjusting the input data
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 // in "fn" and the above two macros
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 void read_lwobj16v0(unsigned char *filedata, long filesize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 unsigned char *fp;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 long cc;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 int val;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 int bss;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 static char *opernames[] = {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 "?",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 "PLUS",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 "MINUS",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 "TIMES",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 "DIVIDE",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 "MOD",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 "INTDIV",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 "BWAND",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 "BWOR",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 "BWXOR",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 "AND",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 "OR",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 "NEG",
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 "COM"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 static const int numopers = 13;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 // start reading *after* the magic number
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 cc = 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 while (1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 bss = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 // bail out if no more sections
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 if (!(CURBYTE()))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 fp = CURSTR();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 printf("SECTION %s\n", fp);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 // read flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 switch (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 case 0x01:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 printf(" FLAG: BSS\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 bss = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 printf(" FLAG: %02X (unknown)\n", CURBYTE());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 // skip NUL terminating flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 printf(" Local symbols:\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 // now parse the local symbol table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 fp = CURSTR();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 // fp is the symbol name
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 val = (CURBYTE()) << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 val |= (CURBYTE());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 // val is now the symbol value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 printf(" %s=%04X\n", fp, val);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 // skip terminating NUL
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 printf(" Exported symbols\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196 // now parse the exported symbol table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 fp = CURSTR();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 // fp is the symbol name
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 val = (CURBYTE()) << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 val |= (CURBYTE());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206 // val is now the symbol value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 printf(" %s=%04X\n", fp, val);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 // skip terminating NUL
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 // now parse the incomplete references and make a list of
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 // external references that need resolution
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 printf(" Incomplete references\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 printf(" (");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 // parse the expression
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 while (CURBYTE())
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 int tt = CURBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 switch (tt)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 case 0x01:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 // 16 bit integer
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 tt = CURBYTE() << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 tt |= CURBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 // normalize for negatives...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 if (tt > 0x7fff)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 tt -= 0x10000;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 printf(" I16=%d", tt);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 case 0x02:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 // external symbol reference
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 printf(" ES=%s", CURSTR());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 case 0x03:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 // internal symbol reference
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245 printf(" IS=%s", CURSTR());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248 case 0x04:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249 // operator
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250 if (CURBYTE() > 0 && CURBYTE() <= numopers)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 printf(" OP=%s", opernames[CURBYTE()]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 printf(" OP=?");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 case 0x05:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258 // section base reference (NULL internal reference is
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 // the section base address
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 printf(" SB");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263 case 0xFF:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 // section flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 printf(" FLAGS=%02X", CURBYTE());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 printf(" ERR");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 // skip the NUL
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276 // fetch the offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 val = CURBYTE() << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 val |= CURBYTE() & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 printf(" ) @ %04X\n", val);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 // skip the NUL terminating the relocations
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286 // now set code location and size and verify that the file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 // contains data going to the end of the code (if !SECTION_BSS)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 val = CURBYTE() << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290 val |= CURBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293 printf(" CODE %04X bytes", val);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295 // skip the code if we're not in a BSS section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 if (!bss)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
299 for (i = 0; i < val; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
301 if (! (i % 16))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
302 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
303 printf("\n %04X ", i);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
304 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
305 printf("%02X", CURBYTE());
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
306 NEXTBYTE();
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
307 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
308 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
309 printf("\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
310 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
311 }