FreeCalypso > hg > freecalypso-reveng
annotate leo-obj/tool/disasm.c @ 132:af0f8bfa3b3a
leo-obj/Makefile: created
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 07 Apr 2014 00:59:34 +0000 |
parents | 87b82398a08b |
children | daeaa5950d10 |
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 |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
17 static int auto_xlat_section_relocs = 1; |
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 |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
81 void |
124
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
82 disasm_end_of_section(sec, symnum) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
83 struct internal_scnhdr *sec; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
84 unsigned symnum; |
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 struct internal_syment *sym; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
87 char *sym_comment; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
88 |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
89 putchar('\n'); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
90 while (symnum < sec->nsymbols) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
91 sym = sec->sorted_symbols[symnum]; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
92 if (sym->value != sec->size) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
93 printf("error: expecting symbol at end of section\n"); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
94 return; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
95 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
96 switch (sym->class) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
97 case C_EXT: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
98 sym_comment = "Global"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
99 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
100 case C_STAT: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
101 sym_comment = "static"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
102 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
103 case C_LABEL: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
104 sym_comment = "label"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
105 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
106 default: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
107 sym_comment = "unexpected class!"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
108 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
109 printf("%s:\t; %s\n", sym->name, sym_comment); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
110 symnum++; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
111 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
112 printf("%8x:\t<end of section>\n", sec->size); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
113 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
114 |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
115 void |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 disasm_text_section(sec) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 struct internal_scnhdr *sec; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 unsigned symnum, relnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 unsigned pos, incr, headroom; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 int state = -1, linebrk = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 struct internal_syment *sym; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 struct internal_reloc *rel; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 char *sym_comment; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 printf("Disassembling code section:\n"); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 if (sec->nsymbols) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 sort_symbols_of_sec(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 if (sec->nreloc) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 get_relocs_of_sec(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 symnum = relnum = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 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
|
133 headroom = sec->size - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 while (symnum < sec->nsymbols) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 sym = sec->sorted_symbols[symnum]; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 if (sym->value > pos) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 if (sym->value - pos < headroom) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 headroom = sym->value - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 /* hit symbol */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 if (!linebrk) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 linebrk = 1; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 switch (sym->class) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 case C_EXT: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 sym_comment = "Global"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 case C_STAT: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 sym_comment = "static"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 case C_LABEL: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 sym_comment = "label"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 if (!strcmp(sym->name, "$CODE16")) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 state = 1; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 else if (!strcmp(sym->name, "$CODE32")) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 state = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 default: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 sym_comment = "unexpected class!"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 printf("%s:\t; %s\n", sym->name, sym_comment); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 symnum++; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 if (relnum < sec->nreloc) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 rel = sec->int_relocs + relnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 if (rel->location == pos) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 relnum++; /* it's ours */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 else { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 if (rel->location - pos < headroom) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 headroom = rel->location - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 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
|
174 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 } else |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 rel = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 printf("%8x:\t", pos); |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
178 if (rel && rel->type == RTYPE_LONG) { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
179 if (pos & 3) { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
180 printf("MISALIGNED pos for word32 reloc, aborting\n"); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
181 return; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
182 } |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
183 disasm_word32_reloc(sec, rel); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
184 incr = 4; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
185 goto next; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
186 } |
123
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
187 if (pos & 1 || headroom < 2) { |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
188 if (rel) { |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
189 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
|
190 return; |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
191 } |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
192 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
|
193 incr = 1; |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
194 goto next; |
5f9cc99930a8
tiobjd: handling of $CODE16 symbols at byte positions
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
121
diff
changeset
|
195 } |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 switch (state) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 case 0: /* ARM */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 if (pos & 3) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 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
|
200 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 } |
114
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
202 if (rel) { |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
203 if (rel->type != RTYPE_ARM_B) { |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
204 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
|
205 return; |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
206 } |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
207 arm_branch_reloc(sec, rel); |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
208 } else |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
209 arm_disasm_line(sec, pos); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 incr = 4; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 case 1: /* Thumb */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 if (pos & 1) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 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
|
215 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 } |
117
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
217 if (rel) { |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
218 if (rel->type != RTYPE_THUMB_BL) { |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
219 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
|
220 return; |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
221 } |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
222 thumb_bl_reloc(sec, rel); |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
223 incr = 4; |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
224 } 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
|
225 incr = 4; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 else { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 thumb_disasm_line(sec, pos); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 incr = 2; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 default: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 printf("UNKNOWN T state, aborting\n"); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 } |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
235 next: linebrk = 0; |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 if (incr > headroom) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 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
|
238 incr, headroom); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
239 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
240 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
241 } |
124
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
242 if (symnum < sec->nsymbols) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
243 disasm_end_of_section(sec, symnum); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
244 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
245 |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
246 void |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
247 disasm_data_section(sec) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
248 struct internal_scnhdr *sec; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
249 { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
250 unsigned symnum, relnum; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
251 unsigned pos, incr, headroom; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
252 int linebrk = 0; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
253 struct internal_syment *sym; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
254 struct internal_reloc *rel; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
255 char *sym_comment; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
256 |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
257 printf("Disassembling data section:\n"); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
258 if (sec->nsymbols) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
259 sort_symbols_of_sec(sec); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
260 if (sec->nreloc) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
261 get_relocs_of_sec(sec); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
262 symnum = relnum = 0; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
263 for (pos = 0; pos < sec->size; pos += incr) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
264 headroom = sec->size - pos; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
265 while (symnum < sec->nsymbols) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
266 sym = sec->sorted_symbols[symnum]; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
267 if (sym->value > pos) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
268 if (sym->value - pos < headroom) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
269 headroom = sym->value - pos; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
270 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
271 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
272 /* hit symbol */ |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
273 if (!linebrk) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
274 putchar('\n'); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
275 linebrk = 1; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
276 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
277 switch (sym->class) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
278 case C_EXT: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
279 sym_comment = "Global"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
280 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
281 case C_STAT: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
282 sym_comment = "static"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
283 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
284 case C_LABEL: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
285 sym_comment = "label"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
286 break; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
287 default: |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
288 sym_comment = "unexpected class!"; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
289 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
290 printf("%s:\t; %s\n", sym->name, sym_comment); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
291 symnum++; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
292 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
293 if (relnum < sec->nreloc) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
294 rel = sec->int_relocs + relnum; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
295 if (rel->location == pos) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
296 relnum++; /* it's ours */ |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
297 else { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
298 if (rel->location - pos < headroom) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
299 headroom = rel->location - pos; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
300 rel = 0; /* no reloc for current pos */ |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
301 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
302 } else |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
303 rel = 0; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
304 printf("%8x:\t", pos); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
305 if (rel) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
306 if (rel->type != RTYPE_LONG) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
307 printf("error: reloc other than word32 in data section\n"); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
308 return; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
309 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
310 if (pos & 3) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
311 printf("MISALIGNED pos for word32 reloc, aborting\n"); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
312 return; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
313 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
314 disasm_word32_reloc(sec, rel); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
315 incr = 4; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
316 } else if (pos & 1 || headroom < 2) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
317 printf("%02x\n", filemap[sec->data_offset + pos]); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
318 incr = 1; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
319 } else if (pos & 2 || headroom < 4) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
320 printf("%04x\n", |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
321 get_u16(filemap + sec->data_offset + pos)); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
322 incr = 2; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
323 } else { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
324 printf("%08x\n", |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
325 get_u32(filemap + sec->data_offset + pos)); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
326 incr = 4; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
327 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
328 linebrk = 0; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
329 if (incr > headroom) { |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
330 printf("error: increment %u > headroom %u, aborting\n", |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
331 incr, headroom); |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
332 return; |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
333 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
334 } |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
335 if (symnum < sec->nsymbols) |
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
336 disasm_end_of_section(sec, symnum); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
337 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
338 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
339 void |
125
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
340 disasm_bss(sec) |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
341 struct internal_scnhdr *sec; |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
342 { |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
343 unsigned m; |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
344 struct internal_syment *sym; |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
345 char classbuf[8]; |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
346 |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
347 putchar('\n'); |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
348 for (m = 0; m < sec->nsymbols; m++) { |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
349 sym = sec->sorted_symbols[m]; |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
350 printf("%08X %-7s %s\n", sym->value, |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
351 storage_class_to_string(sym->class, classbuf), |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
352 sym->name); |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
353 } |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
354 printf("%08X <end of section>\n", sec->size); |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
355 } |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
356 |
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
357 void |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
358 disasm_sec_by_type(sec) |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
359 struct internal_scnhdr *sec; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
360 { |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
361 switch (sec->disasm_mode) { |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
362 case DISASM_MODE_CODE: |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
363 disasm_text_section(sec); |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
364 return; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
365 case DISASM_MODE_DATA: |
124
700d77d5cf00
tiobjd disasm: data section handling added
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
123
diff
changeset
|
366 disasm_data_section(sec); |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
367 return; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
368 case DISASM_MODE_BSS: |
125
b8ac21536779
tiobjd disasm: bss handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
124
diff
changeset
|
369 disasm_bss(sec); |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
370 return; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
371 default: |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
372 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
|
373 } |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
374 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
375 |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
376 cmd_disasm(argc, argv) |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
377 char **argv; |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
378 { |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
379 extern char *optarg; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
380 char *hintsfile = 0; |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
381 struct internal_scnhdr *sec; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
382 unsigned secnum; |
128
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
383 int c; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
384 |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
385 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
|
386 switch (c) { |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
387 case 'h': |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
388 hintsfile = optarg; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
389 continue; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
390 case 's': |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
391 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
|
392 continue; |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
393 default: |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
394 /* error msg already printed */ |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
395 exit(1); |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
396 } |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
397 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
398 printf("%s:\n", objfilename); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
399 dump_filehdr_info(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
400 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
401 get_int_section_table(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
402 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
|
403 if (hintsfile) |
03f8a618689e
tiobjd disasm: initial hook-in of the hints mechanism
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
125
diff
changeset
|
404 read_hints_file(hintsfile); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
405 extern_profile_report("Module"); |
118
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
406 sort_symbols_of_all_sec(); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
407 for (secnum = 0; secnum < nsections; secnum++) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
408 sec = sections + secnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
409 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
|
410 disasm_sec_by_type(sec); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
411 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
412 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
413 exit(0); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
414 } |