Skip to contentSkip to conversation

target-mips: Fix RDHWR on CP0.Count

PATCH Superseded Alex Smith 2 participants 3 messages Sep 4, 2015 – Sep 8, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alex Smith

author
#0 lore raw

PATCH 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]>
---
 target-mips/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-mips/op_helper.c +1 -1
index 809a061e296b..6fe00201c10d 100644
@@ -2185,7 +2185,7 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env)
 {
     if ((env->hflags & MIPS_HFLAG_CP0) ||
         (env->CP0_HWREna & (1 << 2)))
-        return env->CP0_Count;
+        return (int32_t)cpu_mips_get_count(env);
     else
         helper_raise_exception(env, EXCP_RI);
 
Signature · 1 line
2.5.0
#1 lore raw
Quoted 17 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]>
---
 target-mips/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-mips/op_helper.c +0 -0
index 809a061e296b..6fe00201c10d 100644

target-mips/op_helper.c target_ulong helper_rdhwr_cc(CPUMIPSState *env) · line 2191

Quoted 8 lines
target-mips/op_helper.c +1 -1
@@ -2185,7 +2185,7 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env)
 {
     if ((env->hflags & MIPS_HFLAG_CP0) ||
         (env->CP0_HWREna & (1 << 2)))
-        return env->CP0_Count;
+        return (int32_t)cpu_mips_get_count(env);
     else
         helper_raise_exception(env, EXCP_RI);
 

Thanks for the patch, this looks correct for system mode. However, if you try to build mips*-linux-user it will fail -- cpu_mips_get_count() and family aren't defined in linux-user (we don't seem to care about modifying CP0_Count).

Also, QEMU coding style requires that every indented statement is braced (these style issues are in quite many places in existing code, but new code should follow the correct style).

Could you fix these two issues, please?

Thanks,
Leon

author
#2 lore raw
Quoted 32 lines · Leon Alrae
Quoted 17 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]>
---
 target-mips/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-mips/op_helper.c +0 -0
index 809a061e296b..6fe00201c10d 100644

target-mips/op_helper.c target_ulong helper_rdhwr_cc(CPUMIPSState *env) · line 2191

Quoted 8 lines
target-mips/op_helper.c +1 -1
@@ -2185,7 +2185,7 @@ target_ulong helper_rdhwr_cc(CPUMIPSState *env)
 {
     if ((env->hflags & MIPS_HFLAG_CP0) ||
         (env->CP0_HWREna & (1 << 2)))
-        return env->CP0_Count;
+        return (int32_t)cpu_mips_get_count(env);
     else
         helper_raise_exception(env, EXCP_RI);
 

Thanks for the patch, this looks correct for system mode. However, if you try to build mips*-linux-user it will fail -- cpu_mips_get_count() and family aren't defined in linux-user (we don't seem to care about modifying CP0_Count).

Quoted 5 lines

Also, QEMU coding style requires that every indented statement is braced (these style issues are in quite many places in existing code, but new code should follow the correct style).

Could you fix these two issues, please?

Sure, will do. I'll send a new patch shortly.

Thanks,
Alex