Skip to contentSkip to conversation

target/hppa: Generate illegal instruction exception for 64-bit instructions

PATCH Superseded Helge Deller 2 participants 3 messages Sep 24, 2022 – Sep 28, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/hppa: Generate illegal instruction exception for 64-bit instructions

Qemu currently emulates a 32-bit CPU only, and crashes with this error when it faces a 64-bit load (e.g. "ldd 0(r26),r0") or 64-bit store (e.g. "std r26,0(r26)") instruction in the guest:

ERROR:../qemu/tcg/tcg-op.c:2822:tcg_canonicalize_memop: code should not be reached

Fix this by adding checks for 64-bit sizes and generate an illegal instruction exception if necessary.

target/hppa/translate.c +11 -2
index b8dbfee5e9..287cc410cd 100644
@@ -1568,7 +1568,12 @@ static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
         /* Make sure if RT == RB, we see the result of the load.  */
         dest = get_temp(ctx);
     }
-    do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+        dest = tcg_constant_reg(0);
+    } else {
+        do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    }
     save_gpr(ctx, rt, dest);
 
     return nullify_end(ctx);
@@ -1631,7 +1636,11 @@ static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb,
                      int modify, MemOp mop)
 {
     nullify_over(ctx);
-    do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+    } else {
+        do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    }
     return nullify_end(ctx);
 }
 
#1 lore raw
Quoted 16 lines · Helge Deller

Qemu currently emulates a 32-bit CPU only, and crashes with this error when it faces a 64-bit load (e.g. "ldd 0(r26),r0") or 64-bit store (e.g. "std r26,0(r26)") instruction in the guest:

ERROR:../qemu/tcg/tcg-op.c:2822:tcg_canonicalize_memop: code should not be reached

Fix this by adding checks for 64-bit sizes and generate an illegal instruction exception if necessary.

target/hppa/translate.c +0 -0
index b8dbfee5e9..287cc410cd 100644

target/hppa/translate.c static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, · line 1576

Quoted 10 lines
target/hppa/translate.c +6 -1
@@ -1568,7 +1568,12 @@ static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
          /* Make sure if RT == RB, we see the result of the load.  */
          dest = get_temp(ctx);
      }
-    do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+        dest = tcg_constant_reg(0);
+    } else {
+        do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    }

This should be done in trans_ld,

target/hppa/translate.c static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, · line 1643

Quoted 10 lines
target/hppa/translate.c +5 -1
@@ -1631,7 +1636,11 @@ static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb,
                       int modify, MemOp mop)
  {
      nullify_over(ctx);
-    do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+    } else {
+        do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    }

and this in trans_st.

r~

#2 lore raw
Quoted 30 lines · Richard Henderson
Quoted 16 lines · Helge Deller

Qemu currently emulates a 32-bit CPU only, and crashes with this error when it faces a 64-bit load (e.g.  "ldd 0(r26),r0") or 64-bit store (e.g. "std r26,0(r26)") instruction in the guest:

ERROR:../qemu/tcg/tcg-op.c:2822:tcg_canonicalize_memop: code should not be reached

Fix this by adding checks for 64-bit sizes and generate an illegal instruction exception if necessary.

target/hppa/translate.c +0 -0
index b8dbfee5e9..287cc410cd 100644

target/hppa/translate.c static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb, · line 1576

Quoted 10 lines
target/hppa/translate.c +6 -1
@@ -1568,7 +1568,12 @@ static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
           /* Make sure if RT == RB, we see the result of the load.  */
           dest = get_temp(ctx);
       }
-    do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+        dest = tcg_constant_reg(0);
+    } else {
+        do_load_reg(ctx, dest, rb, rx, scale, disp, sp, modify, mop);
+    }

This should be done in trans_ld,

Quoted 12 lines

target/hppa/translate.c static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb, · line 1643

Quoted 10 lines
target/hppa/translate.c +5 -1
@@ -1631,7 +1636,11 @@ static bool do_store(DisasContext *ctx, unsigned rt, unsigned rb,
                        int modify, MemOp mop)
   {
       nullify_over(ctx);
-    do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    if (unlikely(TARGET_REGISTER_BITS == 32 && (mop & MO_SIZE) > MO_32)) {
+        gen_illegal(ctx);
+    } else {
+        do_store_reg(ctx, load_gpr(ctx, rt), rb, 0, 0, disp, sp, modify, mop);
+    }

and this in trans_st.

Yes, you're right.
Will resend fixed patch.

Helge