aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Target/BPF/Disassembler
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-30 16:33:32 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-30 16:33:32 +0000
commit51315c45ff5643a27f9c84b816db54ee870ba29b (patch)
tree1d87443fa0e53d3e6b315ce25787e64be0906bf7 /contrib/llvm/lib/Target/BPF/Disassembler
parent6dfd050075216be8538ae375a22d30db72916f7e (diff)
parenteb11fae6d08f479c0799db45860a98af528fa6e7 (diff)
Merge llvm trunk r338150, and resolve conflicts.
Notes
Notes: svn path=/projects/clang700-import/; revision=336916
Diffstat (limited to 'contrib/llvm/lib/Target/BPF/Disassembler')
-rw-r--r--contrib/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/contrib/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp b/contrib/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
index 6fc87d79c439..e7790ddb3d7e 100644
--- a/contrib/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
+++ b/contrib/llvm/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
@@ -35,6 +35,34 @@ namespace {
/// A disassembler class for BPF.
class BPFDisassembler : public MCDisassembler {
public:
+ enum BPF_CLASS {
+ BPF_LD = 0x0,
+ BPF_LDX = 0x1,
+ BPF_ST = 0x2,
+ BPF_STX = 0x3,
+ BPF_ALU = 0x4,
+ BPF_JMP = 0x5,
+ BPF_RES = 0x6,
+ BPF_ALU64 = 0x7
+ };
+
+ enum BPF_SIZE {
+ BPF_W = 0x0,
+ BPF_H = 0x1,
+ BPF_B = 0x2,
+ BPF_DW = 0x3
+ };
+
+ enum BPF_MODE {
+ BPF_IMM = 0x0,
+ BPF_ABS = 0x1,
+ BPF_IND = 0x2,
+ BPF_MEM = 0x3,
+ BPF_LEN = 0x4,
+ BPF_MSH = 0x5,
+ BPF_XADD = 0x6
+ };
+
BPFDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
: MCDisassembler(STI, Ctx) {}
~BPFDisassembler() override = default;
@@ -43,6 +71,10 @@ public:
ArrayRef<uint8_t> Bytes, uint64_t Address,
raw_ostream &VStream,
raw_ostream &CStream) const override;
+
+ uint8_t getInstClass(uint64_t Inst) const { return (Inst >> 56) & 0x7; };
+ uint8_t getInstSize(uint64_t Inst) const { return (Inst >> 59) & 0x3; };
+ uint8_t getInstMode(uint64_t Inst) const { return (Inst >> 61) & 0x7; };
};
} // end anonymous namespace
@@ -141,8 +173,17 @@ DecodeStatus BPFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
Result = readInstruction64(Bytes, Address, Size, Insn, IsLittleEndian);
if (Result == MCDisassembler::Fail) return MCDisassembler::Fail;
- Result = decodeInstruction(DecoderTableBPF64, Instr, Insn,
- Address, this, STI);
+ uint8_t InstClass = getInstClass(Insn);
+ if ((InstClass == BPF_LDX || InstClass == BPF_STX) &&
+ getInstSize(Insn) != BPF_DW &&
+ getInstMode(Insn) == BPF_MEM &&
+ STI.getFeatureBits()[BPF::ALU32])
+ Result = decodeInstruction(DecoderTableBPFALU3264, Instr, Insn, Address,
+ this, STI);
+ else
+ Result = decodeInstruction(DecoderTableBPF64, Instr, Insn, Address, this,
+ STI);
+
if (Result == MCDisassembler::Fail) return MCDisassembler::Fail;
switch (Instr.getOpcode()) {