Enable Intel ENCLV support.
authorOlga Makhotina <olga.makhotina@intel.com>
Thu, 15 Mar 2018 15:46:38 +0000 (15:46 +0000)
committerIgor Tsimbalist <itsimbal@gcc.gnu.org>
Thu, 15 Mar 2018 15:46:38 +0000 (16:46 +0100)
2018-03-15  Olga Makhotina  <olga.makhotina@intel.com>

gcc/
        * config/i386/sgxintrin.h (_enclv_u32): New intrinsic.
        (__enclv_bc, __enclv_cd, __enclv_generic): New definitions.
        (ERDINFO, ETRACKC, ELDBC, ELDUC): New leaves.

gcc/testsuite/
        * gcc.target/i386/sgx.c (_enclv_u32): Test new intrinsic.

From-SVN: r258560

gcc/ChangeLog
gcc/config/i386/sgxintrin.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/sgx.c

index 41b4d70..0bf5b43 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-15  Olga Makhotina  <olga.makhotina@intel.com>
+
+       * config/i386/sgxintrin.h (_enclv_u32): New intrinsic.
+       (__enclv_bc, __enclv_cd, __enclv_generic): New definitions.
+       (ERDINFO, ETRACKC, ELDBC, ELDUC): New leaves.
+
 2018-03-15  David Malcolm  <dmalcolm@redhat.com>
 
        PR c/84852
index dee9be8..dd3f9cf 100644 (file)
           : "a" (leaf), "b" (b), "c" (c), "d" (d)      \
           : "cc")
 
+#define __enclv_bc(leaf, b, c, retval)                 \
+  __asm__ __volatile__("enclv\n\t"                     \
+          : "=a" (retval)                              \
+          : "a" (leaf), "b" (b), "c" (c)               \
+          : "cc")
+
+#define __enclv_cd(leaf, c, d, retval)                 \
+  __asm__ __volatile__("enclv\n\t"                     \
+          : "=a" (retval)                              \
+          : "a" (leaf), "c" (c), "d" (d)               \
+          : "cc")
 
-extern __inline int
+#define __enclv_generic(leaf, b, c, d, retval)         \
+  __asm__ __volatile__("enclv\n\t"                     \
+          : "=a" (retval), "=b" (b), "=c" (b), "=d" (d)\
+          : "a" (leaf), "b" (b), "c" (c), "d" (d)      \
+          : "cc")
+
+extern __inline unsigned int
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_encls_u32 (const int __L, size_t __D[])
+_encls_u32 (const unsigned int __L, size_t __D[])
 {
   enum __encls_type
   {
@@ -111,10 +128,14 @@ _encls_u32 (const int __L, size_t __D[])
     __SGX_ETRACK  = 0x0C,
     __SGX_EAUG    = 0x0D,
     __SGX_EMODPR  = 0x0E,
-    __SGX_EMODT   = 0x0F
+    __SGX_EMODT   = 0x0F,
+    __SGX_ERDINFO = 0x10,
+    __SGX_ETRACKC = 0x11,
+    __SGX_ELDBC   = 0x12,
+    __SGX_ELDUC   = 0x13
   };
   enum __encls_type __T = (enum __encls_type)__L;
-  int __R = 0;
+  unsigned int __R = 0;
   if (!__builtin_constant_p (__T))
     __encls_generic (__L, __D[0], __D[1], __D[2], __R);
   else switch (__T)
@@ -127,31 +148,35 @@ _encls_u32 (const int __L, size_t __D[])
     case __SGX_EMODPR:
     case __SGX_EMODT:
     case __SGX_EAUG:
+    case __SGX_ERDINFO:
       __encls_bc (__L, __D[0], __D[1], __R);
       break;
     case __SGX_EINIT:
     case __SGX_ELDB:
     case __SGX_ELDU:
     case __SGX_EWB:
+    case __SGX_ELDBC:
+    case __SGX_ELDUC:
       __encls_bcd (__L, __D[0], __D[1], __D[2], __R);
       break;
     case __SGX_EREMOVE:
     case __SGX_EBLOCK:
     case __SGX_ETRACK:
+    case __SGX_ETRACKC:
       __encls_c (__L, __D[1], __R);
       break;
     case __SGX_EDBGRD:
       __encls_edbgrd (__L, __D[0], __D[1], __R);
       break;
     default:
-      return -1;
+      __encls_generic (__L, __D[0], __D[1], __D[2], __R);
     }
   return __R;
 }
 
