spmd_helpers.S 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include "../spmd_private.h"
  8. .global spmd_spm_core_enter
  9. .global spmd_spm_core_exit
  10. /* ---------------------------------------------------------------------
  11. * This function is called with SP_EL0 as stack. Here we stash our EL3
  12. * callee-saved registers on to the stack as a part of saving the C
  13. * runtime and enter the secure payload.
  14. * 'x0' contains a pointer to the memory where the address of the C
  15. * runtime context is to be saved.
  16. * ---------------------------------------------------------------------
  17. */
  18. func spmd_spm_core_enter
  19. /* Make space for the registers that we're going to save */
  20. mov x3, sp
  21. str x3, [x0, #0]
  22. sub sp, sp, #SPMD_C_RT_CTX_SIZE
  23. /* Save callee-saved registers on to the stack */
  24. stp x19, x20, [sp, #SPMD_C_RT_CTX_X19]
  25. stp x21, x22, [sp, #SPMD_C_RT_CTX_X21]
  26. stp x23, x24, [sp, #SPMD_C_RT_CTX_X23]
  27. stp x25, x26, [sp, #SPMD_C_RT_CTX_X25]
  28. stp x27, x28, [sp, #SPMD_C_RT_CTX_X27]
  29. stp x29, x30, [sp, #SPMD_C_RT_CTX_X29]
  30. /* ---------------------------------------------------------------------
  31. * Everything is setup now. el3_exit() will use the secure context to
  32. * restore to the general purpose and EL3 system registers to ERET
  33. * into the secure payload.
  34. * ---------------------------------------------------------------------
  35. */
  36. b el3_exit
  37. endfunc spmd_spm_core_enter
  38. /* ---------------------------------------------------------------------
  39. * This function is called with 'x0' pointing to a C runtime context.
  40. * It restores the saved registers and jumps to that runtime with 'x0'
  41. * as the new SP register. This destroys the C runtime context that had
  42. * been built on the stack below the saved context by the caller. Later
  43. * the second parameter 'x1' is passed as a return value to the caller.
  44. * ---------------------------------------------------------------------
  45. */
  46. func spmd_spm_core_exit
  47. /* Restore the previous stack */
  48. mov sp, x0
  49. /* Restore callee-saved registers on to the stack */
  50. ldp x19, x20, [x0, #(SPMD_C_RT_CTX_X19 - SPMD_C_RT_CTX_SIZE)]
  51. ldp x21, x22, [x0, #(SPMD_C_RT_CTX_X21 - SPMD_C_RT_CTX_SIZE)]
  52. ldp x23, x24, [x0, #(SPMD_C_RT_CTX_X23 - SPMD_C_RT_CTX_SIZE)]
  53. ldp x25, x26, [x0, #(SPMD_C_RT_CTX_X25 - SPMD_C_RT_CTX_SIZE)]
  54. ldp x27, x28, [x0, #(SPMD_C_RT_CTX_X27 - SPMD_C_RT_CTX_SIZE)]
  55. ldp x29, x30, [x0, #(SPMD_C_RT_CTX_X29 - SPMD_C_RT_CTX_SIZE)]
  56. /* ---------------------------------------------------------------------
  57. * This should take us back to the instruction after the call to the
  58. * last spm_secure_partition_enter().* Place the second parameter to x0
  59. * so that the caller will see it as a return value from the original
  60. * entry call.
  61. * ---------------------------------------------------------------------
  62. */
  63. mov x0, x1
  64. ret
  65. endfunc spmd_spm_core_exit