blob: 120767d2275bc12815e3fd1cc03876e68b32e4d7 [file] [log] [blame]
Soby Mathewacc144b2016-05-05 12:53:53 +01001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewacc144b2016-05-05 12:53:53 +01005 */
6#ifndef __SMCC_MACROS_S__
7#define __SMCC_MACROS_S__
8
9#include <arch.h>
10
11/*
12 * Macro to save the General purpose registers including the banked
13 * registers to the SMC context on entry due a SMC call. On return, r0
14 * contains the pointer to the `smc_context_t`.
15 */
16 .macro smcc_save_gp_mode_regs
Soby Mathewadb70272016-12-06 12:10:51 +000017 push {r0-r4, lr}
Soby Mathewacc144b2016-05-05 12:53:53 +010018
19 ldcopr r0, SCR
20 and r0, r0, #SCR_NS_BIT
21 bl smc_get_ctx
22
Soby Mathewadb70272016-12-06 12:10:51 +000023 /* Save r5 - r12 in the SMC context */
24 add r1, r0, #SMC_CTX_GPREG_R5
25 stm r1!, {r5-r12}
Soby Mathewacc144b2016-05-05 12:53:53 +010026
27 /*
Soby Mathewadb70272016-12-06 12:10:51 +000028 * Pop r0 - r4, lr to r4 - r8, lr from stack and then save
Soby Mathewacc144b2016-05-05 12:53:53 +010029 * it to SMC context.
30 */
Soby Mathewadb70272016-12-06 12:10:51 +000031 pop {r4-r8, lr}
32 stm r0, {r4-r8}
Soby Mathewacc144b2016-05-05 12:53:53 +010033
34 /* Save the banked registers including the current SPSR and LR */
35 mrs r4, sp_usr
36 mrs r5, lr_usr
37 mrs r6, spsr_irq
38 mrs r7, sp_irq
39 mrs r8, lr_irq
40 mrs r9, spsr_fiq
41 mrs r10, sp_fiq
42 mrs r11, lr_fiq
43 mrs r12, spsr_svc
44 stm r1!, {r4-r12}
45
46 mrs r4, sp_svc
47 mrs r5, lr_svc
48 mrs r6, spsr_abt
49 mrs r7, sp_abt
50 mrs r8, lr_abt
51 mrs r9, spsr_und
52 mrs r10, sp_und
53 mrs r11, lr_und
54 mrs r12, spsr
55 stm r1!, {r4-r12, lr}
56
57 .endm
58
59/*
60 * Macro to restore the General purpose registers including the banked
61 * registers from the SMC context prior to exit from the SMC call.
62 * r0 must point to the `smc_context_t` to restore from.
63 */
64 .macro smcc_restore_gp_mode_regs
65
66 /* Restore the banked registers including the current SPSR and LR */
67 add r1, r0, #SMC_CTX_SP_USR
68 ldm r1!, {r4-r12}
69 msr sp_usr, r4
70 msr lr_usr, r5
71 msr spsr_irq, r6
72 msr sp_irq, r7
73 msr lr_irq, r8
74 msr spsr_fiq, r9
75 msr sp_fiq, r10
76 msr lr_fiq, r11
77 msr spsr_svc, r12
78
79 ldm r1!, {r4-r12, lr}
80 msr sp_svc, r4
81 msr lr_svc, r5
82 msr spsr_abt, r6
83 msr sp_abt, r7
84 msr lr_abt, r8
85 msr spsr_und, r9
86 msr sp_und, r10
87 msr lr_und, r11
Yatharth Kochard0f5f9c2016-11-09 15:39:25 +000088 /*
89 * Use the `_fsxc` suffix explicitly to instruct the assembler
90 * to update all the 32 bits of SPSR. Else, by default, the
91 * assembler assumes `_fc` suffix which only modifies
92 * f->[31:24] and c->[7:0] bits of SPSR.
93 */
94 msr spsr_fsxc, r12
Soby Mathewacc144b2016-05-05 12:53:53 +010095
96 /* Restore the rest of the general purpose registers */
97 ldm r0, {r0-r12}
98 .endm
99
100#endif /* __SMCC_MACROS_S__ */