-
Notifications
You must be signed in to change notification settings - Fork 165
Hard fault on debug compilation #583
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
Comments
Even if The conclusion may be that you can't change the stack using |
Needs a macro, sounds like. |
Hm, yea, maybe a macro-by-example could emit the inline asm needed. That's probably nicer than just saying everyone has to use asm directly. It would still have to be used pretty carefully though. Certainly I don't see how we can usefully have this method as a normal function today, and now that inline asm is stable the justification from the time ("it's impossible to do this otherwise in stable rust; at least the function works in release mode") doesn't hold up. |
I need this to run a particular proprietary RTOS. I suspect the correct solution is an argument given to the Edit: That or a macro! that takes a function to call as an argument. |
It is not possible to normally proceed the program code once the stack
pointer is manipulated (local variables are gone, etc.).
What about a special function that switches the stack and jumps to a
user mode entry function? Something like
fn enter_usermode(psp: *const u32, entry: fn() -> !) -> !;
This makes it clear that there is no return to the previous code and the
caller has to ensure that all resources are dropped. The entry function
also must not return as there is nowhere to return to. This also solves
the inlining problem.
bootstrap() already exists which does something similar.
|
This adds a function to switch to program stack and unprivileged mode. Fixes rust-embedded#583
This adds a function to switch to program stack and unprivileged mode. Fixes rust-embedded#583
Hello all,
I am experimenting with an STM32F303 and try to enter unprivileged mode with program stack pointer set. I use the following minimal example:
On a debug build this causes a hard fault at control::write(). On release build it works fine. I guess this is because the compiler does not inline the call on debug and the function crashes on return as it fails to pop the return address from the stack, which changed from MSP to PSP.
Maybe #[inline(always)] is necessary for control::write()?
The text was updated successfully, but these errors were encountered: