Add a __reset_handler to startup code

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
Post Reply
drizzi
Posts: 9
Joined: Wed Apr 19, 2017 4:52 pm
Has thanked: 2 times
Been thanked: 5 times

Add a __reset_handler to startup code

Post by drizzi »

Hello,
I often have the need (e.g.: bootloader) to execute some code before anything else, right after the reset.
I can do that overriding the default Reset_Handler (do my stuff, then b _crt0_entry), but I find that adding adding a (weak) __reset_handler hook (like __cpu_init or __early_init) and then doing a b __reset_handler in _crt0_entry is a much more cleaner approach. But this requires to patch all the crt1.c and crt0*.S files (I exclusively use ARMCMx/GCC).
Maybe I am the only one with this request, but - if not - maybe it's an idea worth considering (despite the need to modify all the startup code for all platforms/compilers).

Ciao,
Davide
Attachments
GCC.zip
(4.43 KiB) Downloaded 102 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Add a __reset_handler to startup code

Post by Giovanni »

Hi,

This is already possible, Reset_Handler is a weak symbol, redefine it, do your initialization, then jump to _crt0_entry.

Giovanni
Post Reply