trts_pic.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* SSA GPR */
  60. #define ssa_sp_t 32
  61. #define ssa_sp_u 144
  62. #define ssa_bp_u 152
  63. #define ssa_exit_info 160
  64. #endif
  65. #define EXIT_INFO_VALID 0x80000000
  66. /* OCALL command */
  67. #define OCALL_FLAG 0x04F434944
  68. #define dtv SE_WORDSIZE
  69. #define tls 0
  70. .macro READ_TD_DATA offset
  71. #ifdef SE_SIM
  72. /* TLS support in simulation mode
  73. * see "sdk/simulation/uinst/linux/set_tls.c"
  74. * and "sdk/simulation/assembly/linux/gnu_tls.h"
  75. * TD address (tcs->ofs_base) is set to tcb_head->dtv->value.
  76. * The offset of tcb_head->dtv->value is SE_WORDSIZE.
  77. */
  78. #if defined(LINUX32)
  79. mov %gs:dtv, %xax
  80. #elif defined(LINUX64)
  81. mov %fs:dtv, %xax
  82. #endif
  83. mov tls(%xax), %xax
  84. mov \offset(%xax), %xax
  85. #else /* SE_SIM */
  86. #if defined(LINUX32)
  87. mov %fs:\offset, %xax
  88. #elif defined(LINUX64)
  89. mov %gs:\offset, %xax
  90. #endif
  91. #endif /* !SE_SIM */
  92. .endm
  93. .macro GET_STACK_BASE tcs
  94. mov \tcs, %xax
  95. sub $SE_GUARD_PAGE_SIZE, %xax
  96. .endm