-
Notifications
You must be signed in to change notification settings - Fork 85
add some unsafe method to run code before RAM is initialized #17
Comments
How do you recommend doing this? I was thinking of either something like rust-lang/rfcs#1971 i.e. a default trait implementation and have the macro override it, or adding a new (weakly linked) function and then overriding that a la the r0 crate's init_array. |
The latter, like we do for interrupt / exception handlers. |
Another use case is disabling watchdogs before main() on some devices such as the K64 that have them enabled on reset. Unfortunately, leaving the watchdog enabled can leave the device in a reset loop that is difficult to recover from. I would also like to enable instruction cache on devices that support it, and enter main() with interrupts disabled by default. It sounds like the right way to do this is to add a weakly linked pre_init function that Or would it be better to have a way to replace reset_handler? |
I needed this on the AM5728 IPU1 as both Cortex-M4 cores (there are two) are released out of reset at the same time with the same reset vector. You write a little bit of code (making sure not to use the stack pointer) to put Core 1 to sleep and let Core 0 carry on. You can then take Core 1 out of sleep at a later time if you're running an SMP-capable RTOS. Currently I fixed this by forking the crate. |
81: Add a __pre_init function to be called at the start of the reset handler r=korken89 a=yodaldevoid I needed this for a project so I went ahead and rebased and tweaked @jcsoo 's changes from #71. I will admit, I got a little impatient waiting and that also played into why I did this. If either @jcsoo or @japaric have an issue with this PR, please let me know and I will remove it. I apologize for toes that I have stepped on. Now onto the PR. This is possibly the simplest implementation that is possible. No nightly features were used in this implementation. Also, there is no hand-holding for the end user; if they want to mess with uninitialized statics, that is on them. If you would like me to add more documentation, please let me know what you would like to see. Fixes #17 Co-authored-by: Jonathan Soo <[email protected]> Co-authored-by: Gabriel Smith <[email protected]>
17: update copyright year r=japaric a=japaric Testing branch protection Co-authored-by: Jorge Aparicio <[email protected]>
Some people have expressed that they would like to configure the CPU clock before RAM initialization to speed up the initialization process (specially when lots of RAM need to be initialized).
This has to be unsafe because all the static variables stored in .bss / .data would be uninitialized during the execution of this pre-init routine.
Possible user facing interface:
where
pre_init!
can only be used once.The text was updated successfully, but these errors were encountered: