Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 5 | */ |
| 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 Mathew | adb7027 | 2016-12-06 12:10:51 +0000 | [diff] [blame] | 17 | push {r0-r4, lr} |
Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 18 | |
| 19 | ldcopr r0, SCR |
| 20 | and r0, r0, #SCR_NS_BIT |
| 21 | bl smc_get_ctx |
| 22 | |
Soby Mathew | adb7027 | 2016-12-06 12:10:51 +0000 | [diff] [blame] | 23 | /* Save r5 - r12 in the SMC context */ |
| 24 | add r1, r0, #SMC_CTX_GPREG_R5 |
| 25 | stm r1!, {r5-r12} |
Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 26 | |
| 27 | /* |
Soby Mathew | adb7027 | 2016-12-06 12:10:51 +0000 | [diff] [blame] | 28 | * Pop r0 - r4, lr to r4 - r8, lr from stack and then save |
Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 29 | * it to SMC context. |
| 30 | */ |
Soby Mathew | adb7027 | 2016-12-06 12:10:51 +0000 | [diff] [blame] | 31 | pop {r4-r8, lr} |
| 32 | stm r0, {r4-r8} |
Soby Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 33 | |
| 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 Kochar | d0f5f9c | 2016-11-09 15:39:25 +0000 | [diff] [blame] | 88 | /* |
| 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 Mathew | acc144b | 2016-05-05 12:53:53 +0100 | [diff] [blame] | 95 | |
| 96 | /* Restore the rest of the general purpose registers */ |
| 97 | ldm r0, {r0-r12} |
| 98 | .endm |
| 99 | |
| 100 | #endif /* __SMCC_MACROS_S__ */ |