STM32F103C8T6 Port

This commit is contained in:
2026-05-29 13:18:56 +08:00
commit 345be1983b
6 changed files with 484 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
PRESERVE8
THUMB
AREA |.text|, CODE, READONLY
cpu_clz PROC
EXPORT cpu_clz
CLZ R0, R0
BX LR
ENDP
SVC_Handler PROC
EXPORT SVC_Handler
IMPORT svc_exc_return
IMPORT SVC_Handler_C
tst lr, #4 // EXC_RETURN (LR) 2
ite eq
mrseq r0, msp // 2 0 MSP
mrsne r0, psp // 2 1 PSP
ldr r1, =svc_exc_return
str lr, [r1]
bl SVC_Handler_C // C r0
ldr r1, =svc_exc_return
ldr lr, [r1]
bx lr
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler
IMPORT g_os_port_switch_from_sp
IMPORT g_os_port_switch_to_sp
IMPORT os_port_on_switch_success
mrs r1, primask //
cpsid i //
PUSH {R1}
LDR R1, =g_os_port_switch_from_sp //
LDR R1, [R1] // g_os_port_switch_from_sp
CBZ R1, __PendSV_SwitchTo
/* ---- 压栈 ---- */
MRS R0, PSP
MOV R2, LR
MRS R3, CONTROL
STMDB R0!, {R2-R11}
/* ---- sp值保存到变量中 ---- */
STR R0, [R1] // sp R0
__PendSV_SwitchTo
BL os_port_on_switch_success //
/* ---- 加载目标栈 ---- */
LDR R2, =g_os_port_switch_to_sp //
LDR R2, [R2] //
LDR R0, [R2] // sp
LDMIA R0!, {R2-R11} // R2-R11
MOV LR, R2 // LR
MSR CONTROL, R3 // CONTROL , ISR 退 ISR
ISB // CONTROL
MSR PSP, R0 // PSP
POP {R1}
MSR PRIMASK, R1 //
BX LR
ENDP
END