-
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
Merged
maribu
merged 3 commits into
RIOT-OS:master
from
dylad:pr/cpu/cortexm33/add_splim_support
May 7, 2024
+149
−3
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
BOARD ?= nrf5340dk-app | ||
|
||
include ../Makefile.cpu_common | ||
|
||
FEATURES_REQUIRED += cortexm_stack_limit | ||
|
||
include $(RIOTBASE)/Makefile.include | ||
|
||
ifeq (llvm,$(TOOLCHAIN)) | ||
CFLAGS += -Wno-infinite-recursion | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2024 Mesotic SAS | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for the cortexm_stack_limit pseudo-module | ||
* | ||
* @author Dylan Laduranty <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "cpu.h" | ||
#include "thread.h" | ||
#include "board.h" | ||
|
||
#define CANARY_VALUE 0xdeadbeef | ||
|
||
static struct { | ||
unsigned int canary; | ||
char stack[THREAD_STACKSIZE_MAIN]; | ||
} buf; | ||
|
||
/* Tell modern GCC (12.x) to not complain that this infinite recursion is | ||
* bound to overflow the stack - this is exactly what this test wants to do :) | ||
* | ||
* Also, tell older versions of GCC that do not know about -Winfinit-recursion | ||
* that it is safe to ignore `GCC diagnostics ignored "-Winfinit-recursion"`. | ||
* They behave as intended in this case :) | ||
*/ | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wpragmas" | ||
#pragma GCC diagnostic ignored "-Winfinite-recursion" | ||
static int recurse(int counter) | ||
{ | ||
if (buf.canary != CANARY_VALUE) { | ||
#ifdef LED0_ON | ||
LED0_ON; | ||
#endif | ||
#ifdef LED1_ON | ||
LED1_ON; | ||
#endif | ||
#ifdef LED2_ON | ||
LED2_ON; | ||
#endif | ||
#ifdef LED3_ON | ||
LED3_ON; | ||
#endif | ||
|
||
for (;;) { | ||
thread_sleep(); | ||
} | ||
} | ||
|
||
counter++; | ||
/* Recursing twice here prevents the compiler from optimizing-out the recursion. */ | ||
return recurse(counter) + recurse(counter); | ||
} | ||
#pragma GCC diagnostic pop | ||
|
||
static void *thread(void *arg) | ||
{ | ||
(void) arg; | ||
|
||
recurse(0); | ||
|
||
return NULL; | ||
} | ||
|
||
int main(void) | ||
{ | ||
puts("\nCortex-M Stack limit test\n"); | ||
|
||
puts("If the test fails, all onboard LEDs will be on"); | ||
|
||
#ifdef MODULE_CORTEXM_STACK_LIMIT | ||
puts("The cortexm_stack_limit module is present. Expect the board to crash"\ | ||
" without onboard LEDs on.\n"); | ||
#else | ||
puts("The cortexm_stack_limit module is missing! Expect the test to crash"\ | ||
" with all onboard LEDs on\n"); | ||
#endif | ||
|
||
buf.canary = CANARY_VALUE; | ||
thread_create(buf.stack, sizeof(buf.stack), THREAD_PRIORITY_MAIN + 1, | ||
0, thread, NULL, "thread"); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.