mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 12:15:32 +08:00
[libcpu/arm64] feat: Trimming General Context
This patch focuses on the ARM64 general context handling code. The modifications are aimed at enhancing performance by simplifying context save/restore operations. Changes include: - Adjusted stack alignment in `arch_set_thread_context` function. - Updated `lwp_gcc.S` to reset frame pointer and link register. - Refined `rt_hw_backtrace_frame_unwind` to handle user space address checks. - Added `GET_THREAD_SELF` macro in `asm-generic.h`. - Simplified context saving/restoring in `context_gcc.h` and related files. - Optimized `rt_hw_context_switch_interrupt` and related assembly routines. Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
@@ -23,4 +23,15 @@
|
||||
.cfi_endproc; \
|
||||
.size name, .-name;
|
||||
|
||||
.macro GET_THREAD_SELF, dst:req
|
||||
#ifdef ARCH_USING_HW_THREAD_SELF
|
||||
mrs x0, tpidr_el1
|
||||
#else /* !ARCH_USING_HW_THREAD_SELF */
|
||||
bl rt_thread_self
|
||||
#endif /* ARCH_USING_HW_THREAD_SELF */
|
||||
.if \dst != x0
|
||||
mov dst, x0
|
||||
.endif
|
||||
.endm
|
||||
|
||||
#endif /* __ASM_GENERIC_H__ */
|
||||
|
||||
@@ -10,67 +10,61 @@
|
||||
#ifndef __ARM64_INC_CONTEXT_H__
|
||||
#define __ARM64_INC_CONTEXT_H__
|
||||
|
||||
.macro SAVE_CONTEXT_SWITCH
|
||||
#include "armv8.h"
|
||||
|
||||
.macro SAVE_CONTEXT_SWITCH, tmpx, tmp2x
|
||||
/* Save the entire context. */
|
||||
SAVE_FPU sp
|
||||
stp x0, x1, [sp, #-0x10]!
|
||||
stp x2, x3, [sp, #-0x10]!
|
||||
stp x4, x5, [sp, #-0x10]!
|
||||
stp x6, x7, [sp, #-0x10]!
|
||||
stp x8, x9, [sp, #-0x10]!
|
||||
stp x10, x11, [sp, #-0x10]!
|
||||
stp x12, x13, [sp, #-0x10]!
|
||||
stp x14, x15, [sp, #-0x10]!
|
||||
stp x16, x17, [sp, #-0x10]!
|
||||
stp x18, x19, [sp, #-0x10]!
|
||||
stp x20, x21, [sp, #-0x10]!
|
||||
stp x22, x23, [sp, #-0x10]!
|
||||
stp x24, x25, [sp, #-0x10]!
|
||||
stp x26, x27, [sp, #-0x10]!
|
||||
stp x28, x29, [sp, #-0x10]!
|
||||
mrs x28, fpcr
|
||||
mrs x29, fpsr
|
||||
stp x28, x29, [sp, #-0x10]!
|
||||
mrs x29, sp_el0
|
||||
stp x29, x30, [sp, #-0x10]!
|
||||
|
||||
stp x19, x20, [sp, #-0x10]!
|
||||
stp x21, x22, [sp, #-0x10]!
|
||||
stp x23, x24, [sp, #-0x10]!
|
||||
stp x25, x26, [sp, #-0x10]!
|
||||
stp x27, x28, [sp, #-0x10]!
|
||||
|
||||
mrs \tmpx, sp_el0
|
||||
stp x29, \tmpx, [sp, #-0x10]!
|
||||
|
||||
mrs \tmpx, fpcr
|
||||
mrs \tmp2x, fpsr
|
||||
stp \tmpx, \tmp2x, [sp, #-0x10]!
|
||||
|
||||
mov \tmpx, #((3 << 6) | 0x5) /* el1h, disable interrupt */
|
||||
stp x30, \tmpx, [sp, #-0x10]!
|
||||
|
||||
.endm
|
||||
|
||||
.macro SAVE_CONTEXT_SWITCH_FAST
|
||||
/* Save the entire context. */
|
||||
add sp, sp, #-1 * CONTEXT_FPU_SIZE
|
||||
|
||||
add sp, sp, #-7 * 16
|
||||
|
||||
mov x19, #((3 << 6) | 0x4 | 0x1) /* el1h, disable interrupt */
|
||||
mov x18, x30
|
||||
stp lr, x19, [sp, #-0x10]!
|
||||
|
||||
stp x18, x19, [sp, #-0x10]!
|
||||
.endm
|
||||
|
||||
.macro _RESTORE_CONTEXT_SWITCH
|
||||
ldp x2, x3, [sp], #0x10 /* SPSR and ELR. */
|
||||
ldp x30, x19, [sp], #0x10 /* SPSR and ELR. */
|
||||
msr elr_el1, x30
|
||||
msr spsr_el1, x19
|
||||
|
||||
tst x3, #0x1f
|
||||
msr spsr_el1, x3
|
||||
msr elr_el1, x2
|
||||
|
||||
ldp x29, x30, [sp], #0x10
|
||||
msr sp_el0, x29
|
||||
ldp x28, x29, [sp], #0x10
|
||||
msr fpcr, x28
|
||||
msr fpsr, x29
|
||||
ldp x28, x29, [sp], #0x10
|
||||
ldp x26, x27, [sp], #0x10
|
||||
ldp x24, x25, [sp], #0x10
|
||||
ldp x22, x23, [sp], #0x10
|
||||
ldp x20, x21, [sp], #0x10
|
||||
ldp x18, x19, [sp], #0x10
|
||||
ldp x16, x17, [sp], #0x10
|
||||
ldp x14, x15, [sp], #0x10
|
||||
ldp x12, x13, [sp], #0x10
|
||||
ldp x10, x11, [sp], #0x10
|
||||
ldp x8, x9, [sp], #0x10
|
||||
ldp x6, x7, [sp], #0x10
|
||||
ldp x4, x5, [sp], #0x10
|
||||
ldp x2, x3, [sp], #0x10
|
||||
ldp x0, x1, [sp], #0x10
|
||||
/* restore NEON */
|
||||
ldp x19, x20, [sp], #0x10
|
||||
msr fpcr, x19
|
||||
msr fpsr, x20
|
||||
|
||||
ldp x29, x19, [sp], #0x10
|
||||
msr sp_el0, x19
|
||||
ldp x27, x28, [sp], #0x10
|
||||
ldp x25, x26, [sp], #0x10
|
||||
ldp x23, x24, [sp], #0x10
|
||||
ldp x21, x22, [sp], #0x10
|
||||
ldp x19, x20, [sp], #0x10
|
||||
|
||||
RESTORE_FPU sp
|
||||
#ifdef RT_USING_SMART
|
||||
beq arch_ret_to_user
|
||||
#endif
|
||||
eret
|
||||
.endm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user