test_encl_bootstrap.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright(c) 2016-20 Intel Corporation.
  4. */
  5. .macro ENCLU
  6. .byte 0x0f, 0x01, 0xd7
  7. .endm
  8. .section ".tcs", "aw"
  9. .balign 4096
  10. .fill 1, 8, 0 # STATE (set by CPU)
  11. .fill 1, 8, 0 # FLAGS
  12. .quad encl_ssa_tcs1 # OSSA
  13. .fill 1, 4, 0 # CSSA (set by CPU)
  14. .fill 1, 4, 1 # NSSA
  15. .quad encl_entry # OENTRY
  16. .fill 1, 8, 0 # AEP (set by EENTER and ERESUME)
  17. .fill 1, 8, 0 # OFSBASE
  18. .fill 1, 8, 0 # OGSBASE
  19. .fill 1, 4, 0xFFFFFFFF # FSLIMIT
  20. .fill 1, 4, 0xFFFFFFFF # GSLIMIT
  21. .fill 4024, 1, 0 # Reserved
  22. # TCS2
  23. .fill 1, 8, 0 # STATE (set by CPU)
  24. .fill 1, 8, 0 # FLAGS
  25. .quad encl_ssa_tcs2 # OSSA
  26. .fill 1, 4, 0 # CSSA (set by CPU)
  27. .fill 1, 4, 1 # NSSA
  28. .quad encl_entry # OENTRY
  29. .fill 1, 8, 0 # AEP (set by EENTER and ERESUME)
  30. .fill 1, 8, 0 # OFSBASE
  31. .fill 1, 8, 0 # OGSBASE
  32. .fill 1, 4, 0xFFFFFFFF # FSLIMIT
  33. .fill 1, 4, 0xFFFFFFFF # GSLIMIT
  34. .fill 4024, 1, 0 # Reserved
  35. .text
  36. encl_entry:
  37. # RBX contains the base address for TCS, which is the first address
  38. # inside the enclave for TCS #1 and one page into the enclave for
  39. # TCS #2. First make it relative by substracting __encl_base and
  40. # then add the address of encl_stack to get the address for the stack.
  41. lea __encl_base(%rip), %rax
  42. sub %rax, %rbx
  43. lea encl_stack(%rip), %rax
  44. add %rbx, %rax
  45. jmp encl_entry_core
  46. encl_dyn_entry:
  47. # Entry point for dynamically created TCS page expected to follow
  48. # its stack directly.
  49. lea -1(%rbx), %rax
  50. encl_entry_core:
  51. xchg %rsp, %rax
  52. push %rax
  53. push %rcx # push the address after EENTER
  54. # NOTE: as the selftest enclave is *not* intended for production,
  55. # simplify the code by not initializing ABI registers on entry or
  56. # cleansing caller-save registers on exit.
  57. call encl_body
  58. # Prepare EEXIT target by popping the address of the instruction after
  59. # EENTER to RBX.
  60. pop %rbx
  61. # Restore the caller stack.
  62. pop %rax
  63. mov %rax, %rsp
  64. # EEXIT
  65. mov $4, %rax
  66. enclu
  67. .section ".data", "aw"
  68. encl_ssa_tcs1:
  69. .space 4096
  70. encl_ssa_tcs2:
  71. .space 4096
  72. .balign 4096
  73. # Stack of TCS #1
  74. .space 4096
  75. encl_stack:
  76. .balign 4096
  77. # Stack of TCS #2
  78. .space 4096