Skip to contentSkip to conversation

Fix handling of AVR interrupts above 33.

PATCH Applied Lucas Dietrich 4 participants 5 messages Jun 14, 2023 – Jun 18, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix handling of AVR interrupts above 33.

This commit addresses a bug in the AVR interrupt handling code. The modification involves replacing the usage of the ctz32 function with ctz64 to ensure proper handling of interrupts above 33 in the AVR target.

Previously, timers 3, 4, and 5 interrupts were not functioning correctly because most of their interrupt vectors are numbered above 33.

---
 target/avr/helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/avr/helper.c +2 -2
index 2bad242a66..e6e7d51487 100644
@@ -52,7 +52,7 @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
     }
     if (interrupt_request & CPU_INTERRUPT_HARD) {
         if (cpu_interrupts_enabled(env) && env->intsrc != 0) {
-            int index = ctz32(env->intsrc);
+            int index = ctz64(env->intsrc);
             cs->exception_index = EXCP_INT(index);
             avr_cpu_do_interrupt(cs);
 
@@ -79,7 +79,7 @@ void avr_cpu_do_interrupt(CPUState *cs)
     if (cs->exception_index == EXCP_RESET) {
         vector = 0;
     } else if (env->intsrc != 0) {
-        vector = ctz32(env->intsrc) + 1;
+        vector = ctz64(env->intsrc) + 1;
     }
 
     if (avr_feature(env, AVR_FEATURE_3_BYTE_PC)) {
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lucas Dietrich

This commit addresses a bug in the AVR interrupt handling code. The modification involves replacing the usage of the ctz32 function with ctz64 to ensure proper handling of interrupts above 33 in the AVR target.

Quoted 7 lines

Previously, timers 3, 4, and 5 interrupts were not functioning correctly because most of their interrupt vectors are numbered above 33.

---
  target/avr/helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks for insisting with the patch posting process :)

Reviewed-by
#2 lore raw
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Lucas Dietrich

This commit addresses a bug in the AVR interrupt handling code. The modification involves replacing the usage of the ctz32 function with ctz64 to ensure proper handling of interrupts above 33 in the AVR target.

Quoted 7 lines

Previously, timers 3, 4, and 5 interrupts were not functioning correctly because most of their interrupt vectors are numbered above 33.

---
  target/avr/helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks for insisting with the patch posting process :)

Signature · 2 lines
Best Regards,
Michael Rolnik
#4 lore raw
Quoted 1 line · Michael Tokarev

Applied to the trivial tree, thank you!

Thanks. Do you mind updating the patch subject to:
"target/avr: Fix handling of interrupts above 33"?