Skip to contentSkip to conversation

target-microblaze: Misc bug fixes

PATCH Superseded Edgar E. Iglesias 4 participants 13 messages Apr 19, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target-microblaze: Misc bug fixes

From: "Edgar E. Iglesias" <[email protected]>

Hi,

This is a series of fixes for bugs I ran into when adding support for extended addressing. It would be nice to get these into 2.12 if it's not too late.

Cheers,
Edgar

Edgar E. Iglesias (5):
target-microblaze: Respect MSR.PVR as read-only
target-microblaze: Fix trap checks for FPU insns
target-microblaze: Don't clobber the IMM reg for ld/st reversed
target-microblaze: mmu: Make TLBSX write-only
target-microblaze: mmu: Make the TLBX MISS bit read-only

 target/microblaze/cpu.h       |  4 +++-
 target/microblaze/mmu.c       |  9 ++++++++-
 target/microblaze/translate.c | 12 ++----------
 3 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/5 target-microblaze: Respect MSR.PVR as read-only

From: "Edgar E. Iglesias" <[email protected]>

Respect MSR.PVR as read-only. We were wrongly overwriting the PVR bit.

---
 target/microblaze/cpu.h       | 4 +++-
 target/microblaze/translate.c | 8 +-------
 2 files changed, 4 insertions(+), 8 deletions(-)
target/microblaze/cpu.h +3 -1
index 5be71bc320..0eb9e2b8e2 100644
@@ -59,6 +59,8 @@ typedef struct CPUMBState CPUMBState;
 #define SR_EDR   0xd
 
 /* MSR flags.  */
+#define MSR_PVR_SHIFT 10
+
 #define MSR_BE  (1<<0) /* 0x001 */
 #define MSR_IE  (1<<1) /* 0x002 */
 #define MSR_C   (1<<2) /* 0x004 */
@@ -69,7 +71,7 @@ typedef struct CPUMBState CPUMBState;
 #define MSR_DCE (1<<7) /* 0x080 */
 #define MSR_EE  (1<<8) /* 0x100 */
 #define MSR_EIP (1<<9) /* 0x200 */
-#define MSR_PVR (1<<10) /* 0x400 */
+#define MSR_PVR (1 << MSR_PVR_SHIFT)
 #define MSR_CC  (1<<31)
 
 /* Machine State Register (MSR) Fields */
target/microblaze/translate.c +1 -7
index 7628b0e25b..df62563815 100644
@@ -417,15 +417,9 @@ static inline void msr_read(DisasContext *dc, TCGv d)
 
 static inline void msr_write(DisasContext *dc, TCGv v)
 {
-    TCGv t;
-
-    t = tcg_temp_new();
     dc->cpustate_changed = 1;
     /* PVR bit is not writable.  */
-    tcg_gen_andi_tl(t, v, ~MSR_PVR);
-    tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
-    tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
-    tcg_temp_free(t);
+    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);
 }
 
 static void dec_msr(DisasContext *dc)
Signature · 1 line
2.14.1
#2 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] target-microblaze: Respect MSR.PVR as read-only

target/microblaze/translate.c static inline void msr_read(DisasContext *dc, TCGv d) · line 423

Quoted 13 lines · Edgar E. Iglesias

static inline void msr_write(DisasContext *dc, TCGv v) {

target/microblaze/translate.c +1 -7
-    TCGv t;
-
-    t = tcg_temp_new();
     dc->cpustate_changed = 1;
     /* PVR bit is not writable.  */
-    tcg_gen_andi_tl(t, v, ~MSR_PVR);
-    tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
-    tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
-    tcg_temp_free(t);
+    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);
 }

Um... the old code was correct, but the new code isn't.

The new code sets msr to v, with bit 10 set to the old msr bit 0.

Why do you believe the old code to be wrong?

r~

#3 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] target-microblaze: Respect MSR.PVR as read-only

Quoted 15 lines · Richard Henderson

target/microblaze/translate.c static inline void msr_read(DisasContext *dc, TCGv d) · line 423

Quoted 13 lines · Edgar E. Iglesias

static inline void msr_write(DisasContext *dc, TCGv v) {

target/microblaze/translate.c +1 -7
-    TCGv t;
-
-    t = tcg_temp_new();
     dc->cpustate_changed = 1;
     /* PVR bit is not writable.  */
-    tcg_gen_andi_tl(t, v, ~MSR_PVR);
-    tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
-    tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
-    tcg_temp_free(t);
+    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);
 }
Quoted 5 lines

Um... the old code was correct, but the new code isn't.

The new code sets msr to v, with bit 10 set to the old msr bit 0.

Why do you believe the old code to be wrong?

The old code was incorrectly ORing v instead of t...

What about the following?

    tcg_gen_shri_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR_SHIFT);
    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);

