FreeCalypso > hg > freecalypso-reveng
annotate ticoff/disasm.c @ 118:193926ccd1ec
tiobjd: better handling of section-relative relocs
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 03 Apr 2014 07:47:03 +0000 |
parents | f9fde7f36ae3 |
children | 4d8dfdbd2ea1 |
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(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
118
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
16 static void |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
17 find_better_symbol(symp, addp) |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
18 struct internal_syment **symp; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
19 unsigned *addp; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
20 { |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
21 struct internal_scnhdr *sec; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
22 unsigned addr; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
23 struct internal_syment *sym, *symsel; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
24 unsigned n; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
25 |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
26 sec = (*symp)->section; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
27 addr = *addp; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
28 symsel = 0; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
29 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
|
30 sym = sec->sorted_symbols[n]; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
31 if (sym->value > addr) |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
32 break; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
33 if (sym->class == C_EXT || sym->class == C_STAT) |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
34 symsel = sym; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
35 } |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
36 if (symsel) { |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
37 *symp = symsel; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
38 *addp = addr - symsel->value; |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
39 } |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
40 } |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
41 |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 void |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
43 disasm_reloc_target(sec, rel, addend) |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
44 struct internal_scnhdr *sec; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
45 struct internal_reloc *rel; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
46 unsigned addend; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
47 { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
48 struct internal_syment *sym = rel->sym; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
49 |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
50 addend -= sym->value; |
118
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
51 if (sym->section && !strcmp(sym->name, sym->section->name)) |
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
52 find_better_symbol(&sym, &addend); |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
53 if (addend >= 10) |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
54 printf("%s+0x%x", sym->name, addend); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
55 else if (addend) |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
56 printf("%s+%u", sym->name, addend); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
57 else |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
58 fputs(sym->name, stdout); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
59 } |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
60 |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
61 void |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
62 disasm_word32_reloc(sec, rel) |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
63 struct internal_scnhdr *sec; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
64 struct internal_reloc *rel; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
65 { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
66 unsigned word; |
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 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
|
69 printf("%08x R\t.word\t", word); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
70 disasm_reloc_target(sec, rel, word); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
71 putchar('\n'); |
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 |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
74 void |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 disasm_text_section(sec) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 struct internal_scnhdr *sec; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 unsigned symnum, relnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 unsigned pos, incr, headroom; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 int state = -1, linebrk = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 struct internal_syment *sym; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 struct internal_reloc *rel; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 char *sym_comment; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 printf("Disassembling code section:\n"); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 if (sec->nsymbols) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 sort_symbols_of_sec(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 if (sec->nreloc) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 get_relocs_of_sec(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 symnum = relnum = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 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
|
92 headroom = sec->size - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 while (symnum < sec->nsymbols) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 sym = sec->sorted_symbols[symnum]; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 if (sym->value > pos) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 if (sym->value - pos < headroom) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 headroom = sym->value - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 /* hit symbol */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 if (!linebrk) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 linebrk = 1; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 switch (sym->class) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 case C_EXT: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 sym_comment = "Global"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 case C_STAT: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 sym_comment = "static"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 case C_LABEL: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 sym_comment = "label"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 if (!strcmp(sym->name, "$CODE16")) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 state = 1; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 else if (!strcmp(sym->name, "$CODE32")) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 state = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 default: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 sym_comment = "unexpected class!"; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 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
|
123 symnum++; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 if (relnum < sec->nreloc) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 rel = sec->int_relocs + relnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 if (rel->location == pos) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 relnum++; /* it's ours */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 else { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 if (rel->location - pos < headroom) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 headroom = rel->location - pos; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 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
|
133 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 } else |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 rel = 0; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 printf("%8x:\t", pos); |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
137 if (rel && rel->type == RTYPE_LONG) { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
138 if (pos & 3) { |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
139 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
|
140 return; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
141 } |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
142 disasm_word32_reloc(sec, rel); |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
143 incr = 4; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
144 goto next; |
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
145 } |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 switch (state) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 case 0: /* ARM */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 if (pos & 3) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 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
|
150 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 } |
114
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
152 if (rel) { |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
153 if (rel->type != RTYPE_ARM_B) { |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
154 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
|
155 return; |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
156 } |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
157 arm_branch_reloc(sec, rel); |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
158 } else |
ca8e43288836
tiobjd: ARM_B reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
112
diff
changeset
|
159 arm_disasm_line(sec, pos); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 incr = 4; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 case 1: /* Thumb */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 if (pos & 1) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 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
|
165 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 } |
117
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
167 if (rel) { |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
168 if (rel->type != RTYPE_THUMB_BL) { |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
169 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
|
170 return; |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
171 } |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
172 thumb_bl_reloc(sec, rel); |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
173 incr = 4; |
f9fde7f36ae3
tiobjd: Thumb_BL reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
114
diff
changeset
|
174 } 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
|
175 incr = 4; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 else { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 thumb_disasm_line(sec, pos); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 incr = 2; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 break; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 default: |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 printf("UNKNOWN T state, aborting\n"); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 } |
112
61a58677dc68
tiobjd disasm: beginning of reloc handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
111
diff
changeset
|
185 next: linebrk = 0; |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 if (incr > headroom) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 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
|
188 incr, headroom); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 return; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 void |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 disasm_sectype_by_name(sec) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 struct internal_scnhdr *sec; |
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 if (!strncmp(sec->name, ".text", 5)) |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 disasm_text_section(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 /* other section types to be added */ |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 else |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 printf("Unrecognized section type, skipped\n"); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 cmd_disasm() |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 struct internal_scnhdr *sec; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 unsigned secnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 printf("%s:\n", objfilename); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 dump_filehdr_info(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 get_int_section_table(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 get_int_symbol_table(); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 extern_profile_report("Module"); |
118
193926ccd1ec
tiobjd: better handling of section-relative relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
117
diff
changeset
|
216 sort_symbols_of_all_sec(); |
111
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 for (secnum = 0; secnum < nsections; secnum++) { |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 sec = sections + secnum; |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 printf("=== %s ===\n", sec->name); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 disasm_sectype_by_name(sec); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 putchar('\n'); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 } |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 exit(0); |
0f94d17899b3
tiobjd: disassembly integrated, no relocs or hints yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 } |