efi_stub_64.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Function calling ABI conversion from Linux to EFI for x86_64
  3. *
  4. * Copyright (C) 2007 Intel Corp
  5. * Bibo Mao <bibo.mao@intel.com>
  6. * Huang Ying <ying.huang@intel.com>
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/segment.h>
  10. #include <asm/msr.h>
  11. #include <asm/processor-flags.h>
  12. #include <asm/page_types.h>
  13. #define SAVE_XMM \
  14. mov %rsp, %rax; \
  15. subq $0x70, %rsp; \
  16. and $~0xf, %rsp; \
  17. mov %rax, (%rsp); \
  18. mov %cr0, %rax; \
  19. clts; \
  20. mov %rax, 0x8(%rsp); \
  21. movaps %xmm0, 0x60(%rsp); \
  22. movaps %xmm1, 0x50(%rsp); \
  23. movaps %xmm2, 0x40(%rsp); \
  24. movaps %xmm3, 0x30(%rsp); \
  25. movaps %xmm4, 0x20(%rsp); \
  26. movaps %xmm5, 0x10(%rsp)
  27. #define RESTORE_XMM \
  28. movaps 0x60(%rsp), %xmm0; \
  29. movaps 0x50(%rsp), %xmm1; \
  30. movaps 0x40(%rsp), %xmm2; \
  31. movaps 0x30(%rsp), %xmm3; \
  32. movaps 0x20(%rsp), %xmm4; \
  33. movaps 0x10(%rsp), %xmm5; \
  34. mov 0x8(%rsp), %rsi; \
  35. mov %rsi, %cr0; \
  36. mov (%rsp), %rsp
  37. /* stolen from gcc */
  38. .macro FLUSH_TLB_ALL
  39. movq %r15, efi_scratch(%rip)
  40. movq %r14, efi_scratch+8(%rip)
  41. movq %cr4, %r15
  42. movq %r15, %r14
  43. andb $0x7f, %r14b
  44. movq %r14, %cr4
  45. movq %r15, %cr4
  46. movq efi_scratch+8(%rip), %r14
  47. movq efi_scratch(%rip), %r15
  48. .endm
  49. .macro SWITCH_PGT
  50. cmpb $0, efi_scratch+24(%rip)
  51. je 1f
  52. movq %r15, efi_scratch(%rip) # r15
  53. # save previous CR3
  54. movq %cr3, %r15
  55. movq %r15, efi_scratch+8(%rip) # prev_cr3
  56. movq efi_scratch+16(%rip), %r15 # EFI pgt
  57. movq %r15, %cr3
  58. 1:
  59. .endm
  60. .macro RESTORE_PGT
  61. cmpb $0, efi_scratch+24(%rip)
  62. je 2f
  63. movq efi_scratch+8(%rip), %r15
  64. movq %r15, %cr3
  65. movq efi_scratch(%rip), %r15
  66. FLUSH_TLB_ALL
  67. 2:
  68. .endm
  69. ENTRY(efi_call)
  70. SAVE_XMM
  71. mov (%rsp), %rax
  72. mov 8(%rax), %rax
  73. subq $48, %rsp
  74. mov %r9, 32(%rsp)
  75. mov %rax, 40(%rsp)
  76. mov %r8, %r9
  77. mov %rcx, %r8
  78. mov %rsi, %rcx
  79. SWITCH_PGT
  80. call *%rdi
  81. RESTORE_PGT
  82. addq $48, %rsp
  83. RESTORE_XMM
  84. ret
  85. ENDPROC(efi_call)
  86. .data
  87. ENTRY(efi_scratch)
  88. .fill 3,8,0
  89. .byte 0
  90. .quad 0