-extern __inline int
+extern __inline unsigned int
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_enclu_u32 (const int __L, size_t __D[])
+_enclu_u32 (const unsigned int __L, size_t __D[])
 {
   enum __enclu_type
   {
@@ -165,7 +190,7 @@ _enclu_u32 (const int __L, size_t __D[])
     __SGX_EACCEPTCOPY = 0x07
   };
   enum __enclu_type __T = (enum __enclu_type) __L;
-  int __R = 0;
+  unsigned int __R = 0;
   if (!__builtin_constant_p (__T))
     __enclu_generic (__L, __D[0], __D[1], __D[2], __R);
   else switch (__T)
@@ -187,7 +212,35 @@ _enclu_u32 (const int __L, size_t __D[])
       __enclu_eexit (__L, __D[0], __D[1], __R);
       break;
     default:
-      return -1;
+      __enclu_generic (__L, __D[0], __D[1], __D[2], __R);
+    }
+  return __R;
+}
+
+extern __inline unsigned int
+__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+_enclv_u32 (const unsigned int __L, size_t __D[])
+{
+  enum __enclv_type
+  {
+    __SGX_EDECVIRTCHILD = 0x00,
+    __SGX_EINCVIRTCHILD = 0x01,
+    __SGX_ESETCONTEXT   = 0x02
+  };
+  unsigned int __R = 0;
+  if (!__builtin_constant_p (__L))
+    __enclv_generic (__L, __D[0], __D[1], __D[2], __R);
+  else switch (__L)
+    {
+    case __SGX_EDECVIRTCHILD:
+    case __SGX_EINCVIRTCHILD:
+      __enclv_bc (__L, __D[0], __D[1], __R);
+      break;
+    case __SGX_ESETCONTEXT:
+      __enclv_cd (__L, __D[1], __D[2], __R);
+      break;
+    default:
+      __enclv_generic (__L, __D[0], __D[1], __D[2], __R);
     }
   return __R;
 }
index 77d090a..02ca79f 100644 (file)
@@ -1,3 +1,7 @@
+2018-03-15  Olga Makhotina  <olga.makhotina@intel.com>
+
+       * gcc.target/i386/sgx.c (_enclv_u32): Test new intrinsic.
+
 2018-03-15  Richard Biener  <rguenther@suse.de>
 
        PR c/84873
index 42ad1fc..9f3ab67 100644 (file)
@@ -2,13 +2,15 @@
 /* { dg-options "-O2 -msgx" } */
 /* { dg-final { scan-assembler-times "enclu"  2 } } */
 /* { dg-final { scan-assembler-times "encls"  2 } } */
+/* { dg-final { scan-assembler-times "enclv"  2 } } */
 
 #include <x86intrin.h>
 
-extern int leaf;
+extern unsigned int leaf;
 
 #define SGX_EENTER 0x02
 #define SGX_EBLOCK 0x09
+#define SGX_EINCVIRTCHILD 0x01
 
 int foo ()
 {
@@ -16,9 +18,14 @@ int foo ()
   test[0] = 4;
   test[1] = 5;
   test[2] = 6; 
-  int res1 = _encls_u32 (leaf, test);
-  int res2 = _enclu_u32 (leaf, test);
-  int res3 = _encls_u32 (SGX_EBLOCK, test);
-  int res4 = _enclu_u32 (SGX_EENTER, test);
+
+  unsigned int res1 = _encls_u32 (leaf, test);
+  unsigned int res2 = _enclu_u32 (leaf, test);
+  unsigned int res5 = _enclv_u32 (leaf, test);
+  
+  unsigned int res3 = _encls_u32 (SGX_EBLOCK, test);
+  unsigned int res4 = _enclu_u32 (SGX_EENTER, test);
+  unsigned int res6 = _enclv_u32 (SGX_EINCVIRTCHILD, test);
+
   return 0;
 }