sgx_entry.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. pushq %rbx
  9. # put entry address in RDX
  10. leaq sgx_entry(%rip), %rdx
  11. # other arguments: RDI - code, RSI - ms
  12. .Ldo_ecall:
  13. # RBX has to be the TCS of the thread
  14. movq %gs:PAL_TCB_URTS_TCS, %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. # currently only ECALL_THREAD_RESET returns
  20. popq %rbx
  21. retq
  22. .global async_exit_pointer
  23. .type async_exit_pointer, @function
  24. async_exit_pointer:
  25. ENCLU
  26. .global sgx_raise
  27. .type sgx_raise, @function
  28. sgx_raise:
  29. leaq .Lafter_resume(%rip), %rdx
  30. jmp .Ldo_ecall
  31. .Lafter_resume:
  32. retq
  33. sgx_entry:
  34. # arguments: RDI - code, RSI - ms
  35. .cfi_startproc
  36. leaq ocall_table(%rip), %rbx
  37. movq (%rbx,%rdi,8), %rbx
  38. movq %rsi, %rdi
  39. pushq %rbp
  40. .cfi_adjust_cfa_offset 8
  41. movq %rsp, %rbp
  42. .cfi_offset %rbp, -16
  43. .cfi_def_cfa_register %rbp
  44. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  45. callq *%rbx
  46. movq %rbp, %rsp
  47. popq %rbp
  48. .cfi_def_cfa %rsp, 8
  49. movq %rax, %rdi
  50. # Not interrupted
  51. xorq %rsi, %rsi
  52. .global sgx_entry_return
  53. .type sgx_entry_return, @function
  54. sgx_entry_return:
  55. # return to enclave, arguments:
  56. # RDI - return value
  57. # RSI - external event
  58. jmp .Ldo_ecall
  59. .cfi_endproc