You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/04/25 08:19:33 UTC
[incubator-nuttx] 02/03: arch: rp2040: Add stack coloration for the
idle task
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 8e161bc992a4ad478f7704dc1adba9ca862b7cad
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Sun Apr 25 11:01:27 2021 +0900
arch: rp2040: Add stack coloration for the idle task
Summary:
- This commit adds stack coloration for the idle task
Impact:
- rp2040 with CONFIG_STACK_COLORATION=y
Testing:
- Tested with nsh, nshsram and smp configurations
- NOTE: CONFIG_STACK_COLORATION=y needs to be added
---
arch/arm/src/rp2040/rp2040_start.c | 60 ++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/arch/arm/src/rp2040/rp2040_start.c b/arch/arm/src/rp2040/rp2040_start.c
index 498befd..8952e68 100644
--- a/arch/arm/src/rp2040/rp2040_start.c
+++ b/arch/arm/src/rp2040/rp2040_start.c
@@ -52,6 +52,14 @@
const uintptr_t g_idle_topstack = IDLE_STACK;
/****************************************************************************
+ * Private Function prototypes
+ ****************************************************************************/
+
+#ifdef CONFIG_STACK_COLORATION
+static inline void go_nx_start(void *pv, unsigned int nbytes);
+#endif
+
+/****************************************************************************
* Private Functions
****************************************************************************/
@@ -70,6 +78,51 @@ const uintptr_t g_idle_topstack = IDLE_STACK;
#endif
/****************************************************************************
+ * Name: go_nx_start
+ ****************************************************************************/
+
+#ifdef CONFIG_STACK_COLORATION
+static inline void go_nx_start(void *pv, unsigned int nbytes)
+{
+ /* Set the IDLE stack to the stack coloration value then jump to
+ * nx_start(). We take extreme care here because were currently
+ * executing on this stack.
+ *
+ * We want to avoid sneak stack access generated by the compiler.
+ * NOTE: this function must be inlined so that SRAM boot can work.
+ */
+
+ __asm__ __volatile__
+ (
+ "\t.global nx_start\n"
+ "\tlsr %1, %1, #2\n" /* %1 = nwords = nbytes >> 2 */
+ "\tcmp %1, #0\n" /* Check (nwords == 0) */
+ "\tbeq 2f\n" /* (should not happen) */
+
+ "\tmov r2, #3\n"
+ "\tadd %0, %0, #3\n"
+ "\tbic %0, r2\n" /* %0 = Aligned stackptr */
+ "\tldr r2, =0xdeadbeef\n" /* R2 = STACK_COLOR = 0xdeadbeef */
+
+ "1:\n" /* Top of the loop */
+ "\tstr r2, [%0, #0]\n" /* Save stack color word */
+ "\tadd %0, %0, #4\n" /* Increment stackptr */
+ "\tsub %1, %1, #1\n" /* %1 nwords-- */
+ "\tcmp %1, #0\n" /* Check (nwords == 0) */
+ "\tbne 1b\n" /* Bottom of the loop */
+
+ "2:\n"
+ "\tmov r2, #0\n"
+ "\tmov r14, r2\n" /* LR = return address (none) */
+ "\tbl nx_start\n" /* Branch to nx_start */
+ :
+ : "r" (pv), "r" (nbytes)
+ : "r2"
+ );
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -169,7 +222,14 @@ void __start(void)
showprogress('\r');
showprogress('\n');
+
+#ifdef CONFIG_STACK_COLORATION
+ /* Set the IDLE stack to the coloration value and jump into nx_start() */
+
+ go_nx_start((FAR void *)&_ebss, CONFIG_IDLETHREAD_STACKSIZE);
+#else
nx_start();
+#endif
/* Shouldn't get here */