sgx_entry.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "pal_linux_defs.h"
  2. #include "sgx_arch.h"
  3. .extern tcs_base
  4. .global sgx_ecall
  5. .type sgx_ecall, @function
  6. sgx_ecall:
  7. # put entry address in RDX
  8. lea sgx_entry(%rip), %rdx
  9. # other arguments: RDI - code, RSI - ms
  10. .Ldo_ecall:
  11. # put debug register in R8, so we can know the enclave actually runs
  12. mov debug_register@gottpoff(%rip), %r8
  13. mov %fs:0, %rcx
  14. lea (%rcx,%r8), %r8
  15. # RBX has to be the TCS of the thread
  16. mov current_tcs@gottpoff(%rip), %rbx
  17. mov %fs:(%rbx), %rbx
  18. # RCX has to be the AEP (Asynchronous Exit Pointer)
  19. lea async_exit_pointer(%rip), %rcx
  20. mov $EENTER, %rax
  21. ENCLU
  22. .global async_exit_pointer
  23. .type async_exit_pointer, @function
  24. #if SGX_HAS_FSGSBASE == 0
  25. async_exit_pointer:
  26. # because ERESUME doesn't restore FS/GS, we must do EENTER
  27. # put debug register in R8, so we can know the enclave actually runs
  28. mov debug_register@gottpoff(%rip), %r8
  29. mov %fs:0, %rcx
  30. lea (%rcx,%r8), %r8
  31. mov current_tcs@gottpoff(%rip), %rbx
  32. mov %fs:(%rbx), %rbx
  33. lea double_async_exit(%rip), %rcx
  34. # put the exit address in RDX
  35. lea .Lreal_resume(%rip), %rdx
  36. mov $EENTER, %rax
  37. ENCLU
  38. .Lreal_resume:
  39. # RBX has to be the TCS of the thread
  40. mov current_tcs@gottpoff(%rip), %rbx
  41. mov %fs:(%rbx), %rbx
  42. # RCX has to be the AEP (Asynchronous Exit Pointer)
  43. lea async_exit_pointer(%rip), %rcx
  44. mov $ERESUME, %rax
  45. ENCLU
  46. .global double_async_exit
  47. .type double_async_exit, @function
  48. double_async_exit:
  49. ENCLU
  50. #else
  51. async_exit_pointer:
  52. ENCLU
  53. .global sgx_raise
  54. .type sgx_raise, @function
  55. sgx_raise:
  56. mov %edi, %r9d
  57. xor %rdi, %rdi
  58. lea .Lafter_resume(%rip), %rdx
  59. jmp .Ldo_ecall
  60. .Lafter_resume:
  61. retq
  62. #endif
  63. sgx_entry:
  64. # arguments: RDI - code, RSI - ms
  65. lea ocall_table(%rip), %rbx
  66. mov (%rbx,%rdi,8), %rbx
  67. mov %rsi, %rdi
  68. call *%rbx
  69. xor %r9, %r9
  70. .global sgx_entry_return
  71. .type sgx_entry_return, @function
  72. sgx_entry_return:
  73. # return to enclave, arguments: RDI = -1, RSI - return value
  74. mov $RETURN_FROM_OCALL, %rdi
  75. mov %rax, %rsi
  76. # external event in R9, so we can know if it happens
  77. jmp .Ldo_ecall
  78. /*
  79. * rdfsbase:
  80. * read FS register (allowed in enclaves).
  81. */
  82. .global rdfsbase
  83. .type rdfsbase, @function
  84. rdfsbase:
  85. .cfi_startproc
  86. .byte 0xf3, 0x48, 0x0f, 0xae, 0xc0 /* RDFSBASE %RAX */
  87. ret
  88. .cfi_endproc
  89. .size rdfsbase, .-rdfsbase
  90. /*
  91. * wrfsbase:
  92. * modify FS register (allowed in enclaves).
  93. */
  94. .global wrfsbase
  95. .type wrfsbase, @function
  96. wrfsbase:
  97. .cfi_startproc
  98. .byte 0xf3, 0x48, 0x0f, 0xae, 0xd7 /* WRFSBASE %RDI */
  99. ret
  100. .cfi_endproc
  101. .size wrfsbase, .-wrfsbase