2024-06-28 00:23:09 +08:00
|
|
|
/*
|
|
|
|
* 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
|
2024-04-18 17:12:10 +08:00
|
|
|
|
|
|
|
/* reserved to_thread */
|
|
|
|
mov x19, x1
|
|
|
|
|
|
|
|
mov x0, x19
|
2024-06-28 00:23:09 +08:00
|
|
|
bl rt_cpus_lock_status_restore
|
|
|
|
#ifdef RT_USING_SMART
|
2024-04-18 17:12:10 +08:00
|
|
|
mov x0, x19
|
2024-06-28 00:23:09 +08:00
|
|
|
bl lwp_user_setting_restore
|
|
|
|
#endif
|
2024-04-18 17:12:10 +08:00
|
|
|
b _context_switch_exit
|
2024-06-28 00:23:09 +08:00
|
|
|
|
|
|
|
.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:
|
2024-04-18 17:12:10 +08:00
|
|
|
SAVE_CONTEXT_SWITCH x19, x20
|
2024-06-28 00:23:09 +08:00
|
|
|
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
|
2024-04-18 17:12:10 +08:00
|
|
|
b _context_switch_exit
|
2024-06-28 00:23:09 +08:00
|
|
|
|
2024-04-18 17:12:10 +08:00
|
|
|
.globl rt_hw_irq_exit
|
2024-06-28 00:23:09 +08:00
|
|
|
.globl rt_hw_context_switch_interrupt
|
|
|
|
|
2024-04-18 17:12:10 +08:00
|
|
|
#define EXP_FRAME x19
|
|
|
|
#define FROM_SPP x20
|
|
|
|
#define TO_SPP x21
|
|
|
|
#define TO_TCB x22
|
2024-06-28 00:23:09 +08:00
|
|
|
/*
|
|
|
|
* 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:
|
2024-04-18 17:12:10 +08:00
|
|
|
#ifdef RT_USING_DEBUG
|
|
|
|
/* debug frame for backtrace */
|
2024-06-28 00:23:09 +08:00
|
|
|
stp x29, x30, [sp, #-0x10]!
|
2024-04-18 17:12:10 +08:00
|
|
|
#endif /* RT_USING_DEBUG */
|
|
|
|
|
|
|
|
/* we can discard all the previous ABI here */
|
|
|
|
mov EXP_FRAME, x0
|
|
|
|
mov FROM_SPP, x1
|
|
|
|
mov TO_SPP, x2
|
|
|
|
mov TO_TCB, x3
|
|
|
|
|
2024-06-28 00:23:09 +08:00
|
|
|
#ifdef RT_USING_SMART
|
2024-04-18 17:12:10 +08:00
|
|
|
GET_THREAD_SELF x0
|
2024-06-28 00:23:09 +08:00
|
|
|
bl lwp_user_setting_save
|
2024-04-18 17:12:10 +08:00
|
|
|
#endif /* RT_USING_SMART */
|
|
|
|
|
|
|
|
/* reset SP of from-thread */
|
|
|
|
mov sp, EXP_FRAME
|
|
|
|
|
|
|
|
/* push context for swtich */
|
|
|
|
adr lr, rt_hw_irq_exit
|
|
|
|
SAVE_CONTEXT_SWITCH_FAST
|
|
|
|
|
|
|
|
/* save SP of from-thread */
|
|
|
|
mov x0, sp
|
|
|
|
str x0, [FROM_SPP]
|
|
|
|
|
|
|
|
/* setup SP to to-thread's */
|
|
|
|
ldr x0, [TO_SPP]
|
2024-06-28 00:23:09 +08:00
|
|
|
mov sp, x0
|
2024-04-18 17:12:10 +08:00
|
|
|
|
|
|
|
mov x0, TO_TCB
|
2024-06-28 00:23:09 +08:00
|
|
|
bl rt_cpus_lock_status_restore
|
|
|
|
#ifdef RT_USING_SMART
|
2024-04-18 17:12:10 +08:00
|
|
|
mov x0, TO_TCB
|
2024-06-28 00:23:09 +08:00
|
|
|
bl lwp_user_setting_restore
|
2024-04-18 17:12:10 +08:00
|
|
|
#endif /* RT_USING_SMART */
|
|
|
|
b _context_switch_exit
|
2024-06-28 00:23:09 +08:00
|
|
|
|
2024-04-18 17:12:10 +08:00
|
|
|
_context_switch_exit:
|
2024-08-27 12:45:12 +08:00
|
|
|
.local _context_switch_exit
|
|
|
|
|
2024-06-28 00:23:09 +08:00
|
|
|
clrex
|
|
|
|
RESTORE_CONTEXT_SWITCH
|