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