Mark Wielaard ea8797
commit a7907a271cd158db319edc516299353213acb958
Mark Wielaard ea8797
Author: carll <carll@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard ea8797
Date:   Thu Apr 9 16:23:20 2015 +0000
Mark Wielaard ea8797
Mark Wielaard ea8797
    ADD AT_DCACHEBSIZE and AT_HWCAP2 support for POWER PC
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    Valgrind currently does not support the following AUX vector entries:
Mark Wielaard ea8797
    AT_DCACHEBSIZE, and AT_HWCAP2. By default these entries are suppressed by
Mark Wielaard ea8797
    Valgrind. The attached patch adds the needed support so the user level programs
Mark Wielaard ea8797
    can correctly determine that hardware level they are running on. Specifically
Mark Wielaard ea8797
    that the ISA 2.07 for Power 8 is supported.
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    Bugzilla 345695
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    This fix adds the needed support.  It makes a minor change to allow the
Mark Wielaard ea8797
    VEX settings of the host platform to be passed down so they can be checked
Mark Wielaard ea8797
    against the HWCAP values.
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    The files touched are:
Mark Wielaard ea8797
      coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
      coregrind/pub_core_initimg.h
Mark Wielaard ea8797
      coregrind/m_main.c
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    committed by Carl Love cel@us.ibm.com
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15078 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard ea8797
Mark Wielaard ea8797
diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
index 964e355..b198dbf 100644
Mark Wielaard ea8797
--- a/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
+++ b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
@@ -246,6 +246,10 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname)
Mark Wielaard ea8797
 /*=== Setting up the client's stack                                ===*/
Mark Wielaard ea8797
 /*====================================================================*/
Mark Wielaard ea8797
 
Mark Wielaard ea8797
+#ifndef AT_DCACHEBSIZE
Mark Wielaard ea8797
+#define AT_DCACHEBSIZE		19
Mark Wielaard ea8797
+#endif /* AT_DCACHEBSIZE */
Mark Wielaard ea8797
+
Mark Wielaard ea8797
 #ifndef AT_ICACHEBSIZE
Mark Wielaard ea8797
 #define AT_ICACHEBSIZE		20
Mark Wielaard ea8797
 #endif /* AT_ICACHEBSIZE */
Mark Wielaard ea8797
@@ -262,6 +266,10 @@ static HChar** setup_client_env ( HChar** origenv, const HChar* toolname)
Mark Wielaard ea8797
 #define AT_RANDOM		25
Mark Wielaard ea8797
 #endif /* AT_RANDOM */
Mark Wielaard ea8797
 
Mark Wielaard ea8797
+#ifndef AT_HWCAP2
Mark Wielaard ea8797
+#define AT_HWCAP2		26
Mark Wielaard ea8797
+#endif /* AT_HWCAP2 */
Mark Wielaard ea8797
+
Mark Wielaard ea8797
 #ifndef AT_EXECFN
Mark Wielaard ea8797
 #define AT_EXECFN		31
Mark Wielaard ea8797
 #endif /* AT_EXECFN */
