annotate leo-obj/tool/disasm.c @ 136:81fc8da9a29c

tiobjd: disasm hints work now
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 07 Apr 2014 04:56:29 +0000
parents df432a4b1b84
children acdf75463e30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Putting it all together: section-, symbol- and reloc-aware disassembly
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "intstruct.h"
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "coffconst.h"
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "globals.h"
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 extern unsigned get_u16(), get_u32();
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
15 extern char *storage_class_to_string();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
133
daeaa5950d10 tiobjd: Thumb bl w/o reloc: find symbol if there is one
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 130
diff changeset
17 int auto_xlat_section_relocs = 1;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
18
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
19 static void
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
20 find_better_symbol(sec, symp, addp)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
21 struct internal_scnhdr *sec;
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
22 struct internal_syment **symp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
23 unsigned *addp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
24 {
120
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
25 unsigned addr, delta;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
26 struct internal_syment *sym;
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
27 unsigned n;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
28
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
29 addr = *addp;
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
30 for (n = 0; n < sec->nsymbols; n++) {
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
31 sym = sec->sorted_symbols[n];
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
32 if (sym->value > addr)
120
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
33 return;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
34 if (sym->class != C_EXT && sym->class != C_STAT)
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
35 continue;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
36 delta = addr - sym->value;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
37 if (sym->name[0] == '_' && !delta ||
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
38 sym->name[0] == '$' && delta <= 1) {
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
39 *symp = sym;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
40 *addp = delta;
4d8dfdbd2ea1 tiobjd: auto-translation of section-relative relocs made more conservative
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 118
diff changeset
41 }
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
42 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
43 }
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
44
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 void
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
46 disasm_reloc_target(sec, rel, addend)
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
47 struct internal_scnhdr *sec;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
48 struct internal_reloc *rel;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
49 unsigned addend;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
50 {
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
51 struct internal_syment *sym = rel->sym;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
52
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
53 if (sym)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
54 addend -= sym->value;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
55 if (auto_xlat_section_relocs &&
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
56 (!sym || sym->section && !strcmp(sym->name, sym->section->name)))
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
57 find_better_symbol(sym ? sym->section : sec, &sym, &addend);
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
58 if (sym)
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
59 fputs(sym->name, stdout);
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
60 else
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
61 fputs(sec->name, stdout);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
62 if (addend >= 10)
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
63 printf("+0x%x", addend);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
64 else if (addend)
121
d88f2f40e3ae tiobjd: handling of symbol-less relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 120
diff changeset
65 printf("+%u", addend);
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
66 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
67
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
68 void
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
69 disasm_word32_reloc(sec, rel)
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
70 struct internal_scnhdr *sec;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
71 struct internal_reloc *rel;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
72 {
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
73 unsigned word;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
74
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
75 word = get_u32(filemap + sec->data_offset + rel->location);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
76 printf("%08x R\t.word\t", word);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
77 disasm_reloc_target(sec, rel, word);
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
78 putchar('\n');
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
79 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
80
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
81 static void
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
82 handle_symbol(sym, statep, linebrkp)
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
83 struct internal_syment *sym;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
84 int *statep, *linebrkp;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
85 {
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
86 char *sym_comment;
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
87
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
88 if (sym->class == C_FCN && !strcmp(sym->name, ".ef")) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
89 printf("; End function\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
90 return;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
91 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
92 if (!*linebrkp) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
93 putchar('\n');
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
94 *linebrkp = 1;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
95 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
96 if (sym->class == C_FCN && !strcmp(sym->name, ".bf")) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
97 printf("; Begin function\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
98 return;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
99 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
100 switch (sym->class) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
101 case C_EXT:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
102 sym_comment = "Global";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
103 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
104 case C_STAT:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
105 sym_comment = "static";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
106 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
107 case C_LABEL:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
108 sym_comment = "label";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
109 if (!strcmp(sym->name, "$CODE16"))
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
110 *statep = 1;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
111 else if (!strcmp(sym->name, "$CODE32"))
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
112 *statep = 0;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
113 break;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
114 default:
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
115 sym_comment = "unexpected class!";
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
116 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
117 printf("%s:\t; %s\n", sym->name, sym_comment);
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
118 }
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
119
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
120 void
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
121 disasm_emit_asciz(sec, pos, len)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
122 struct internal_scnhdr *sec;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
123 unsigned pos, len;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
124 {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
125 int c;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
126 unsigned endpos = pos + len;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
127
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
128 fputs("\t.asciz\t\"", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
129 for (; pos < endpos; pos++) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
130 c = filemap[sec->data_offset + pos];
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
131 switch (c) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
132 case '\b':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
133 fputs("\\b", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
134 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
135 case '\t':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
136 fputs("\\t", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
137 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
138 case '\n':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
139 fputs("\\n", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
140 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
141 case '\r':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
142 fputs("\\r", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
143 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
144 case '"':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
145 fputs("\\\"", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
146 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
147 case '\\':
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
148 fputs("\\\\", stdout);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
149 continue;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
150 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
151 if (c >= ' ' && c <= '~')
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
152 putchar(c);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
153 else
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
154 printf("\\%03o", c);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
155 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
156 putchar('"');
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
157 putchar('\n');
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
158 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
159
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
160 void
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
161 disasm_codedata_section(sec)
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 unsigned symnum, relnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 unsigned pos, incr, headroom;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
166 int state = -1, linebrk = 0, gothint;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 struct internal_syment *sym;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 struct internal_reloc *rel;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
169 struct hint *hint = sec->hints;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
170 u_char *asciz_end;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
171 unsigned asciz_len;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 if (sec->nreloc)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 get_relocs_of_sec(sec);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 symnum = relnum = 0;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 for (pos = 0; pos < sec->size; pos += incr) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 headroom = sec->size - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 while (symnum < sec->nsymbols) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 sym = sec->sorted_symbols[symnum];
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 if (sym->value > pos) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 if (sym->value - pos < headroom)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 headroom = sym->value - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 /* hit symbol */
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
186 handle_symbol(sym, &state, &linebrk);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 symnum++;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 if (relnum < sec->nreloc) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 rel = sec->int_relocs + relnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 if (rel->location == pos)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 relnum++; /* it's ours */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 else {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 if (rel->location - pos < headroom)
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 headroom = rel->location - pos;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 rel = 0; /* no reloc for current pos */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 } else
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 rel = 0;
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
200 if (hint) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
201 if (pos >= hint->pos)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
202 gothint++;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
203 else {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
204 gothint = 0;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
205 if (hint->pos - pos < headroom)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
206 headroom = hint->pos - pos;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
207 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
208 } else
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
209 gothint = 0;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
210 if (gothint && pos == hint->pos && hint->linebrk)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
211 putchar('\n');
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 printf("%8x:\t", pos);
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
213 if (gothint && hint->type) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
214 if (rel) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
215 printf("error: hint/reloc conflict\n");
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
216 return;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
217 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
218 switch (hint->type) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
219 case HINT_D8:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
220 printf("%02x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
221 filemap[sec->data_offset + pos]);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
222 incr = 1;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
223 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
224 case HINT_D16:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
225 printf("%04x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
226 get_u16(filemap+sec->data_offset+pos));
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
227 incr = 2;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
228 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
229 case HINT_D32:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
230 printf("%08x\n",
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
231 get_u32(filemap+sec->data_offset+pos));
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
232 incr = 4;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
233 break;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
234 case HINT_ASCIZ:
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
235 asciz_end = memchr(filemap+sec->data_offset+pos,
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
236 0, headroom);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
237 if (!asciz_end) {
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
238 printf("bad asciz hint: no 0 found\n");
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
239 return;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
240 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
241 asciz_len = asciz_end - filemap -
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
242 sec->data_offset - pos;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
243 disasm_emit_asciz(sec, pos, asciz_len);
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
244 incr = asciz_len + 1;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
245 }
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
246 goto next;
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
247 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
248 if (rel) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
249 if (rel->type == RTYPE_LONG) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
250 if (pos & 3) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
251 printf("MISALIGNED pos for word32 reloc, aborting\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
252 return;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
253 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
254 disasm_word32_reloc(sec, rel);
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
255 incr = 4;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
256 goto next;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
257 } else if (sec->disasm_mode == DISASM_MODE_DATA) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
258 printf("error: reloc other than word32 in data section\n");
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
259 return;
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
260 }
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
261 }
123
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
262 if (pos & 1 || headroom < 2) {
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
263 if (rel) {
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
264 printf("error: reloc at byte pos, aborting\n");
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
265 return;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
266 }
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
267 printf("%02x\n", filemap[sec->data_offset + pos]);
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
268 incr = 1;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
269 goto next;
5f9cc99930a8 tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 121
diff changeset
270 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
271 if (sec->disasm_mode == DISASM_MODE_DATA) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
272 if (pos & 2 || headroom < 4) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
273 printf("%04x\n",
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
274 get_u16(filemap+sec->data_offset+pos));
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
275 incr = 2;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
276 } else {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
277 printf("%08x\n",
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
278 get_u32(filemap+sec->data_offset+pos));
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
279 incr = 4;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
280 }
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
281 goto next;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
282 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 switch (state) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 case 0: /* ARM */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 if (pos & 3) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 printf("MISALIGNED pos in CODE32 state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 }
114
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
289 if (rel) {
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
290 if (rel->type != RTYPE_ARM_B) {
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
291 printf("Wrong reloc type in CODE32 state, aborting\n");
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
292 return;
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
293 }
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
294 arm_branch_reloc(sec, rel);
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
295 } else
ca8e43288836 tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 112
diff changeset
296 arm_disasm_line(sec, pos);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297 incr = 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 case 1: /* Thumb */
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 if (pos & 1) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301 printf("MISALIGNED pos in CODE16 state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 }
117
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
304 if (rel) {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
305 if (rel->type != RTYPE_THUMB_BL) {
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
306 printf("Wrong reloc type in CODE16 state, aborting\n");
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
307 return;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
308 }
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
309 thumb_bl_reloc(sec, rel);
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
310 incr = 4;
f9fde7f36ae3 tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 114
diff changeset
311 } else if (headroom >= 4 && thumb_check_bl(sec, pos))
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 incr = 4;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 else {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 thumb_disasm_line(sec, pos);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 incr = 2;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
316 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 break;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
318 default:
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319 printf("UNKNOWN T state, aborting\n");
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
321 }
112
61a58677dc68 tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 111
diff changeset
322 next: linebrk = 0;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 if (incr > headroom) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324 printf("error: increment %u > headroom %u, aborting\n",
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 incr, headroom);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
326 return;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
327 }
136
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
328 if (hint && pos >= hint->endpos)
81fc8da9a29c tiobjd: disasm hints work now
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 135
diff changeset
329 hint = hint->next;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
330 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
331 if (symnum == sec->nsymbols)
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
332 return;
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
333 while (symnum < sec->nsymbols) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
334 sym = sec->sorted_symbols[symnum];
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
335 if (sym->value != sec->size) {
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
336 printf("error: expecting symbol at end of section\n");
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
337 return;
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
338 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
339 handle_symbol(sym, &state, &linebrk);
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
340 symnum++;
124
700d77d5cf00 tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 123
diff changeset
341 }
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
342 printf("%8x:\t<end of section>\n", sec->size);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 void
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
346 disasm_bss(sec)
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
347 struct internal_scnhdr *sec;
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
348 {
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
349 unsigned m;
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
350 struct internal_syment *sym;
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
351 char classbuf[8];
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
352
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
353 putchar('\n');
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
354 for (m = 0; m < sec->nsymbols; m++) {
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
355 sym = sec->sorted_symbols[m];
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
356 printf("%08X %-7s %s\n", sym->value,
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
357 storage_class_to_string(sym->class, classbuf),
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
358 sym->name);
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
359 }
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
360 printf("%08X <end of section>\n", sec->size);
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
361 }
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
362
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
363 void
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
364 disasm_sec_by_type(sec)
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
365 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 {
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
367 switch (sec->disasm_mode) {
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
368 case DISASM_MODE_CODE:
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
369 printf("Disassembling code section:\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
370 disasm_codedata_section(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
371 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
372 case DISASM_MODE_DATA:
135
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
373 printf("Disassembling data section:\n");
df432a4b1b84 tiobjd: disasm of code and data sections unified
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 133
diff changeset
374 disasm_codedata_section(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
375 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
376 case DISASM_MODE_BSS:
125
b8ac21536779 tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 124
diff changeset
377 disasm_bss(sec);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
378 return;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
379 default:
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 printf("Unrecognized section type, skipped\n");
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
381 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
382 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
383
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
384 cmd_disasm(argc, argv)
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
385 char **argv;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
386 {
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
387 extern char *optarg;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
388 char *hintsfile = 0;
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 struct internal_scnhdr *sec;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
390 unsigned secnum;
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
391 int c;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
392
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
393 while ((c = getopt(argc, argv, "h:s")) != EOF)
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
394 switch (c) {
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
395 case 'h':
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
396 hintsfile = optarg;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
397 continue;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
398 case 's':
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
399 auto_xlat_section_relocs = 0;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
400 continue;
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
401 default:
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
402 /* error msg already printed */
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
403 exit(1);
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
404 }
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
406 printf("%s:\n", objfilename);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 dump_filehdr_info();
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
408 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409 get_int_section_table();
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
410 get_int_symbol_table();
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
411 if (hintsfile)
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
412 read_hints_file(hintsfile);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
413 extern_profile_report("Module");
118
193926ccd1ec tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 117
diff changeset
414 sort_symbols_of_all_sec();
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
415 for (secnum = 0; secnum < nsections; secnum++) {
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
416 sec = sections + secnum;
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
417 printf("=== %s ===\n", sec->name);
128
03f8a618689e tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 125
diff changeset
418 disasm_sec_by_type(sec);
111
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
419 putchar('\n');
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
420 }
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
421 exit(0);
0f94d17899b3 tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
422 }