diff options
| author | Shell <[email protected]> | 2024-06-28 00:23:09 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-28 00:23:09 +0800 |
| commit | 90917cc75af9406834c14fd25140405ba6f72d6d (patch) | |
| tree | e5ac39bbcb922d380a272c4d80ed439ad316604b /libcpu/aarch64/common/mp | |
| parent | 3d8c27bcc998c0a43aedc069a4a826e349b85485 (diff) | |
[format] cleanup libcpu/aarch64 (#8950)
* [dfs] fixup compiler warning
Signed-off-by: Shell <[email protected]>
* [format] libcpu/arm64: separate context switching codes
Signed-off-by: Shell <[email protected]>
* [format] libcpu/arm64: separate vector
Signed-off-by: Shell <[email protected]>
* [format] libcpu/arm64: separate context_gcc.S
Signed-off-by: Shell <[email protected]>
* [format] libcpu/arm64: moving headers to include directory
Signed-off-by: Shell <[email protected]>
* style: replace tab with space
---------
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'libcpu/aarch64/common/mp')
| -rw-r--r-- | libcpu/aarch64/common/mp/context_gcc.S | 109 | ||||
| -rw-r--r-- | libcpu/aarch64/common/mp/context_gcc.h | 66 | ||||
| -rw-r--r-- | libcpu/aarch64/common/mp/vector_gcc.S | 48 |
3 files changed, 223 insertions, 0 deletions
diff --git a/libcpu/aarch64/common/mp/context_gcc.S b/libcpu/aarch64/common/mp/context_gcc.S new file mode 100644 index 0000000000..9b91d1d3d0 --- /dev/null +++ b/libcpu/aarch64/common/mp/context_gcc.S @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2006-2024, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-05-18 Jesven the first version + * 2023-06-24 Shell Support backtrace for user thread + * 2024-01-06 Shell Fix barrier on irq_disable/enable + * 2024-03-28 Shell Move vector handling codes from context_gcc.S + */ + +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include "context_gcc.h" +#include "../include/vector_gcc.h" + +#include <rtconfig.h> +#include <asm-generic.h> +#include <asm-fpu.h> +#include <armv8.h> + +.section .text + +.globl rt_hw_context_switch_to + +/* + * void rt_hw_context_switch_to(rt_uint3 to, struct rt_thread *to_thread); + * X0 --> to (thread stack) + * X1 --> to_thread + */ +rt_hw_context_switch_to: + ldr x0, [x0] + mov sp, x0 + mov x0, x1 + bl rt_cpus_lock_status_restore +#ifdef RT_USING_SMART + bl rt_thread_self + bl lwp_user_setting_restore +#endif + b rt_hw_context_switch_exit + +.globl rt_hw_context_switch + +/* + * void rt_hw_context_switch(rt_uint32 from, rt_uint32 +to, struct rt_thread *to_thread); + * X0 --> from (from_thread stack) + * X1 --> to (to_thread stack) + * X2 --> to_thread + */ +rt_hw_context_switch: + SAVE_CONTEXT_SWITCH + mov x3, sp + str x3, [x0] // store sp in preempted tasks TCB + ldr x0, [x1] // get new task stack pointer + mov sp, x0 + + /* backup thread self */ + mov x19, x2 + + mov x0, x19 + bl rt_cpus_lock_status_restore +#ifdef RT_USING_SMART + mov x0, x19 + bl lwp_user_setting_restore +#endif + b rt_hw_context_switch_exit + +.globl rt_hw_context_switch_interrupt + +/* + * void rt_hw_context_switch_interrupt(context, from sp, to sp, tp tcb) + * X0 :interrupt context + * X1 :addr of from_thread's sp + * X2 :addr of to_thread's sp + * X3 :to_thread's tcb + */ +rt_hw_context_switch_interrupt: + stp x0, x1, [sp, #-0x10]! + stp x2, x3, [sp, #-0x10]! + stp x29, x30, [sp, #-0x10]! +#ifdef RT_USING_SMART + bl rt_thread_self + bl lwp_user_setting_save +#endif + ldp x29, x30, [sp], #0x10 + ldp x2, x3, [sp], #0x10 + ldp x0, x1, [sp], #0x10 + str x0, [x1] + ldr x0, [x2] + mov sp, x0 + mov x0, x3 + mov x19, x0 + bl rt_cpus_lock_status_restore + mov x0, x19 +#ifdef RT_USING_SMART + bl lwp_user_setting_restore +#endif + b rt_hw_context_switch_exit + +.global rt_hw_context_switch_exit +rt_hw_context_switch_exit: + clrex + mov x0, sp + RESTORE_CONTEXT_SWITCH diff --git a/libcpu/aarch64/common/mp/context_gcc.h b/libcpu/aarch64/common/mp/context_gcc.h new file mode 100644 index 0000000000..2a1e7fe92b --- /dev/null +++ b/libcpu/aarch64/common/mp/context_gcc.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2006-2024, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-03-25 Shell Trimming unecessary ops and + * improve the performance of ctx switch + */ + +#ifndef __ARM64_CONTEXT_H__ +#define __ARM64_CONTEXT_H__ + +#include "../include/context_gcc.h" + +#include <rtconfig.h> +#include <asm-generic.h> +#include <asm-fpu.h> +#include <armv8.h> + +.macro RESTORE_CONTEXT_SWITCH + /* Set the SP to point to the stack of the task being restored. */ + mov sp, x0 + + _RESTORE_CONTEXT_SWITCH +.endm + +.macro RESTORE_IRQ_CONTEXT + /* Set the SP to point to the stack of the task being restored. */ + mov sp, x0 + + ldp x2, x3, [sp], #0x10 /* SPSR and ELR. */ + + 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_FPU sp +#ifdef RT_USING_SMART + beq arch_ret_to_user +#endif + eret +.endm + +#endif /* __ARM64_CONTEXT_H__ */ diff --git a/libcpu/aarch64/common/mp/vector_gcc.S b/libcpu/aarch64/common/mp/vector_gcc.S new file mode 100644 index 0000000000..67b4bc5fe8 --- /dev/null +++ b/libcpu/aarch64/common/mp/vector_gcc.S @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2006-2020, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-03-28 Shell Move vector handling codes from context_gcc.S + */ + +#ifndef __ASSEMBLY__ +#define __ASSEMBLY__ +#endif + +#include "../include/vector_gcc.h" +#include "context_gcc.h" + +.globl vector_fiq +vector_fiq: + b . + +START_POINT(vector_irq) + SAVE_IRQ_CONTEXT + stp x0, x1, [sp, #-0x10]! /* X0 is thread sp */ + + bl rt_interrupt_enter + ldp x0, x1, [sp] + +#ifdef RT_USING_SMART + SAVE_USER_CTX +#endif /* RT_USING_SMART */ + + bl rt_hw_trap_irq + +#ifdef RT_USING_SMART + ldp x0, x1, [sp] + RESTORE_USER_CTX x0 +#endif /* RT_USING_SMART */ + + bl rt_interrupt_leave + + ldp x0, x1, [sp], #0x10 + bl rt_scheduler_do_irq_switch + + mov x0, sp + RESTORE_IRQ_CONTEXT + +START_POINT_END(vector_irq) |
