From dd828c8920cf7b43a89ece3cf10697963519d3e9 Mon Sep 17 00:00:00 2001 From: Kerogit Date: Sat, 5 Apr 2025 23:41:54 +0200 Subject: [PATCH] arch/avr: fixed PC load on chips with more than 128kB program memory The code used subi instruction to decrement the Y pointer but this instruction only affects a byte, not a word. Fixed it by using pre-decrement in the LD instruction instead. --- arch/avr/src/avr/excptmacros.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/avr/src/avr/excptmacros.h b/arch/avr/src/avr/excptmacros.h index dcfa8c4e547..a6046abf873 100644 --- a/arch/avr/src/avr/excptmacros.h +++ b/arch/avr/src/avr/excptmacros.h @@ -465,7 +465,7 @@ #if AVR_PC_SIZE <= 16 adiw r28, REG_PC0 #else - adiw r28, REG_PC2 + adiw r28, (REG_PC2+1) /* Will pre-decrement this on use */ #endif /* Fetch and set the new stack pointer */ @@ -490,14 +490,11 @@ push r24 /* Push PC0 and PC1 on the stack (PC1 then PC0) */ push r25 #else - ld r25, y /* Load PC2 (r25) */ - subi r28,1 + ld r25, -y /* Load PC2 (r25) */ push r25 - ld r25, y /* Load PC1 (r25) */ - subi r28,1 + ld r25, -y /* Load PC1 (r25) */ push r25 - ld r25, y /* Load PC0 (r25) */ - subi r28,1 + ld r25, -y /* Load PC0 (r25) */ push r25 #endif