efi_thunk_64.S 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2014 Intel Corporation; author Matt Fleming
  4. *
  5. * Support for invoking 32-bit EFI runtime services from a 64-bit
  6. * kernel.
  7. *
  8. * The below thunking functions are only used after ExitBootServices()
  9. * has been called. This simplifies things considerably as compared with
  10. * the early EFI thunking because we can leave all the kernel state
  11. * intact (GDT, IDT, etc) and simply invoke the 32-bit EFI runtime
  12. * services from __KERNEL32_CS. This means we can continue to service
  13. * interrupts across an EFI mixed mode call.
  14. *
  15. * We do however, need to handle the fact that we're running in a full
  16. * 64-bit virtual address space. Things like the stack and instruction
  17. * addresses need to be accessible by the 32-bit firmware, so we rely on
  18. * using the identity mappings in the EFI page table to access the stack
  19. * and kernel text (see efi_setup_page_tables()).
  20. */
  21. #include <linux/linkage.h>
  22. #include <linux/objtool.h>
  23. #include <asm/page_types.h>
  24. #include <asm/segment.h>
  25. .text
  26. .code64
  27. SYM_FUNC_START(__efi64_thunk)
  28. STACK_FRAME_NON_STANDARD __efi64_thunk
  29. push %rbp
  30. push %rbx
  31. /*
  32. * Switch to 1:1 mapped 32-bit stack pointer.
  33. */
  34. movq %rsp, %rax
  35. movq efi_mixed_mode_stack_pa(%rip), %rsp
  36. push %rax
  37. /*
  38. * Copy args passed via the stack
  39. */
  40. subq $0x24, %rsp
  41. movq 0x18(%rax), %rbp
  42. movq 0x20(%rax), %rbx
  43. movq 0x28(%rax), %rax
  44. movl %ebp, 0x18(%rsp)
  45. movl %ebx, 0x1c(%rsp)
  46. movl %eax, 0x20(%rsp)
  47. /*
  48. * Calculate the physical address of the kernel text.
  49. */
  50. movq $__START_KERNEL_map, %rax
  51. subq phys_base(%rip), %rax
  52. leaq 1f(%rip), %rbp
  53. leaq 2f(%rip), %rbx
  54. subq %rax, %rbp
  55. subq %rax, %rbx
  56. movl %ebx, 0x0(%rsp) /* return address */
  57. movl %esi, 0x4(%rsp)
  58. movl %edx, 0x8(%rsp)
  59. movl %ecx, 0xc(%rsp)
  60. movl %r8d, 0x10(%rsp)
  61. movl %r9d, 0x14(%rsp)
  62. /* Switch to 32-bit descriptor */
  63. pushq $__KERNEL32_CS
  64. pushq %rdi /* EFI runtime service address */
  65. lretq
  66. // This return instruction is not needed for correctness, as it will
  67. // never be reached. It only exists to make objtool happy, which will
  68. // otherwise complain about unreachable instructions in the callers.
  69. RET
  70. SYM_FUNC_END(__efi64_thunk)
  71. .section ".rodata", "a", @progbits
  72. .balign 16
  73. SYM_DATA_START(__efi64_thunk_ret_tramp)
  74. 1: movq 0x20(%rsp), %rsp
  75. pop %rbx
  76. pop %rbp
  77. ret
  78. int3
  79. .code32
  80. 2: pushl $__KERNEL_CS
  81. pushl %ebp
  82. lret
  83. SYM_DATA_END(__efi64_thunk_ret_tramp)
  84. .bss
  85. .balign 8
  86. SYM_DATA(efi_mixed_mode_stack_pa, .quad 0)