1 /* Copyright (C) 2017-2024 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) \
92 #define __enclv_bc(leaf, b, c, retval) \
93 __asm__ __volatile__("enclv\n\t" \
95 : "a" (leaf), "b" (b), "c" (c) \
98 #define __enclv_cd(leaf, c, d, retval) \
99 __asm__ __volatile__("enclv\n\t" \
101 : "a" (leaf), "c" (c), "d" (d) \
104 #define __enclv_generic(leaf, b, c, d, retval) \
105 __asm__ __volatile__("enclv\n\t" \
106 : "=a" (retval), "=b" (b), "=c" (b), "=d" (d)\
107 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
110 extern __inline
unsigned int
111 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
112 _encls_u32 (const unsigned int __L
, size_t __D
[])
116 __SGX_ECREATE
= 0x00,
119 __SGX_EREMOVE
= 0x03,
122 __SGX_EEXTEND
= 0x06,
132 __SGX_ERDINFO
= 0x10,
133 __SGX_ETRACKC
= 0x11,
137 enum __encls_type __T
= (enum __encls_type
)__L
;
138 unsigned int __R
= 0;
139 if (!__builtin_constant_p (__T
))
140 __encls_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
152 __encls_bc (__L
, __D
[0], __D
[1], __R
);
160 __encls_bcd (__L
, __D
[0], __D
[1], __D
[2], __R
);
166 __encls_c (__L
, __D
[1], __R
);
169 __encls_edbgrd (__L
, __D
[0], __D
[1], __R
);
172 __encls_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
177 extern __inline
unsigned int
178 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
179 _enclu_u32 (const unsigned int __L
, size_t __D
[])
183 __SGX_EREPORT
= 0x00,
184 __SGX_EGETKEY
= 0x01,
186 __SGX_ERESUME
= 0x03,
188 __SGX_EACCEPT
= 0x05,
190 __SGX_EACCEPTCOPY
= 0x07
192 enum __enclu_type __T
= (enum __enclu_type
) __L
;
193 unsigned int __R
= 0;
194 if (!__builtin_constant_p (__T
))
195 __enclu_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
199 case __SGX_EACCEPTCOPY
:
200 __enclu_bcd (__L
, __D
[0], __D
[1], __D
[2], __R
);
206 __enclu_bc (__L
, __D
[0], __D
[1], __R
);
209 __enclu_eenter (__L
, __D
[0], __D
[1], __R
);
212 __enclu_eexit (__L
, __D
[0], __D
[1], __R
);
215 __enclu_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
220 extern __inline
unsigned int
221 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
222 _enclv_u32 (const unsigned int __L
, size_t __D
[])
226 __SGX_EDECVIRTCHILD
= 0x00,
227 __SGX_EINCVIRTCHILD
= 0x01,
228 __SGX_ESETCONTEXT
= 0x02
230 unsigned int __R
= 0;
231 if (!__builtin_constant_p (__L
))
232 __enclv_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
235 case __SGX_EDECVIRTCHILD
:
236 case __SGX_EINCVIRTCHILD
:
237 __enclv_bc (__L
, __D
[0], __D
[1], __R
);
239 case __SGX_ESETCONTEXT
:
240 __enclv_cd (__L
, __D
[1], __D
[2], __R
);
243 __enclv_generic (__L
, __D
[0], __D
[1], __D
[2], __R
);
248 #ifdef __DISABLE_SGX__
249 #undef __DISABLE_SGX__
250 #pragma GCC pop_options
251 #endif /* __DISABLE_SGX__ */
253 #endif /* _SGXINTRIN_H_INCLUDED */