Move interrupts to bootloader when IVSEL is set
I wanted to simulate a bootloader with interrupts a while back, but realized that the value of IVSEL didn't affect the location of the interrupt table in simavr. So I added this patch to be able to try out my bootloader for an ATmega328p (in another project: https://github.com/emanuelen5/kitchen-timer/pull/58) and switch between the bootloader and application interrupt table. Not sure if you want this upstream, or not, I just wanted to share it in case you find it valuable (since I have really appreciated simavr).
Note:
- the implementation might not be correct for other AVR models.
- IVSEL is modelled without timing considerations (in reality, IVSEL must be written within 4 clock cycles after a write to IVCE was performed for it to take effect).
CI was failing, so I rebased onto the upstream master branch. I could see there were some changes to Github actions there.
I see now that the CI build fails on the import of #include "sim_core_declare.h" that I added. I wanted to somehow check if IVSEL is set, so I did that by reading _SFR_IO8(0x35). Perhaps there is a better way?
@emanuelen5 wrote:
I see now that the CI build fails on the import of
#include "sim_core_declare.h"that I added.
It looks like that file is meant to be used in the context of a specific microcontroller, as it uses MCU-specific macros such as RAMSTART, RAMEND and FLASHEND. Probably not what you want.
I wanted to [read]
_SFR_IO8(0x35). Perhaps there is a better way?
This macro is defined by sim_core_declare.h as:
#define _SFR_IO8(v) ((v)+32)
I think the macro adds little, particularly when the argument is a raw number. 0x55 would be just as good, perhaps with more comment.
But I think this too special-purpose to be merged. It might do something horrible on some other chip, as there is no test for Mega 88/168/328. And I would like to see at least a sketch of a general solution, including reset vector redirection.