sgx_entry.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. .cfi_startproc
  33. leaq ocall_table(%rip), %rbx
  34. movq (%rbx,%rdi,8), %rbx
  35. movq %rsi, %rdi
  36. pushq %rbp
  37. .cfi_adjust_cfa_offset 8
  38. movq %rsp, %rbp
  39. .cfi_offset %rbp, -16
  40. .cfi_def_cfa_register %rbp
  41. andq $~0xF, %rsp # Required by System V AMD64 ABI.
  42. callq *%rbx
  43. movq %rbp, %rsp
  44. popq %rbp
  45. .cfi_def_cfa %rsp, 8
  46. movq %rax, %rdi
  47. # Not interrupted
  48. xorq %rsi, %rsi
  49. .global sgx_entry_return
  50. .type sgx_entry_return, @function
  51. sgx_entry_return:
  52. # return to enclave, arguments:
  53. # RDI - return value
  54. # RSI - external event
  55. jmp .Ldo_ecall
  56. .cfi_endproc