[llvm] r301653 - [bpf] add bigendian support to disassembler
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 10:12:01 PDT 2017
llvm/include/llvm/Support/Endian.h provides read32le and read32be to read
32-bit little or big-endian integers. Doesn't it work for you?
On Fri, Apr 28, 2017 at 9:51 AM, Alexei Starovoitov via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: ast
> Date: Fri Apr 28 11:51:01 2017
> New Revision: 301653
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301653&view=rev
> Log:
> [bpf] add bigendian support to disassembler
>
> . swap 4-bit register encoding, 16-bit offset and 32-bit imm to support
> big endian archs
> . add a test
>
> Reported-by: David S. Miller <davem at davemloft.net>
> Signed-off-by: Alexei Starovoitov <ast at kernel.org>
>
> Added:
> llvm/trunk/test/CodeGen/BPF/mem_offset_be.ll
> Modified:
> llvm/trunk/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
>
> Modified: llvm/trunk/lib/Target/BPF/Disassembler/BPFDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/
> BPF/Disassembler/BPFDisassembler.cpp?rev=301653&r1=301652&r2=301653&
> view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Target/BPF/Disassembler/BPFDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/BPF/Disassembler/BPFDisassembler.cpp Fri Apr 28
> 11:51:01 2017
> @@ -17,6 +17,8 @@
> #include "llvm/ADT/ArrayRef.h"
> #include "llvm/MC/MCDisassembler/MCDisassembler.h"
> #include "llvm/MC/MCFixedLenDisassembler.h"
> +#include "llvm/MC/MCContext.h"
> +#include "llvm/MC/MCAsmInfo.h"
> #include "llvm/MC/MCInst.h"
> #include "llvm/Support/MathExtras.h"
> #include "llvm/Support/TargetRegistry.h"
> @@ -88,9 +90,9 @@ static DecodeStatus decodeMemoryOpValue(
> }
>
> #include "BPFGenDisassemblerTables.inc"
> -
> static DecodeStatus readInstruction64(ArrayRef<uint8_t> Bytes, uint64_t
> Address,
> - uint64_t &Size, uint64_t &Insn) {
> + uint64_t &Size, uint64_t &Insn,
> + bool IsLittleEndian) {
> uint64_t Lo, Hi;
>
> if (Bytes.size() < 8) {
> @@ -99,8 +101,14 @@ static DecodeStatus readInstruction64(Ar
> }
>
> Size = 8;
> - Hi = (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 0) | (Bytes[3]
> << 8);
> - Lo = (Bytes[4] << 0) | (Bytes[5] << 8) | (Bytes[6] << 16) | (Bytes[7]
> << 24);
> + if (IsLittleEndian) {
> + Hi = (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 0) |
> (Bytes[3] << 8);
> + Lo = (Bytes[4] << 0) | (Bytes[5] << 8) | (Bytes[6] << 16) | (Bytes[7]
> << 24);
> + } else {
> + Hi = (Bytes[0] << 24) | ((Bytes[1] & 0x0F) << 20) | ((Bytes[1] &
> 0xF0) << 12) |
> + (Bytes[2] << 8) | (Bytes[3] << 0);
> + Lo = (Bytes[4] << 24) | (Bytes[5] << 16) | (Bytes[6] << 8) |
> (Bytes[7] << 0);
> + }
> Insn = Make_64(Hi, Lo);
>
> return MCDisassembler::Success;
> @@ -111,10 +119,11 @@ DecodeStatus BPFDisassembler::getInstruc
> uint64_t Address,
> raw_ostream &VStream,
> raw_ostream &CStream) const {
> - uint64_t Insn;
> + bool IsLittleEndian = getContext().getAsmInfo()->isLittleEndian();
> + uint64_t Insn, Hi;
> DecodeStatus Result;
>
> - Result = readInstruction64(Bytes, Address, Size, Insn);
> + Result = readInstruction64(Bytes, Address, Size, Insn, IsLittleEndian);
> if (Result == MCDisassembler::Fail) return MCDisassembler::Fail;
>
> Result = decodeInstruction(DecoderTableBPF64, Instr, Insn,
> @@ -128,7 +137,10 @@ DecodeStatus BPFDisassembler::getInstruc
> return MCDisassembler::Fail;
> }
> Size = 16;
> - uint64_t Hi = (Bytes[12] << 0) | (Bytes[13] << 8) | (Bytes[14] << 16)
> | (Bytes[15] << 24);
> + if (IsLittleEndian)
> + Hi = (Bytes[12] << 0) | (Bytes[13] << 8) | (Bytes[14] << 16) |
> (Bytes[15] << 24);
> + else
> + Hi = (Bytes[12] << 24) | (Bytes[13] << 16) | (Bytes[14] << 8) |
> (Bytes[15] << 0);
> auto& Op = Instr.getOperand(1);
> Op.setImm(Make_64(Hi, Op.getImm()));
> break;
>
> Added: llvm/trunk/test/CodeGen/BPF/mem_offset_be.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> CodeGen/BPF/mem_offset_be.ll?rev=301653&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/CodeGen/BPF/mem_offset_be.ll (added)
> +++ llvm/trunk/test/CodeGen/BPF/mem_offset_be.ll Fri Apr 28 11:51:01 2017
> @@ -0,0 +1,18 @@
> +; RUN: llc -march=bpfeb -show-mc-encoding < %s | FileCheck %s
> +
> +; Function Attrs: nounwind
> +define i32 @bpf_prog1(i8* nocapture readnone) local_unnamed_addr #0 {
> +; CHECK: r1 = 590618314553ll # encoding: [0x18,0x10,0x00,0x00,0x83,
> 0x98,0x47,0x39,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x89]
> +; CHECK: r1 += -1879113726 # encoding: [0x07,0x10,0x00,0x00,0x8f,
> 0xff,0x00,0x02]
> +; CHECK: r0 = *(u64 *)(r1 + 0) # encoding: [0x79,0x01,0x00,0x00,0x00,
> 0x00,0x00,0x00]
> + %2 = alloca i64, align 8
> + %3 = bitcast i64* %2 to i8*
> + store volatile i64 590618314553, i64* %2, align 8
> + %4 = load volatile i64, i64* %2, align 8
> + %5 = add i64 %4, -1879113726
> + %6 = inttoptr i64 %5 to i64*
> + %7 = load i64, i64* %6, align 8
> + %8 = trunc i64 %7 to i32
> + ret i32 %8
> +}
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170428/3e73ee00/attachment.html>
More information about the llvm-commits
mailing list