@@ -227,6 +227,20 @@ avr_interrupt_reti(
227227 table -> running [table -> running_ptr - 1 ]-> vector : 0 );
228228}
229229
230+ static int interrupt_table_offset (avr_t * avr )
231+ {
232+ const int mcucr = _SFR_IO8 (0x35 );
233+ const int ivsel = 1 ;
234+ const char interrupt_sector_moved_to_bootloader = avr -> data [mcucr ] & (1 << ivsel );
235+
236+ const int bootloader_size = 0x800 ;
237+
238+ if (interrupt_sector_moved_to_bootloader )
239+ return avr -> flashend - bootloader_size + 1 ;
240+
241+ return 0 ;
242+ }
243+
230244/*
231245 * check whether interrupts are pending. If so, check if the interrupt "latency" is reached,
232246 * and if so triggers the handlers and jump to the vector.
@@ -282,13 +296,7 @@ avr_service_interrupts(
282296 printf ("IRQ%d calling\n" , vector -> vector );
283297 _avr_push_addr (avr , avr -> pc );
284298 avr_sreg_set (avr , S_I , 0 );
285- const int mcucr = _SFR_IO8 (0x35 );
286- const int ivsel = 1 ;
287- const char interrupt_sector_moved_to_bootloader = avr -> data [mcucr ] & (1 << ivsel );
288- if (interrupt_sector_moved_to_bootloader )
289- avr -> pc = vector -> vector * avr -> vector_size + 0x7000 ;
290- else
291- avr -> pc = vector -> vector * avr -> vector_size ;
299+ avr -> pc = vector -> vector * avr -> vector_size + interrupt_table_offset (avr );
292300
293301 avr_raise_irq (vector -> irq + AVR_INT_IRQ_RUNNING , 1 );
294302 avr_raise_irq (table -> irq + AVR_INT_IRQ_RUNNING , vector -> vector );
0 commit comments