122038315SVarun Wadekar/* 222038315SVarun Wadekar * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 322038315SVarun Wadekar * 4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 522038315SVarun Wadekar */ 622038315SVarun Wadekar 722038315SVarun Wadekar#include <asm_macros.S> 822038315SVarun Wadekar#include "tlkd_private.h" 922038315SVarun Wadekar 1022038315SVarun Wadekar .global tlkd_enter_sp 1122038315SVarun Wadekar .global tlkd_exit_sp 1222038315SVarun Wadekar 1322038315SVarun Wadekar /* --------------------------------------------- 1422038315SVarun Wadekar * This function is called with SP_EL0 as stack. 1522038315SVarun Wadekar * Here we stash our EL3 callee-saved registers 1622038315SVarun Wadekar * on to the stack as a part of saving the C 1722038315SVarun Wadekar * runtime and enter the secure payload. 1822038315SVarun Wadekar * 'x0' contains a pointer to the memory where 1922038315SVarun Wadekar * the address of the C runtime context is to be 2022038315SVarun Wadekar * saved. 2122038315SVarun Wadekar * --------------------------------------------- 2222038315SVarun Wadekar */ 2322038315SVarun Wadekarfunc tlkd_enter_sp 2422038315SVarun Wadekar /* Make space for the registers that we're going to save */ 2522038315SVarun Wadekar mov x3, sp 2622038315SVarun Wadekar str x3, [x0, #0] 2722038315SVarun Wadekar sub sp, sp, #TLKD_C_RT_CTX_SIZE 2822038315SVarun Wadekar 2922038315SVarun Wadekar /* Save callee-saved registers on to the stack */ 3022038315SVarun Wadekar stp x19, x20, [sp, #TLKD_C_RT_CTX_X19] 3122038315SVarun Wadekar stp x21, x22, [sp, #TLKD_C_RT_CTX_X21] 3222038315SVarun Wadekar stp x23, x24, [sp, #TLKD_C_RT_CTX_X23] 3322038315SVarun Wadekar stp x25, x26, [sp, #TLKD_C_RT_CTX_X25] 3422038315SVarun Wadekar stp x27, x28, [sp, #TLKD_C_RT_CTX_X27] 3522038315SVarun Wadekar stp x29, x30, [sp, #TLKD_C_RT_CTX_X29] 3622038315SVarun Wadekar 3722038315SVarun Wadekar /* ---------------------------------------------- 3822038315SVarun Wadekar * Everything is setup now. el3_exit() will 3922038315SVarun Wadekar * use the secure context to restore to the 4022038315SVarun Wadekar * general purpose and EL3 system registers to 4122038315SVarun Wadekar * ERET into the secure payload. 4222038315SVarun Wadekar * ---------------------------------------------- 4322038315SVarun Wadekar */ 4422038315SVarun Wadekar b el3_exit 458b779620SKévin Petitendfunc tlkd_enter_sp 4622038315SVarun Wadekar 4722038315SVarun Wadekar /* ---------------------------------------------- 4822038315SVarun Wadekar * This function is called with 'x0' pointing to 4922038315SVarun Wadekar * a C runtime context saved in tlkd_enter_sp(). 5022038315SVarun Wadekar * It restores the saved registers and jumps to 5122038315SVarun Wadekar * that runtime with 'x0' as the new sp. This 5222038315SVarun Wadekar * destroys the C runtime context that had been 5322038315SVarun Wadekar * built on the stack below the saved context by 5422038315SVarun Wadekar * the caller. Later the second parameter 'x1' 5522038315SVarun Wadekar * is passed as return value to the caller 5622038315SVarun Wadekar * ---------------------------------------------- 5722038315SVarun Wadekar */ 5822038315SVarun Wadekarfunc tlkd_exit_sp 5922038315SVarun Wadekar /* Restore the previous stack */ 6022038315SVarun Wadekar mov sp, x0 6122038315SVarun Wadekar 6222038315SVarun Wadekar /* Restore callee-saved registers on to the stack */ 6322038315SVarun Wadekar ldp x19, x20, [x0, #(TLKD_C_RT_CTX_X19 - TLKD_C_RT_CTX_SIZE)] 6422038315SVarun Wadekar ldp x21, x22, [x0, #(TLKD_C_RT_CTX_X21 - TLKD_C_RT_CTX_SIZE)] 6522038315SVarun Wadekar ldp x23, x24, [x0, #(TLKD_C_RT_CTX_X23 - TLKD_C_RT_CTX_SIZE)] 6622038315SVarun Wadekar ldp x25, x26, [x0, #(TLKD_C_RT_CTX_X25 - TLKD_C_RT_CTX_SIZE)] 6722038315SVarun Wadekar ldp x27, x28, [x0, #(TLKD_C_RT_CTX_X27 - TLKD_C_RT_CTX_SIZE)] 6822038315SVarun Wadekar ldp x29, x30, [x0, #(TLKD_C_RT_CTX_X29 - TLKD_C_RT_CTX_SIZE)] 6922038315SVarun Wadekar 7022038315SVarun Wadekar /* ------------------------------------------------ 7122038315SVarun Wadekar * This should take us back to the instruction 7222038315SVarun Wadekar * after the call to the last tlkd_enter_sp(). 7322038315SVarun Wadekar * Place the second parameter to x0 so that the 7422038315SVarun Wadekar * caller will see it as a return value from the 7522038315SVarun Wadekar * original entry call 7622038315SVarun Wadekar * ------------------------------------------------ 7722038315SVarun Wadekar */ 7822038315SVarun Wadekar mov x0, x1 7922038315SVarun Wadekar ret 808b779620SKévin Petitendfunc tlkd_exit_sp 81