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