1 /* Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #ifndef _SGXINTRIN_H_INCLUDED
25 #define _SGXINTRIN_H_INCLUDED
28 #pragma GCC push_options
29 #pragma GCC target("sgx")
30 #define __DISABLE_SGX__
33 #define __encls_bc(leaf, b, c, retval) \
34 __asm__ __volatile__ ("encls\n\t" \
36 : "a" (leaf), "b" (b), "c" (c) \
39 #define __encls_bcd(leaf, b, c, d, retval) \
40 __asm__ __volatile__("encls\n\t" \
42 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
45 #define __encls_c(leaf, c, retval) \
46 __asm__ __volatile__("encls\n\t" \
48 : "a" (leaf), "c" (c) \
51 #define __encls_edbgrd(leaf, b, c, retval) \
52 __asm__ __volatile__("encls\n\t" \
53 : "=a" (retval), "=b" (b) \
54 : "a" (leaf), "c" (c))
56 #define __encls_generic(leaf, b, c, d, retval) \
57 __asm__ __volatile__("encls\n\t" \
58 : "=a" (retval), "=b" (b), "=c" (c), "=d" (d)\
59 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
62 #define __enclu_bc(leaf, b, c, retval) \
63 __asm__ __volatile__("enclu\n\t" \
65 : "a" (leaf), "b" (b), "c" (c) \
68 #define __enclu_bcd(leaf, b, c, d, retval) \
69 __asm__ __volatile__("enclu\n\t" \
71 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
74 #define __enclu_eenter(leaf, b, c, retval) \
75 __asm__ __volatile__("enclu\n\t" \
76 : "=a" (retval), "=c" (c) \
77 : "a" (leaf), "b" (b), "c" (c) \
80 #define __enclu_eexit(leaf, b, c, retval) \
81 __asm__ __volatile__("enclu\n\t" \
82 : "=a" (retval), "=c" (c) \
83 : "a" (leaf), "b" (b) \
86 #define __enclu_generic(leaf, b, c, d, retval) \
87 __asm__ __volatile__("enclu\n\t" \
88 : "=a" (retval), "=b" (b), "=c" (c), "=d" (d)\
89 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
94 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
95 _encls_u32 (const int __L
, size_t __D
[])
102 __SGX_EREMOVE
= 0x03,
105 __SGX_EEXTEND
= 0x06,
116 enum __encls_type __T
= (enum __encls_type
)__L
;
118 if (!__builtin_constant_p (__T
))
119 __encls_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
130 __encls_bc (__L
, __D
[0], __D
[1], __R
);
136 __encls_bcd (__L
, __D
[0], __D
[1], __D
[2], __R
);
141 __encls_c (__L
, __D
[1], __R
);
144 __encls_edbgrd (__L
, __D
[0], __D
[1], __R
);
153 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
154 _enclu_u32 (const int __L
, size_t __D
[])
158 __SGX_EREPORT
= 0x00,
159 __SGX_EGETKEY
= 0x01,
161 __SGX_ERESUME
= 0x03,
163 __SGX_EACCEPT
= 0x05,
165 __SGX_EACCEPTCOPY
= 0x07
167 enum __enclu_type __T
= (enum __enclu_type
) __L
;
169 if (!__builtin_constant_p (__T
))
170 __enclu_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
174 case __SGX_EACCEPTCOPY
:
175 __enclu_bcd (__L
, __D
[0], __D
[1], __D
[2], __R
);
181 __enclu_bc (__L
, __D
[0], __D
[1], __R
);
184 __enclu_eenter (__L
, __D
[0], __D
[1], __R
);
187 __enclu_eexit (__L
, __D
[0], __D
[1], __R
);
195 #ifdef __DISABLE_SGX__
196 #undef __DISABLE_SGX__
197 #pragma GCC pop_options
198 #endif /* __DISABLE_SGX__ */
200 #endif /* _SGXINTRIN_H_INCLUDED */