Cheers,
Edgar

#4 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] target-microblaze: Respect MSR.PVR as read-only

Quoted 16 lines · Edgar E. Iglesias
Quoted 15 lines · Richard Henderson
Quoted 13 lines · Edgar E. Iglesias

static inline void msr_write(DisasContext *dc, TCGv v) {

target/microblaze/translate.c +1 -7
-    TCGv t;
-
-    t = tcg_temp_new();
     dc->cpustate_changed = 1;
     /* PVR bit is not writable.  */
-    tcg_gen_andi_tl(t, v, ~MSR_PVR);
-    tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
-    tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
-    tcg_temp_free(t);
+    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);
 }
Quoted 7 lines
Quoted 5 lines

Um... the old code was correct, but the new code isn't.

The new code sets msr to v, with bit 10 set to the old msr bit 0.

Why do you believe the old code to be wrong?

The old code was incorrectly ORing v instead of t...

Ah, yes.

Quoted 3 lines

What about the following?

    tcg_gen_shri_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR_SHIFT);
    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);

*shrug* While that would be functional, I don't think it's any better than just fixing the typo in the OR.

r~

#5 lore raw

Re: [Qemu-devel] [PATCH v1 1/5] target-microblaze: Respect MSR.PVR as read-only

Quoted 25 lines · Richard Henderson
Quoted 16 lines · Edgar E. Iglesias
Quoted 15 lines · Richard Henderson
Quoted 13 lines · Edgar E. Iglesias

static inline void msr_write(DisasContext *dc, TCGv v) {

target/microblaze/translate.c +1 -7
-    TCGv t;
-
-    t = tcg_temp_new();
     dc->cpustate_changed = 1;
     /* PVR bit is not writable.  */
-    tcg_gen_andi_tl(t, v, ~MSR_PVR);
-    tcg_gen_andi_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
-    tcg_gen_or_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], v);
-    tcg_temp_free(t);
+    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);
 }
Quoted 7 lines
Quoted 5 lines

Um... the old code was correct, but the new code isn't.

The new code sets msr to v, with bit 10 set to the old msr bit 0.

Why do you believe the old code to be wrong?

The old code was incorrectly ORing v instead of t...

Quoted 8 lines

Ah, yes.

Quoted 3 lines

What about the following?

    tcg_gen_shri_tl(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR_SHIFT);
    tcg_gen_deposit_tl(cpu_SR[SR_MSR], v, cpu_SR[SR_MSR], MSR_PVR_SHIFT, 1);

*shrug* While that would be functional, I don't think it's any better than just fixing the typo in the OR.

Allright, I'll fix the typo and send out a v2.

Thanks for catching this.

Cheers,
Edgar

#6 lore raw

PATCH 2/5 target-microblaze: Fix trap checks for FPU insns

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Fix trap checks for FPU insns when extended FPU insns are enabled.

---
 target/microblaze/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/microblaze/translate.c +1 -1
index df62563815..5f9efcdd11 100644
@@ -1406,7 +1406,7 @@ static void dec_fpu(DisasContext *dc)
 
     if ((dc->tb_flags & MSR_EE_FLAG)
           && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
-          && (dc->cpu->cfg.use_fpu != 1)) {
+          && !dc->cpu->cfg.use_fpu) {
         tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
         t_gen_raise_exception(dc, EXCP_HW_EXCP);
         return;
Signature · 1 line
2.14.1
Reviewed-by on v1 2/5
#7 lore raw

Re: [Qemu-devel] [PATCH v1 2/5] target-microblaze: Fix trap checks for FPU insns

Quoted 5 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Fix trap checks for FPU insns when extended FPU insns are enabled.

Alistair

Quoted 21 lines
---
 target/microblaze/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/microblaze/translate.c +1 -2
index df62563815..5f9efcdd11 100644
@@ -1406,7 +1406,7 @@ static void dec_fpu(DisasContext *dc)
 
     if ((dc->tb_flags & MSR_EE_FLAG)
           && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)
-          && (dc->cpu->cfg.use_fpu != 1)) {
+          && !dc->cpu->cfg.use_fpu) {
         tcg_gen_movi_tl(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
         t_gen_raise_exception(dc, EXCP_HW_EXCP);
         return;
--

2.14.1

#8 lore raw

PATCH 3/5 target-microblaze: Don't clobber the IMM reg for ld/st reversed

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Do not clobber the IMM register on reversed load/stores.

---
 target/microblaze/translate.c | 2 --
 1 file changed, 2 deletions(-)
target/microblaze/translate.c +0 -2
index 5f9efcdd11..9dcbdf5509 100644
@@ -946,7 +946,6 @@ static void dec_load(DisasContext *dc)
                 tcg_gen_sub_tl(low, tcg_const_tl(3), low);
                 tcg_gen_andi_tl(t, t, ~3);
                 tcg_gen_or_tl(t, t, low);
-                tcg_gen_mov_tl(env_imm, t);
                 tcg_temp_free(low);
                 break;
             }
@@ -1098,7 +1097,6 @@ static void dec_store(DisasContext *dc)
                 tcg_gen_sub_tl(low, tcg_const_tl(3), low);
                 tcg_gen_andi_tl(t, t, ~3);
                 tcg_gen_or_tl(t, t, low);
-                tcg_gen_mov_tl(env_imm, t);
                 tcg_temp_free(low);
                 break;
             }
