sgx_entry.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "pal_linux_defs.h"
  2. #include "sgx_arch.h"
  3. #include "asm-offsets.h"
  4. .extern tcs_base
  5. .global sgx_ecall
  6. .type sgx_ecall, @function
  7. sgx_ecall:
  8. # put entry address in RDX
  9. leaq sgx_entry(%rip), %rdx
  10. # other arguments: RDI - code, RSI - ms
  11. .Ldo_ecall:
  12. # RBX has to be the TCS of the thread
  13. movq current_tcs@gottpoff(%rip), %rbx
  14. movq %fs:(%rbx), %rbx
  15. # RCX has to be the AEP (Asynchronous Exit Pointer)
  16. leaq async_exit_pointer(%rip), %rcx
  17. movq $EENTER, %rax
  18. ENCLU
  19. .global async_exit_pointer
  20. .type async_exit_pointer, @function
  21. async_exit_pointer:
  22. ENCLU
  23. .global sgx_raise
  24. .type sgx_raise, @function
  25. sgx_raise:
  26. leaq .Lafter_resume(%rip), %rdx
  27. jmp .Ldo_ecall
  28. .Lafter_resume:
  29. retq
  30. sgx_entry:
  31. # arguments: RDI - code, RSI - ms
  32. leaq ocall_table(%rip), %rbx
  33. movq (%rbx,%rdi,8), %rbx
  34. movq %rsi, %rdi
  35. pushq %rbp
  36. movq %rsp, %rbp
  37. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  38. callq *%rbx
  39. movq %rbp, %rsp
  40. popq %rbp
  41. movq %rax, %rdi
  42. # Not interrupted
  43. xorq %rsi, %rsi
  44. .global sgx_entry_return
  45. .type sgx_entry_return, @function
  46. sgx_entry_return:
  47. # return to enclave, arguments:
  48. # RDI - return value
  49. # RSI - external event
  50. jmp .Ldo_ecall
  51. /*
  52. * rdfsbase:
  53. * read FS register (allowed in enclaves).
  54. */
  55. .global rdfsbase
  56. .type rdfsbase, @function
  57. rdfsbase:
  58. .cfi_startproc
  59. .byte 0xf3, 0x48, 0x0f, 0xae, 0xc0 /* RDFSBASE %RAX */
  60. retq
  61. .cfi_endproc
  62. .size rdfsbase, .-rdfsbase
  63. /*
  64. * wrfsbase:
  65. * modify FS register (allowed in enclaves).
  66. */
  67. .global wrfsbase
  68. .type wrfsbase, @function
  69. wrfsbase:
  70. .cfi_startproc
  71. .byte 0xf3, 0x48, 0x0f, 0xae, 0xd7 /* WRFSBASE %RDI */
  72. retq
  73. .cfi_endproc
  74. .size wrfsbase, .-wrfsbase