blob: dd3b07b452616b087e3d7433d6242cb97f5adc2e [file] [log] [blame]
Achin Gupta375f5382014-02-18 18:12:48 +00001/*
2 * Copyright (c) 2013-2014, 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
Achin Gupta375f5382014-02-18 18:12:48 +000031#include <asm_macros.S>
Dan Handley714a0d22014-04-09 13:13:04 +010032#include "tspd_private.h"
Achin Gupta375f5382014-02-18 18:12:48 +000033
34 .global tspd_enter_sp
35 /* ---------------------------------------------
36 * This function is called with SP_EL0 as stack.
37 * Here we stash our EL3 callee-saved registers
38 * on to the stack as a part of saving the C
39 * runtime and enter the secure payload.
40 * 'x0' contains a pointer to the memory where
41 * the address of the C runtime context is to be
42 * saved.
43 * ---------------------------------------------
44 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000045func tspd_enter_sp
Achin Gupta375f5382014-02-18 18:12:48 +000046 /* Make space for the registers that we're going to save */
47 mov x3, sp
48 str x3, [x0, #0]
49 sub sp, sp, #TSPD_C_RT_CTX_SIZE
50
51 /* Save callee-saved registers on to the stack */
52 stp x19, x20, [sp, #TSPD_C_RT_CTX_X19]
53 stp x21, x22, [sp, #TSPD_C_RT_CTX_X21]
54 stp x23, x24, [sp, #TSPD_C_RT_CTX_X23]
55 stp x25, x26, [sp, #TSPD_C_RT_CTX_X25]
56 stp x27, x28, [sp, #TSPD_C_RT_CTX_X27]
57 stp x29, x30, [sp, #TSPD_C_RT_CTX_X29]
58
59 /* ---------------------------------------------
60 * Everything is setup now. el3_exit() will
61 * use the secure context to restore to the
62 * general purpose and EL3 system registers to
63 * ERET into the secure payload.
64 * ---------------------------------------------
65 */
66 b el3_exit
67
68 /* ---------------------------------------------
69 * This function is called 'x0' pointing to a C
70 * runtime context saved in tspd_enter_sp(). It
71 * restores the saved registers and jumps to
72 * that runtime with 'x0' as the new sp. This
73 * destroys the C runtime context that had been
74 * built on the stack below the saved context by
75 * the caller. Later the second parameter 'x1'
76 * is passed as return value to the caller
77 * ---------------------------------------------
78 */
79 .global tspd_exit_sp
Andrew Thoelke38bde412014-03-18 13:46:55 +000080func tspd_exit_sp
Achin Gupta375f5382014-02-18 18:12:48 +000081 /* Restore the previous stack */
82 mov sp, x0
83
84 /* Restore callee-saved registers on to the stack */
85 ldp x19, x20, [x0, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)]
86 ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)]
87 ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)]
88 ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)]
89 ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)]
90 ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)]
91
92 /* ---------------------------------------------
93 * This should take us back to the instruction
94 * after the call to the last tspd_enter_sp().
95 * Place the second parameter to x0 so that the
96 * caller will see it as a return value from the
97 * original entry call
98 * ---------------------------------------------
99 */
100 mov x0, x1
101 ret