1*bdd2596dSAchin Gupta/* 2*bdd2596dSAchin Gupta * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. 3*bdd2596dSAchin Gupta * 4*bdd2596dSAchin Gupta * SPDX-License-Identifier: BSD-3-Clause 5*bdd2596dSAchin Gupta */ 6*bdd2596dSAchin Gupta 7*bdd2596dSAchin Gupta#include <asm_macros.S> 8*bdd2596dSAchin Gupta#include "../spmd_private.h" 9*bdd2596dSAchin Gupta 10*bdd2596dSAchin Gupta .global spmd_spm_core_enter 11*bdd2596dSAchin Gupta .global spmd_spm_core_exit 12*bdd2596dSAchin Gupta 13*bdd2596dSAchin Gupta /* --------------------------------------------------------------------- 14*bdd2596dSAchin Gupta * This function is called with SP_EL0 as stack. Here we stash our EL3 15*bdd2596dSAchin Gupta * callee-saved registers on to the stack as a part of saving the C 16*bdd2596dSAchin Gupta * runtime and enter the secure payload. 17*bdd2596dSAchin Gupta * 'x0' contains a pointer to the memory where the address of the C 18*bdd2596dSAchin Gupta * runtime context is to be saved. 19*bdd2596dSAchin Gupta * --------------------------------------------------------------------- 20*bdd2596dSAchin Gupta */ 21*bdd2596dSAchin Guptafunc spmd_spm_core_enter 22*bdd2596dSAchin Gupta /* Make space for the registers that we're going to save */ 23*bdd2596dSAchin Gupta mov x3, sp 24*bdd2596dSAchin Gupta str x3, [x0, #0] 25*bdd2596dSAchin Gupta sub sp, sp, #SPMD_C_RT_CTX_SIZE 26*bdd2596dSAchin Gupta 27*bdd2596dSAchin Gupta /* Save callee-saved registers on to the stack */ 28*bdd2596dSAchin Gupta stp x19, x20, [sp, #SPMD_C_RT_CTX_X19] 29*bdd2596dSAchin Gupta stp x21, x22, [sp, #SPMD_C_RT_CTX_X21] 30*bdd2596dSAchin Gupta stp x23, x24, [sp, #SPMD_C_RT_CTX_X23] 31*bdd2596dSAchin Gupta stp x25, x26, [sp, #SPMD_C_RT_CTX_X25] 32*bdd2596dSAchin Gupta stp x27, x28, [sp, #SPMD_C_RT_CTX_X27] 33*bdd2596dSAchin Gupta stp x29, x30, [sp, #SPMD_C_RT_CTX_X29] 34*bdd2596dSAchin Gupta 35*bdd2596dSAchin Gupta /* --------------------------------------------------------------------- 36*bdd2596dSAchin Gupta * Everything is setup now. el3_exit() will use the secure context to 37*bdd2596dSAchin Gupta * restore to the general purpose and EL3 system registers to ERET 38*bdd2596dSAchin Gupta * into the secure payload. 39*bdd2596dSAchin Gupta * --------------------------------------------------------------------- 40*bdd2596dSAchin Gupta */ 41*bdd2596dSAchin Gupta b el3_exit 42*bdd2596dSAchin Guptaendfunc spmd_spm_core_enter 43*bdd2596dSAchin Gupta 44*bdd2596dSAchin Gupta /* --------------------------------------------------------------------- 45*bdd2596dSAchin Gupta * This function is called with 'x0' pointing to a C runtime context. 46*bdd2596dSAchin Gupta * It restores the saved registers and jumps to that runtime with 'x0' 47*bdd2596dSAchin Gupta * as the new SP register. This destroys the C runtime context that had 48*bdd2596dSAchin Gupta * been built on the stack below the saved context by the caller. Later 49*bdd2596dSAchin Gupta * the second parameter 'x1' is passed as a return value to the caller. 50*bdd2596dSAchin Gupta * --------------------------------------------------------------------- 51*bdd2596dSAchin Gupta */ 52*bdd2596dSAchin Guptafunc spmd_spm_core_exit 53*bdd2596dSAchin Gupta /* Restore the previous stack */ 54*bdd2596dSAchin Gupta mov sp, x0 55*bdd2596dSAchin Gupta 56*bdd2596dSAchin Gupta /* Restore callee-saved registers on to the stack */ 57*bdd2596dSAchin Gupta ldp x19, x20, [x0, #(SPMD_C_RT_CTX_X19 - SPMD_C_RT_CTX_SIZE)] 58*bdd2596dSAchin Gupta ldp x21, x22, [x0, #(SPMD_C_RT_CTX_X21 - SPMD_C_RT_CTX_SIZE)] 59*bdd2596dSAchin Gupta ldp x23, x24, [x0, #(SPMD_C_RT_CTX_X23 - SPMD_C_RT_CTX_SIZE)] 60*bdd2596dSAchin Gupta ldp x25, x26, [x0, #(SPMD_C_RT_CTX_X25 - SPMD_C_RT_CTX_SIZE)] 61*bdd2596dSAchin Gupta ldp x27, x28, [x0, #(SPMD_C_RT_CTX_X27 - SPMD_C_RT_CTX_SIZE)] 62*bdd2596dSAchin Gupta ldp x29, x30, [x0, #(SPMD_C_RT_CTX_X29 - SPMD_C_RT_CTX_SIZE)] 63*bdd2596dSAchin Gupta 64*bdd2596dSAchin Gupta /* --------------------------------------------------------------------- 65*bdd2596dSAchin Gupta * This should take us back to the instruction after the call to the 66*bdd2596dSAchin Gupta * last spm_secure_partition_enter().* Place the second parameter to x0 67*bdd2596dSAchin Gupta * so that the caller will see it as a return value from the original 68*bdd2596dSAchin Gupta * entry call. 69*bdd2596dSAchin Gupta * --------------------------------------------------------------------- 70*bdd2596dSAchin Gupta */ 71*bdd2596dSAchin Gupta mov x0, x1 72*bdd2596dSAchin Gupta ret 73*bdd2596dSAchin Guptaendfunc spmd_spm_core_exit 74