blob: f15d66bcfd623d97981103d851ad1a1fdfd29a20 [file] [log] [blame]
Achin Gupta375f5382014-02-18 18:12:48 +00001/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta375f5382014-02-18 18:12:48 +00005 */
6
Achin Gupta375f5382014-02-18 18:12:48 +00007#include <asm_macros.S>
Dan Handley714a0d22014-04-09 13:13:04 +01008#include "tspd_private.h"
Achin Gupta375f5382014-02-18 18:12:48 +00009
10 .global tspd_enter_sp
11 /* ---------------------------------------------
12 * This function is called with SP_EL0 as stack.
13 * Here we stash our EL3 callee-saved registers
14 * on to the stack as a part of saving the C
15 * runtime and enter the secure payload.
16 * 'x0' contains a pointer to the memory where
17 * the address of the C runtime context is to be
18 * saved.
19 * ---------------------------------------------
20 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000021func tspd_enter_sp
Achin Gupta375f5382014-02-18 18:12:48 +000022 /* Make space for the registers that we're going to save */
23 mov x3, sp
24 str x3, [x0, #0]
25 sub sp, sp, #TSPD_C_RT_CTX_SIZE
26
27 /* Save callee-saved registers on to the stack */
28 stp x19, x20, [sp, #TSPD_C_RT_CTX_X19]
29 stp x21, x22, [sp, #TSPD_C_RT_CTX_X21]
30 stp x23, x24, [sp, #TSPD_C_RT_CTX_X23]
31 stp x25, x26, [sp, #TSPD_C_RT_CTX_X25]
32 stp x27, x28, [sp, #TSPD_C_RT_CTX_X27]
33 stp x29, x30, [sp, #TSPD_C_RT_CTX_X29]
34
35 /* ---------------------------------------------
36 * Everything is setup now. el3_exit() will
37 * use the secure context to restore to the
38 * general purpose and EL3 system registers to
39 * ERET into the secure payload.
40 * ---------------------------------------------
41 */
42 b el3_exit
Kévin Petita877c252015-03-24 14:03:57 +000043endfunc tspd_enter_sp
Achin Gupta375f5382014-02-18 18:12:48 +000044
45 /* ---------------------------------------------
46 * This function is called 'x0' pointing to a C
47 * runtime context saved in tspd_enter_sp(). It
48 * restores the saved registers and jumps to
49 * that runtime with 'x0' as the new sp. This
50 * destroys the C runtime context that had been
51 * built on the stack below the saved context by
52 * the caller. Later the second parameter 'x1'
53 * is passed as return value to the caller
54 * ---------------------------------------------
55 */
56 .global tspd_exit_sp
Andrew Thoelke38bde412014-03-18 13:46:55 +000057func tspd_exit_sp
Achin Gupta375f5382014-02-18 18:12:48 +000058 /* Restore the previous stack */
59 mov sp, x0
60
61 /* Restore callee-saved registers on to the stack */
62 ldp x19, x20, [x0, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)]
63 ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)]
64 ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)]
65 ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)]
66 ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)]
67 ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)]
68
69 /* ---------------------------------------------
70 * This should take us back to the instruction
71 * after the call to the last tspd_enter_sp().
72 * Place the second parameter to x0 so that the
73 * caller will see it as a return value from the
74 * original entry call
75 * ---------------------------------------------
76 */
77 mov x0, x1
78 ret
Kévin Petita877c252015-03-24 14:03:57 +000079endfunc tspd_exit_sp