-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/cortexm: add stack limit support for Cortex-M33 #20633
cpu/cortexm: add stack limit support for Cortex-M33 #20633
Conversation
I'll take care of static tests after the first round of review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool feature! Lgtm except for one issue (see inline), but that may also just me not having written thumb asm in a long time.
"ldr r0, [r0] \n" /* load tcb->sp to register 1 */ | ||
#ifdef MODULE_CORTEXM_STACK_LIMIT | ||
"mov r2, r0 \n" /* Save content of R0 into R2*/ | ||
"bl _get_new_stacksize \n" /* Get the new lower limit stack in R0 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been quite some time since I've last have written thumb asm, so maybe I'm just a bit lost here. But if I recall correctly r0 to r3 are used to pass arguments and return values and are assumed to be saved by the caller. In that case, r2
could be overwritten by the code _get_new_stacksize()
emits, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right.
When I looked at objdump, only R0 and R3 were used by this function so I just kept R2 to temporary save R0 content.
I'll try to use another register, it shouldn't be too much pain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved to R4 for storing R0 content now. This register is restored a few instructions after anyways so it shouldn't be an issue.
Signed-off-by: Dylan Laduranty <[email protected]>
Signed-off-by: Dylan Laduranty <[email protected]>
Signed-off-by: Dylan Laduranty <[email protected]>
5019fed
to
071a1d8
Compare
Thanks! |
Contribution description
ARMv8-M architecture introduces
PSPLIM
andMSPLIM
as CPU registers to be used alongside withPSP
andMSP
.The idea of these registers is to define the lower limit of a stack. If the stack pointer reaches this limit, a fault is generated before the adjacent memory of the stack can be corrupted.
This module is not enabled by default as it introduces a bit of overhead per context switch (We need to update
PSPLIM
every time we also change PSP).I didn't add Cortex-M23 here on purpose. It seems to be a little be different because of
Testing procedure
This PR also introduces a basic test application. I don't know if it's relevant enough to be merged.
I took inspiration from
tests/cpu/mpu_stack_guard
except that I remove all theprintf
as they eat too much stack.Here, the stack overflows at some point, but a fault is generated before the canary word is modified.
If you remove the feature from the makefile, the stack will also overflows but the canary word will be modified, then all onboard LEDs will be switch on.
All of this can also be checked with GDB.
Regarding the overhead introduces in the context switching
Here are the result from
tests/bench/thread_yield_pingpong
On current master:
With this PR and
FEATURES_REQUIRED+="cortexm_stack_limit"
:Issues/PRs references
None.