Skip to content

Move interrupts to bootloader when IVSEL is set #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

emanuelen5
Copy link

@emanuelen5 emanuelen5 commented May 1, 2025

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: emanuelen5/kitchen-timer#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).

@emanuelen5 emanuelen5 force-pushed the move-interrupts-to-bootloader branch from 6021804 to b80b39f Compare May 4, 2025 08:49
@emanuelen5
Copy link
Author

CI was failing, so I rebased onto the upstream master branch. I could see there were some changes to Github actions there.

@emanuelen5
Copy link
Author

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?

@edgar-bonet
Copy link

@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)

@gatk555
Copy link
Collaborator

gatk555 commented May 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants