summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseteiro <[email protected]>2026-11-12 14:19:45 +0800
committerRbb666 <[email protected]>2026-11-13 09:30:58 +0800
commit45f59a16abba9ba907d2f320bc446dee5b0adb23 (patch)
tree76d046c1e7158a2cff3da8b00b0a2253d2377351
parentbf56b87f5d542dc5f9e5a7e268b77aa13c9dac74 (diff)
[libcpu][m23] select HardFault stack via EXC_RETURN
-rw-r--r--libcpu/arm/cortex-m23/context_gcc.S8
-rw-r--r--libcpu/arm/cortex-m23/context_iar.S8
-rw-r--r--libcpu/arm/cortex-m23/context_rvds.S8
3 files changed, 21 insertions, 3 deletions
diff --git a/libcpu/arm/cortex-m23/context_gcc.S b/libcpu/arm/cortex-m23/context_gcc.S
index abec76f934..03757a720b 100644
--- a/libcpu/arm/cortex-m23/context_gcc.S
+++ b/libcpu/arm/cortex-m23/context_gcc.S
@@ -198,7 +198,13 @@ rt_hw_interrupt_thread_switch:
.type HardFault_Handler, %function
HardFault_Handler:
/* get current context */
- MRS R0, PSP /* get fault thread stack pointer */
+ MRS R0, MSP /* get fault context from handler. */
+ MOV R1, LR /* Cortex-M23 baseline has no Thumb-2 TST immediate */
+ MOVS R2, #0x04
+ TST R1, R2 /* if(!EXC_RETURN[2]) */
+ BEQ _get_sp_done
+ MRS R0, PSP /* get fault context from thread. */
+_get_sp_done:
PUSH {LR}
BL rt_hw_hard_fault_exception
POP {PC}
diff --git a/libcpu/arm/cortex-m23/context_iar.S b/libcpu/arm/cortex-m23/context_iar.S
index 7600ef3b77..fa5d568440 100644
--- a/libcpu/arm/cortex-m23/context_iar.S
+++ b/libcpu/arm/cortex-m23/context_iar.S
@@ -203,7 +203,13 @@ rt_hw_interrupt_thread_switch:
HardFault_Handler:
; get current context
- MRS r0, psp ; get fault thread stack pointer
+ MRS r0, msp ; get fault context from handler.
+ MOV r1, lr ; Cortex-M23 baseline has no Thumb-2 TST immediate
+ MOVS r2, #0x04
+ TST r1, r2 ; if(!EXC_RETURN[2])
+ BEQ _get_sp_done
+ MRS r0, psp ; get fault context from thread.
+_get_sp_done
PUSH {lr}
BL rt_hw_hard_fault_exception
POP {pc}
diff --git a/libcpu/arm/cortex-m23/context_rvds.S b/libcpu/arm/cortex-m23/context_rvds.S
index 38c3c36f31..884b16357b 100644
--- a/libcpu/arm/cortex-m23/context_rvds.S
+++ b/libcpu/arm/cortex-m23/context_rvds.S
@@ -209,7 +209,13 @@ HardFault_Handler PROC
EXPORT HardFault_Handler
; get current context
- MRS r0, psp ; get fault thread stack pointer
+ MRS r0, msp ; get fault context from handler.
+ MOV r1, lr ; Cortex-M23 baseline has no Thumb-2 TST immediate
+ MOVS r2, #0x04
+ TST r1, r2 ; if(!EXC_RETURN[2])
+ BEQ _get_sp_done
+ MRS r0, psp ; get fault context from thread.
+_get_sp_done
PUSH {lr}
BL rt_hw_hard_fault_exception
POP {pc}