trts_pic.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2011-2017 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. #define SE_GUARD_PAGE_SIZE 0x1000
  39. #define ENCLAVE_INIT_NOT_STARTED 0
  40. #define ENCLAVE_INIT_IN_PROGRESS 1
  41. #define ENCLAVE_INIT_DONE 2
  42. #define ENCLAVE_CRASHED 3
  43. /* Status */
  44. #define SGX_SUCCESS 0
  45. #define SGX_ERROR_UNEXPECTED 0x000000001 // Unexpected error
  46. #define SGX_ERROR_INVALID_FUNCTION 0x000001001 // Invalid ecall/ocall function
  47. #define SGX_ERROR_INVALID_ENCLAVE 0x000002001 // The enclave image is incorrect
  48. #define SGX_ERROR_ENCLAVE_CRASHED 0x000001006 // enclave is crashed
  49. #define SGX_ERROR_STACK_OVERRUN 0x000001009 // enclave is running out of stack
  50. #define STATIC_STACK_SIZE (SE_WORDSIZE * 100)
  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 self_addr 0
  59. #define stack_guard (SE_WORDSIZE * 5)
  60. /* SSA GPR */
  61. #define ssa_sp_t 32
  62. #define ssa_sp_u 144
  63. #define ssa_bp_u 152
  64. #define ssa_exit_info 160
  65. #endif
  66. #define EXIT_INFO_VALID 0x80000000
  67. /* OCALL command */
  68. #define OCALL_FLAG 0x04F434944
  69. #define dtv SE_WORDSIZE
  70. #define tls 0
  71. .macro READ_TD_DATA offset
  72. #ifdef SE_SIM
  73. /* TLS support in simulation mode
  74. * see "sdk/simulation/uinst/linux/set_tls.c"
  75. * and "sdk/simulation/assembly/linux/gnu_tls.h"
  76. * TD address (tcs->ofs_base) is set to tcb_head->dtv->value.
  77. * The offset of tcb_head->dtv->value is SE_WORDSIZE.
  78. */
  79. #if defined(LINUX32)
  80. mov %gs:dtv, %xax
  81. #elif defined(LINUX64)
  82. mov %fs:dtv, %xax
  83. #endif
  84. mov tls(%xax), %xax
  85. mov \offset(%xax), %xax
  86. #else /* SE_SIM */
  87. #if defined(LINUX32)
  88. mov %fs:\offset, %xax
  89. #elif defined(LINUX64)
  90. mov %gs:\offset, %xax
  91. #endif
  92. #endif /* !SE_SIM */
  93. .endm
  94. .macro GET_STACK_BASE tcs
  95. mov \tcs, %xax
  96. sub $SE_GUARD_PAGE_SIZE, %xax
  97. .endm