1375f538aSAchin Gupta/* 2375f538aSAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3375f538aSAchin Gupta * 4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5375f538aSAchin Gupta */ 6375f538aSAchin Gupta 7375f538aSAchin Gupta#include <asm_macros.S> 835e98e55SDan Handley#include "tspd_private.h" 9375f538aSAchin Gupta 10375f538aSAchin Gupta .global tspd_enter_sp 11375f538aSAchin Gupta /* --------------------------------------------- 12375f538aSAchin Gupta * This function is called with SP_EL0 as stack. 13375f538aSAchin Gupta * Here we stash our EL3 callee-saved registers 14375f538aSAchin Gupta * on to the stack as a part of saving the C 15375f538aSAchin Gupta * runtime and enter the secure payload. 16375f538aSAchin Gupta * 'x0' contains a pointer to the memory where 17375f538aSAchin Gupta * the address of the C runtime context is to be 18375f538aSAchin Gupta * saved. 19375f538aSAchin Gupta * --------------------------------------------- 20375f538aSAchin Gupta */ 210a30cf54SAndrew Thoelkefunc tspd_enter_sp 22375f538aSAchin Gupta /* Make space for the registers that we're going to save */ 23375f538aSAchin Gupta mov x3, sp 24375f538aSAchin Gupta str x3, [x0, #0] 25375f538aSAchin Gupta sub sp, sp, #TSPD_C_RT_CTX_SIZE 26375f538aSAchin Gupta 27375f538aSAchin Gupta /* Save callee-saved registers on to the stack */ 28375f538aSAchin Gupta stp x19, x20, [sp, #TSPD_C_RT_CTX_X19] 29375f538aSAchin Gupta stp x21, x22, [sp, #TSPD_C_RT_CTX_X21] 30375f538aSAchin Gupta stp x23, x24, [sp, #TSPD_C_RT_CTX_X23] 31375f538aSAchin Gupta stp x25, x26, [sp, #TSPD_C_RT_CTX_X25] 32375f538aSAchin Gupta stp x27, x28, [sp, #TSPD_C_RT_CTX_X27] 33375f538aSAchin Gupta stp x29, x30, [sp, #TSPD_C_RT_CTX_X29] 34375f538aSAchin Gupta 35375f538aSAchin Gupta /* --------------------------------------------- 36375f538aSAchin Gupta * Everything is setup now. el3_exit() will 37375f538aSAchin Gupta * use the secure context to restore to the 38375f538aSAchin Gupta * general purpose and EL3 system registers to 39375f538aSAchin Gupta * ERET into the secure payload. 40375f538aSAchin Gupta * --------------------------------------------- 41375f538aSAchin Gupta */ 42375f538aSAchin Gupta b el3_exit 438b779620SKévin Petitendfunc tspd_enter_sp 44375f538aSAchin Gupta 45375f538aSAchin Gupta /* --------------------------------------------- 46375f538aSAchin Gupta * This function is called 'x0' pointing to a C 47375f538aSAchin Gupta * runtime context saved in tspd_enter_sp(). It 48375f538aSAchin Gupta * restores the saved registers and jumps to 49375f538aSAchin Gupta * that runtime with 'x0' as the new sp. This 50375f538aSAchin Gupta * destroys the C runtime context that had been 51375f538aSAchin Gupta * built on the stack below the saved context by 52375f538aSAchin Gupta * the caller. Later the second parameter 'x1' 53375f538aSAchin Gupta * is passed as return value to the caller 54375f538aSAchin Gupta * --------------------------------------------- 55375f538aSAchin Gupta */ 56375f538aSAchin Gupta .global tspd_exit_sp 570a30cf54SAndrew Thoelkefunc tspd_exit_sp 58375f538aSAchin Gupta /* Restore the previous stack */ 59375f538aSAchin Gupta mov sp, x0 60375f538aSAchin Gupta 61375f538aSAchin Gupta /* Restore callee-saved registers on to the stack */ 62375f538aSAchin Gupta ldp x19, x20, [x0, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)] 63375f538aSAchin Gupta ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)] 64375f538aSAchin Gupta ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)] 65375f538aSAchin Gupta ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)] 66375f538aSAchin Gupta ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)] 67375f538aSAchin Gupta ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)] 68375f538aSAchin Gupta 69375f538aSAchin Gupta /* --------------------------------------------- 70375f538aSAchin Gupta * This should take us back to the instruction 71375f538aSAchin Gupta * after the call to the last tspd_enter_sp(). 72375f538aSAchin Gupta * Place the second parameter to x0 so that the 73375f538aSAchin Gupta * caller will see it as a return value from the 74375f538aSAchin Gupta * original entry call 75375f538aSAchin Gupta * --------------------------------------------- 76375f538aSAchin Gupta */ 77375f538aSAchin Gupta mov x0, x1 78375f538aSAchin Gupta ret 798b779620SKévin Petitendfunc tspd_exit_sp 80