sgx_entry.S 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 .Lsgx_entry(%rip), %rdx
  10. # other arguments: RDI - code, RSI - ms
  11. .Ldo_ecall_callee_save:
  12. pushq %rbx
  13. pushq %rbp
  14. pushq %r12
  15. pushq %r13
  16. pushq %r14
  17. pushq %r15
  18. .Ldo_ecall:
  19. # RBX has to be the TCS of the thread
  20. movq %gs:PAL_TCB_URTS_TCS, %rbx
  21. # RCX has to be the AEP (Asynchronous Exit Pointer)
  22. leaq async_exit_pointer(%rip), %rcx
  23. movq $EENTER, %rax
  24. ENCLU
  25. # currently only ECALL_THREAD_RESET returns
  26. .Lafter_resume:
  27. popq %r15
  28. popq %r14
  29. popq %r13
  30. popq %r12
  31. popq %rbp
  32. popq %rbx
  33. retq
  34. .global async_exit_pointer
  35. .type async_exit_pointer, @function
  36. async_exit_pointer:
  37. ENCLU
  38. .global sgx_raise
  39. .type sgx_raise, @function
  40. sgx_raise:
  41. leaq .Lafter_resume(%rip), %rdx
  42. jmp .Ldo_ecall_callee_save
  43. .Lsgx_entry:
  44. # arguments: RDI - code, RSI - ms
  45. .cfi_startproc
  46. leaq ocall_table(%rip), %rbx
  47. movq (%rbx,%rdi,8), %rbx
  48. movq %rsi, %rdi
  49. pushq %rbp
  50. .cfi_adjust_cfa_offset 8
  51. movq %rsp, %rbp
  52. .cfi_offset %rbp, -16
  53. .cfi_def_cfa_register %rbp
  54. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  55. callq *%rbx
  56. movq %rbp, %rsp
  57. popq %rbp
  58. .cfi_def_cfa %rsp, 8
  59. movq %rax, %rdi
  60. # Not interrupted
  61. xorq %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 - external event
  68. jmp .Ldo_ecall
  69. .cfi_endproc