comparison lib/Target/Sparc/Disassembler/SparcDisassembler.cpp @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents afa8332a0e37
children 803732b1fca8
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "Sparc.h" 14 #include "Sparc.h"
15 #include "SparcRegisterInfo.h" 15 #include "SparcRegisterInfo.h"
16 #include "SparcSubtarget.h" 16 #include "SparcSubtarget.h"
17 #include "llvm/MC/MCDisassembler.h" 17 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
18 #include "llvm/MC/MCFixedLenDisassembler.h" 18 #include "llvm/MC/MCFixedLenDisassembler.h"
19 #include "llvm/MC/MCInst.h" 19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCContext.h" 20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCAsmInfo.h" 21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/Support/TargetRegistry.h" 22 #include "llvm/Support/TargetRegistry.h"
42 raw_ostream &CStream) const override; 42 raw_ostream &CStream) const override;
43 }; 43 };
44 } 44 }
45 45
46 namespace llvm { 46 namespace llvm {
47 extern Target TheSparcTarget, TheSparcV9Target, TheSparcelTarget; 47 Target &getTheSparcTarget();
48 Target &getTheSparcV9Target();
49 Target &getTheSparcelTarget();
48 } 50 }
49 51
50 static MCDisassembler *createSparcDisassembler(const Target &T, 52 static MCDisassembler *createSparcDisassembler(const Target &T,
51 const MCSubtargetInfo &STI, 53 const MCSubtargetInfo &STI,
52 MCContext &Ctx) { 54 MCContext &Ctx) {
54 } 56 }
55 57
56 58
57 extern "C" void LLVMInitializeSparcDisassembler() { 59 extern "C" void LLVMInitializeSparcDisassembler() {
58 // Register the disassembler. 60 // Register the disassembler.
59 TargetRegistry::RegisterMCDisassembler(TheSparcTarget, 61 TargetRegistry::RegisterMCDisassembler(getTheSparcTarget(),
60 createSparcDisassembler); 62 createSparcDisassembler);
61 TargetRegistry::RegisterMCDisassembler(TheSparcV9Target, 63 TargetRegistry::RegisterMCDisassembler(getTheSparcV9Target(),
62 createSparcDisassembler); 64 createSparcDisassembler);
63 TargetRegistry::RegisterMCDisassembler(TheSparcelTarget, 65 TargetRegistry::RegisterMCDisassembler(getTheSparcelTarget(),
64 createSparcDisassembler); 66 createSparcDisassembler);
65 } 67 }
66 68
67 static const unsigned IntRegDecoderTable[] = { 69 static const unsigned IntRegDecoderTable[] = {
68 SP::G0, SP::G1, SP::G2, SP::G3, 70 SP::G0, SP::G1, SP::G2, SP::G3,
128 SP::O0_O1, SP::O2_O3, SP::O4_O5, SP::O6_O7, 130 SP::O0_O1, SP::O2_O3, SP::O4_O5, SP::O6_O7,
129 SP::L0_L1, SP::L2_L3, SP::L4_L5, SP::L6_L7, 131 SP::L0_L1, SP::L2_L3, SP::L4_L5, SP::L6_L7,
130 SP::I0_I1, SP::I2_I3, SP::I4_I5, SP::I6_I7, 132 SP::I0_I1, SP::I2_I3, SP::I4_I5, SP::I6_I7,
131 }; 133 };
132 134
135 static const unsigned CPRegDecoderTable[] = {
136 SP::C0, SP::C1, SP::C2, SP::C3,
137 SP::C4, SP::C5, SP::C6, SP::C7,
138 SP::C8, SP::C9, SP::C10, SP::C11,
139 SP::C12, SP::C13, SP::C14, SP::C15,
140 SP::C16, SP::C17, SP::C18, SP::C19,
141 SP::C20, SP::C21, SP::C22, SP::C23,
142 SP::C24, SP::C25, SP::C26, SP::C27,
143 SP::C28, SP::C29, SP::C30, SP::C31
144 };
145
146
147 static const uint16_t CPPairDecoderTable[] = {
148 SP::C0_C1, SP::C2_C3, SP::C4_C5, SP::C6_C7,
149 SP::C8_C9, SP::C10_C11, SP::C12_C13, SP::C14_C15,
150 SP::C16_C17, SP::C18_C19, SP::C20_C21, SP::C22_C23,
151 SP::C24_C25, SP::C26_C27, SP::C28_C29, SP::C30_C31
152 };
153
133 static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, 154 static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst,
134 unsigned RegNo, 155 unsigned RegNo,
135 uint64_t Address, 156 uint64_t Address,
136 const void *Decoder) { 157 const void *Decoder) {
137 if (RegNo > 31) 158 if (RegNo > 31)
189 return MCDisassembler::Fail; 210 return MCDisassembler::Fail;
190 Inst.addOperand(MCOperand::createReg(Reg)); 211 Inst.addOperand(MCOperand::createReg(Reg));
191 return MCDisassembler::Success; 212 return MCDisassembler::Success;
192 } 213 }
193 214
215 static DecodeStatus DecodeCPRegsRegisterClass(MCInst &Inst,
216 unsigned RegNo,
217 uint64_t Address,
218 const void *Decoder) {
219 if (RegNo > 31)
220 return MCDisassembler::Fail;
221 unsigned Reg = CPRegDecoderTable[RegNo];
222 Inst.addOperand(MCOperand::createReg(Reg));
223 return MCDisassembler::Success;
224 }
225
194 static DecodeStatus DecodeFCCRegsRegisterClass(MCInst &Inst, unsigned RegNo, 226 static DecodeStatus DecodeFCCRegsRegisterClass(MCInst &Inst, unsigned RegNo,
195 uint64_t Address, 227 uint64_t Address,
196 const void *Decoder) { 228 const void *Decoder) {
197 if (RegNo > 3) 229 if (RegNo > 3)
198 return MCDisassembler::Fail; 230 return MCDisassembler::Fail;
229 S = MCDisassembler::SoftFail; 261 S = MCDisassembler::SoftFail;
230 262
231 unsigned RegisterPair = IntPairDecoderTable[RegNo/2]; 263 unsigned RegisterPair = IntPairDecoderTable[RegNo/2];
232 Inst.addOperand(MCOperand::createReg(RegisterPair)); 264 Inst.addOperand(MCOperand::createReg(RegisterPair));
233 return S; 265 return S;
266 }
267
268 static DecodeStatus DecodeCPPairRegisterClass(MCInst &Inst, unsigned RegNo,
269 uint64_t Address, const void *Decoder) {
270 if (RegNo > 31)
271 return MCDisassembler::Fail;
272
273 unsigned RegisterPair = CPPairDecoderTable[RegNo/2];
274 Inst.addOperand(MCOperand::createReg(RegisterPair));
275 return MCDisassembler::Success;
234 } 276 }
235 277
236 static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address, 278 static DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
237 const void *Decoder); 279 const void *Decoder);
238 static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn, uint64_t Address, 280 static DecodeStatus DecodeLoadIntPair(MCInst &Inst, unsigned insn, uint64_t Address,
240 static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address, 282 static DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
241 const void *Decoder); 283 const void *Decoder);
242 static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address, 284 static DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
243 const void *Decoder); 285 const void *Decoder);
244 static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address, 286 static DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
287 const void *Decoder);
288 static DecodeStatus DecodeLoadCP(MCInst &Inst, unsigned insn, uint64_t Address,
289 const void *Decoder);
290 static DecodeStatus DecodeLoadCPPair(MCInst &Inst, unsigned insn, uint64_t Address,
245 const void *Decoder); 291 const void *Decoder);
246 static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn, 292 static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
247 uint64_t Address, const void *Decoder); 293 uint64_t Address, const void *Decoder);
248 static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn, 294 static DecodeStatus DecodeStoreIntPair(MCInst &Inst, unsigned insn,
249 uint64_t Address, const void *Decoder); 295 uint64_t Address, const void *Decoder);
251 uint64_t Address, const void *Decoder); 297 uint64_t Address, const void *Decoder);
252 static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn, 298 static DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
253 uint64_t Address, const void *Decoder); 299 uint64_t Address, const void *Decoder);
254 static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn, 300 static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
255 uint64_t Address, const void *Decoder); 301 uint64_t Address, const void *Decoder);
302 static DecodeStatus DecodeStoreCP(MCInst &Inst, unsigned insn,
303 uint64_t Address, const void *Decoder);
304 static DecodeStatus DecodeStoreCPPair(MCInst &Inst, unsigned insn,
305 uint64_t Address, const void *Decoder);
256 static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, 306 static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn,
257 uint64_t Address, const void *Decoder); 307 uint64_t Address, const void *Decoder);
258 static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, 308 static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn,
259 uint64_t Address, const void *Decoder); 309 uint64_t Address, const void *Decoder);
260 static DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address, 310 static DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address,
261 const void *Decoder); 311 const void *Decoder);
262 static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address, 312 static DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
263 const void *Decoder); 313 const void *Decoder);
264 static DecodeStatus DecodeSWAP(MCInst &Inst, unsigned insn, uint64_t Address, 314 static DecodeStatus DecodeSWAP(MCInst &Inst, unsigned insn, uint64_t Address,
265 const void *Decoder); 315 const void *Decoder);
316 static DecodeStatus DecodeTRAP(MCInst &Inst, unsigned insn, uint64_t Address,
317 const void *Decoder);
266 318
267 #include "SparcGenDisassemblerTables.inc" 319 #include "SparcGenDisassemblerTables.inc"
268 320
269 /// Read four bytes from the ArrayRef and return 32 bit word. 321 /// Read four bytes from the ArrayRef and return 32 bit word.
270 static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address, 322 static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
296 readInstruction32(Bytes, Address, Size, Insn, isLittleEndian); 348 readInstruction32(Bytes, Address, Size, Insn, isLittleEndian);
297 if (Result == MCDisassembler::Fail) 349 if (Result == MCDisassembler::Fail)
298 return MCDisassembler::Fail; 350 return MCDisassembler::Fail;
299 351
300 // Calling the auto-generated decoder function. 352 // Calling the auto-generated decoder function.
353
354 if (STI.getFeatureBits()[Sparc::FeatureV9])
355 {
356 Result = decodeInstruction(DecoderTableSparcV932, Instr, Insn, Address, this, STI);
357 }
358 else
359 {
360 Result = decodeInstruction(DecoderTableSparcV832, Instr, Insn, Address, this, STI);
361 }
362 if (Result != MCDisassembler::Fail)
363 return Result;
364
301 Result = 365 Result =
302 decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI); 366 decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI);
303 367
304 if (Result != MCDisassembler::Fail) { 368 if (Result != MCDisassembler::Fail) {
305 Size = 4; 369 Size = 4;
388 const void *Decoder) { 452 const void *Decoder) {
389 return DecodeMem(Inst, insn, Address, Decoder, true, 453 return DecodeMem(Inst, insn, Address, Decoder, true,
390 DecodeQFPRegsRegisterClass); 454 DecodeQFPRegsRegisterClass);
391 } 455 }
392 456
457 static DecodeStatus DecodeLoadCP(MCInst &Inst, unsigned insn, uint64_t Address,
458 const void *Decoder) {
459 return DecodeMem(Inst, insn, Address, Decoder, true,
460 DecodeCPRegsRegisterClass);
461 }
462
463 static DecodeStatus DecodeLoadCPPair(MCInst &Inst, unsigned insn, uint64_t Address,
464 const void *Decoder) {
465 return DecodeMem(Inst, insn, Address, Decoder, true,
466 DecodeCPPairRegisterClass);
467 }
468
393 static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn, 469 static DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
394 uint64_t Address, const void *Decoder) { 470 uint64_t Address, const void *Decoder) {
395 return DecodeMem(Inst, insn, Address, Decoder, false, 471 return DecodeMem(Inst, insn, Address, Decoder, false,
396 DecodeIntRegsRegisterClass); 472 DecodeIntRegsRegisterClass);
397 } 473 }
416 492
417 static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn, 493 static DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
418 uint64_t Address, const void *Decoder) { 494 uint64_t Address, const void *Decoder) {
419 return DecodeMem(Inst, insn, Address, Decoder, false, 495 return DecodeMem(Inst, insn, Address, Decoder, false,
420 DecodeQFPRegsRegisterClass); 496 DecodeQFPRegsRegisterClass);
497 }
498
499 static DecodeStatus DecodeStoreCP(MCInst &Inst, unsigned insn,
500 uint64_t Address, const void *Decoder) {
501 return DecodeMem(Inst, insn, Address, Decoder, false,
502 DecodeCPRegsRegisterClass);
503 }
504
505 static DecodeStatus DecodeStoreCPPair(MCInst &Inst, unsigned insn,
506 uint64_t Address, const void *Decoder) {
507 return DecodeMem(Inst, insn, Address, Decoder, false,
508 DecodeCPPairRegisterClass);
421 } 509 }
422 510
423 static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch, 511 static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
424 uint64_t Address, uint64_t Offset, 512 uint64_t Address, uint64_t Offset,
425 uint64_t Width, MCInst &MI, 513 uint64_t Width, MCInst &MI,
545 if (hasAsi) 633 if (hasAsi)
546 MI.addOperand(MCOperand::createImm(asi)); 634 MI.addOperand(MCOperand::createImm(asi));
547 635
548 return MCDisassembler::Success; 636 return MCDisassembler::Success;
549 } 637 }
638
639 static DecodeStatus DecodeTRAP(MCInst &MI, unsigned insn, uint64_t Address,
640 const void *Decoder) {
641
642 unsigned rs1 = fieldFromInstruction(insn, 14, 5);
643 unsigned isImm = fieldFromInstruction(insn, 13, 1);
644 unsigned cc =fieldFromInstruction(insn, 25, 4);
645 unsigned rs2 = 0;
646 unsigned imm7 = 0;
647 if (isImm)
648 imm7 = fieldFromInstruction(insn, 0, 7);
649 else
650 rs2 = fieldFromInstruction(insn, 0, 5);
651
652 // Decode RS1.
653 DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
654 if (status != MCDisassembler::Success)
655 return status;
656
657 // Decode RS1 | IMM7.
658 if (isImm)
659 MI.addOperand(MCOperand::createImm(imm7));
660 else {
661 status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
662 if (status != MCDisassembler::Success)
663 return status;
664 }
665
666 // Decode CC
667 MI.addOperand(MCOperand::createImm(cc));
668
669 return MCDisassembler::Success;
670 }