]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
riscv: Ensure LE instruction fetching
authorBranislav Brzak <branislav.brzak@syrmia.com>
Tue, 20 Jun 2023 14:19:55 +0000 (16:19 +0200)
committerTom Tromey <tom@tromey.com>
Thu, 6 Jul 2023 15:57:04 +0000 (09:57 -0600)
Currently riscv gdb code looks at arch byte order
when fetching instructions. This works when the
target is LE, but on BE arch it will byte swap the
instruction, while the riscv spec defines all
instructions are LE encoded regardless of
system memory endianess.

gdb/riscv-tdep.c

index 500279e1ae9ecc9bd1971aef000a5c7f91f1a0ec..ae18eb644527e90570bdf434914e0e2145bbf1ab 100644 (file)
@@ -1812,7 +1812,6 @@ ULONGEST
 riscv_insn::fetch_instruction (struct gdbarch *gdbarch,
                               CORE_ADDR addr, int *len)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order_for_code (gdbarch);
   gdb_byte buf[RISCV_MAX_INSN_LEN];
   int instlen, status;
 
@@ -1833,7 +1832,8 @@ riscv_insn::fetch_instruction (struct gdbarch *gdbarch,
        memory_error (TARGET_XFER_E_IO, addr + 2);
     }
 
-  return extract_unsigned_integer (buf, instlen, byte_order);
+  /* RISC-V Specification states instructions are always little endian */
+  return extract_unsigned_integer (buf, instlen, BFD_ENDIAN_LITTLE);
 }
 
 /* Fetch from target memory an instruction at PC and decode it.  This can