cpu/cortexm: add stack limit support for Cortex-M33#20633
cpu/cortexm: add stack limit support for Cortex-M33#20633maribu merged 3 commits intoRIOT-OS:masterfrom
Conversation
|
I'll take care of static tests after the first round of review. |
maribu
left a comment
There was a problem hiding this comment.
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.
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.
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.
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
PSPLIMandMSPLIMas CPU registers to be used alongside withPSPandMSP.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
PSPLIMevery 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_guardexcept that I remove all theprintfas 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_pingpongOn current master:
With this PR and
FEATURES_REQUIRED+="cortexm_stack_limit":Issues/PRs references
None.