Mark Wielaard ea8797
@@ -377,8 +385,14 @@ Addr setup_client_stack( void*  init_sp,
Mark Wielaard ea8797
                          const ExeInfo* info,
Mark Wielaard ea8797
                          UInt** client_auxv,
Mark Wielaard ea8797
                          Addr   clstack_end,
Mark Wielaard ea8797
-                         SizeT  clstack_max_size )
Mark Wielaard ea8797
+                         SizeT  clstack_max_size,
Mark Wielaard ea8797
+                         const VexArchInfo* vex_archinfo )
Mark Wielaard ea8797
 {
Mark Wielaard ea8797
+  /* The HW configuration setting (hwcaps) of the target can be
Mark Wielaard ea8797
+   * checked against the Vex settings of the host platform as given
Mark Wielaard ea8797
+   * by the values in vex_archinfo.
Mark Wielaard ea8797
+   */
Mark Wielaard ea8797
+
Mark Wielaard ea8797
    SysRes res;
Mark Wielaard ea8797
    HChar **cpp;
Mark Wielaard ea8797
    HChar *strtab;		/* string table */
Mark Wielaard ea8797
@@ -690,8 +704,44 @@ Addr setup_client_stack( void*  init_sp,
Mark Wielaard ea8797
             }
Mark Wielaard ea8797
 #           endif
Mark Wielaard ea8797
             break;
Mark Wielaard ea8797
+#        if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
Mark Wielaard ea8797
+         case AT_HWCAP2:
Mark Wielaard ea8797
+            /* The HWCAP2 value has the entry arch_2_07 which indicates the
Mark Wielaard ea8797
+             * processor is a Power 8 or beyond.  The Valgrind vai.hwcaps
Mark Wielaard ea8797
+             * value (coregrind/m_machine.c) has the VEX_HWCAPS_PPC64_ISA2_07
Mark Wielaard ea8797
+             * flag set so Valgrind knows about Power8.  Need to pass the
Mark Wielaard ea8797
+             * HWCAP2 value along so the user level programs can detect that
Mark Wielaard ea8797
+             * the processor supports ISA 2.07 and beyond.
Mark Wielaard ea8797
+             */
Mark Wielaard ea8797
+            /*  Power Architecture 64-Bit ELF V2 ABI Specification
Mark Wielaard ea8797
+                July 21, 2014, version 1.0, Page 124
Mark Wielaard ea8797
+                www-03.ibm.com/technologyconnect/tgcm/TGCMServlet.wss?alias=OpenPOWER&linkid=1n0000
Mark Wielaard ea8797
+
Mark Wielaard ea8797
+                AT_HWCAP2
Mark Wielaard ea8797
+                The a_val member of this entry is a bit map of hardware
Mark Wielaard ea8797
+                capabilities. Some bit mask values include:
Mark Wielaard ea8797
+
Mark Wielaard ea8797
+                PPC_FEATURE2_ARCH_2_07        0x80000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_HTM          0x40000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_DSCR         0x20000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_EBB          0x10000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_ISEL         0x08000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_TAR          0x04000000
Mark Wielaard ea8797
+                PPC_FEATURE2_HAS_VCRYPTO      0x02000000
Mark Wielaard ea8797
+            */
Mark Wielaard ea8797
+
Mark Wielaard ea8797
+	    if ((auxv->u.a_val & ~(0x80000000ULL)) != 0) {
Mark Wielaard ea8797
+                /* Verify if PPC_FEATURE2_ARCH_2_07 is set in HWCAP2
Mark Wielaard ea8797
+                 * that arch_2_07 is also set in VEX HWCAPS
Mark Wielaard ea8797
+                 */
Mark Wielaard ea8797
+		vg_assert((vex_archinfo->hwcaps & VEX_HWCAPS_PPC64_ISA2_07) == VEX_HWCAPS_PPC64_ISA2_07);
Mark Wielaard ea8797
+	      }
Mark Wielaard ea8797
+
Mark Wielaard ea8797
+            break;
Mark Wielaard ea8797
+#           endif
Mark Wielaard ea8797
 
Mark Wielaard ea8797
          case AT_ICACHEBSIZE:
Mark Wielaard ea8797
+         case AT_DCACHEBSIZE:
Mark Wielaard ea8797
          case AT_UCACHEBSIZE:
Mark Wielaard ea8797
 #           if defined(VGP_ppc32_linux)
Mark Wielaard ea8797
             /* acquire cache info */
Mark Wielaard ea8797
@@ -852,7 +902,8 @@ static void setup_client_dataseg ( SizeT max_size )
Mark Wielaard ea8797
 /*====================================================================*/
Mark Wielaard ea8797
 
Mark Wielaard ea8797
 /* Create the client's initial memory image. */
Mark Wielaard ea8797
-IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii )
Mark Wielaard ea8797
+IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii,
Mark Wielaard ea8797
+                                          const VexArchInfo* vex_archinfo )
Mark Wielaard ea8797
 {
Mark Wielaard ea8797
    ExeInfo info;
Mark Wielaard ea8797
    HChar** env = NULL;
Mark Wielaard ea8797
@@ -913,7 +964,8 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii )
Mark Wielaard ea8797
       iifii.initial_client_SP
Mark Wielaard ea8797
          = setup_client_stack( init_sp, env, 
Mark Wielaard ea8797
                                &info, &iifii.client_auxv, 
Mark Wielaard ea8797
-                               iicii.clstack_end, iifii.clstack_max_size );
Mark Wielaard ea8797
+                               iicii.clstack_end, iifii.clstack_max_size,
Mark Wielaard ea8797
+                               vex_archinfo );
Mark Wielaard ea8797
 
Mark Wielaard ea8797
       VG_(free)(env);
