annotate lwlink/objdump.c @ 211:51511cf1c9f8

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