1*375f538aSAchin Gupta/* 2*375f538aSAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3*375f538aSAchin Gupta * 4*375f538aSAchin Gupta * Redistribution and use in source and binary forms, with or without 5*375f538aSAchin Gupta * modification, are permitted provided that the following conditions are met: 6*375f538aSAchin Gupta * 7*375f538aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 8*375f538aSAchin Gupta * list of conditions and the following disclaimer. 9*375f538aSAchin Gupta * 10*375f538aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 11*375f538aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 12*375f538aSAchin Gupta * and/or other materials provided with the distribution. 13*375f538aSAchin Gupta * 14*375f538aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 15*375f538aSAchin Gupta * to endorse or promote products derived from this software without specific 16*375f538aSAchin Gupta * prior written permission. 17*375f538aSAchin Gupta * 18*375f538aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*375f538aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*375f538aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*375f538aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*375f538aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*375f538aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*375f538aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*375f538aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*375f538aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*375f538aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*375f538aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 29*375f538aSAchin Gupta */ 30*375f538aSAchin Gupta 31*375f538aSAchin Gupta#include <context.h> 32*375f538aSAchin Gupta#include <tspd_private.h> 33*375f538aSAchin Gupta#include <asm_macros.S> 34*375f538aSAchin Gupta#include <cm_macros.S> 35*375f538aSAchin Gupta 36*375f538aSAchin Gupta .global tspd_enter_sp 37*375f538aSAchin Gupta /* --------------------------------------------- 38*375f538aSAchin Gupta * This function is called with SP_EL0 as stack. 39*375f538aSAchin Gupta * Here we stash our EL3 callee-saved registers 40*375f538aSAchin Gupta * on to the stack as a part of saving the C 41*375f538aSAchin Gupta * runtime and enter the secure payload. 42*375f538aSAchin Gupta * 'x0' contains a pointer to the memory where 43*375f538aSAchin Gupta * the address of the C runtime context is to be 44*375f538aSAchin Gupta * saved. 45*375f538aSAchin Gupta * --------------------------------------------- 46*375f538aSAchin Gupta */ 47*375f538aSAchin Guptatspd_enter_sp: 48*375f538aSAchin Gupta /* Make space for the registers that we're going to save */ 49*375f538aSAchin Gupta mov x3, sp 50*375f538aSAchin Gupta str x3, [x0, #0] 51*375f538aSAchin Gupta sub sp, sp, #TSPD_C_RT_CTX_SIZE 52*375f538aSAchin Gupta 53*375f538aSAchin Gupta /* Save callee-saved registers on to the stack */ 54*375f538aSAchin Gupta stp x19, x20, [sp, #TSPD_C_RT_CTX_X19] 55*375f538aSAchin Gupta stp x21, x22, [sp, #TSPD_C_RT_CTX_X21] 56*375f538aSAchin Gupta stp x23, x24, [sp, #TSPD_C_RT_CTX_X23] 57*375f538aSAchin Gupta stp x25, x26, [sp, #TSPD_C_RT_CTX_X25] 58*375f538aSAchin Gupta stp x27, x28, [sp, #TSPD_C_RT_CTX_X27] 59*375f538aSAchin Gupta stp x29, x30, [sp, #TSPD_C_RT_CTX_X29] 60*375f538aSAchin Gupta 61*375f538aSAchin Gupta /* --------------------------------------------- 62*375f538aSAchin Gupta * Everything is setup now. el3_exit() will 63*375f538aSAchin Gupta * use the secure context to restore to the 64*375f538aSAchin Gupta * general purpose and EL3 system registers to 65*375f538aSAchin Gupta * ERET into the secure payload. 66*375f538aSAchin Gupta * --------------------------------------------- 67*375f538aSAchin Gupta */ 68*375f538aSAchin Gupta b el3_exit 69*375f538aSAchin Gupta 70*375f538aSAchin Gupta /* --------------------------------------------- 71*375f538aSAchin Gupta * This function is called 'x0' pointing to a C 72*375f538aSAchin Gupta * runtime context saved in tspd_enter_sp(). It 73*375f538aSAchin Gupta * restores the saved registers and jumps to 74*375f538aSAchin Gupta * that runtime with 'x0' as the new sp. This 75*375f538aSAchin Gupta * destroys the C runtime context that had been 76*375f538aSAchin Gupta * built on the stack below the saved context by 77*375f538aSAchin Gupta * the caller. Later the second parameter 'x1' 78*375f538aSAchin Gupta * is passed as return value to the caller 79*375f538aSAchin Gupta * --------------------------------------------- 80*375f538aSAchin Gupta */ 81*375f538aSAchin Gupta .global tspd_exit_sp 82*375f538aSAchin Guptatspd_exit_sp: 83*375f538aSAchin Gupta /* Restore the previous stack */ 84*375f538aSAchin Gupta mov sp, x0 85*375f538aSAchin Gupta 86*375f538aSAchin Gupta /* Restore callee-saved registers on to the stack */ 87*375f538aSAchin Gupta ldp x19, x20, [x0, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)] 88*375f538aSAchin Gupta ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)] 89*375f538aSAchin Gupta ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)] 90*375f538aSAchin Gupta ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)] 91*375f538aSAchin Gupta ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)] 92*375f538aSAchin Gupta ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)] 93*375f538aSAchin Gupta 94*375f538aSAchin Gupta /* --------------------------------------------- 95*375f538aSAchin Gupta * This should take us back to the instruction 96*375f538aSAchin Gupta * after the call to the last tspd_enter_sp(). 97*375f538aSAchin Gupta * Place the second parameter to x0 so that the 98*375f538aSAchin Gupta * caller will see it as a return value from the 99*375f538aSAchin Gupta * original entry call 100*375f538aSAchin Gupta * --------------------------------------------- 101*375f538aSAchin Gupta */ 102*375f538aSAchin Gupta mov x0, x1 103*375f538aSAchin Gupta ret 104