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