28#define DEBUG_TYPE "bpf-disassembler"
66 ~BPFDisassembler()
override =
default;
72 uint8_t getInstClass(
uint64_t Inst)
const {
return (Inst >> 56) & 0x7; };
73 uint8_t getInstSize(
uint64_t Inst)
const {
return (Inst >> 59) & 0x3; };
74 uint8_t getInstMode(
uint64_t Inst)
const {
return (Inst >> 61) & 0x7; };
82 return new BPFDisassembler(STI, Ctx);
97 BPF::R0, BPF::R1, BPF::R2, BPF::R3, BPF::R4, BPF::R5,
98 BPF::R6, BPF::R7, BPF::R8, BPF::R9, BPF::R10, BPF::R11};
112 BPF::W0, BPF::W1, BPF::W2, BPF::W3, BPF::W4, BPF::W5,
113 BPF::W6, BPF::W7, BPF::W8, BPF::W9, BPF::W10, BPF::W11};
140#include "BPFGenDisassemblerTables.inc"
143 bool IsLittleEndian) {
146 if (Bytes.
size() < 8) {
152 if (IsLittleEndian) {
153 Hi = (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 0) | (Bytes[3] << 8);
154 Lo = (Bytes[4] << 0) | (Bytes[5] << 8) | (Bytes[6] << 16) | (Bytes[7] << 24);
156 Hi = (Bytes[0] << 24) | ((Bytes[1] & 0x0F) << 20) | ((Bytes[1] & 0xF0) << 12) |
157 (Bytes[2] << 8) | (Bytes[3] << 0);
158 Lo = (Bytes[4] << 24) | (Bytes[5] << 16) | (Bytes[6] << 8) | (Bytes[7] << 0);
169 bool IsLittleEndian = getContext().getAsmInfo()->isLittleEndian();
176 uint8_t InstClass = getInstClass(
Insn);
177 uint8_t InstMode = getInstMode(
Insn);
178 if ((InstClass == BPF_LDX || InstClass == BPF_STX) &&
179 getInstSize(
Insn) != BPF_DW &&
180 (InstMode == BPF_MEM || InstMode == BPF_ATOMIC) &&
181 STI.hasFeature(BPF::ALU32))
182 Result = decodeInstruction(DecoderTableBPFALU3264, Instr,
Insn, Address,
185 Result = decodeInstruction(DecoderTableBPF64, Instr,
Insn, Address,
this,
190 switch (
Instr.getOpcode()) {
192 case BPF::LD_pseudo: {
193 if (Bytes.
size() < 16) {
199 Hi = (Bytes[12] << 0) | (Bytes[13] << 8) | (Bytes[14] << 16) | (Bytes[15] << 24);
201 Hi = (Bytes[12] << 24) | (Bytes[13] << 16) | (Bytes[14] << 8) | (Bytes[15] << 0);
202 auto&
Op =
Instr.getOperand(1);
211 case BPF::LD_IND_W: {
SmallVector< AArch64_IMM::ImmInsnModel, 4 > Insn
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus decodeMemoryOpValue(MCInst &Inst, unsigned Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus readInstruction64(ArrayRef< uint8_t > Bytes, uint64_t Address, uint64_t &Size, uint64_t &Insn, bool IsLittleEndian)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFDisassembler()
DecodeStatus(* DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address, const MCDisassembler *Decoder)
static const unsigned GPR32DecoderTable[]
static const unsigned GPRDecoderTable[]
static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t, const MCDisassembler *)
static MCDisassembler * createBPFDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t, const MCDisassembler *)
#define LLVM_EXTERNAL_VISIBILITY
support::ulittle16_t & Lo
support::ulittle16_t & Hi
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
This class represents an Operation in the Expression.
Context object for machine code objects.
Superclass for all disassemblers.
DecodeStatus
Ternary decode status.
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
Instances of this class represent a single low-level machine instruction.
void addOperand(const MCOperand Op)
static MCOperand createReg(unsigned Reg)
static MCOperand createImm(int64_t Val)
Generic base class for all target subtargets.
Wrapper class representing virtual and physical registers.
Target - Wrapper for Target specific information.
This class implements an extremely fast bulk output stream that can only output to a stream.
NodeAddr< InstrNode * > Instr
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheBPFleTarget()
Target & getTheBPFbeTarget()
Target & getTheBPFTarget()
constexpr uint64_t Make_64(uint32_t High, uint32_t Low)
Make a 64-bit integer from a high / low pair of 32-bit integers.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.