1375f538aSAchin Gupta/* 2375f538aSAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3375f538aSAchin Gupta * 4375f538aSAchin Gupta * Redistribution and use in source and binary forms, with or without 5375f538aSAchin Gupta * modification, are permitted provided that the following conditions are met: 6375f538aSAchin Gupta * 7375f538aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 8375f538aSAchin Gupta * list of conditions and the following disclaimer. 9375f538aSAchin Gupta * 10375f538aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 11375f538aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 12375f538aSAchin Gupta * and/or other materials provided with the distribution. 13375f538aSAchin Gupta * 14375f538aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 15375f538aSAchin Gupta * to endorse or promote products derived from this software without specific 16375f538aSAchin Gupta * prior written permission. 17375f538aSAchin Gupta * 18375f538aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19375f538aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20375f538aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21375f538aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22375f538aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23375f538aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24375f538aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25375f538aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26375f538aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27375f538aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28375f538aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 29375f538aSAchin Gupta */ 30375f538aSAchin Gupta 31375f538aSAchin Gupta#include <asm_macros.S> 3235e98e55SDan Handley#include "tspd_private.h" 33375f538aSAchin Gupta 34375f538aSAchin Gupta .global tspd_enter_sp 35375f538aSAchin Gupta /* --------------------------------------------- 36375f538aSAchin Gupta * This function is called with SP_EL0 as stack. 37375f538aSAchin Gupta * Here we stash our EL3 callee-saved registers 38375f538aSAchin Gupta * on to the stack as a part of saving the C 39375f538aSAchin Gupta * runtime and enter the secure payload. 40375f538aSAchin Gupta * 'x0' contains a pointer to the memory where 41375f538aSAchin Gupta * the address of the C runtime context is to be 42375f538aSAchin Gupta * saved. 43375f538aSAchin Gupta * --------------------------------------------- 44375f538aSAchin Gupta */ 450a30cf54SAndrew Thoelkefunc tspd_enter_sp 46375f538aSAchin Gupta /* Make space for the registers that we're going to save */ 47375f538aSAchin Gupta mov x3, sp 48375f538aSAchin Gupta str x3, [x0, #0] 49375f538aSAchin Gupta sub sp, sp, #TSPD_C_RT_CTX_SIZE 50375f538aSAchin Gupta 51375f538aSAchin Gupta /* Save callee-saved registers on to the stack */ 52375f538aSAchin Gupta stp x19, x20, [sp, #TSPD_C_RT_CTX_X19] 53375f538aSAchin Gupta stp x21, x22, [sp, #TSPD_C_RT_CTX_X21] 54375f538aSAchin Gupta stp x23, x24, [sp, #TSPD_C_RT_CTX_X23] 55375f538aSAchin Gupta stp x25, x26, [sp, #TSPD_C_RT_CTX_X25] 56375f538aSAchin Gupta stp x27, x28, [sp, #TSPD_C_RT_CTX_X27] 57375f538aSAchin Gupta stp x29, x30, [sp, #TSPD_C_RT_CTX_X29] 58375f538aSAchin Gupta 59375f538aSAchin Gupta /* --------------------------------------------- 60375f538aSAchin Gupta * Everything is setup now. el3_exit() will 61375f538aSAchin Gupta * use the secure context to restore to the 62375f538aSAchin Gupta * general purpose and EL3 system registers to 63375f538aSAchin Gupta * ERET into the secure payload. 64375f538aSAchin Gupta * --------------------------------------------- 65375f538aSAchin Gupta */ 66375f538aSAchin Gupta b el3_exit 67*8b779620SKévin Petitendfunc tspd_enter_sp 68375f538aSAchin Gupta 69375f538aSAchin Gupta /* --------------------------------------------- 70375f538aSAchin Gupta * This function is called 'x0' pointing to a C 71375f538aSAchin Gupta * runtime context saved in tspd_enter_sp(). It 72375f538aSAchin Gupta * restores the saved registers and jumps to 73375f538aSAchin Gupta * that runtime with 'x0' as the new sp. This 74375f538aSAchin Gupta * destroys the C runtime context that had been 75375f538aSAchin Gupta * built on the stack below the saved context by 76375f538aSAchin Gupta * the caller. Later the second parameter 'x1' 77375f538aSAchin Gupta * is passed as return value to the caller 78375f538aSAchin Gupta * --------------------------------------------- 79375f538aSAchin Gupta */ 80375f538aSAchin Gupta .global tspd_exit_sp 810a30cf54SAndrew Thoelkefunc tspd_exit_sp 82375f538aSAchin Gupta /* Restore the previous stack */ 83375f538aSAchin Gupta mov sp, x0 84375f538aSAchin Gupta 85375f538aSAchin Gupta /* Restore callee-saved registers on to the stack */ 86375f538aSAchin Gupta ldp x19, x20, [x0, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)] 87375f538aSAchin Gupta ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)] 88375f538aSAchin Gupta ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)] 89375f538aSAchin Gupta ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)] 90375f538aSAchin Gupta ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)] 91375f538aSAchin Gupta ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)] 92375f538aSAchin Gupta 93375f538aSAchin Gupta /* --------------------------------------------- 94375f538aSAchin Gupta * This should take us back to the instruction 95375f538aSAchin Gupta * after the call to the last tspd_enter_sp(). 96375f538aSAchin Gupta * Place the second parameter to x0 so that the 97375f538aSAchin Gupta * caller will see it as a return value from the 98375f538aSAchin Gupta * original entry call 99375f538aSAchin Gupta * --------------------------------------------- 100375f538aSAchin Gupta */ 101375f538aSAchin Gupta mov x0, x1 102375f538aSAchin Gupta ret 103*8b779620SKévin Petitendfunc tspd_exit_sp 104