Skip to contentSkip to conversation

tcg/mips: Bugfix for crash when running program with qemu-i386.

PATCH Superseded Jiang Biao 2 participants 2 messages Jul 10, 2017

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiang Biao

author
#0 lore raw

PATCH v2 1/1 tcg/mips: Bugfix for crash when running program with qemu-i386.

When running a helloworld program with qemu-i386 in linux-user mode on Loongson 3A3000, it will crash. The reasion is wrong assigning from base to addr_regl directly. This patch fix the bug.

---
 tcg/mips/tcg-target.inc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tcg/mips/tcg-target.inc.c +6 -4
index 8cff9a6..cebca8e 100644
@@ -1539,16 +1539,18 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
                         s->code_ptr, label_ptr);
 #else
     if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
-        tcg_out_ext32u(s, base, addr_regl);
-        addr_regl = base;
+        tcg_out_ext32u(s, TCG_TMP0, addr_regl);
+    } else {
+        tcg_out_mov(s, TCG_TYPE_PTR, TCG_TMP0, addr_regl);
     }
+
     if (guest_base == 0 && data_regl != addr_regl) {
         base = addr_regl;
     } else if (guest_base == (int16_t)guest_base) {
-        tcg_out_opc_imm(s, ALIAS_PADDI, base, addr_regl, guest_base);
+        tcg_out_opc_imm(s, ALIAS_PADDI, base, TCG_TMP0, guest_base);
     } else {
         tcg_out_movi(s, TCG_TYPE_PTR, base, guest_base);
-        tcg_out_opc_reg(s, ALIAS_PADD, base, base, addr_regl);
+        tcg_out_opc_reg(s, ALIAS_PADD, base, base, TCG_TMP0);
     }
     tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
 #endif
Signature · 1 line
2.7.4
#1 lore raw
Quoted 16 lines · Jiang Biao

When running a helloworld program with qemu-i386 in linux-user mode on Loongson 3A3000, it will crash. The reasion is wrong assigning from base to addr_regl directly. This patch fix the bug.

---
  tcg/mips/tcg-target.inc.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
tcg/mips/tcg-target.inc.c +0 -0
index 8cff9a6..cebca8e 100644

tcg/mips/tcg-target.inc.c static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64) · line 1545

Quoted 9 lines
tcg/mips/tcg-target.inc.c +3 -2
@@ -1539,16 +1539,18 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
                          s->code_ptr, label_ptr);
  #else
      if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
-        tcg_out_ext32u(s, base, addr_regl);
-        addr_regl = base;
+        tcg_out_ext32u(s, TCG_TMP0, addr_regl);
+    } else {
+        tcg_out_mov(s, TCG_TYPE_PTR, TCG_TMP0, addr_regl);
      }

No, this is exactly why the assignment to the addr_regl variable exists, so that you do not need to emit an extra instruction for a 64-bit guest.

r~