spm_helpers.S 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2017-2022, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <asm_macros.S>
  7. #include "spm_common.h"
  8. .global spm_secure_partition_enter
  9. .global spm_secure_partition_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 spm_secure_partition_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, #SP_C_RT_CTX_SIZE
  23. /* Save callee-saved registers on to the stack */
  24. stp x19, x20, [sp, #SP_C_RT_CTX_X19]
  25. stp x21, x22, [sp, #SP_C_RT_CTX_X21]
  26. stp x23, x24, [sp, #SP_C_RT_CTX_X23]
  27. stp x25, x26, [sp, #SP_C_RT_CTX_X25]
  28. stp x27, x28, [sp, #SP_C_RT_CTX_X27]
  29. stp x29, x30, [sp, #SP_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 spm_secure_partition_enter
  38. /* ---------------------------------------------------------------------
  39. * This function is called with 'x0' pointing to a C runtime context
  40. * saved in spm_secure_partition_enter().
  41. * It restores the saved registers and jumps to that runtime with 'x0'
  42. * as the new SP register. This destroys the C runtime context that had
  43. * been built on the stack below the saved context by the caller. Later
  44. * the second parameter 'x1' is passed as a return value to the caller.
  45. * ---------------------------------------------------------------------
  46. */
  47. func spm_secure_partition_exit
  48. /* Restore the previous stack */
  49. mov sp, x0
  50. /* Restore callee-saved registers on to the stack */
  51. ldp x19, x20, [x0, #(SP_C_RT_CTX_X19 - SP_C_RT_CTX_SIZE)]
  52. ldp x21, x22, [x0, #(SP_C_RT_CTX_X21 - SP_C_RT_CTX_SIZE)]
  53. ldp x23, x24, [x0, #(SP_C_RT_CTX_X23 - SP_C_RT_CTX_SIZE)]
  54. ldp x25, x26, [x0, #(SP_C_RT_CTX_X25 - SP_C_RT_CTX_SIZE)]
  55. ldp x27, x28, [x0, #(SP_C_RT_CTX_X27 - SP_C_RT_CTX_SIZE)]
  56. ldp x29, x30, [x0, #(SP_C_RT_CTX_X29 - SP_C_RT_CTX_SIZE)]
  57. /* ---------------------------------------------------------------------
  58. * This should take us back to the instruction after the call to the
  59. * last spm_secure_partition_enter().* Place the second parameter to x0
  60. * so that the caller will see it as a return value from the original
  61. * entry call.
  62. * ---------------------------------------------------------------------
  63. */
  64. mov x0, x1
  65. ret
  66. endfunc spm_secure_partition_exit