mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 12:15:32 +08:00
tms320f28379d fix init (#6343)
解决 tms320f28379d bsp 启动的问题。主要改动如下。 修正context.s中汇编代码错误。在旧版的代码中,操作数为32位而汇编命令却使用了针对16位数据的命令MOV,导致程序在某些情况无法正常启动线程。 由于C28x的平台下,SP只支持16bit寻址,所以用于线程空间存放的heap以及ebss段都需要放在低16位的空间,针对这个问题修改了CMD文件。此外还增加基于CMD文件基于RAM的支持,方便调试。 新增rtdef.h中RT_SECTION,RT_USED,ALIGN和RT_WEAK的定义。旧版bsp中这些定义为空,导致INIT_EXPORT注册的函数失效。 修改程序启动代码,在程序入口直接调用原生启动代码 以上改动在LAUNCHXL-F28379D 通过了测试。
This commit is contained in:
+61
-102
@@ -10,6 +10,7 @@
|
||||
; 2019-07-03 zhaoxiaowei add _rt_hw_calc_csb function to support __rt_ffs.
|
||||
; 2019-12-05 xiaolifan add support for hardware fpu32
|
||||
; 2022-06-21 guyunjie trim pendsv (RTOSINT_Handler)
|
||||
; 2022-08-24 guyunjie fix bugs in context switching
|
||||
|
||||
.ref _rt_interrupt_to_thread
|
||||
.ref _rt_interrupt_from_thread
|
||||
@@ -39,7 +40,6 @@
|
||||
|
||||
RT_CTX_SAVE .macro
|
||||
|
||||
|
||||
PUSH AR1H:AR0H
|
||||
PUSH XAR2
|
||||
PUSH XAR3
|
||||
@@ -90,7 +90,6 @@ RT_CTX_RESTORE .macro
|
||||
POP XAR3
|
||||
POP XAR2
|
||||
|
||||
|
||||
MOVZ AR0 , @SP
|
||||
SUBB XAR0, #6
|
||||
MOVL ACC , *XAR0
|
||||
@@ -98,7 +97,6 @@ RT_CTX_RESTORE .macro
|
||||
MOV AL, IER
|
||||
MOVL *XAR0, ACC
|
||||
|
||||
|
||||
POP AR1H:AR0H
|
||||
|
||||
.endm
|
||||
@@ -130,23 +128,19 @@ _rt_hw_interrupt_enable:
|
||||
|
||||
;
|
||||
; void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
|
||||
; r0 --> from
|
||||
; r4 --> to
|
||||
|
||||
|
||||
; ACC --> from
|
||||
; SP[4] --> to
|
||||
;
|
||||
.asmfunc
|
||||
_rt_hw_context_switch_interrupt:
|
||||
MOVL XAR0, #0
|
||||
MOV AR0, AL
|
||||
MOVL XAR0, ACC
|
||||
MOVL XAR4, *-SP[4]
|
||||
; set rt_thread_switch_interrupt_flag to 1
|
||||
MOVL XAR5, #_rt_thread_switch_interrupt_flag
|
||||
MOVL XAR6, *XAR5
|
||||
MOVL ACC, XAR6
|
||||
CMPB AL, #1
|
||||
B _reswitch, EQ
|
||||
MOVL XAR6, #1
|
||||
MOVL *XAR5, XAR6
|
||||
MOVL ACC, *XAR5
|
||||
BF _reswitch, NEQ ; ACC!=0
|
||||
MOVB ACC, #1
|
||||
MOVL *XAR5, ACC
|
||||
|
||||
MOVL XAR5, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
|
||||
MOVL *XAR5, XAR0
|
||||
@@ -160,23 +154,19 @@ _reswitch:
|
||||
|
||||
;
|
||||
; void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
|
||||
; r0 --> from
|
||||
; r4 --> to
|
||||
|
||||
|
||||
; ACC --> from
|
||||
; SP[4] --> to
|
||||
;
|
||||
.asmfunc
|
||||
_rt_hw_context_switch:
|
||||
MOVL XAR0, #0
|
||||
MOV AR0, AL
|
||||
MOVL XAR0, ACC
|
||||
MOVL XAR4, *-SP[4]
|
||||
; set rt_thread_switch_interrupt_flag to 1
|
||||
MOVL XAR5, #_rt_thread_switch_interrupt_flag
|
||||
MOVL XAR6, *XAR5
|
||||
MOVL ACC, XAR6
|
||||
CMPB AL, #1
|
||||
B _reswitch2, EQ
|
||||
MOVL XAR6, #1
|
||||
MOVL *XAR5, XAR6
|
||||
MOVL ACC, *XAR5
|
||||
BF _reswitch2, NEQ ; ACC!=0
|
||||
MOVB ACC, #1
|
||||
MOVL *XAR5, ACC
|
||||
|
||||
MOVL XAR5, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
|
||||
MOVL *XAR5, XAR0
|
||||
@@ -189,63 +179,64 @@ _reswitch2:
|
||||
LRETR
|
||||
.endasmfunc
|
||||
|
||||
.asmfunc
|
||||
;
|
||||
; * void rt_hw_context_switch_to(rt_uint32 to);
|
||||
; * ACC --> to
|
||||
;
|
||||
.asmfunc
|
||||
_rt_hw_context_switch_to:
|
||||
; get to thread
|
||||
MOVL XAR1, #_rt_interrupt_to_thread
|
||||
MOVL *XAR1, ACC
|
||||
|
||||
; set from thread to 0
|
||||
MOVL XAR1, #_rt_interrupt_from_thread
|
||||
MOVL XAR0, #0
|
||||
MOVL *XAR1, XAR0
|
||||
|
||||
; set interrupt flag to 1
|
||||
MOVL XAR1, #_rt_thread_switch_interrupt_flag
|
||||
MOVL XAR0, #1
|
||||
MOVL *XAR1, XAR0
|
||||
|
||||
TRAP #16
|
||||
|
||||
; never reach here!
|
||||
.endasmfunc
|
||||
|
||||
.asmfunc
|
||||
_RTOSINT_Handler:
|
||||
; disable interrupt to protect context switch
|
||||
; DINT ;this is done by hardware so not needed
|
||||
|
||||
; get rt_thread_switch_interrupt_flag
|
||||
MOV AR0, #_rt_thread_switch_interrupt_flag
|
||||
MOV AL, *AR0
|
||||
MOV AR1, AL
|
||||
CMP AR1, #0
|
||||
B rtosint_exit, EQ ; pendsv already handled
|
||||
MOVL XAR0, #_rt_thread_switch_interrupt_flag
|
||||
MOVL ACC, *XAR0
|
||||
BF rtosint_exit, EQ ; pendsv already handled
|
||||
|
||||
; clear rt_thread_switch_interrupt_flag to 0
|
||||
MOV AR1, #0x00
|
||||
MOV *AR0, AR1
|
||||
MOVL XAR1, #0
|
||||
MOVL *XAR0, XAR1
|
||||
|
||||
MOV AR0, #_rt_interrupt_from_thread
|
||||
MOV AL, *AR0
|
||||
MOV AR1, AL
|
||||
CMP AR1, #0
|
||||
B switch_to_thread, EQ ; skip register save at the first time
|
||||
MOVL XAR0, #_rt_interrupt_from_thread
|
||||
MOVL ACC, *XAR0
|
||||
BF switch_to_thread, EQ ; skip register save at the first time
|
||||
|
||||
;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
; TST lr, #0x10 ; if(!EXC_RETURN[4])
|
||||
; VSTMDBEQ r1!, {d8 - d15} ; push FPU register s16~s31
|
||||
;#endif
|
||||
RT_CTX_SAVE ; push cpu registers
|
||||
|
||||
RT_CTX_SAVE ; push r4 - r11 register
|
||||
|
||||
;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
; MOV r4, #0x00 ; flag = 0
|
||||
|
||||
; TST lr, #0x10 ; if(!EXC_RETURN[4])
|
||||
; MOVEQ r4, #0x01 ; flag = 1
|
||||
|
||||
; STMFD r1!, {r4} ; push flag
|
||||
;#endif
|
||||
|
||||
MOV AL, *AR0
|
||||
MOV AR0, AL
|
||||
MOVL ACC, *XAR0
|
||||
MOVL XAR0, ACC
|
||||
MOVZ AR1, @SP ; get from thread stack pointer
|
||||
MOV *AR0, AR1 ; update from thread stack pointer
|
||||
MOVL *XAR0, XAR1 ; update from thread stack pointer
|
||||
|
||||
switch_to_thread:
|
||||
MOV AR1, #_rt_interrupt_to_thread
|
||||
MOV AL, *AR1
|
||||
MOV AR1, AL
|
||||
MOV AL, *AR1
|
||||
MOV AR1, AL ; load thread stack pointer
|
||||
MOVL XAR1, #_rt_interrupt_to_thread
|
||||
MOVL ACC, *XAR1
|
||||
MOVL XAR1, ACC
|
||||
MOVL ACC, *XAR1
|
||||
MOV @SP, AL ; load thread stack pointer
|
||||
|
||||
;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
; LDMFD r1!, {r3} ; pop flag
|
||||
;#endif
|
||||
|
||||
MOV @SP, AR1
|
||||
|
||||
RT_CTX_RESTORE ; pop r4 - r11 register
|
||||
RT_CTX_RESTORE ; pop cpu registers
|
||||
|
||||
rtosint_exit:
|
||||
; do not restore interrupt here: to be restored according to the
|
||||
@@ -287,38 +278,6 @@ _rt_hw_calc_csb:
|
||||
lretr
|
||||
.endasmfunc
|
||||
|
||||
;
|
||||
; * void rt_hw_context_switch_to(rt_uint32 to);
|
||||
; * r0 --> to
|
||||
|
||||
.asmfunc
|
||||
_rt_hw_context_switch_to:
|
||||
MOV AR1, #_rt_interrupt_to_thread
|
||||
MOV *AR1, AL
|
||||
|
||||
;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||
; CLEAR CONTROL.FPCA
|
||||
; MRS r2, CONTROL ; read
|
||||
; BIC r2, #0x04 ; modify
|
||||
; MSR CONTROL, r2 ; write-back
|
||||
;#endif
|
||||
|
||||
; set from thread to 0
|
||||
MOV AR1, #_rt_interrupt_from_thread
|
||||
MOV AR0, #0x0
|
||||
MOV *AR1, AR0
|
||||
|
||||
; set interrupt flag to 1
|
||||
MOV AR1, #_rt_thread_switch_interrupt_flag
|
||||
MOV AR0, #1
|
||||
MOV *AR1, AR0
|
||||
|
||||
TRAP #16
|
||||
|
||||
|
||||
; never reach here!
|
||||
.endasmfunc
|
||||
|
||||
; compatible with old version
|
||||
.asmfunc
|
||||
_rt_hw_interrupt_thread_switch:
|
||||
|
||||
@@ -76,9 +76,8 @@ rt_uint8_t *rt_hw_stack_init(void *tentry,
|
||||
unsigned long i;
|
||||
|
||||
stk = stack_addr;
|
||||
stk = (rt_uint8_t *)RT_ALIGN((rt_uint32_t)stk, 8);
|
||||
//stk -= sizeof(struct stack_frame);
|
||||
stk += 1;
|
||||
stk = (rt_uint8_t *)RT_ALIGN((rt_uint32_t)stk, 2);
|
||||
stk += 1; /*to work around the stack alignment*/
|
||||
|
||||
stack_frame = (struct stack_frame *)stk;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user