2017-01-23 00:21:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Cadence Design Systems, Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief kernel swapper code for Xtensa
|
|
|
|
*
|
2017-04-07 06:30:27 +08:00
|
|
|
* This module implements the __swap() routine for the Xtensa architecture.
|
2017-01-23 00:21:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xtensa_context.h>
|
|
|
|
#include <kernel_arch_data.h>
|
|
|
|
#include <offsets_short.h>
|
|
|
|
|
|
|
|
.extern _kernel
|
2017-04-07 06:30:27 +08:00
|
|
|
/* unsigned int __swap (unsigned int basepri); */
|
|
|
|
.globl __swap
|
|
|
|
.type __swap,@function
|
2017-01-23 00:21:34 +08:00
|
|
|
.align 4
|
2017-04-07 06:30:27 +08:00
|
|
|
__swap:
|
2017-01-23 00:21:34 +08:00
|
|
|
#ifdef __XTENSA_CALL0_ABI__
|
|
|
|
addi sp, sp, -XT_SOL_FRMSZ
|
|
|
|
#else
|
|
|
|
entry sp, XT_SOL_FRMSZ
|
|
|
|
#endif
|
|
|
|
s32i a0, sp, XT_SOL_pc
|
|
|
|
s32i a2, sp, XT_SOL_ps
|
|
|
|
#ifdef __XTENSA_CALL0_ABI__
|
2017-02-11 04:58:08 +08:00
|
|
|
s32i a12, sp, XT_SOL_a12 /* save callee-saved registers */
|
2017-01-23 00:21:34 +08:00
|
|
|
s32i a13, sp, XT_SOL_a13
|
|
|
|
s32i a14, sp, XT_SOL_a14
|
|
|
|
s32i a15, sp, XT_SOL_a15
|
|
|
|
#else
|
2017-02-11 04:58:08 +08:00
|
|
|
/* Spill register windows. Calling xthal_window_spill() causes extra
|
|
|
|
* spills and reloads, so we will set things up to call the _nw version
|
|
|
|
* instead to save cycles.
|
|
|
|
*/
|
|
|
|
/* spills a4-a7 if needed */
|
|
|
|
movi a6, ~(PS_WOE_MASK|PS_INTLEVEL_MASK)
|
|
|
|
and a2, a2, a6 /* clear WOE, INTLEVEL */
|
|
|
|
addi a2, a2, XCHAL_EXCM_LEVEL /* set INTLEVEL */
|
2017-01-23 00:21:34 +08:00
|
|
|
wsr a2, PS
|
|
|
|
rsync
|
|
|
|
call0 xthal_window_spill_nw
|
2017-02-11 04:58:08 +08:00
|
|
|
l32i a2, sp, XT_SOL_ps /* restore PS */
|
2017-01-23 00:21:34 +08:00
|
|
|
addi a2, a2, XCHAL_EXCM_LEVEL
|
|
|
|
wsr a2, PS
|
|
|
|
#endif
|
|
|
|
#if XCHAL_CP_NUM > 0
|
2017-02-11 04:58:08 +08:00
|
|
|
/* Save coprocessor callee-saved state (if any). At this point CPENABLE
|
|
|
|
* should still reflect which CPs were in use (enabled).
|
|
|
|
*/
|
2017-01-23 00:21:34 +08:00
|
|
|
call0 _xt_coproc_savecs
|
|
|
|
#endif
|
|
|
|
movi a2, _kernel
|
|
|
|
movi a3, 0
|
|
|
|
l32i a4, a2, KERNEL_OFFSET(current) /* a4 := _kernel->current */
|
|
|
|
|
2017-02-11 04:58:08 +08:00
|
|
|
s32i a3, sp, XT_SOL_exit /* 0 to flag as solicited frame */
|
2017-01-28 02:11:48 +08:00
|
|
|
s32i sp, a4, THREAD_OFFSET(sp) /* current->arch.topOfStack := sp */
|
2017-02-05 18:51:26 +08:00
|
|
|
/*
|
2017-04-07 06:30:27 +08:00
|
|
|
* Set __swap()'s default return code to -EAGAIN. This eliminates the
|
2017-02-05 18:51:26 +08:00
|
|
|
* need for the timeout code to set it itself.
|
|
|
|
*/
|
|
|
|
movi a3, -11 /* a3 := -EAGAIN. TODO: Use a macro here insted of 11 */
|
|
|
|
s32i a3, a4, THREAD_OFFSET(retval) /* current->arch.retval := -EAGAIN */
|
2017-01-23 00:21:34 +08:00
|
|
|
|
|
|
|
#if XCHAL_CP_NUM > 0
|
|
|
|
/* Clear CPENABLE, also in task's co-processor state save area. */
|
|
|
|
movi a3, 0
|
2017-04-14 02:02:49 +08:00
|
|
|
/* a4 = _kernel->current */
|
2017-01-23 00:21:34 +08:00
|
|
|
wsr a3, CPENABLE
|
2017-04-14 02:02:49 +08:00
|
|
|
s16i a3, a4, THREAD_OFFSET(cpEnable) /* clear saved cpenable */
|
2017-01-23 00:21:34 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-06 19:48:53 +08:00
|
|
|
#ifdef CONFIG_TRACING
|
2017-01-23 00:21:34 +08:00
|
|
|
/* Register the context switch */
|
|
|
|
#ifdef __XTENSA_CALL0_ABI__
|
2018-04-06 09:06:33 +08:00
|
|
|
call0 z_sys_trace_thread_switched_in
|
2017-01-23 00:21:34 +08:00
|
|
|
#else
|
2018-04-06 09:06:33 +08:00
|
|
|
call4 z_sys_trace_thread_switched_in
|
2017-01-23 00:21:34 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-02-10 05:30:29 +08:00
|
|
|
/* _thread := _kernel.ready_q.cache */
|
|
|
|
l32i a3, a2, KERNEL_OFFSET(ready_q_cache)
|
2017-01-23 00:21:34 +08:00
|
|
|
/*
|
2017-02-04 01:33:23 +08:00
|
|
|
* Swap threads if any is to be swapped in.
|
2017-01-23 00:21:34 +08:00
|
|
|
*/
|
2017-02-10 05:30:29 +08:00
|
|
|
call0 _zxt_dispatch /* (_kernel@a2, _thread@a3) */
|
2017-01-23 00:21:34 +08:00
|
|
|
/* Never reaches here. */
|
|
|
|
|