Skip to content

Commit b46c4ec

Browse files
joabreushahab-vahedi
authored andcommitted
target: arc: timer: Misc fixes
Signed-off-by: Jose Abreu <[email protected]>
1 parent 7790730 commit b46c4ec

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

target/arc/timer.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void cpu_arc_timer_update(CPUARCState *env, uint32_t timer)
6969
delta = env->timer[timer].T_Limit - t_count;
7070

7171
#ifndef CONFIG_USER_ONLY
72-
timer_mod_ns(env->cpu_timer[timer], now + CYCLES_TO_NS((uint64_t)delta));
72+
timer_mod_anticipate_ns(env->cpu_timer[timer], now + CYCLES_TO_NS((uint64_t)delta));
7373
#endif
7474

7575
qemu_log_mask(LOG_UNIMP,
@@ -87,10 +87,14 @@ static void cpu_arc_timer_expire(CPUARCState *env, uint32_t timer)
8787
assert(timer == 1 || timer == 0);
8888
qemu_log_mask(LOG_UNIMP, "[TMR%d] Timer expired\n", timer);
8989

90-
uint32_t overflow = env->timer[timer].T_Cntrl & TMR_IP;
90+
uint32_t overflow = get_t_count(env, timer) >= env->timer[timer].T_Limit;
9191
/* Set the IP bit. */
9292

9393
bool unlocked = !qemu_mutex_iothread_locked();
94+
95+
if (!overflow)
96+
return;
97+
9498
if (unlocked) {
9599
qemu_mutex_lock_iothread();
96100
}
@@ -101,7 +105,7 @@ static void cpu_arc_timer_expire(CPUARCState *env, uint32_t timer)
101105
}
102106

103107
/* Raise an interrupt if enabled. */
104-
if ((env->timer[timer].T_Cntrl & TMR_IE) && !overflow) {
108+
if (env->timer[timer].T_Cntrl & TMR_IE) {
105109
qemu_log_mask(CPU_LOG_INT, "[TMR%d] Rising IRQ\n", timer);
106110
qemu_irq_raise(env->irq[TIMER0_IRQ + (timer & 0x01)]);
107111
}
@@ -237,7 +241,7 @@ static void cpu_arc_count_set(CPUARCState *env, uint32_t timer, uint32_t val)
237241
if (unlocked) {
238242
qemu_mutex_lock_iothread();
239243
}
240-
env->timer[timer].last_clk = get_ns(env) - CYCLES_TO_NS(val);
244+
env->timer[timer].last_clk = get_ns(env) + CYCLES_TO_NS(val);
241245
cpu_arc_timer_update(env, timer);
242246
if (unlocked) {
243247
qemu_mutex_unlock_iothread();

0 commit comments

Comments
 (0)