PR target/84564
[official-gcc.git] / gcc / config / i386 / sgxintrin.h
blobdee9be81515ff43ec3c90129a6acdc31170e2fa0
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)
8 any later version.
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
27 #ifndef __SGX__
28 #pragma GCC push_options
29 #pragma GCC target("sgx")
30 #define __DISABLE_SGX__
31 #endif /* __SGX__ */
33 #define __encls_bc(leaf, b, c, retval) \
34 __asm__ __volatile__ ("encls\n\t" \
35 : "=a" (retval) \
36 : "a" (leaf), "b" (b), "c" (c) \
37 : "cc")
39 #define __encls_bcd(leaf, b, c, d, retval) \
40 __asm__ __volatile__("encls\n\t" \
41 : "=a" (retval) \
42 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
43 : "cc")
45 #define __encls_c(leaf, c, retval) \
46 __asm__ __volatile__("encls\n\t" \
47 : "=a" (retval) \
48 : "a" (leaf), "c" (c) \
49 : "cc")
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) \
60 : "cc")
62 #define __enclu_bc(leaf, b, c, retval) \
63 __asm__ __volatile__("enclu\n\t" \
64 : "=a" (retval) \
65 : "a" (leaf), "b" (b), "c" (c) \
66 : "cc")
68 #define __enclu_bcd(leaf, b, c, d, retval) \
69 __asm__ __volatile__("enclu\n\t" \
70 : "=a" (retval) \
71 : "a" (leaf), "b" (b), "c" (c), "d" (d) \
72 : "cc")
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) \
78 : "cc")
80 #define __enclu_eexit(leaf, b, c, retval) \
81 __asm__ __volatile__("enclu\n\t" \
82 : "=a" (retval), "=c" (c) \
83 : "a" (leaf), "b" (b) \
84 : "cc")
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) \
90 : "cc")
93 extern __inline int
94 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
95 _encls_u32 (const int __L, size_t __D[])
97 enum __encls_type
99 __SGX_ECREATE = 0x00,
100 __SGX_EADD = 0x01,
101 __SGX_EINIT = 0x02,
102 __SGX_EREMOVE = 0x03,
103 __SGX_EDBGRD = 0x04,
104 __SGX_EDBGWR = 0x05,
105 __SGX_EEXTEND = 0x06,
106 __SGX_ELDB = 0x07,
107 __SGX_ELDU = 0x08,
108 __SGX_EBLOCK = 0x09,
109 __SGX_EPA = 0x0A,
110 __SGX_EWB = 0x0B,
111 __SGX_ETRACK = 0x0C,
112 __SGX_EAUG = 0x0D,
113 __SGX_EMODPR = 0x0E,
114 __SGX_EMODT = 0x0F
116 enum __encls_type __T = (enum __encls_type)__L;
117 int __R = 0;
118 if (!__builtin_constant_p (__T))
119 __encls_generic (__L, __D[0], __D[1], __D[2], __R);
120 else switch (__T)
122 case __SGX_ECREATE:
123 case __SGX_EADD:
124 case __SGX_EDBGWR:
125 case __SGX_EEXTEND:
126 case __SGX_EPA:
127 case __SGX_EMODPR:
128 case __SGX_EMODT:
129 case __SGX_EAUG:
130 __encls_bc (__L, __D[0], __D[1], __R);
131 break;
132 case __SGX_EINIT:
133 case __SGX_ELDB:
134 case __SGX_ELDU:
135 case __SGX_EWB:
136 __encls_bcd (__L, __D[0], __D[1], __D[2], __R);
137 break;
138 case __SGX_EREMOVE:
139 case __SGX_EBLOCK:
140 case __SGX_ETRACK:
141 __encls_c (__L, __D[1], __R);
142 break;
143 case __SGX_EDBGRD:
144 __encls_edbgrd (__L, __D[0], __D[1], __R);
145 break;
146 default:
147 return -1;
149 return __R;
152 extern __inline int
153 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
154 _enclu_u32 (const int __L, size_t __D[])
156 enum __enclu_type
158 __SGX_EREPORT = 0x00,
159 __SGX_EGETKEY = 0x01,
160 __SGX_EENTER = 0x02,
161 __SGX_ERESUME = 0x03,
162 __SGX_EEXIT = 0x04,
163 __SGX_EACCEPT = 0x05,
164 __SGX_EMODPE = 0x06,
165 __SGX_EACCEPTCOPY = 0x07
167 enum __enclu_type __T = (enum __enclu_type) __L;
168 int __R = 0;
169 if (!__builtin_constant_p (__T))
170 __enclu_generic (__L, __D[0], __D[1], __D[2], __R);
171 else switch (__T)
173 case __SGX_EREPORT:
174 case __SGX_EACCEPTCOPY:
175 __enclu_bcd (__L, __D[0], __D[1], __D[2], __R);
176 break;
177 case __SGX_EGETKEY:
178 case __SGX_ERESUME:
179 case __SGX_EACCEPT:
180 case __SGX_EMODPE:
181 __enclu_bc (__L, __D[0], __D[1], __R);
182 break;
183 case __SGX_EENTER:
184 __enclu_eenter (__L, __D[0], __D[1], __R);
185 break;
186 case __SGX_EEXIT:
187 __enclu_eexit (__L, __D[0], __D[1], __R);
188 break;
189 default:
190 return -1;
192 return __R;
195 #ifdef __DISABLE_SGX__
196 #undef __DISABLE_SGX__
197 #pragma GCC pop_options
198 #endif /* __DISABLE_SGX__ */
200 #endif /* _SGXINTRIN_H_INCLUDED */