blob: 736b30f95d0fd2af88f8bd525607c6aa3ac31c99 [file] [log] [blame]
Florian Lugou71d33be2021-09-08 12:42:54 +02001/*
2 * Copyright (c) 2021-2022, ProvenRun S.A.S. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8#include "pncd_private.h"
9
10 .global pncd_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 */
21func pncd_enter_sp
22 /* Make space for the registers that we're going to save */
23 mov x3, sp
24 str x3, [x0, #0]
25 sub sp, sp, #PNCD_C_RT_CTX_SIZE
26
27 /* Save callee-saved registers on to the stack */
28 stp x19, x20, [sp, #PNCD_C_RT_CTX_X19]
29 stp x21, x22, [sp, #PNCD_C_RT_CTX_X21]
30 stp x23, x24, [sp, #PNCD_C_RT_CTX_X23]
31 stp x25, x26, [sp, #PNCD_C_RT_CTX_X25]
32 stp x27, x28, [sp, #PNCD_C_RT_CTX_X27]
33 stp x29, x30, [sp, #PNCD_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
43endfunc pncd_enter_sp
44
45 /* ---------------------------------------------
46 * This function is called 'x0' pointing to a C
47 * runtime context saved in pncd_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 pncd_exit_sp
57func pncd_exit_sp
58 /* Restore the previous stack */
59 mov sp, x0
60
61 /* Restore callee-saved registers on to the stack */
62 ldp x19, x20, [x0, #(PNCD_C_RT_CTX_X19 - PNCD_C_RT_CTX_SIZE)]
63 ldp x21, x22, [x0, #(PNCD_C_RT_CTX_X21 - PNCD_C_RT_CTX_SIZE)]
64 ldp x23, x24, [x0, #(PNCD_C_RT_CTX_X23 - PNCD_C_RT_CTX_SIZE)]
65 ldp x25, x26, [x0, #(PNCD_C_RT_CTX_X25 - PNCD_C_RT_CTX_SIZE)]
66 ldp x27, x28, [x0, #(PNCD_C_RT_CTX_X27 - PNCD_C_RT_CTX_SIZE)]
67 ldp x29, x30, [x0, #(PNCD_C_RT_CTX_X29 - PNCD_C_RT_CTX_SIZE)]
68
69 /* ---------------------------------------------
70 * This should take us back to the instruction
71 * after the call to the last pncd_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
79endfunc pncd_exit_sp