Mark Wielaard ea8797
 
Mark Wielaard ea8797
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
Mark Wielaard ea8797
index 732e60e..05ddc35 100644
Mark Wielaard ea8797
--- a/coregrind/m_main.c
Mark Wielaard ea8797
+++ b/coregrind/m_main.c
Mark Wielaard ea8797
@@ -1822,9 +1822,12 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
Mark Wielaard ea8797
    //--------------------------------------------------------------
Mark Wielaard ea8797
    // Figure out what sort of CPU we're on, and whether it is 
Mark Wielaard ea8797
    // able to run V.
Mark Wielaard ea8797
+   /* The vex_archinfo structure is passed down later to the client
Mark Wielaard ea8797
+    * to verify the HW info settings are consistent.
Mark Wielaard ea8797
+    */
Mark Wielaard ea8797
+   VexArchInfo vex_archinfo;
Mark Wielaard ea8797
    VG_(debugLog)(1, "main", "Get hardware capabilities ...\n");
Mark Wielaard ea8797
    { VexArch     vex_arch;
Mark Wielaard ea8797
-     VexArchInfo vex_archinfo;
Mark Wielaard ea8797
      Bool ok = VG_(machine_get_hwcaps)();
Mark Wielaard ea8797
      if (!ok) {
Mark Wielaard ea8797
         VG_(printf)("\n");
Mark Wielaard ea8797
@@ -1952,7 +1955,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp )
Mark Wielaard ea8797
 #     endif
Mark Wielaard ea8797
 
Mark Wielaard ea8797
       /* NOTE: this call reads VG_(clo_main_stacksize). */
Mark Wielaard ea8797
-      the_iifii = VG_(ii_create_image)( the_iicii );
Mark Wielaard ea8797
+      the_iifii = VG_(ii_create_image)( the_iicii, &vex_archinfo );
Mark Wielaard ea8797
    }
Mark Wielaard ea8797
 
Mark Wielaard ea8797
    //==============================================================
Mark Wielaard ea8797
diff --git a/coregrind/pub_core_initimg.h b/coregrind/pub_core_initimg.h
Mark Wielaard ea8797
index 5623498..428b0c2 100644
Mark Wielaard ea8797
--- a/coregrind/pub_core_initimg.h
Mark Wielaard ea8797
+++ b/coregrind/pub_core_initimg.h
Mark Wielaard ea8797
@@ -33,6 +33,7 @@
Mark Wielaard ea8797
 #define __PUB_CORE_INITIMG_H
Mark Wielaard ea8797
 
Mark Wielaard ea8797
 #include "pub_core_basics.h"      // Addr
Mark Wielaard ea8797
+#include "libvex.h"
Mark Wielaard ea8797
 
Mark Wielaard ea8797
 //--------------------------------------------------------------------
Mark Wielaard ea8797
 // PURPOSE: Map the client executable into memory, then set up its
Mark Wielaard ea8797
@@ -50,7 +51,8 @@ typedef  struct _IIFinaliseImageInfo  IIFinaliseImageInfo;
Mark Wielaard ea8797
    structure, which is gathered in an OS-specific way at startup.
Mark Wielaard ea8797
    This returns an IIFinaliseImageInfo structure: */
Mark Wielaard ea8797
 extern 
Mark Wielaard ea8797
-IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo );
Mark Wielaard ea8797
+IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo,
Mark Wielaard ea8797
+                                          const VexArchInfo* vex_archinfo );
Mark Wielaard ea8797
 
