[libcpu][component] fixed the r52 kernel gcc context switch assembly

This commit is contained in:
kurisaw 2024-11-06 13:07:56 +08:00 committed by Rbb666
parent 1572a44055
commit 2241f4676b
2 changed files with 116 additions and 118 deletions

View File

@ -92,7 +92,7 @@ struct ramfs_dirent *dfs_ramfs_lookup(struct dfs_ramfs *ramfs,
return NULL; return NULL;
} }
int dfs_ramfs_read(struct dfs_file *file, void *buf, size_t count) ssize_t dfs_ramfs_read(struct dfs_file *file, void *buf, size_t count)
{ {
rt_size_t length; rt_size_t length;
struct ramfs_dirent *dirent; struct ramfs_dirent *dirent;
@ -114,7 +114,7 @@ int dfs_ramfs_read(struct dfs_file *file, void *buf, size_t count)
return length; return length;
} }
int dfs_ramfs_write(struct dfs_file *fd, const void *buf, size_t count) ssize_t dfs_ramfs_write(struct dfs_file *fd, const void *buf, size_t count)
{ {
struct ramfs_dirent *dirent; struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs; struct dfs_ramfs *ramfs;
@ -151,7 +151,7 @@ int dfs_ramfs_write(struct dfs_file *fd, const void *buf, size_t count)
return count; return count;
} }
int dfs_ramfs_lseek(struct dfs_file *file, off_t offset) off_t dfs_ramfs_lseek(struct dfs_file *file, off_t offset)
{ {
if (offset <= (off_t)file->vnode->size) if (offset <= (off_t)file->vnode->size)
{ {

View File

@ -8,116 +8,113 @@
* 2024-03-01 Wangyuqiang first version * 2024-03-01 Wangyuqiang first version
*/ */
/** #include "rtconfig.h"
* @addtogroup cortex-r52 .syntax unified
*/ .text
/*@{*/
//#include <rtconfig.h> .globl rt_thread_switch_interrupt_flag
.globl rt_interrupt_from_thread
.text .globl rt_interrupt_to_thread
.arm .globl rt_interrupt_enter
.globl rt_thread_switch_interrupt_flag .globl rt_interrupt_leave
.globl rt_interrupt_from_thread .globl rt_hw_trap_irq
.globl rt_interrupt_to_thread
.globl rt_interrupt_enter
.globl rt_interrupt_leave
.globl rt_hw_trap_irq
/* /*
* rt_base_t rt_hw_interrupt_disable() * rt_base_t rt_hw_interrupt_disable();
*/ */
.globl rt_hw_interrupt_disable .globl rt_hw_interrupt_disable
rt_hw_interrupt_disable: rt_hw_interrupt_disable:
MRS r0, cpsr mrs r0, cpsr
CPSID IF cpsid i
BX lr bx lr
/* /*
* void rt_hw_interrupt_enable(rt_base_t level) * void rt_hw_interrupt_enable(rt_base_t level);
*/ */
.globl rt_hw_interrupt_enable .globl rt_hw_interrupt_enable
rt_hw_interrupt_enable: rt_hw_interrupt_enable:
MSR cpsr_c, r0 msr cpsr, r0
BX lr bx lr
/* /*
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to) * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
* r0 --> from * r0 --> from
* r1 --> to * r1 --> to
*/ */
.globl rt_hw_context_switch .globl rt_hw_context_switch
rt_hw_context_switch: rt_hw_context_switch:
STMDB sp!, {lr} @ push pc (lr should be pushed in place of PC) clrex
STMDB sp!, {r0-r12, lr} @ push lr & register file stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
stmfd sp!, {r0-r12, lr} @ push lr & register file
MRS r4, cpsr mrs r4, cpsr
TST lr, #0x01 tst lr, #0x01
ORRNE r4, r4, #0x20 @ it's thumb code orrne r4, r4, #0x20 @ it's thumb code
STMDB sp!, {r4} @ push cpsr stmfd sp!, {r4} @ push cpsr
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
VMRS r4, fpexc /* fpu context */
TST r4, #0x40000000 vmrs r6, fpexc
BEQ __no_vfp_frame1 tst r6, #(1<<30)
VSTMDB sp!, {d0-d15} beq __no_vfp_frame1
VMRS r5, fpscr vstmdb sp!, {d0-d15}
@ TODO: add support for Common VFPv3. vstmdb sp!, {d16-d31}
@ Save registers like FPINST, FPINST2 vmrs r5, fpscr
STMDB sp!, {r5} stmfd sp!, {r5}
__no_vfp_frame1: __no_vfp_frame1:
STMDB sp!, {r4} stmfd sp!, {r6}
#endif
str sp, [r0] @ store sp in preempted tasks TCB
ldr sp, [r1] @ get new task stack pointer
#ifdef RT_USING_FPU
/* fpu context */
ldmfd sp!, {r6}
vmsr fpexc, r6
tst r6, #(1<<30)
beq __no_vfp_frame2
ldmfd sp!, {r5}
vmsr fpscr, r5
vldmia sp!, {d16-d31}
vldmia sp!, {d0-d15}
__no_vfp_frame2:
#endif #endif
STR sp, [r0] @ store sp in preempted tasks TCB ldmfd sp!, {r1}
LDR sp, [r1] @ get new task stack pointer msr spsr_cxsf, r1 /* original mode */
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) ldmfd sp!, {r0-r12,lr,pc}^ /* irq return */
LDMIA sp!, {r0} @ get fpexc
VMSR fpexc, r0 @ restore fpexc
TST r0, #0x40000000
BEQ __no_vfp_frame2
LDMIA sp!, {r1} @ get fpscr
VMSR fpscr, r1
VLDMIA sp!, {d0-d15}
__no_vfp_frame2:
#endif
LDMIA sp!, {r4} @ pop new task cpsr to spsr
MSR spsr_cxsf, r4
LDMIA sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
/* /*
* void rt_hw_context_switch_to(rt_uint32 to) * void rt_hw_context_switch_to(rt_uint32 to)
* r0 --> to * r0 --> to
*/ */
.globl rt_hw_context_switch_to .globl rt_hw_context_switch_to
rt_hw_context_switch_to: rt_hw_context_switch_to:
LDR sp, [r0] @ get new task stack pointer LDR sp, [r0] @ get new task stack pointer
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
LDMIA sp!, {r0} @ get fpexc ldmfd sp!, {r6}
VMSR fpexc, r0 vmsr fpexc, r6
TST r0, #0x40000000 tst r6, #(1<<30)
BEQ __no_vfp_frame_to beq __no_vfp_frame_to
LDMIA sp!, {r1} @ get fpscr ldmfd sp!, {r5}
VMSR fpscr, r1 vmsr fpscr, r5
VLDMIA sp!, {d0-d15} vldmia sp!, {d0-d15}
__no_vfp_frame_to: __no_vfp_frame_to:
#endif #endif
LDMIA sp!, {r4} @ pop new task cpsr to spsr LDMIA sp!, {r4} @ pop new task cpsr to spsr
MSR spsr_cxsf, r4 MSR spsr_cxsf, r4
LDMIA sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr ldmfd sp!, {r0-r12,lr,pc}^ /* irq return */
/* /*
* void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)@ * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)@
*/ */
.globl rt_hw_context_switch_interrupt .globl rt_hw_context_switch_interrupt
rt_hw_context_switch_interrupt: rt_hw_context_switch_interrupt:
LDR r2, =rt_thread_switch_interrupt_flag LDR r2, =rt_thread_switch_interrupt_flag
LDR r3, [r2] LDR r3, [r2]
@ -133,21 +130,21 @@ _reswitch:
STR r1, [r2] STR r1, [r2]
BX lr BX lr
.globl IRQ_Handler .globl IRQ_Handler
IRQ_Handler: IRQ_Handler:
STMDB sp!, {r0-r12,lr} STMDB sp!, {r0-r12,lr}
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
VMRS r0, fpexc VMRS r0, fpexc
TST r0, #0x40000000 TST r0, #0x40000000
BEQ __no_vfp_frame_str_irq BEQ __no_vfp_frame_str_irq
VSTMDB sp!, {d0-d15} VSTMDB sp!, {d0-d15}
VMRS r1, fpscr VMRS r1, fpscr
@ TODO: add support for Common VFPv3. @ TODO: add support for Common VFPv3.
@ Save registers like FPINST, FPINST2 @ Save registers like FPINST, FPINST2
STMDB sp!, {r1} STMDB sp!, {r1}
__no_vfp_frame_str_irq: __no_vfp_frame_str_irq:
STMDB sp!, {r0} STMDB sp!, {r0}
#endif #endif
BL rt_interrupt_enter BL rt_interrupt_enter
@ -161,14 +158,14 @@ __no_vfp_frame_str_irq:
CMP r1, #1 CMP r1, #1
BEQ rt_hw_context_switch_interrupt_do BEQ rt_hw_context_switch_interrupt_do
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
LDMIA sp!, {r0} @ get fpexc LDMIA sp!, {r0} @ get fpexc
VMSR fpexc, r0 VMSR fpexc, r0
TST r0, #0x40000000 TST r0, #0x40000000
BEQ __no_vfp_frame_ldr_irq BEQ __no_vfp_frame_ldr_irq
LDMIA sp!, {r1} @ get fpscr LDMIA sp!, {r1} @ get fpscr
VMSR fpscr, r1 VMSR fpscr, r1
VLDMIA sp!, {d0-d15} VLDMIA sp!, {d0-d15}
__no_vfp_frame_ldr_irq: __no_vfp_frame_ldr_irq:
#endif #endif
@ -178,19 +175,19 @@ __no_vfp_frame_ldr_irq:
/* /*
* void rt_hw_context_switch_interrupt_do(rt_base_t flag) * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
*/ */
.globl rt_hw_context_switch_interrupt_do .globl rt_hw_context_switch_interrupt_do
rt_hw_context_switch_interrupt_do: rt_hw_context_switch_interrupt_do:
MOV r1, #0 @ clear flag MOV r1, #0 @ clear flag
STR r1, [r0] STR r1, [r0]
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
LDMIA sp!, {r0} @ get fpexc LDMIA sp!, {r0} @ get fpexc
VMSR fpexc, r0 VMSR fpexc, r0
TST r0, #0x40000000 TST r0, #0x40000000
BEQ __no_vfp_frame_do1 BEQ __no_vfp_frame_do1
LDMIA sp!, {r1} @ get fpscr LDMIA sp!, {r1} @ get fpscr
VMSR fpscr, r1 VMSR fpscr, r1
VLDMIA sp!, {d0-d15} VLDMIA sp!, {d0-d15}
__no_vfp_frame_do1: __no_vfp_frame_do1:
#endif #endif
@ -213,17 +210,17 @@ __no_vfp_frame_do1:
@ use them here. @ use them here.
STMDB sp!, {r3} @ push old task's cpsr STMDB sp!, {r3} @ push old task's cpsr
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
VMRS r0, fpexc VMRS r0, fpexc
TST r0, #0x40000000 TST r0, #0x40000000
BEQ __no_vfp_frame_do2 BEQ __no_vfp_frame_do2
VSTMDB sp!, {d0-d15} VSTMDB sp!, {d0-d15}
VMRS r1, fpscr VMRS r1, fpscr
@ TODO: add support for Common VFPv3. @ TODO: add support for Common VFPv3.
@ Save registers like FPINST, FPINST2 @ Save registers like FPINST, FPINST2
STMDB sp!, {r1} STMDB sp!, {r1}
__no_vfp_frame_do2: __no_vfp_frame_do2:
STMDB sp!, {r0} STMDB sp!, {r0}
#endif #endif
LDR r4, =rt_interrupt_from_thread LDR r4, =rt_interrupt_from_thread
@ -234,19 +231,20 @@ __no_vfp_frame_do2:
LDR r6, [r6] LDR r6, [r6]
LDR sp, [r6] @ get new task's stack pointer LDR sp, [r6] @ get new task's stack pointer
#if defined (__VFP_FP__) && !defined(__SOFTFP__) && defined(RT_VFP_LAZY_STACKING) #ifdef RT_USING_FPU
LDMIA sp!, {r0} @ get fpexc ldmfd sp!, {r6}
VMSR fpexc, r0 vmsr fpexc, r6
TST r0, #0x40000000 tst r6, #(1<<30)
BEQ __no_vfp_frame_do3 beq __no_vfp_frame_do3
LDMIA sp!, {r1} @ get fpscr ldmfd sp!, {r5}
VMSR fpscr, r1 vmsr fpscr, r5
VLDMIA sp!, {d0-d15} vldmia sp!, {d0-d15}
__no_vfp_frame_do3: __no_vfp_frame_do3:
#endif #endif
LDMIA sp!, {r4} @ pop new task's cpsr to spsr LDMIA sp!, {r4} @ pop new task's cpsr to spsr
MSR spsr_cxsf, r4 MSR spsr_cxsf, r4
LDMIA sp!, {r0-r12,lr,pc}^ @ pop new task's r0-r12,lr & pc, copy spsr to cpsr ldmfd sp!, {r0-r12,lr,pc}^ /* irq return */