• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
8#include "tspd_private.h"
9
10	.global	tspd_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 tspd_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, #TSPD_C_RT_CTX_SIZE
26
27	/* Save callee-saved registers on to the stack */
28	stp	x19, x20, [sp, #TSPD_C_RT_CTX_X19]
29	stp	x21, x22, [sp, #TSPD_C_RT_CTX_X21]
30	stp	x23, x24, [sp, #TSPD_C_RT_CTX_X23]
31	stp	x25, x26, [sp, #TSPD_C_RT_CTX_X25]
32	stp	x27, x28, [sp, #TSPD_C_RT_CTX_X27]
33	stp	x29, x30, [sp, #TSPD_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 tspd_enter_sp
44
45	/* ---------------------------------------------
46	 * This function is called 'x0' pointing to a C
47	 * runtime context saved in tspd_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 tspd_exit_sp
57func tspd_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, #(TSPD_C_RT_CTX_X19 - TSPD_C_RT_CTX_SIZE)]
63	ldp	x21, x22, [x0, #(TSPD_C_RT_CTX_X21 - TSPD_C_RT_CTX_SIZE)]
64	ldp	x23, x24, [x0, #(TSPD_C_RT_CTX_X23 - TSPD_C_RT_CTX_SIZE)]
65	ldp	x25, x26, [x0, #(TSPD_C_RT_CTX_X25 - TSPD_C_RT_CTX_SIZE)]
66	ldp	x27, x28, [x0, #(TSPD_C_RT_CTX_X27 - TSPD_C_RT_CTX_SIZE)]
67	ldp	x29, x30, [x0, #(TSPD_C_RT_CTX_X29 - TSPD_C_RT_CTX_SIZE)]
68
69	/* ---------------------------------------------
70	 * This should take us back to the instruction
71	 * after the call to the last tspd_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 tspd_exit_sp
80