Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/arm/hvf/hvf.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 36fa67caf62..dbf6b83532d 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -201,6 +201,9 @@ void hvf_arm_init_debug(void)
#define SYSREG_PMCEID0_EL0 SYSREG(3, 3, 9, 12, 6)
#define SYSREG_PMCEID1_EL0 SYSREG(3, 3, 9, 12, 7)
#define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 9, 13, 0)
+
+#define SYSREG_CNTV_CTL_EL0 SYSREG(3, 3, 14, 3, 1)
+#define SYSREG_CNTV_CVAL_EL0 SYSREG(3, 3, 14, 3, 2)
#define SYSREG_PMCCFILTR_EL0 SYSREG(3, 3, 14, 15, 7)
#define SYSREG_ICC_AP0R0_EL1 SYSREG(3, 0, 12, 8, 4)
@@ -2009,13 +2012,49 @@ static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
return ret;
}
+static void hvf_sync_vtimer_pre_exec(CPUState *cpu)
+{
+ hv_return_t r;
+ uint64_t val;
+ bool b;
+
+ b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
+ assert(b);
+ r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
+ assert_hvf_ok(r);
+
+ b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
+ assert(b);
+ r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
+ assert_hvf_ok(r);
+}
+
+static void hvf_sync_vtimer_post_exec(CPUState *cpu)
+{
+ hv_return_t r;
+ uint64_t val;
+ bool b;
+
+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
+ assert_hvf_ok(r);
+ b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
+ assert(b);
+
+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
+ assert_hvf_ok(r);
+ b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
+ assert(b);
+}
+
void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
{
+ hvf_sync_vtimer_pre_exec(cpu);
flush_cpu_state(cpu);
}
void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
{
+ hvf_sync_vtimer_post_exec(cpu);
}
int hvf_arch_vcpu_exec(CPUState *cpu)
--
2.51.0