annotate src/objdump.c @ 311:8272b46b5a34

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