util: integrate LLVM-based Disassembler
The LLVM Disassembler infrastructure can be used to analyze many kinds of ELF Binaries. For every instruction the used and defined registers is available as well as information about the instruction itself. Change-Id: I9cc89b6c116ceff7b5143a6f179ae31c4e994d2d
This commit is contained in:
BIN
src/core/util/llvmdisassembler/testing/arm9
Executable file
BIN
src/core/util/llvmdisassembler/testing/arm9
Executable file
Binary file not shown.
BIN
src/core/util/llvmdisassembler/testing/armm3
Executable file
BIN
src/core/util/llvmdisassembler/testing/armm3
Executable file
Binary file not shown.
281
src/core/util/llvmdisassembler/testing/armregs.txt
Normal file
281
src/core/util/llvmdisassembler/testing/armregs.txt
Normal file
@ -0,0 +1,281 @@
|
||||
Triple: arm-unknown-unknown
|
||||
|
||||
Number of Registers: 278
|
||||
0 - NOREG
|
||||
1 - APSR
|
||||
2 - CPSR
|
||||
3 - D0
|
||||
4 - D1
|
||||
5 - D2
|
||||
6 - D3
|
||||
7 - D4
|
||||
8 - D5
|
||||
9 - D6
|
||||
10 - D7
|
||||
11 - D8
|
||||
12 - D9
|
||||
13 - D10
|
||||
14 - D11
|
||||
15 - D12
|
||||
16 - D13
|
||||
17 - D14
|
||||
18 - D15
|
||||
19 - D16
|
||||
20 - D17
|
||||
21 - D18
|
||||
22 - D19
|
||||
23 - D20
|
||||
24 - D21
|
||||
25 - D22
|
||||
26 - D23
|
||||
27 - D24
|
||||
28 - D25
|
||||
29 - D26
|
||||
30 - D27
|
||||
31 - D28
|
||||
32 - D29
|
||||
33 - D30
|
||||
34 - D31
|
||||
35 - FPEXC
|
||||
36 - FPSCR
|
||||
37 - FPSCR_NZCV
|
||||
38 - FPSID
|
||||
39 - ITSTATE
|
||||
40 - LR
|
||||
41 - MVFR0
|
||||
42 - MVFR1
|
||||
43 - PC
|
||||
44 - Q0
|
||||
45 - Q1
|
||||
46 - Q2
|
||||
47 - Q3
|
||||
48 - Q4
|
||||
49 - Q5
|
||||
50 - Q6
|
||||
51 - Q7
|
||||
52 - Q8
|
||||
53 - Q9
|
||||
54 - Q10
|
||||
55 - Q11
|
||||
56 - Q12
|
||||
57 - Q13
|
||||
58 - Q14
|
||||
59 - Q15
|
||||
60 - R0
|
||||
61 - R1
|
||||
62 - R2
|
||||
63 - R3
|
||||
64 - R4
|
||||
65 - R5
|
||||
66 - R6
|
||||
67 - R7
|
||||
68 - R8
|
||||
69 - R9
|
||||
70 - R10
|
||||
71 - R11
|
||||
72 - R12
|
||||
73 - S0
|
||||
74 - S1
|
||||
75 - S2
|
||||
76 - S3
|
||||
77 - S4
|
||||
78 - S5
|
||||
79 - S6
|
||||
80 - S7
|
||||
81 - S8
|
||||
82 - S9
|
||||
83 - S10
|
||||
84 - S11
|
||||
85 - S12
|
||||
86 - S13
|
||||
87 - S14
|
||||
88 - S15
|
||||
89 - S16
|
||||
90 - S17
|
||||
91 - S18
|
||||
92 - S19
|
||||
93 - S20
|
||||
94 - S21
|
||||
95 - S22
|
||||
96 - S23
|
||||
97 - S24
|
||||
98 - S25
|
||||
99 - S26
|
||||
100 - S27
|
||||
101 - S28
|
||||
102 - S29
|
||||
103 - S30
|
||||
104 - S31
|
||||
105 - SP
|
||||
106 - SPSR
|
||||
107 - D0_D2
|
||||
108 - D1_D3
|
||||
109 - D2_D4
|
||||
110 - D3_D5
|
||||
111 - D4_D6
|
||||
112 - D5_D7
|
||||
113 - D6_D8
|
||||
114 - D7_D9
|
||||
115 - D8_D10
|
||||
116 - D9_D11
|
||||
117 - D10_D12
|
||||
118 - D11_D13
|
||||
119 - D12_D14
|
||||
120 - D13_D15
|
||||
121 - D14_D16
|
||||
122 - D15_D17
|
||||
123 - D16_D18
|
||||
124 - D17_D19
|
||||
125 - D18_D20
|
||||
126 - D19_D21
|
||||
127 - D20_D22
|
||||
128 - D21_D23
|
||||
129 - D22_D24
|
||||
130 - D23_D25
|
||||
131 - D24_D26
|
||||
132 - D25_D27
|
||||
133 - D26_D28
|
||||
134 - D27_D29
|
||||
135 - D28_D30
|
||||
136 - D29_D31
|
||||
137 - Q0_Q1
|
||||
138 - Q1_Q2
|
||||
139 - Q2_Q3
|
||||
140 - Q3_Q4
|
||||
141 - Q4_Q5
|
||||
142 - Q5_Q6
|
||||
143 - Q6_Q7
|
||||
144 - Q7_Q8
|
||||
145 - Q8_Q9
|
||||
146 - Q9_Q10
|
||||
147 - Q10_Q11
|
||||
148 - Q11_Q12
|
||||
149 - Q12_Q13
|
||||
150 - Q13_Q14
|
||||
151 - Q14_Q15
|
||||
152 - Q0_Q1_Q2_Q3
|
||||
153 - Q1_Q2_Q3_Q4
|
||||
154 - Q2_Q3_Q4_Q5
|
||||
155 - Q3_Q4_Q5_Q6
|
||||
156 - Q4_Q5_Q6_Q7
|
||||
157 - Q5_Q6_Q7_Q8
|
||||
158 - Q6_Q7_Q8_Q9
|
||||
159 - Q7_Q8_Q9_Q10
|
||||
160 - Q8_Q9_Q10_Q11
|
||||
161 - Q9_Q10_Q11_Q12
|
||||
162 - Q10_Q11_Q12_Q13
|
||||
163 - Q11_Q12_Q13_Q14
|
||||
164 - Q12_Q13_Q14_Q15
|
||||
165 - D0_D1_D2
|
||||
166 - D1_D2_D3
|
||||
167 - D2_D3_D4
|
||||
168 - D3_D4_D5
|
||||
169 - D4_D5_D6
|
||||
170 - D5_D6_D7
|
||||
171 - D6_D7_D8
|
||||
172 - D7_D8_D9
|
||||
173 - D8_D9_D10
|
||||
174 - D9_D10_D11
|
||||
175 - D10_D11_D12
|
||||
176 - D11_D12_D13
|
||||
177 - D12_D13_D14
|
||||
178 - D13_D14_D15
|
||||
179 - D14_D15_D16
|
||||
180 - D15_D16_D17
|
||||
181 - D16_D17_D18
|
||||
182 - D17_D18_D19
|
||||
183 - D18_D19_D20
|
||||
184 - D19_D20_D21
|
||||
185 - D20_D21_D22
|
||||
186 - D21_D22_D23
|
||||
187 - D22_D23_D24
|
||||
188 - D23_D24_D25
|
||||
189 - D24_D25_D26
|
||||
190 - D25_D26_D27
|
||||
191 - D26_D27_D28
|
||||
192 - D27_D28_D29
|
||||
193 - D28_D29_D30
|
||||
194 - D29_D30_D31
|
||||
195 - D0_D2_D4
|
||||
196 - D1_D3_D5
|
||||
197 - D2_D4_D6
|
||||
198 - D3_D5_D7
|
||||
199 - D4_D6_D8
|
||||
200 - D5_D7_D9
|
||||
201 - D6_D8_D10
|
||||
202 - D7_D9_D11
|
||||
203 - D8_D10_D12
|
||||
204 - D9_D11_D13
|
||||
205 - D10_D12_D14
|
||||
206 - D11_D13_D15
|
||||
207 - D12_D14_D16
|
||||
208 - D13_D15_D17
|
||||
209 - D14_D16_D18
|
||||
210 - D15_D17_D19
|
||||
211 - D16_D18_D20
|
||||
212 - D17_D19_D21
|
||||
213 - D18_D20_D22
|
||||
214 - D19_D21_D23
|
||||
215 - D20_D22_D24
|
||||
216 - D21_D23_D25
|
||||
217 - D22_D24_D26
|
||||
218 - D23_D25_D27
|
||||
219 - D24_D26_D28
|
||||
220 - D25_D27_D29
|
||||
221 - D26_D28_D30
|
||||
222 - D27_D29_D31
|
||||
223 - D0_D2_D4_D6
|
||||
224 - D1_D3_D5_D7
|
||||
225 - D2_D4_D6_D8
|
||||
226 - D3_D5_D7_D9
|
||||
227 - D4_D6_D8_D10
|
||||
228 - D5_D7_D9_D11
|
||||
229 - D6_D8_D10_D12
|
||||
230 - D7_D9_D11_D13
|
||||
231 - D8_D10_D12_D14
|
||||
232 - D9_D11_D13_D15
|
||||
233 - D10_D12_D14_D16
|
||||
234 - D11_D13_D15_D17
|
||||
235 - D12_D14_D16_D18
|
||||
236 - D13_D15_D17_D19
|
||||
237 - D14_D16_D18_D20
|
||||
238 - D15_D17_D19_D21
|
||||
239 - D16_D18_D20_D22
|
||||
240 - D17_D19_D21_D23
|
||||
241 - D18_D20_D22_D24
|
||||
242 - D19_D21_D23_D25
|
||||
243 - D20_D22_D24_D26
|
||||
244 - D21_D23_D25_D27
|
||||
245 - D22_D24_D26_D28
|
||||
246 - D23_D25_D27_D29
|
||||
247 - D24_D26_D28_D30
|
||||
248 - D25_D27_D29_D31
|
||||
249 - D1_D2
|
||||
250 - D3_D4
|
||||
251 - D5_D6
|
||||
252 - D7_D8
|
||||
253 - D9_D10
|
||||
254 - D11_D12
|
||||
255 - D13_D14
|
||||
256 - D15_D16
|
||||
257 - D17_D18
|
||||
258 - D19_D20
|
||||
259 - D21_D22
|
||||
260 - D23_D24
|
||||
261 - D25_D26
|
||||
262 - D27_D28
|
||||
263 - D29_D30
|
||||
264 - D1_D2_D3_D4
|
||||
265 - D3_D4_D5_D6
|
||||
266 - D5_D6_D7_D8
|
||||
267 - D7_D8_D9_D10
|
||||
268 - D9_D10_D11_D12
|
||||
269 - D11_D12_D13_D14
|
||||
270 - D13_D14_D15_D16
|
||||
271 - D15_D16_D17_D18
|
||||
272 - D17_D18_D19_D20
|
||||
273 - D19_D20_D21_D22
|
||||
274 - D21_D22_D23_D24
|
||||
275 - D23_D24_D25_D26
|
||||
276 - D25_D26_D27_D28
|
||||
277 - D27_D28_D29_D30
|
||||
71
src/core/util/llvmdisassembler/testing/bubble.cc
Normal file
71
src/core/util/llvmdisassembler/testing/bubble.cc
Normal file
@ -0,0 +1,71 @@
|
||||
#include <assert.h>
|
||||
|
||||
class random_generator_t
|
||||
{
|
||||
private:
|
||||
unsigned int a; // (sqrt(5)-1)/2 = 0.61803398875
|
||||
unsigned int b;
|
||||
unsigned int last_val;
|
||||
unsigned int sd;
|
||||
public:
|
||||
void forth() {
|
||||
last_val = a*last_val + b;
|
||||
}
|
||||
|
||||
|
||||
random_generator_t(unsigned int seed = 1)
|
||||
: a(2654435769), b(seed), last_val(1), sd(seed){
|
||||
forth();
|
||||
}
|
||||
|
||||
unsigned int item() const {
|
||||
return last_val;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
last_val = 1;
|
||||
b = sd;
|
||||
forth();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void sort(int len, int arr[] )
|
||||
{
|
||||
int tmp;
|
||||
int again;
|
||||
int i;
|
||||
|
||||
for(again=1; again; )
|
||||
for( again=0, i=0; i < (len-1); ++i){
|
||||
assert(0<=i && i+1 <len);
|
||||
if( arr[i] > arr[i+1] ){
|
||||
tmp = arr[i];
|
||||
arr[i] = arr[i+1];
|
||||
arr[i+1] = tmp;
|
||||
again = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int arr_size = 10000; //50000;
|
||||
|
||||
int arr[arr_size];
|
||||
int i;
|
||||
random_generator_t rand;
|
||||
|
||||
for(i=0; i!=arr_size; ++i){
|
||||
arr[i] = rand.item();
|
||||
rand.forth();
|
||||
}
|
||||
|
||||
sort(arr_size, arr);
|
||||
}
|
||||
|
||||
4
src/core/util/llvmdisassembler/testing/howtobuild.txt
Normal file
4
src/core/util/llvmdisassembler/testing/howtobuild.txt
Normal file
@ -0,0 +1,4 @@
|
||||
g++ -m32 bubble.cc -o x86
|
||||
g++ -m64 bubble.cc -o x86_64
|
||||
arm-none-eabi-g++ -mcpu=cortex-m3 bubble.cc -o armm3
|
||||
arm-none-eabi-g++ -mcpu=arm9 bubble.cc -o arm9
|
||||
68
src/core/util/llvmdisassembler/testing/llvmDisTest.cc
Normal file
68
src/core/util/llvmdisassembler/testing/llvmDisTest.cc
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef __puma
|
||||
#include "../LLVMDisassembler.hpp"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::object;
|
||||
using namespace fail;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||
// Initialize targets and assembly printers/parsers.
|
||||
llvm::InitializeAllTargetInfos();
|
||||
llvm::InitializeAllTargetMCs();
|
||||
// llvm::InitializeAllAsmParsers();
|
||||
llvm::InitializeAllDisassemblers();
|
||||
|
||||
std::string file;
|
||||
|
||||
if(argc > 1){
|
||||
std::cout << "Trying to disassemble: " << argv[1] << std::endl;
|
||||
file = argv[1];
|
||||
} else {
|
||||
std::cerr << "No file to disassemble :(" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
OwningPtr<Binary> binary;
|
||||
if (error_code ec = createBinary(file, binary)) {
|
||||
std::cerr << "Dis" << ": '" << file << "': " << ec.message() << ".\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ObjectFile *obj = dyn_cast<ObjectFile>(binary.get());
|
||||
|
||||
LLVMDisassembler disas(obj);
|
||||
disas.disassemble();
|
||||
|
||||
LLVMDisassembler::InstrMap &instr_map = disas.getInstrMap();
|
||||
std::cout << "Map Size: " << instr_map.size() << "\nTriple: " << disas.GetTriple() << std::endl;
|
||||
|
||||
LLVMDisassembler::InstrMap::const_iterator itr;
|
||||
const MCRegisterInfo ®_info = disas.getRegisterInfo();
|
||||
|
||||
std::cout << std::endl << "Number of Registers: " << reg_info.getNumRegs() << std::endl;
|
||||
// for(unsigned int i = 0; i < reg_info.getNumRegs(); ++i){
|
||||
// std::cout << i << " - " << reg_info.getName(i) << std::endl;
|
||||
// }
|
||||
fail::LLVMtoFailTranslator & ltof = disas.getTranslator() ;
|
||||
|
||||
for(itr = instr_map.begin(); itr != instr_map.end(); ++itr){
|
||||
const LLVMDisassembler::Instr &instr = (*itr).second;
|
||||
std::cout << std::hex << (*itr).first << " | " << instr.opcode << std::endl;
|
||||
std::cout << std::dec << "USES: ";
|
||||
for (std::vector<uint16_t>::const_iterator it = instr.reg_uses.begin();
|
||||
it != instr.reg_uses.end(); ++it) {
|
||||
std::cout << reg_info.getName(*it) <<"(" << *it << ") ";
|
||||
std::cout << "Fail: " << ltof.getFailRegisterId(*it) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "DEFS: ";
|
||||
for (std::vector<uint16_t>::const_iterator it = instr.reg_defs.begin();
|
||||
it != instr.reg_defs.end(); ++it) {
|
||||
std::cout << reg_info.getName(*it) << "(" << *it << ") ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
BIN
src/core/util/llvmdisassembler/testing/x86
Executable file
BIN
src/core/util/llvmdisassembler/testing/x86
Executable file
Binary file not shown.
BIN
src/core/util/llvmdisassembler/testing/x86_64
Executable file
BIN
src/core/util/llvmdisassembler/testing/x86_64
Executable file
Binary file not shown.
163
src/core/util/llvmdisassembler/testing/x86regs.txt
Normal file
163
src/core/util/llvmdisassembler/testing/x86regs.txt
Normal file
@ -0,0 +1,163 @@
|
||||
Triple: x86_64-unknown-unknown
|
||||
|
||||
Number of Registers: 160
|
||||
0 - NOREG
|
||||
1 - AH
|
||||
2 - AL
|
||||
3 - AX
|
||||
4 - BH
|
||||
5 - BL
|
||||
6 - BP
|
||||
7 - BPL
|
||||
8 - BX
|
||||
9 - CH
|
||||
10 - CL
|
||||
11 - CR0
|
||||
12 - CR1
|
||||
13 - CR2
|
||||
14 - CR3
|
||||
15 - CR4
|
||||
16 - CR5
|
||||
17 - CR6
|
||||
18 - CR7
|
||||
19 - CR8
|
||||
20 - CR9
|
||||
21 - CR10
|
||||
22 - CR11
|
||||
23 - CR12
|
||||
24 - CR13
|
||||
25 - CR14
|
||||
26 - CR15
|
||||
27 - CS
|
||||
28 - CX
|
||||
29 - DH
|
||||
30 - DI
|
||||
31 - DIL
|
||||
32 - DL
|
||||
33 - DR0
|
||||
34 - DR1
|
||||
35 - DR2
|
||||
36 - DR3
|
||||
37 - DR4
|
||||
38 - DR5
|
||||
39 - DR6
|
||||
40 - DR7
|
||||
41 - DS
|
||||
42 - DX
|
||||
43 - EAX
|
||||
44 - EBP
|
||||
45 - EBX
|
||||
46 - ECX
|
||||
47 - EDI
|
||||
48 - EDX
|
||||
49 - EFLAGS
|
||||
50 - EIP
|
||||
51 - EIZ
|
||||
52 - ES
|
||||
53 - ESI
|
||||
54 - ESP
|
||||
55 - FP0
|
||||
56 - FP1
|
||||
57 - FP2
|
||||
58 - FP3
|
||||
59 - FP4
|
||||
60 - FP5
|
||||
61 - FP6
|
||||
62 - FS
|
||||
63 - GS
|
||||
64 - IP
|
||||
65 - MM0
|
||||
66 - MM1
|
||||
67 - MM2
|
||||
68 - MM3
|
||||
69 - MM4
|
||||
70 - MM5
|
||||
71 - MM6
|
||||
72 - MM7
|
||||
73 - R8
|
||||
74 - R8B
|
||||
75 - R8D
|
||||
76 - R8W
|
||||
77 - R9
|
||||
78 - R9B
|
||||
79 - R9D
|
||||
80 - R9W
|
||||
81 - R10
|
||||
82 - R10B
|
||||
83 - R10D
|
||||
84 - R10W
|
||||
85 - R11
|
||||
86 - R11B
|
||||
87 - R11D
|
||||
88 - R11W
|
||||
89 - R12
|
||||
90 - R12B
|
||||
91 - R12D
|
||||
92 - R12W
|
||||
93 - R13
|
||||
94 - R13B
|
||||
95 - R13D
|
||||
96 - R13W
|
||||
97 - R14
|
||||
98 - R14B
|
||||
99 - R14D
|
||||
100 - R14W
|
||||
101 - R15
|
||||
102 - R15B
|
||||
103 - R15D
|
||||
104 - R15W
|
||||
105 - RAX
|
||||
106 - RBP
|
||||
107 - RBX
|
||||
108 - RCX
|
||||
109 - RDI
|
||||
110 - RDX
|
||||
111 - RIP
|
||||
112 - RIZ
|
||||
113 - RSI
|
||||
114 - RSP
|
||||
115 - SI
|
||||
116 - SIL
|
||||
117 - SP
|
||||
118 - SPL
|
||||
119 - SS
|
||||
120 - ST0
|
||||
121 - ST1
|
||||
122 - ST2
|
||||
123 - ST3
|
||||
124 - ST4
|
||||
125 - ST5
|
||||
126 - ST6
|
||||
127 - ST7
|
||||
128 - XMM0
|
||||
129 - XMM1
|
||||
130 - XMM2
|
||||
131 - XMM3
|
||||
132 - XMM4
|
||||
133 - XMM5
|
||||
134 - XMM6
|
||||
135 - XMM7
|
||||
136 - XMM8
|
||||
137 - XMM9
|
||||
138 - XMM10
|
||||
139 - XMM11
|
||||
140 - XMM12
|
||||
141 - XMM13
|
||||
142 - XMM14
|
||||
143 - XMM15
|
||||
144 - YMM0
|
||||
145 - YMM1
|
||||
146 - YMM2
|
||||
147 - YMM3
|
||||
148 - YMM4
|
||||
149 - YMM5
|
||||
150 - YMM6
|
||||
151 - YMM7
|
||||
152 - YMM8
|
||||
153 - YMM9
|
||||
154 - YMM10
|
||||
155 - YMM11
|
||||
156 - YMM12
|
||||
157 - YMM13
|
||||
158 - YMM14
|
||||
159 - YMM15
|
||||
Reference in New Issue
Block a user