Mark Wielaard ea8797
 /* Just before starting the client, we may need to make final
Mark Wielaard ea8797
    adjustments to its initial image.  Also we need to set up the VEX
Mark Wielaard ea8797
commit 21340a2747ac0dbe531949f2e6fbdb2683f1e444
Mark Wielaard ea8797
Author: carll <carll@a5019735-40e9-0310-863c-91ae7b9d1cf9>
Mark Wielaard ea8797
Date:   Tue May 19 16:08:05 2015 +0000
Mark Wielaard ea8797
Mark Wielaard ea8797
    Fix for the HWCAP2 aux vector.
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    The support assumed that if HWCAP2 is present that the system also supports
Mark Wielaard ea8797
    ISA2.07.  That assumption is not correct as we have found a few systems (OS)
Mark Wielaard ea8797
    where the HWCAP2 entry is present but the ISA2.07 bit is not set.  This patch
Mark Wielaard ea8797
    fixes the assertion test to specifically check the ISA2.07 support bit setting
Mark Wielaard ea8797
    in the HWCAP2 and vex_archinfo->hwcaps variable.  The setting for the
Mark Wielaard ea8797
    ISA2.07 support must be the same in both variables if the HWCAP2 entry exists.
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    This patch updates Vagrind bugzilla 345695.
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    
Mark Wielaard ea8797
    git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15257 a5019735-40e9-0310-863c-91ae7b9d1cf9
Mark Wielaard ea8797
Mark Wielaard ea8797
diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
index cd0b7f3..d8ff159 100644
Mark Wielaard ea8797
--- a/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
+++ b/coregrind/m_initimg/initimg-linux.c
Mark Wielaard ea8797
@@ -704,10 +704,12 @@ Addr setup_client_stack( void*  init_sp,
Mark Wielaard ea8797
 #           endif
Mark Wielaard ea8797
             break;
Mark Wielaard ea8797
 #        if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
Mark Wielaard ea8797
-         case AT_HWCAP2:
Mark Wielaard ea8797
-            /* The HWCAP2 value has the entry arch_2_07 which indicates the
Mark Wielaard ea8797
-             * processor is a Power 8 or beyond.  The Valgrind vai.hwcaps
Mark Wielaard ea8797
-             * value (coregrind/m_machine.c) has the VEX_HWCAPS_PPC64_ISA2_07
Mark Wielaard ea8797
+         case AT_HWCAP2:  {
Mark Wielaard ea8797
+            Bool auxv_2_07, hw_caps_2_07;
Mark Wielaard ea8797
+	    /* The HWCAP2 field may contain an arch_2_07 entry that indicates
Mark Wielaard ea8797
+             * if the processor is compliant with the 2.07 ISA. (i.e. Power 8
Mark Wielaard ea8797
+             * or beyond).  The Valgrind vai.hwcaps value
Mark Wielaard ea8797
+             * (coregrind/m_machine.c) has the VEX_HWCAPS_PPC64_ISA2_07
Mark Wielaard ea8797
              * flag set so Valgrind knows about Power8.  Need to pass the
Mark Wielaard ea8797
              * HWCAP2 value along so the user level programs can detect that
Mark Wielaard ea8797
              * the processor supports ISA 2.07 and beyond.
Mark Wielaard ea8797
@@ -728,13 +730,15 @@ Addr setup_client_stack( void*  init_sp,
Mark Wielaard ea8797
                 PPC_FEATURE2_HAS_TAR          0x04000000
Mark Wielaard ea8797
                 PPC_FEATURE2_HAS_VCRYPTO      0x02000000
Mark Wielaard ea8797
             */
Mark Wielaard ea8797
-
Mark Wielaard ea8797
-	    if ((auxv->u.a_val & ~(0x80000000ULL)) != 0) {
Mark Wielaard ea8797
-                /* Verify if PPC_FEATURE2_ARCH_2_07 is set in HWCAP2
Mark Wielaard ea8797
-                 * that arch_2_07 is also set in VEX HWCAPS
Mark Wielaard ea8797
-                 */
Mark Wielaard ea8797
-		vg_assert((vex_archinfo->hwcaps & VEX_HWCAPS_PPC64_ISA2_07) == VEX_HWCAPS_PPC64_ISA2_07);
Mark Wielaard ea8797
-	      }
Mark Wielaard ea8797
+            auxv_2_07 = (auxv->u.a_val & 0x80000000ULL) == 0x80000000ULL;
Mark Wielaard ea8797
+            hw_caps_2_07 = (vex_archinfo->hwcaps & VEX_HWCAPS_PPC64_ISA2_07)
Mark Wielaard ea8797
+               == VEX_HWCAPS_PPC64_ISA2_07;
Mark Wielaard ea8797
+
Mark Wielaard ea8797
+            /* Verify the PPC_FEATURE2_ARCH_2_07 setting in HWCAP2
Mark Wielaard ea8797
+	     * matches the setting in VEX HWCAPS.
Mark Wielaard ea8797
+	     */
Mark Wielaard ea8797
+            vg_assert(auxv_2_07 == hw_caps_2_07);
Mark Wielaard ea8797
+            }
Mark Wielaard ea8797
 
Mark Wielaard ea8797
             break;
Mark Wielaard ea8797
 #           endif