RP2350 RCP Initialization
Originally I had thought there was an issue with needing to enable the RCP on the RP2350 but it turns out the bootrom by default leaves this in the expected enabled state. What was actually happening was when the FPU was enabled the write to CPACR clobbered any default port states including deactivating the RCP. I believe we need to change the FPU activation to be RMW to avoid deactivating any coprocessors that were previously enabled.
PSPLIM
The initial stack PSPLIM is always set at startup yet in the ARMV8-M-ML port the code to update it is guarded behind the CH_DBG_ENABLE_STACK_CHECK flag which is false by default. I believe we should either assume PSPLIM is always activate for ARMv8-M-ML or only set the PSPLIM at startup conditionally when its expected to be used? I've used CRT0_INIT_PSPLIM in the patch below but I'm a little unclear whether the ARM architecture guide assumes PSPLIM should always be used with ARMv8-M-ML or whether it should be optional. I'm a little less sure about this than the above issue.
os/common/startup/ARMCMx/compilers/GCC/crt0_v8m-ml.S
Code: Select all
--- os/common/startup/ARMCMx/compilers/GCC/crt0_v8m-ml.S (revision 17872)
+++ os/common/startup/ARMCMx/compilers/GCC/crt0_v8m-ml.S (working copy)
@@ -62,6 +62,20 @@
#endif
/**
+ * @brief PSPLIM initialization switch.
+ * @details PSPLIM is initialized to the process stack base address providing
+ * hardware stack overflow detection during early startup.
+ * @note Defaults to @p FALSE because the OS must save/restore PSPLIM
+ * per-thread (PORT_SAVE_PSPLIM == TRUE) for this to be safe.
+ * When enabled without per-thread PSPLIM management, threads whose
+ * stacks reside below __process_stack_base__ will UsageFault on
+ * their first stack operation.
+ */
+#if !defined(CRT0_INIT_PSPLIM) || defined(__DOXYGEN__)
+#define CRT0_INIT_PSPLIM FALSE
+#endif
+
+/**
* @brief VTOR special register initialization.
* @details VTOR is initialized to point to the vectors table.
*/
@@ -215,8 +229,10 @@
/* PSP stack pointers initialization.*/
ldr r0, =__process_stack_end__
msr PSP, r0
+#if CRT0_INIT_PSPLIM == TRUE
ldr r0, =__process_stack_base__
msr PSPLIM, r0
+#endif
#if CRT0_VTOR_INIT == TRUE
ldr r0, =_vectors
@@ -234,11 +250,12 @@
dsb
isb
- /* CPACR initialization.*/
- movw r0, #CRT0_CPACR_INIT & 0xFFFF
- movt r0, #CRT0_CPACR_INIT >> 16
+ /* CPACR initialization, read-modify-write to preserve
+ coprocessor bits set by bootrom (e.g. CP7/RCP on RP2350).*/
movw r1, #SCB_CPACR & 0xFFFF
movt r1, #SCB_CPACR >> 16
+ ldr r0, [r1]
+ orr r0, r0, #CRT0_CPACR_INIT
str r0, [r1]
dsb
isb
@@ -401,8 +418,10 @@
/* PSP stack pointers initialization.*/
ldr r0, =__c\core\()_process_stack_end__
msr PSP, r0
+#if CRT0_INIT_PSPLIM == TRUE
ldr r0, =__c\core\()_process_stack_base__
msr PSPLIM, r0
+#endif
#if CRT0_VTOR_INIT == TRUE
ldr r0, =_vectors
@@ -420,11 +439,12 @@
dsb
isb
- /* CPACR initialization.*/
- movw r0, #CRT0_CPACR_INIT & 0xFFFF
- movt r0, #CRT0_CPACR_INIT >> 16
+ /* CPACR initialization, read-modify-write to preserve
+ coprocessor bits set by bootrom (e.g. CP7/RCP on RP2350).*/
movw r1, #SCB_CPACR & 0xFFFF
movt r1, #SCB_CPACR >> 16
+ ldr r0, [r1]
+ orr r0, r0, #CRT0_CPACR_INIT
str r0, [r1]
dsb
isb