blob: b56b2aa384b74fb12d32623d946189f114818f42 [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
31#include <context.h>
32#include <tspd_private.h>
33#include <asm_macros.S>
34#include <cm_macros.S>
35
36 .global tspd_enter_sp
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 */
47tspd_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, #TSPD_C_RT_CTX_SIZE
52
53 /* Save callee-saved registers on to the stack */
54 stp x19, x20, [sp, #TSPD_C_RT_CTX_X19]
55 stp x21, x22, [sp, #TSPD_C_RT_CTX_X21]
56 stp x23, x24, [sp, #TSPD_C_RT_CTX_X23]
57 stp x25, x26, [sp, #TSPD_C_RT_CTX_X25]
58 stp x27, x28, [sp, #TSPD_C_RT_CTX_X27]
59 stp x29, x30, [sp, #TSPD_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
69
70 /* ---------------------------------------------
71 * This function is called 'x0' pointing to a C
72 * runtime context saved in tspd_enter_sp(). It
73 * restores the saved registers and jumps to
74 * that runtime with 'x0' as the new sp. This
75 * destroys the C runtime context that had been
76 * built on the stack below the saved context by
77 * the caller. Later the second parameter 'x1'
78 * is passed as return value to the caller
79 * ---------------------------------------------
80 */
81 .global tspd_exit_sp
82tspd_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, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)]
88 ldp x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)]
89 ldp x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)]
90 ldp x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)]
91 ldp x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)]
92 ldp x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)]
93
94 /* ---------------------------------------------
95 * This should take us back to the instruction
96 * after the call to the last tspd_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