tlkd_helpers.S 2.7 KB

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