annotate lwlink/objdump.c @ 213:c40960370fd8

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