s390: Add support for the ecag insn. Patch from Divya Vyas
(divyvyas@linux.vnet.ibm.com) with mods to terminate the super block
with EmFail in case the insn is not available on the host.
Part of fixing bugzilla #275800.


git-svn-id: svn://svn.valgrind.org/vex/trunk@2488 8f6e269a-dfd6-0310-a8e1-e2731360e62c
diff --git a/priv/guest_s390_defs.h b/priv/guest_s390_defs.h
index 1d771af..1c99e50 100644
--- a/priv/guest_s390_defs.h
+++ b/priv/guest_s390_defs.h
@@ -92,6 +92,7 @@
 ULong s390_do_cu42(UInt srcvalue);
 UInt  s390_do_cvb(ULong decimal);
 ULong s390_do_cvd(ULong binary);
+ULong s390_do_ecag(ULong op2addr);
 
 /* The various ways to compute the condition code. */
 enum {
diff --git a/priv/guest_s390_helpers.c b/priv/guest_s390_helpers.c
index 09ee158..81d6727 100644
--- a/priv/guest_s390_helpers.c
+++ b/priv/guest_s390_helpers.c
@@ -848,6 +848,24 @@
 ULong s390_do_cvd(ULong binary) { return 0; }
 #endif
 
+/*------------------------------------------------------------*/
+/*--- Clean helper for "Extract cache attribute".          ---*/
+/*------------------------------------------------------------*/
+#if defined(VGA_s390x)
+ULong
+s390_do_ecag(ULong op2addr)
+{
+   ULong result;
+
+   __asm__ volatile(".insn rsy,0xEB000000004C,%[out],0,0(%[in])\n\t"
+                    : [out] "=d"(result)
+                    : [in] "d"(op2addr));
+   return result;
+}
+
+#else
+ULong s390_do_ecag(ULong op2addr) { return 0; }
+#endif
 
 /*------------------------------------------------------------*/
 /*--- Helper for condition code.                           ---*/
diff --git a/priv/guest_s390_toIR.c b/priv/guest_s390_toIR.c
index 3612f05..da1c92f 100644
--- a/priv/guest_s390_toIR.c
+++ b/priv/guest_s390_toIR.c
@@ -11766,6 +11766,38 @@
    return "cu14";
 }
 
+static IRExpr *
+s390_call_ecag(IRExpr *op2addr)
+{
+   IRExpr **args, *call;
+
+   args = mkIRExprVec_1(op2addr);
+   call = mkIRExprCCall(Ity_I64, 0 /*regparm*/,
+                        "s390_do_ecag", &s390_do_ecag, args);
+
+   /* Nothing is excluded from definedness checking. */
+   call->Iex.CCall.cee->mcx_mask = 0;
+
+   return call;
+}
+
+static HChar *
+s390_irgen_ECAG(UChar r1, UChar r3, IRTemp op2addr)
+{
+   if (! s390_host_has_gie) {
+      stmt(IRStmt_Put(S390X_GUEST_OFFSET(guest_EMNOTE),
+           mkU32(EmFail_S390X_ecag)));
+      put_IA(mkaddr_expr(guest_IA_next_instr));
+      dis_res->whatNext = Dis_StopHere;
+      dis_res->jk_StopHere = Ijk_EmFail;
+   } else {
+      put_gpr_dw0(r1, s390_call_ecag(mkexpr(op2addr)));
+   }
+
+   return "ecag";
+}
+
+
 /*------------------------------------------------------------*/
 /*--- Build IR for special instructions                    ---*/
 /*------------------------------------------------------------*/
@@ -13488,7 +13520,10 @@
                                                 ovl.fmt.RSY.r1, ovl.fmt.RSY.r3,
                                                 ovl.fmt.RSY.b2, ovl.fmt.RSY.dl2,
                                                 ovl.fmt.RSY.dh2);  goto ok;
-   case 0xeb000000004cULL: /* ECAG */ goto unimplemented;
+   case 0xeb000000004cULL: s390_format_RSY_RRRD(s390_irgen_ECAG, ovl.fmt.RSY.r1,
+                                                ovl.fmt.RSY.r3, ovl.fmt.RSY.b2,
+                                                ovl.fmt.RSY.dl2, 
+                                                ovl.fmt.RSY.dh2);  goto ok;
    case 0xeb0000000051ULL: s390_format_SIY_URD(s390_irgen_TMY, ovl.fmt.SIY.i2,
                                                ovl.fmt.SIY.b1, ovl.fmt.SIY.dl1,
                                                ovl.fmt.SIY.dh1);  goto ok;
diff --git a/priv/main_main.c b/priv/main_main.c
index 26f259e..58e166b 100644
--- a/priv/main_main.c
+++ b/priv/main_main.c
@@ -1030,6 +1030,8 @@
         return "Instruction stfle is not supported on this host";
    case EmFail_S390X_stckf:
         return "Instruction stckf is not supported on this host";
+   case EmFail_S390X_ecag:
+        return "Instruction ecag is not supported on this host";
      default: 
         vpanic("LibVEX_EmNote_string: unknown warning");
    }