efi-rt-wrapper.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2018 Linaro Ltd <[email protected]>
  4. */
  5. #include <linux/linkage.h>
  6. #include <asm/assembler.h>
  7. SYM_FUNC_START(__efi_rt_asm_wrapper)
  8. stp x29, x30, [sp, #-112]!
  9. mov x29, sp
  10. /*
  11. * Register x18 is designated as the 'platform' register by the AAPCS,
  12. * which means firmware running at the same exception level as the OS
  13. * (such as UEFI) should never touch it.
  14. */
  15. stp x1, x18, [sp, #16]
  16. /*
  17. * Preserve all callee saved registers and preserve the stack pointer
  18. * value at the base of the EFI runtime stack so we can recover from
  19. * synchronous exceptions occurring while executing the firmware
  20. * routines.
  21. */
  22. stp x19, x20, [sp, #32]
  23. stp x21, x22, [sp, #48]
  24. stp x23, x24, [sp, #64]
  25. stp x25, x26, [sp, #80]
  26. stp x27, x28, [sp, #96]
  27. ldr_l x16, efi_rt_stack_top
  28. mov sp, x16
  29. stp x18, x29, [sp, #-16]!
  30. /*
  31. * We are lucky enough that no EFI runtime services take more than
  32. * 5 arguments, so all are passed in registers rather than via the
  33. * stack.
  34. */
  35. mov x8, x0
  36. mov x0, x2
  37. mov x1, x3
  38. mov x2, x4
  39. mov x3, x5
  40. mov x4, x6
  41. blr x8
  42. mov x16, sp
  43. mov sp, x29
  44. str xzr, [x16, #8] // clear recorded task SP value
  45. ldp x1, x2, [sp, #16]
  46. cmp x2, x18
  47. ldp x29, x30, [sp], #112
  48. b.ne 0f
  49. ret
  50. 0:
  51. /*
  52. * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a
  53. * shadow stack pointer, which we need to restore before returning to
  54. * potentially instrumented code. This is safe because the wrapper is
  55. * called with preemption disabled and a separate shadow stack is used
  56. * for interrupts.
  57. */
  58. #ifdef CONFIG_SHADOW_CALL_STACK
  59. ldr_l x18, efi_rt_stack_top
  60. ldr x18, [x18, #-16]
  61. #endif
  62. b efi_handle_corrupted_x18 // tail call
  63. SYM_FUNC_END(__efi_rt_asm_wrapper)
  64. SYM_CODE_START(__efi_rt_asm_recover)
  65. mov sp, x30
  66. ldr_l x16, efi_rt_stack_top // clear recorded task SP value
  67. str xzr, [x16, #-8]
  68. ldp x19, x20, [sp, #32]
  69. ldp x21, x22, [sp, #48]
  70. ldp x23, x24, [sp, #64]
  71. ldp x25, x26, [sp, #80]
  72. ldp x27, x28, [sp, #96]
  73. ldp x29, x30, [sp], #112
  74. ret
  75. SYM_CODE_END(__efi_rt_asm_recover)