Skip to contentSkip to conversation

target-mips: Fix RDHWR on CP0.Count

PATCH In review Alex Smith 3 participants 4 messages Sep 8, 2015 – Sep 16, 2015

lore
Share & tools
lore

Alex Smith

author
#0 lore raw

PATCH v2 1/1 target-mips: Fix RDHWR on CP0.Count

For RDHWR on the CP0.Count register, env->CP0_Count was being returned. This value is a delta against the QEMU_CLOCK_VIRTUAL clock, not the correct current value of CP0.Count. Use cpu_mips_get_count() instead.

Cc Aurelien Jarno <[email protected]>
Cc Leon Alrae <[email protected]>

---
Changes in v2:
- Fix build breakage for user builds.
- Correct existing code to follow QEMU coding style.

---
 target-mips/op_helper.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
target-mips/op_helper.c +7 -2
index 809a061e296b..99574322a29c 100644
@@ -2184,10 +2184,15 @@ target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
 target_ulong helper_rdhwr_cc(CPUMIPSState *env)
 {
     if ((env->hflags & MIPS_HFLAG_CP0) ||
-        (env->CP0_HWREna & (1 << 2)))
+        (env->CP0_HWREna & (1 << 2))) {
+#ifdef CONFIG_USER_ONLY
         return env->CP0_Count;
-    else
+#else
+        return (int32_t)cpu_mips_get_count(env);
+#endif
+    } else {
         helper_raise_exception(env, EXCP_RI);
+    }
 
     return 0;
 }
Signature · 1 line
2.5.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Alex Smith

For RDHWR on the CP0.Count register, env->CP0_Count was being returned. This value is a delta against the QEMU_CLOCK_VIRTUAL clock, not the correct current value of CP0.Count. Use cpu_mips_get_count() instead.

Cc Aurelien Jarno <[email protected]>
Cc Leon Alrae <[email protected]>
Quoted 7 lines

---
Changes in v2:
- Fix build breakage for user builds.
- Correct existing code to follow QEMU coding style.

---
 target-mips/op_helper.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Alex Smith
Quoted 27 lines · Alex Smith

For RDHWR on the CP0.Count register, env->CP0_Count was being returned. This value is a delta against the QEMU_CLOCK_VIRTUAL clock, not the correct current value of CP0.Count. Use cpu_mips_get_count() instead.

Cc Aurelien Jarno <[email protected]>
Cc Leon Alrae <[email protected]>

---
Changes in v2:
- Fix build breakage for user builds.
- Correct existing code to follow QEMU coding style.

---
 target-mips/op_helper.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
target-mips/op_helper.c +2 -1
index 809a061e296b..99574322a29c 100644
@@ -2184,10 +2184,15 @@ target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
 target_ulong helper_rdhwr_cc(CPUMIPSState *env)
 {
     if ((env->hflags & MIPS_HFLAG_CP0) ||
-        (env->CP0_HWREna & (1 << 2)))
+        (env->CP0_HWREna & (1 << 2))) {
+#ifdef CONFIG_USER_ONLY
         return env->CP0_Count;

target-mips/op_helper.c target_ulong helper_rdhwr_synci_step(CPUMIPSState *env) · line 2198

Quoted 10 lines
target-mips/op_helper.c +5 -1
-    else
+#else
+        return (int32_t)cpu_mips_get_count(env);
+#endif
+    } else {
         helper_raise_exception(env, EXCP_RI);
+    }
 
     return 0;
 }

Independently of your patch, I do wonder if we shouldn't change the return type of cpu_mips_get_count to int32_t. With your patch, there are now 2 calls to this functions, and both cast the value to int32_t.

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                 http://www.aurel32.net
#3 lore raw
Quoted 3 lines · Aurelien Jarno

Independently of your patch, I do wonder if we shouldn't change the return type of cpu_mips_get_count to int32_t. With your patch, there are now 2 calls to this functions, and both cast the value to int32_t.

Yes, I think that will make more sense if the return type of cpu_mips_get_count() matches CP0_Count.

Leon