• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 *     http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12
13#include <asm_macros.S>
14
15#define __ASSEMBLY__
16
17#include <teed_private.h>
18
19    .global    teed_enter_sp
20func teed_enter_sp
21    /* Make space for the registers that we're going to save */
22    mov    x3, sp
23    str    x3, [x0, #0]
24    sub    sp, sp, #TEED_C_RT_CTX_SIZE
25
26    /* Save callee-saved registers on to the stack */
27    stp    x19, x20, [sp, #TEED_C_RT_CTX_X19]
28    stp    x21, x22, [sp, #TEED_C_RT_CTX_X21]
29    stp    x23, x24, [sp, #TEED_C_RT_CTX_X23]
30    stp    x25, x26, [sp, #TEED_C_RT_CTX_X25]
31    stp    x27, x28, [sp, #TEED_C_RT_CTX_X27]
32    stp    x29, x30, [sp, #TEED_C_RT_CTX_X29]
33
34    /*
35     * el3_exit() will use the secure context to restore to the
36     * general purpose and EL3 system registers to ERET into the secure payload
37     */
38    b    el3_exit
39endfunc teed_enter_sp
40
41    /*
42     * This function is called 'x0' pointing to a C
43     * runtime context saved in teed_enter_sp()
44     */
45    .global teed_exit_sp
46func teed_exit_sp
47    /* Restore the previous stack */
48    mov    sp, x0
49
50    /* Restore callee-saved registers on to the stack */
51    ldp    x19, x20, [x0, #(TEED_C_RT_CTX_X19 - TEED_C_RT_CTX_SIZE)]
52    ldp    x21, x22, [x0, #(TEED_C_RT_CTX_X21 - TEED_C_RT_CTX_SIZE)]
53    ldp    x23, x24, [x0, #(TEED_C_RT_CTX_X23 - TEED_C_RT_CTX_SIZE)]
54    ldp    x25, x26, [x0, #(TEED_C_RT_CTX_X25 - TEED_C_RT_CTX_SIZE)]
55    ldp    x27, x28, [x0, #(TEED_C_RT_CTX_X27 - TEED_C_RT_CTX_SIZE)]
56    ldp    x29, x30, [x0, #(TEED_C_RT_CTX_X29 - TEED_C_RT_CTX_SIZE)]
57
58    /*
59     * This should take us back to the instruction
60     * after the call to the last teed_enter_sp().
61     */
62    mov    x0, x1
63    ret
64endfunc teed_exit_sp
65