trts_pic.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. /*
  32. * This header contains constant definitions for tRTS.
  33. */
  34. #ifndef TRTS_PIC_H__
  35. #define TRTS_PIC_H__
  36. #include "linux/linux-regs.h"
  37. #include "rts_cmd.h"
  38. #include "trts_shared_constants.h"
  39. #define SE_GUARD_PAGE_SIZE 0x10000
  40. #define ENCLAVE_INIT_NOT_STARTED 0
  41. #define ENCLAVE_INIT_IN_PROGRESS 1
  42. #define ENCLAVE_INIT_DONE 2
  43. #define ENCLAVE_CRASHED 3
  44. /* Status */
  45. #define SGX_SUCCESS 0
  46. #define SGX_ERROR_UNEXPECTED 0x000000001 // Unexpected error
  47. #define SGX_ERROR_INVALID_FUNCTION 0x000001001 // Invalid ecall/ocall function
  48. #define SGX_ERROR_INVALID_ENCLAVE 0x000002001 // The enclave image is incorrect
  49. #define SGX_ERROR_ENCLAVE_CRASHED 0x000001006 // enclave is crashed
  50. #define SGX_ERROR_STACK_OVERRUN 0x000001009 // enclave is running out of stack
  51. /* Thread Data
  52. * c.f. data structure defintion for thread_data_t in `rts.h'.
  53. */
  54. #define last_sp (SE_WORDSIZE * 1)
  55. #define stack_base_addr (SE_WORDSIZE * 2)
  56. #define stack_limit_addr (SE_WORDSIZE * 3)
  57. #define first_ssa_gpr (SE_WORDSIZE * 4)
  58. #define xsave_size (SE_WORDSIZE * 7)
  59. #define self_addr 0
  60. #define stack_guard (SE_WORDSIZE * 5)
  61. /* SSA GPR */
  62. #define ssa_sp_t 32
  63. #define ssa_sp_u 144
  64. #define ssa_bp_u 152
  65. #define ssa_exit_info 160
  66. #endif
  67. #define EXIT_INFO_VALID 0x80000000
  68. /* OCALL command */
  69. #define OCALL_FLAG 0x04F434944
  70. #define dtv SE_WORDSIZE
  71. #define tls 0
  72. .macro READ_TD_DATA offset
  73. #ifdef SE_SIM
  74. /* TLS support in simulation mode
  75. * see "sdk/simulation/uinst/linux/set_tls.c"
  76. * and "sdk/simulation/assembly/linux/gnu_tls.h"
  77. * TD address (tcs->ofs_base) is set to tcb_head->dtv->value.
  78. * The offset of tcb_head->dtv->value is SE_WORDSIZE.
  79. */
  80. #if defined(LINUX32)
  81. mov %gs:dtv, %xax
  82. #elif defined(LINUX64)
  83. mov %fs:dtv, %xax
  84. #endif
  85. mov tls(%xax), %xax
  86. mov \offset(%xax), %xax
  87. #else /* SE_SIM */
  88. #if defined(LINUX32)
  89. mov %fs:\offset, %xax
  90. #elif defined(LINUX64)
  91. mov %gs:\offset, %xax
  92. #endif
  93. #endif /* !SE_SIM */
  94. .endm
  95. .macro GET_STACK_BASE tcs
  96. mov \tcs, %xax
  97. sub $SE_GUARD_PAGE_SIZE, %xax
  98. .endm