sgx_entry.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. # RBX has to be the TCS of the thread
  12. mov current_tcs@gottpoff(%rip), %rbx
  13. mov %fs:(%rbx), %rbx
  14. # RCX has to be the AEP (Asynchronous Exit Pointer)
  15. lea async_exit_pointer(%rip), %rcx
  16. mov $EENTER, %rax
  17. ENCLU
  18. .global async_exit_pointer
  19. .type async_exit_pointer, @function
  20. #if SGX_HAS_FSGSBASE == 0
  21. async_exit_pointer:
  22. # because ERESUME doesn't restore FS/GS, we must do EENTER
  23. mov current_tcs@gottpoff(%rip), %rbx
  24. mov %fs:(%rbx), %rbx
  25. lea double_async_exit(%rip), %rcx
  26. # put the exit address in RDX
  27. lea .Lreal_resume(%rip), %rdx
  28. mov $EENTER, %rax
  29. ENCLU
  30. .Lreal_resume:
  31. # RBX has to be the TCS of the thread
  32. mov current_tcs@gottpoff(%rip), %rbx
  33. mov %fs:(%rbx), %rbx
  34. # RCX has to be the AEP (Asynchronous Exit Pointer)
  35. lea async_exit_pointer(%rip), %rcx
  36. mov $ERESUME, %rax
  37. ENCLU
  38. .global double_async_exit
  39. .type double_async_exit, @function
  40. double_async_exit:
  41. ENCLU
  42. #else
  43. async_exit_pointer:
  44. ENCLU
  45. .global sgx_raise
  46. .type sgx_raise, @function
  47. sgx_raise:
  48. lea .Lafter_resume(%rip), %rdx
  49. jmp .Ldo_ecall
  50. .Lafter_resume:
  51. retq
  52. #endif
  53. sgx_entry:
  54. # arguments: RDI - code, RSI - ms
  55. lea ocall_table(%rip), %rbx
  56. mov (%rbx,%rdi,8), %rbx
  57. mov %rsi, %rdi
  58. call *%rbx
  59. mov %rax, %rdi
  60. # Not interrupted
  61. xor %rsi, %rsi
  62. .global sgx_entry_return
  63. .type sgx_entry_return, @function
  64. sgx_entry_return:
  65. # return to enclave, arguments:
  66. # RDI - return value
  67. # RSI - externel event
  68. jmp .Ldo_ecall
  69. /*
  70. * rdfsbase:
  71. * read FS register (allowed in enclaves).
  72. */
  73. .global rdfsbase
  74. .type rdfsbase, @function
  75. rdfsbase:
  76. .cfi_startproc
  77. .byte 0xf3, 0x48, 0x0f, 0xae, 0xc0 /* RDFSBASE %RAX */
  78. ret
  79. .cfi_endproc
  80. .size rdfsbase, .-rdfsbase
  81. /*
  82. * wrfsbase:
  83. * modify FS register (allowed in enclaves).
  84. */
  85. .global wrfsbase
  86. .type wrfsbase, @function
  87. wrfsbase:
  88. .cfi_startproc
  89. .byte 0xf3, 0x48, 0x0f, 0xae, 0xd7 /* WRFSBASE %RDI */
  90. ret
  91. .cfi_endproc
  92. .size wrfsbase, .-wrfsbase