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
+80
View File
@@ -0,0 +1,80 @@
#include "os_config.h"
.syntax unified
.thumb
.section .text.PendSV_Handler,"ax",%progbits
.global g_os_port_switch_from_sp
.global g_os_port_switch_to_sp
.global PendSV_Handler
.thumb_func
PendSV_Handler:
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
#if(OS_CFG_CPU_FPU_PRESENT)
TST LR, #0x10 // 40
VSTMDBEQ R0!, {S16-S31}
#endif
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
#if(OS_CFG_CPU_FPU_PRESENT)
TST LR, #0x10
IT EQ
VLDMIAEQ R0!, {S16-S31}
#endif
MSR PSP, R0 // PSP
POP {R1}
MSR PRIMASK, R1 //
BX LR
.section .text.SVC_Handler,"ax",%progbits
.global SVC_Handler
.global svc_exc_return
.global SVC_Handler_C
.type SVC_Handler, %function
SVC_Handler:
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
.section .text.cpu_clz,"ax",%progbits
.global cpu_clz
.thumb_func
cpu_clz:
CLZ R0, R0
BX LR
.align 4
.end