blob: 32c38f1b2b90b82dceead42c32ae7db16a87393a [file] [log] [blame]
Jens Wiklanderc2888862014-08-04 15:39:58 +02001/*
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 <asm_macros.S>
32#include "opteed_private.h"
33
34 .global opteed_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 */
45func opteed_enter_sp
46 /* Make space for the registers that we're going to save */
47 mov x3, sp
48 str x3, [x0, #0]
49 sub sp, sp, #OPTEED_C_RT_CTX_SIZE
50
51 /* Save callee-saved registers on to the stack */
52 stp x19, x20, [sp, #OPTEED_C_RT_CTX_X19]
53 stp x21, x22, [sp, #OPTEED_C_RT_CTX_X21]
54 stp x23, x24, [sp, #OPTEED_C_RT_CTX_X23]
55 stp x25, x26, [sp, #OPTEED_C_RT_CTX_X25]
56 stp x27, x28, [sp, #OPTEED_C_RT_CTX_X27]
57 stp x29, x30, [sp, #OPTEED_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 OPTEE.
64 * ---------------------------------------------
65 */
66 b el3_exit
Kévin Petita877c252015-03-24 14:03:57 +000067endfunc opteed_enter_sp
Jens Wiklanderc2888862014-08-04 15:39:58 +020068
69 /* ---------------------------------------------
70 * This function is called 'x0' pointing to a C
71 * runtime context saved in opteed_enter_sp(). It
72 * restores the saved registers and jumps to
73 * that runtime with 'x0' as the new sp. This
74 * destroys the C runtime context that had been
75 * built on the stack below the saved context by
76 * the caller. Later the second parameter 'x1'
77 * is passed as return value to the caller
78 * ---------------------------------------------
79 */
80 .global opteed_exit_sp
81func opteed_exit_sp
82 /* Restore the previous stack */
83 mov sp, x0
84
85 /* Restore callee-saved registers on to the stack */
86 ldp x19, x20, [x0, #(OPTEED_C_RT_CTX_X19 - OPTEED_C_RT_CTX_SIZE)]
87 ldp x21, x22, [x0, #(OPTEED_C_RT_CTX_X21 - OPTEED_C_RT_CTX_SIZE)]
88 ldp x23, x24, [x0, #(OPTEED_C_RT_CTX_X23 - OPTEED_C_RT_CTX_SIZE)]
89 ldp x25, x26, [x0, #(OPTEED_C_RT_CTX_X25 - OPTEED_C_RT_CTX_SIZE)]
90 ldp x27, x28, [x0, #(OPTEED_C_RT_CTX_X27 - OPTEED_C_RT_CTX_SIZE)]
91 ldp x29, x30, [x0, #(OPTEED_C_RT_CTX_X29 - OPTEED_C_RT_CTX_SIZE)]
92
93 /* ---------------------------------------------
94 * This should take us back to the instruction
95 * after the call to the last opteed_enter_sp().
96 * Place the second parameter to x0 so that the
97 * caller will see it as a return value from the
98 * original entry call
99 * ---------------------------------------------
100 */
101 mov x0, x1
102 ret
Kévin Petita877c252015-03-24 14:03:57 +0000103endfunc opteed_exit_sp