opteed_helpers.S 2.7 KB

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