Signature · 1 line
2.14.1
#9 lore raw

PATCH 4/5 target-microblaze: mmu: Make TLBSX write-only

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Make TLBSX write-only and guest-error log reads from it.

---
 target/microblaze/mmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/microblaze/mmu.c +4 -1
index a0f06758f8..8391811900 100644
@@ -182,7 +182,7 @@ done:
 uint32_t mmu_read(CPUMBState *env, uint32_t rn)
 {
     unsigned int i;
-    uint32_t r;
+    uint32_t r = 0;
 
     if (env->mmu.c_mmu < 2 || !env->mmu.c_mmu_tlb_access) {
         qemu_log_mask(LOG_GUEST_ERROR, "MMU access on MMU-less system\n");
@@ -211,6 +211,9 @@ uint32_t mmu_read(CPUMBState *env, uint32_t rn)
             }
             r = env->mmu.regs[rn];
             break;
+        case MMU_R_TLBSX:
+            qemu_log_mask(LOG_GUEST_ERROR, "TLBSX is write-only.\n");
+            break;
         default:
             r = env->mmu.regs[rn];
             break;
Signature · 1 line
2.14.1
Reviewed-by on v1 4/5
#10 lore raw

Re: [Qemu-devel] [PATCH v1 4/5] target-microblaze: mmu: Make TLBSX write-only

Quoted 5 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Make TLBSX write-only and guest-error log reads from it.

Alistair

Quoted 31 lines
---
 target/microblaze/mmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/microblaze/mmu.c +4 -2
index a0f06758f8..8391811900 100644
@@ -182,7 +182,7 @@ done:
 uint32_t mmu_read(CPUMBState *env, uint32_t rn)
 {
     unsigned int i;
-    uint32_t r;
+    uint32_t r = 0;
 
     if (env->mmu.c_mmu < 2 || !env->mmu.c_mmu_tlb_access) {
         qemu_log_mask(LOG_GUEST_ERROR, "MMU access on MMU-less system\n");
@@ -211,6 +211,9 @@ uint32_t mmu_read(CPUMBState *env, uint32_t rn)
             }
             r = env->mmu.regs[rn];
             break;
+        case MMU_R_TLBSX:
+            qemu_log_mask(LOG_GUEST_ERROR, "TLBSX is write-only.\n");
+            break;
         default:
             r = env->mmu.regs[rn];
             break;
--

2.14.1

#11 lore raw

PATCH 5/5 target-microblaze: mmu: Make the TLBX MISS bit read-only

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Make the TLBX MISS bit read-only.

---
 target/microblaze/mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/microblaze/mmu.c +4 -0
index 8391811900..9d5e6aa8a5 100644
@@ -273,6 +273,10 @@ void mmu_write(CPUMBState *env, uint32_t rn, uint32_t v)
                 env->mmu.regs[rn] = v;
             }
             break;
+        case MMU_R_TLBX:
+            /* Bit 31 is read-only.  */
+            env->mmu.regs[rn] = deposit32(env->mmu.regs[rn], 0, 31, v);
+            break;
         case MMU_R_TLBSX:
         {
             struct microblaze_mmu_lookup lu;
Signature · 1 line
2.14.1
Reviewed-by on v1 5/5
#12 lore raw

Re: [Qemu-devel] [PATCH v1 5/5] target-microblaze: mmu: Make the TLBX MISS bit read-only

Quoted 5 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Make the TLBX MISS bit read-only.

Alistair

Quoted 23 lines
---
 target/microblaze/mmu.c | 4 ++++
 1 file changed, 4 insertions(+)
target/microblaze/mmu.c +4 -1
index 8391811900..9d5e6aa8a5 100644
@@ -273,6 +273,10 @@ void mmu_write(CPUMBState *env, uint32_t rn, uint32_t v)
                 env->mmu.regs[rn] = v;
             }
             break;
+        case MMU_R_TLBX:
+            /* Bit 31 is read-only.  */
+            env->mmu.regs[rn] = deposit32(env->mmu.regs[rn], 0, 31, v);
+            break;
         case MMU_R_TLBSX:
         {
             struct microblaze_mmu_lookup lu;
--

2.14.1