Skip to contentSkip to conversation

Some improvements in z/Arch instructions support

PATCH Applied Pavel Zbitskiy 3 participants 19 messages Aug 21, 2018

v1 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Some improvements in z/Arch instructions support

Found while attempting to run an old tool in qemu.

* BAL and BALR:    Added.
* CSST:            Qemu crashed after an accidental jump to garbage.
* IPM:             A tool produced an incorrect output.
* EX TRT/TRTR:     A tool ran quite slow.
* PACK:            A tool produced an incorrect output.

* CVB, CVBY, CVBG: Added.

Changes since v2:
* Updated MAINTAINERS.
* Updated BAL and BAS not to overwrite high 32 bits in 24- and 31- bit modes.

Changes since v1:
* Tests.
* Call pc_to_link_info() instead of op_bas().
* Clarified CSST commit message.
* Rewrote IPM using extract/deposit.
* Clarified PACK commit message.
* Do not use LowCore for CONFIG_USER_ONLY.
* Reduce duplication in CVB code.

Pavel Zbitskiy (7):
tests/tcg: add a simple s390x test
target/s390x: add BAL and BALR instructions target/s390x: fix CSST decoding and runtime alignment check target/s390x: fix IPM polluting irrelevant bits target/s390x: add EX support for TRT and TRTR target/s390x: fix PACK reading 1 byte less and writing 1 byte more target/s390x: implement CVB, CVBY and CVBG

 MAINTAINERS                     |  1 +
 target/s390x/helper.h           |  1 +
 target/s390x/insn-data.def      |  7 +++
 target/s390x/int_helper.c       | 50 +++++++++++++++++++
 target/s390x/mem_helper.c       | 24 +++++++--
 target/s390x/translate.c        | 86 +++++++++++++++++++++++++--------
 tests/tcg/s390x/Makefile.target |  9 ++++
 tests/tcg/s390x/csst.c          | 43 +++++++++++++++++
 tests/tcg/s390x/cvb.c           | 18 +++++++
 tests/tcg/s390x/exrl-trt.c      | 48 ++++++++++++++++++
 tests/tcg/s390x/exrl-trtr.c     | 48 ++++++++++++++++++
 tests/tcg/s390x/hello-s390x.c   |  7 +++
 tests/tcg/s390x/ipm.c           | 22 +++++++++
 tests/tcg/s390x/pack.c          | 21 ++++++++
 14 files changed, 362 insertions(+), 23 deletions(-)
 create mode 100644 tests/tcg/s390x/Makefile.target
 create mode 100644 tests/tcg/s390x/csst.c
 create mode 100644 tests/tcg/s390x/cvb.c
 create mode 100644 tests/tcg/s390x/exrl-trt.c
 create mode 100644 tests/tcg/s390x/exrl-trtr.c
 create mode 100644 tests/tcg/s390x/hello-s390x.c
 create mode 100644 tests/tcg/s390x/ipm.c
 create mode 100644 tests/tcg/s390x/pack.c
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/7 tests/tcg: add a simple s390x test

Copied from alpha.

---
 MAINTAINERS                     | 1 +
 tests/tcg/s390x/Makefile.target | 3 +++
 tests/tcg/s390x/hello-s390x.c   | 7 +++++++
 3 files changed, 11 insertions(+)
 create mode 100644 tests/tcg/s390x/Makefile.target
 create mode 100644 tests/tcg/s390x/hello-s390x.c
MAINTAINERS +1 -0
index 6902a568f4..27af17caa7 100644
@@ -253,6 +253,7 @@ S: Maintained
 F: target/s390x/
 F: hw/s390x/
 F: disas/s390.c
+F: tests/tcg/s390x/
 L: [email protected]
 
 SH4
tests/tcg/s390x/Makefile.target new file +3 -0
new file mode 100644
index 0000000000..9f4076901f
@@ -0,0 +1,3 @@
+VPATH+=$(SRC_PATH)/tests/tcg/s390x
+CFLAGS+=-march=zEC12 -m64
+TESTS+=hello-s390x
tests/tcg/s390x/hello-s390x.c new file +7 -0
new file mode 100644
index 0000000000..3dc0a05f2b
@@ -0,0 +1,7 @@
+#include <unistd.h>
+
+int main(void)
+{
+    write(1, "hello\n", 6);
+    return 0;
+}
Signature · 1 line
2.18.0
Reviewed-by on v1 1/7
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] tests/tcg: add a simple s390x test

Quoted 39 lines · Pavel Zbitskiy

Copied from alpha.

---
 MAINTAINERS                     | 1 +
 tests/tcg/s390x/Makefile.target | 3 +++
 tests/tcg/s390x/hello-s390x.c   | 7 +++++++
 3 files changed, 11 insertions(+)
 create mode 100644 tests/tcg/s390x/Makefile.target
 create mode 100644 tests/tcg/s390x/hello-s390x.c
MAINTAINERS +1 -0
index 6902a568f4..27af17caa7 100644
@@ -253,6 +253,7 @@ S: Maintained
 F: target/s390x/
 F: hw/s390x/
 F: disas/s390.c
+F: tests/tcg/s390x/
 L: [email protected]
 
 SH4
tests/tcg/s390x/Makefile.target new file +3 -0
new file mode 100644
index 0000000000..9f4076901f
@@ -0,0 +1,3 @@
+VPATH+=$(SRC_PATH)/tests/tcg/s390x
+CFLAGS+=-march=zEC12 -m64
+TESTS+=hello-s390x
tests/tcg/s390x/hello-s390x.c new file +0 -0
new file mode 100644
index 0000000000..3dc0a05f2b

tests/tcg/s390x/hello-s390x.c line 7

Quoted 7 lines
tests/tcg/s390x/hello-s390x.c new file +7 -0
@@ -0,0 +1,7 @@
+#include <unistd.h>
+
+int main(void)
+{
+    write(1, "hello\n", 6);
+    return 0;
+}
Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH 2/7 target/s390x: add BAL and BALR instructions

In reply to Pavel Zbitskiy

These instructions are provided for compatibility purposes and are used only by old software, in the new code BAS and BASR are preferred. The difference between the old and new instruction exists only in the 24-bit mode.

In addition, fix BAS polluting high 32 bits of the first operand in 24- and 31-bit addressing modes.

---
 target/s390x/insn-data.def |  3 +++
 target/s390x/translate.c   | 55 +++++++++++++++++++++++++++++++++-----
 2 files changed, 51 insertions(+), 7 deletions(-)
target/s390x/insn-data.def +3 -0
index 5c6f33ed9c..9c7b434fca 100644
@@ -102,6 +102,9 @@
     D(0x9400, NI,      SI,    Z,   la1, i2_8u, new, 0, ni, nz64, MO_UB)
     D(0xeb54, NIY,     SIY,   LD,  la1, i2_8u, new, 0, ni, nz64, MO_UB)
 
+/* BRANCH AND LINK */
+    C(0x0500, BALR,    RR_a,  Z,   0, r2_nz, r1, 0, bal, 0)
+    C(0x4500, BAL,     RX_a,  Z,   0, a2, r1, 0, bal, 0)
 /* BRANCH AND SAVE */
     C(0x0d00, BASR,    RR_a,  Z,   0, r2_nz, r1, 0, bas, 0)
     C(0x4d00, BAS,     RX_a,  Z,   0, a2, r1, 0, bas, 0)
target/s390x/translate.c +48 -7

76 lines not on this page · raw message

Signature · 1 line
2.18.0
Reviewed-by on v1 2/7
#4 lore raw

Re: [Qemu-devel] [PATCH 2/7] target/s390x: add BAL and BALR instructions

Quoted 45 lines · Pavel Zbitskiy

These instructions are provided for compatibility purposes and are used only by old software, in the new code BAS and BASR are preferred. The difference between the old and new instruction exists only in the 24-bit mode.

In addition, fix BAS polluting high 32 bits of the first operand in 24- and 31-bit addressing modes.

---
 target/s390x/insn-data.def |  3 +++
 target/s390x/translate.c   | 55 +++++++++++++++++++++++++++++++++-----
 2 files changed, 51 insertions(+), 7 deletions(-)
target/s390x/insn-data.def +3 -0
index 5c6f33ed9c..9c7b434fca 100644
@@ -102,6 +102,9 @@
     D(0x9400, NI,      SI,    Z,   la1, i2_8u, new, 0, ni, nz64, MO_UB)
     D(0xeb54, NIY,     SIY,   LD,  la1, i2_8u, new, 0, ni, nz64, MO_UB)
 
+/* BRANCH AND LINK */
+    C(0x0500, BALR,    RR_a,  Z,   0, r2_nz, r1, 0, bal, 0)
+    C(0x4500, BAL,     RX_a,  Z,   0, a2, r1, 0, bal, 0)
 /* BRANCH AND SAVE */
     C(0x0d00, BASR,    RR_a,  Z,   0, r2_nz, r1, 0, bas, 0)
     C(0x4d00, BAS,     RX_a,  Z,   0, a2, r1, 0, bas, 0)
target/s390x/translate.c +4 -4
index 57c03cbf58..111d575c41 100644
@@ -84,14 +84,22 @@ static uint64_t inline_branch_hit[CC_OP_MAX];
 static uint64_t inline_branch_miss[CC_OP_MAX];
 #endif
 
-static uint64_t pc_to_link_info(DisasContext *s, uint64_t pc)
+static void pc_to_link_info(TCGv_i64 out, DisasContext *s, uint64_t pc)
 {
-    if (!(s->base.tb->flags & FLAG_MASK_64)) {
-        if (s->base.tb->flags & FLAG_MASK_32) {
-            return pc | 0x80000000;
+    TCGv_i64 tmp;
+
+    if (s->base.tb->flags & FLAG_MASK_32) {

target/s390x/translate.c static uint64_t inline_branch_hit[CC_OP_MAX]; · line 100

Quoted 10 lines
target/s390x/translate.c +7 -1
+        if (s->base.tb->flags & FLAG_MASK_64) {
+            tcg_gen_movi_i64(out, pc);
+            return;
         }
+        pc |= 0x80000000;
     }
-    return pc;
+    assert(!(s->base.tb->flags & FLAG_MASK_64));
+    tmp = tcg_temp_new_i64();
+    tcg_gen_movi_i64(tmp, pc);

these two can be combined into a tcg_const_i64()

Quoted 48 lines
target/s390x/translate.c +36 -1
+    tcg_gen_deposit_i64(out, out, tmp, 0, 32);
+    tcg_temp_free_i64(tmp);
 }
 
 static TCGv_i64 psw_addr;
@@ -1453,7 +1461,40 @@ static DisasJumpType op_ni(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_bas(DisasContext *s, DisasOps *o)
 {
-    tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->pc_tmp));
+    pc_to_link_info(o->out, s, s->pc_tmp);
+    if (o->in2) {
+        tcg_gen_mov_i64(psw_addr, o->in2);
+        per_branch(s, false);
+        return DISAS_PC_UPDATED;
+    } else {
+        return DISAS_NEXT;
+    }
+}
+
+static void save_link_info(DisasContext *s, DisasOps *o)
+{
+    TCGv_i64 t;
+
+    if (s->base.tb->flags & (FLAG_MASK_32 | FLAG_MASK_64)) {
+        pc_to_link_info(o->out, s, s->pc_tmp);
+        return;
+    }
+    gen_op_calc_cc(s);
+    tcg_gen_andi_i64(o->out, o->out, 0xffffffff00000000ull);
+    tcg_gen_ori_i64(o->out, o->out, ((s->ilen / 2) << 30) | s->pc_tmp);
+    t = tcg_temp_new_i64();
+    tcg_gen_shri_i64(t, psw_mask, 16);
+    tcg_gen_andi_i64(t, t, 0x0f000000);
+    tcg_gen_or_i64(o->out, o->out, t);
+    tcg_gen_extu_i32_i64(t, cc_op);
+    tcg_gen_shli_i64(t, t, 28);
+    tcg_gen_or_i64(o->out, o->out, t);
+    tcg_temp_free_i64(t);
+}
+
+static DisasJumpType op_bal(DisasContext *s, DisasOps *o)
+{
+    save_link_info(s, o);
     if (o->in2) {
         tcg_gen_mov_i64(psw_addr, o->in2);
         per_branch(s, false);

target/s390x/translate.c static DisasJumpType op_bas(DisasContext *s, DisasOps *o) · line 1509

Quoted 5 lines
target/s390x/translate.c +1 -1
@@ -1465,7 +1506,7 @@ static DisasJumpType op_bas(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_basi(DisasContext *s, DisasOps *o)
 {
-    tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->pc_tmp));
+    pc_to_link_info(o->out, s, s->pc_tmp);

We could not pass the pc explicitly, but maybe the function can be reused this way.

target/s390x/translate.c static DisasJumpType op_bas(DisasContext *s, DisasOps *o) · line 1512

Quoted 4 lines
target/s390x/translate.c +0 -0
     return help_goto_direct(s, s->base.pc_next + 2 * get_field(s->fields, i2));
 }
 

Conny, can you fixup that one tcg_const_i64() ? Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw

Re: [Qemu-devel] [PATCH 2/7] target/s390x: add BAL and BALR instructions

Quoted 1 line · On Tue, 21 Aug 2018 09:31:25 +0200 David Hildenbrand <[email protected]> wrote:

Conny, can you fixup that one tcg_const_i64() ? Thanks!

Sure, done.

#6 lore raw

PATCH 3/7 target/s390x: fix CSST decoding and runtime alignment check

In reply to Pavel Zbitskiy

CSST is defined as:

    C(0xc802, CSST,    SSF,   CASS, la1, a2, 0, 0, csst, 0)

It means that the first parameter is handled by in1_la1(). in1_la1() fills addr1 field, and not in1.

Furthermore, when extract32() is used for the alignment check, the third parameter should specify the number of trailing bits that must be 0. For FC these numbers are:

    FC=0 (word, 4 bytes):        2
    FC=1 (double word, 8 bytes): 3
    FC=2 (quad word, 16 bytes):  4

For SC these numbers correspond to the size:

    SC=0: 0
    SC=1: 1
    SC=2: 2
    SC=3: 3
    SC=4: 4
---
 target/s390x/mem_helper.c       |  2 +-
 target/s390x/translate.c        |  4 +--
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/csst.c          | 43 +++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/s390x/csst.c
target/s390x/mem_helper.c +1 -1
index e21a47fb4d..c94dbf3fcb 100644
@@ -1442,7 +1442,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
     }
 
     /* Sanity check the alignments.  */
-    if (extract32(a1, 0, 4 << fc) || extract32(a2, 0, 1 << sc)) {
+    if (extract32(a1, 0, fc + 2) || extract32(a2, 0, sc)) {
         goto spec_exception;
     }
 
target/s390x/translate.c +2 -2
index 111d575c41..929fc2db28 100644
@@ -2059,9 +2059,9 @@ static DisasJumpType op_csst(DisasContext *s, DisasOps *o)
     TCGv_i32 t_r3 = tcg_const_i32(r3);
 
     if (tb_cflags(s->base.tb) & CF_PARALLEL) {
-        gen_helper_csst_parallel(cc_op, cpu_env, t_r3, o->in1, o->in2);
+        gen_helper_csst_parallel(cc_op, cpu_env, t_r3, o->addr1, o->in2);
     } else {
-        gen_helper_csst(cc_op, cpu_env, t_r3, o->in1, o->in2);
+        gen_helper_csst(cc_op, cpu_env, t_r3, o->addr1, o->in2);
     }
     tcg_temp_free_i32(t_r3);
 
tests/tcg/s390x/Makefile.target +1 -0
index 9f4076901f..f62f950d8e 100644
@@ -1,3 +1,4 @@
 VPATH+=$(SRC_PATH)/tests/tcg/s390x
 CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
+TESTS+=csst
tests/tcg/s390x/csst.c new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.18.0
Reviewed-by on v1 3/7
#7 lore raw

Re: [Qemu-devel] [PATCH 3/7] target/s390x: fix CSST decoding and runtime alignment check

Quoted 110 lines · Pavel Zbitskiy

CSST is defined as:

    C(0xc802, CSST,    SSF,   CASS, la1, a2, 0, 0, csst, 0)

It means that the first parameter is handled by in1_la1(). in1_la1() fills addr1 field, and not in1.

Furthermore, when extract32() is used for the alignment check, the third parameter should specify the number of trailing bits that must be 0. For FC these numbers are:

    FC=0 (word, 4 bytes):        2
    FC=1 (double word, 8 bytes): 3
    FC=2 (quad word, 16 bytes):  4

For SC these numbers correspond to the size:

    SC=0: 0
    SC=1: 1
    SC=2: 2
    SC=3: 3
    SC=4: 4
---
 target/s390x/mem_helper.c       |  2 +-
 target/s390x/translate.c        |  4 +--
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/csst.c          | 43 +++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/s390x/csst.c
target/s390x/mem_helper.c +1 -1
index e21a47fb4d..c94dbf3fcb 100644
@@ -1442,7 +1442,7 @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
     }
 
     /* Sanity check the alignments.  */
-    if (extract32(a1, 0, 4 << fc) || extract32(a2, 0, 1 << sc)) {
+    if (extract32(a1, 0, fc + 2) || extract32(a2, 0, sc)) {
         goto spec_exception;
     }
 
target/s390x/translate.c +2 -2
index 111d575c41..929fc2db28 100644
@@ -2059,9 +2059,9 @@ static DisasJumpType op_csst(DisasContext *s, DisasOps *o)
     TCGv_i32 t_r3 = tcg_const_i32(r3);
 
     if (tb_cflags(s->base.tb) & CF_PARALLEL) {
-        gen_helper_csst_parallel(cc_op, cpu_env, t_r3, o->in1, o->in2);
+        gen_helper_csst_parallel(cc_op, cpu_env, t_r3, o->addr1, o->in2);
     } else {
-        gen_helper_csst(cc_op, cpu_env, t_r3, o->in1, o->in2);
+        gen_helper_csst(cc_op, cpu_env, t_r3, o->addr1, o->in2);
     }
     tcg_temp_free_i32(t_r3);
 
tests/tcg/s390x/Makefile.target +1 -0
index 9f4076901f..f62f950d8e 100644
@@ -1,3 +1,4 @@
 VPATH+=$(SRC_PATH)/tests/tcg/s390x
 CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
+TESTS+=csst
tests/tcg/s390x/csst.c new file +33 -0
new file mode 100644
index 0000000000..1dae9071fb
@@ -0,0 +1,43 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    uint64_t parmlist[] = {
+        0xfedcba9876543210ull,
+        0,
+        0x7777777777777777ull,
+        0,
+    };
+    uint64_t op1 = 0x0123456789abcdefull;
+    uint64_t op2 = 0;
+    uint64_t op3 = op1;
+    uint64_t cc;
+
+    asm volatile(
+        "    lghi %%r0,%[flags]\n"
+        "    la %%r1,%[parmlist]\n"
+        "    csst %[op1],%[op2],%[op3]\n"
+        "    ipm %[cc]\n"
+        : [op1] "+m" (op1),
+          [op2] "+m" (op2),
+          [op3] "+r" (op3),
+          [cc] "=r" (cc)
+        : [flags] "K" (0x0301),
+          [parmlist] "m" (parmlist)
+        : "r0", "r1", "cc", "memory");
+    cc = (cc >> 28) & 3;
+    if (cc) {
+        write(1, "bad cc\n", 7);
+        return 1;
+    }

tests/tcg/s390x/csst.c line 43

Quoted 10 lines
tests/tcg/s390x/csst.c new file +10 -0
+    if (op1 != parmlist[0]) {
+        write(1, "bad op1\n", 8);
+        return 1;
+    }
+    if (op2 != parmlist[2]) {
+        write(1, "bad op2\n", 8);
+        return 1;
+    }
+    return 0;
+}
Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw

PATCH 4/7 target/s390x: fix IPM polluting irrelevant bits

In reply to Pavel Zbitskiy

Suppose psw.mask=0x0000000080000000, cc=2, r1=0 and we do "ipm 1". This command must touch only bits 32-39, so the expected output is r1=0x20000000. However, currently qemu yields r1=0x20008000, because irrelevant parts of PSW leak into r1 during program mask transfer.

---
 target/s390x/translate.c        | 17 +++++++----------
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/ipm.c           | 22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)
 create mode 100644 tests/tcg/s390x/ipm.c
target/s390x/translate.c +7 -10
index 929fc2db28..f58b36b789 100644
@@ -2445,20 +2445,17 @@ static DisasJumpType op_insi(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_ipm(DisasContext *s, DisasOps *o)
 {
-    TCGv_i64 t1;
+    TCGv_i64 t1, t2;
 
     gen_op_calc_cc(s);
-    tcg_gen_andi_i64(o->out, o->out, ~0xff000000ull);
-
     t1 = tcg_temp_new_i64();
-    tcg_gen_shli_i64(t1, psw_mask, 20);
-    tcg_gen_shri_i64(t1, t1, 36);
-    tcg_gen_or_i64(o->out, o->out, t1);
-
-    tcg_gen_extu_i32_i64(t1, cc_op);
-    tcg_gen_shli_i64(t1, t1, 28);
-    tcg_gen_or_i64(o->out, o->out, t1);
+    tcg_gen_extract_i64(t1, psw_mask, 40, 4);
+    t2 = tcg_temp_new_i64();
+    tcg_gen_extu_i32_i64(t2, cc_op);
+    tcg_gen_deposit_i64(t1, t1, t2, 4, 60);
+    tcg_gen_deposit_i64(o->out, o->out, t1, 24, 8);
     tcg_temp_free_i64(t1);
+    tcg_temp_free_i64(t2);
     return DISAS_NEXT;
 }
 
tests/tcg/s390x/Makefile.target +1 -0
index f62f950d8e..c800a582e5 100644
@@ -2,3 +2,4 @@ VPATH+=$(SRC_PATH)/tests/tcg/s390x
 CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
 TESTS+=csst
+TESTS+=ipm
tests/tcg/s390x/ipm.c new file +22 -0
new file mode 100644
index 0000000000..742f3a18c5
@@ -0,0 +1,22 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    uint32_t op1 = 0x55555555;
+    uint32_t op2 = 0x44444444;
+    uint64_t cc = 0xffffffffffffffffull;
+
+    asm volatile(
+        "    clc 0(4,%[op1]),0(%[op2])\n"
+        "    ipm %[cc]\n"
+        : [cc] "+r" (cc)
+        : [op1] "r" (&op1),
+          [op2] "r" (&op2)
+        : "cc");
+    if (cc != 0xffffffff20ffffffull) {
+        write(1, "bad cc\n", 7);
+        return 1;
+    }
+    return 0;
+}
Signature · 1 line
2.18.0
Reviewed-by on v1 4/7
#9 lore raw

Re: [Qemu-devel] [PATCH 4/7] target/s390x: fix IPM polluting irrelevant bits

Quoted 74 lines · Pavel Zbitskiy

Suppose psw.mask=0x0000000080000000, cc=2, r1=0 and we do "ipm 1". This command must touch only bits 32-39, so the expected output is r1=0x20000000. However, currently qemu yields r1=0x20008000, because irrelevant parts of PSW leak into r1 during program mask transfer.

---
 target/s390x/translate.c        | 17 +++++++----------
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/ipm.c           | 22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)
 create mode 100644 tests/tcg/s390x/ipm.c
target/s390x/translate.c +7 -10
index 929fc2db28..f58b36b789 100644
@@ -2445,20 +2445,17 @@ static DisasJumpType op_insi(DisasContext *s, DisasOps *o)
 
 static DisasJumpType op_ipm(DisasContext *s, DisasOps *o)
 {
-    TCGv_i64 t1;
+    TCGv_i64 t1, t2;
 
     gen_op_calc_cc(s);
-    tcg_gen_andi_i64(o->out, o->out, ~0xff000000ull);
-
     t1 = tcg_temp_new_i64();
-    tcg_gen_shli_i64(t1, psw_mask, 20);
-    tcg_gen_shri_i64(t1, t1, 36);
-    tcg_gen_or_i64(o->out, o->out, t1);
-
-    tcg_gen_extu_i32_i64(t1, cc_op);
-    tcg_gen_shli_i64(t1, t1, 28);
-    tcg_gen_or_i64(o->out, o->out, t1);
+    tcg_gen_extract_i64(t1, psw_mask, 40, 4);
+    t2 = tcg_temp_new_i64();
+    tcg_gen_extu_i32_i64(t2, cc_op);
+    tcg_gen_deposit_i64(t1, t1, t2, 4, 60);
+    tcg_gen_deposit_i64(o->out, o->out, t1, 24, 8);
     tcg_temp_free_i64(t1);
+    tcg_temp_free_i64(t2);
     return DISAS_NEXT;
 }
 
tests/tcg/s390x/Makefile.target +1 -0
index f62f950d8e..c800a582e5 100644
@@ -2,3 +2,4 @@ VPATH+=$(SRC_PATH)/tests/tcg/s390x
 CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
 TESTS+=csst
+TESTS+=ipm
tests/tcg/s390x/ipm.c new file +12 -0
new file mode 100644
index 0000000000..742f3a18c5
@@ -0,0 +1,22 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    uint32_t op1 = 0x55555555;
+    uint32_t op2 = 0x44444444;
+    uint64_t cc = 0xffffffffffffffffull;
+
+    asm volatile(
+        "    clc 0(4,%[op1]),0(%[op2])\n"
+        "    ipm %[cc]\n"

tests/tcg/s390x/ipm.c line 22

Quoted 10 lines
tests/tcg/s390x/ipm.c new file +10 -0
+        : [cc] "+r" (cc)
+        : [op1] "r" (&op1),
+          [op2] "r" (&op2)
+        : "cc");
+    if (cc != 0xffffffff20ffffffull) {
+        write(1, "bad cc\n", 7);
+        return 1;
+    }
+    return 0;
+}
Signature · 3 lines
Thanks,

David / dhildenb
#10 lore raw

PATCH 5/7 target/s390x: add EX support for TRT and TRTR

In reply to Pavel Zbitskiy

Improves "b213c9f5: target/s390x: Implement TRTR" by introducing the intermediate functions, which are compatible with dx_helper type.

---
 target/s390x/mem_helper.c       | 16 +++++++++++
 tests/tcg/s390x/Makefile.target |  2 ++
 tests/tcg/s390x/exrl-trt.c      | 48 +++++++++++++++++++++++++++++++++
 tests/tcg/s390x/exrl-trtr.c     | 48 +++++++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
 create mode 100644 tests/tcg/s390x/exrl-trt.c
 create mode 100644 tests/tcg/s390x/exrl-trtr.c
target/s390x/mem_helper.c +16 -0
index c94dbf3fcb..704d0193b5 100644
@@ -1299,12 +1299,26 @@ static inline uint32_t do_helper_trt(CPUS390XState *env, int len,
     return 0;
 }
 
+static uint32_t do_helper_trt_fwd(CPUS390XState *env, uint32_t len,
+                                  uint64_t array, uint64_t trans,
+                                  uintptr_t ra)
+{
+    return do_helper_trt(env, len, array, trans, 1, ra);
+}
+
 uint32_t HELPER(trt)(CPUS390XState *env, uint32_t len, uint64_t array,
                      uint64_t trans)
 {
     return do_helper_trt(env, len, array, trans, 1, GETPC());
 }
 
+static uint32_t do_helper_trt_bkwd(CPUS390XState *env, uint32_t len,
+                                   uint64_t array, uint64_t trans,
+                                   uintptr_t ra)
+{
+    return do_helper_trt(env, len, array, trans, -1, ra);
+}
+
 uint32_t HELPER(trtr)(CPUS390XState *env, uint32_t len, uint64_t array,
                       uint64_t trans)
 {
@@ -2193,12 +2207,14 @@ void HELPER(ex)(CPUS390XState *env, uint32_t ilen, uint64_t r1, uint64_t addr)
         typedef uint32_t (*dx_helper)(CPUS390XState *, uint32_t, uint64_t,
                                       uint64_t, uintptr_t);
         static const dx_helper dx[16] = {
+            [0x0] = do_helper_trt_bkwd,
             [0x2] = do_helper_mvc,
             [0x4] = do_helper_nc,
             [0x5] = do_helper_clc,
             [0x6] = do_helper_oc,
             [0x7] = do_helper_xc,
             [0xc] = do_helper_tr,
+            [0xd] = do_helper_trt_fwd,
         };
         dx_helper helper = dx[opc & 0xf];
 
tests/tcg/s390x/Makefile.target +2 -0
index c800a582e5..7de4376f52 100644
@@ -3,3 +3,5 @@ CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
 TESTS+=csst
 TESTS+=ipm
+TESTS+=exrl-trt
+TESTS+=exrl-trtr
tests/tcg/s390x/exrl-trt.c new file +48 -0

48 lines not on this page · raw message

tests/tcg/s390x/exrl-trtr.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.18.0
Reviewed-by on v1 5/7
#11 lore raw

Re: [Qemu-devel] [PATCH 5/7] target/s390x: add EX support for TRT and TRTR

Quoted 168 lines · Pavel Zbitskiy

Improves "b213c9f5: target/s390x: Implement TRTR" by introducing the intermediate functions, which are compatible with dx_helper type.

---
 target/s390x/mem_helper.c       | 16 +++++++++++
 tests/tcg/s390x/Makefile.target |  2 ++
 tests/tcg/s390x/exrl-trt.c      | 48 +++++++++++++++++++++++++++++++++
 tests/tcg/s390x/exrl-trtr.c     | 48 +++++++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
 create mode 100644 tests/tcg/s390x/exrl-trt.c
 create mode 100644 tests/tcg/s390x/exrl-trtr.c
target/s390x/mem_helper.c +16 -0
index c94dbf3fcb..704d0193b5 100644
@@ -1299,12 +1299,26 @@ static inline uint32_t do_helper_trt(CPUS390XState *env, int len,
     return 0;
 }
 
+static uint32_t do_helper_trt_fwd(CPUS390XState *env, uint32_t len,
+                                  uint64_t array, uint64_t trans,
+                                  uintptr_t ra)
+{
+    return do_helper_trt(env, len, array, trans, 1, ra);
+}
+
 uint32_t HELPER(trt)(CPUS390XState *env, uint32_t len, uint64_t array,
                      uint64_t trans)
 {
     return do_helper_trt(env, len, array, trans, 1, GETPC());
 }
 
+static uint32_t do_helper_trt_bkwd(CPUS390XState *env, uint32_t len,
+                                   uint64_t array, uint64_t trans,
+                                   uintptr_t ra)
+{
+    return do_helper_trt(env, len, array, trans, -1, ra);
+}
+
 uint32_t HELPER(trtr)(CPUS390XState *env, uint32_t len, uint64_t array,
                       uint64_t trans)
 {
@@ -2193,12 +2207,14 @@ void HELPER(ex)(CPUS390XState *env, uint32_t ilen, uint64_t r1, uint64_t addr)
         typedef uint32_t (*dx_helper)(CPUS390XState *, uint32_t, uint64_t,
                                       uint64_t, uintptr_t);
         static const dx_helper dx[16] = {
+            [0x0] = do_helper_trt_bkwd,
             [0x2] = do_helper_mvc,
             [0x4] = do_helper_nc,
             [0x5] = do_helper_clc,
             [0x6] = do_helper_oc,
             [0x7] = do_helper_xc,
             [0xc] = do_helper_tr,
+            [0xd] = do_helper_trt_fwd,
         };
         dx_helper helper = dx[opc & 0xf];
 
tests/tcg/s390x/Makefile.target +2 -0
index c800a582e5..7de4376f52 100644
@@ -3,3 +3,5 @@ CFLAGS+=-march=zEC12 -m64
 TESTS+=hello-s390x
 TESTS+=csst
 TESTS+=ipm
+TESTS+=exrl-trt
+TESTS+=exrl-trtr
tests/tcg/s390x/exrl-trt.c new file +48 -0
new file mode 100644
index 0000000000..3c5323aecb
@@ -0,0 +1,48 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    char op1[] = "hello";
+    char op2[256];
+    uint64_t r1 = 0xffffffffffffffffull;
+    uint64_t r2 = 0xffffffffffffffffull;
+    uint64_t cc;
+    int i;
+
+    for (i = 0; i < 256; i++) {
+        if (i == 0) {
+            op2[i] = 0xaa;
+        } else {
+            op2[i] = 0;
+        }
+    }
+    asm volatile(
+        "    j 2f\n"
+        "1:  trt 0(1,%[op1]),0(%[op2])\n"
+        "2:  exrl %[op1_len],1b\n"
+        "    lgr %[r1],%%r1\n"
+        "    lgr %[r2],%%r2\n"
+        "    ipm %[cc]\n"
+        : [r1] "+r" (r1),
+          [r2] "+r" (r2),
+          [cc] "=r" (cc)
+        : [op1] "r" (&op1),
+          [op1_len] "r" (5),
+          [op2] "r" (&op2)
+        : "r1", "r2", "cc");
+    cc = (cc >> 28) & 3;
+    if (cc != 2) {
+        write(1, "bad cc\n", 7);
+        return 1;
+    }
+    if ((char *)r1 != &op1[5]) {
+        write(1, "bad r1\n", 7);
+        return 1;
+    }
+    if (r2 != 0xffffffffffffffaaull) {
+        write(1, "bad r2\n", 7);
+        return 1;
+    }
+    return 0;
+}
tests/tcg/s390x/exrl-trtr.c new file +38 -0
new file mode 100644
index 0000000000..c33153ad7e
@@ -0,0 +1,48 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    char op1[] = {0, 1, 2, 3};
+    char op2[256];
+    uint64_t r1 = 0xffffffffffffffffull;
+    uint64_t r2 = 0xffffffffffffffffull;
+    uint64_t cc;
+    int i;
+
+    for (i = 0; i < 256; i++) {
+        if (i == 1) {
+            op2[i] = 0xbb;
+        } else {
+            op2[i] = 0;
+        }
+    }
+    asm volatile(
+        "    j 2f\n"
+        "1:  trtr 3(1,%[op1]),0(%[op2])\n"
+        "2:  exrl %[op1_len],1b\n"
+        "    lgr %[r1],%%r1\n"
+        "    lgr %[r2],%%r2\n"
+        "    ipm %[cc]\n"
+        : [r1] "+r" (r1),
+          [r2] "+r" (r2),
+          [cc] "=r" (cc)
+        : [op1] "r" (&op1),
+          [op1_len] "r" (3),
+          [op2] "r" (&op2)
+        : "r1", "r2", "cc");
+    cc = (cc >> 28) & 3;
+    if (cc != 1) {
+        write(1, "bad cc\n", 7);
+        return 1;
+    }

tests/tcg/s390x/exrl-trtr.c line 48

Quoted 10 lines
tests/tcg/s390x/exrl-trtr.c new file +10 -0
+    if ((char *)r1 != &op1[1]) {
+        write(1, "bad r1\n", 7);
+        return 1;
+    }
+    if (r2 != 0xffffffffffffffbbull) {
+        write(1, "bad r2\n", 7);
+        return 1;
+    }
+    return 0;
+}
Signature · 3 lines
Thanks,

David / dhildenb
#12 lore raw

PATCH 6/7 target/s390x: fix PACK reading 1 byte less and writing 1 byte more

In reply to Pavel Zbitskiy

PACK fails on the test from the Principles of Operation: F1F2F3F4 becomes 0000234C instead of 0001234C due to an off-by-one error. Furthermore, it overwrites one extra byte to the left of F1.

If len_dest is 0, then we only want to flip the 1st byte and never loop over the rest. Therefore, the loop condition should be > and not >=.

If len_src is 1, then we should flip the 1st byte and pack the 2nd. Since len_src is already decremented before the loop, the first condition should be >=, and not >.

Likewise for len_src == 2 and the second condition.

---
 target/s390x/mem_helper.c       |  6 +++---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/pack.c          | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/s390x/pack.c
target/s390x/mem_helper.c +3 -3
index 704d0193b5..bacae4f503 100644
@@ -1019,15 +1019,15 @@ void HELPER(pack)(CPUS390XState *env, uint32_t len, uint64_t dest, uint64_t src)
     len_src--;
 
     /* now pack every value */
-    while (len_dest >= 0) {
+    while (len_dest > 0) {
         b = 0;
 
-        if (len_src > 0) {
+        if (len_src >= 0) {
             b = cpu_ldub_data_ra(env, src, ra) & 0x0f;
             src--;
             len_src--;
         }
-        if (len_src > 0) {
+        if (len_src >= 0) {
             b |= cpu_ldub_data_ra(env, src, ra) << 4;
             src--;
             len_src--;
tests/tcg/s390x/Makefile.target +1 -0
index 7de4376f52..151dc075aa 100644
@@ -5,3 +5,4 @@ TESTS+=csst
 TESTS+=ipm
 TESTS+=exrl-trt
 TESTS+=exrl-trtr
+TESTS+=pack
tests/tcg/s390x/pack.c new file +21 -0
new file mode 100644
index 0000000000..4be36f29a7
@@ -0,0 +1,21 @@
+#include <unistd.h>
+
+int main(void)
+{
+    char data[] = {0xaa, 0xaa, 0xf1, 0xf2, 0xf3, 0xc4, 0xaa, 0xaa};
+    char exp[] = {0xaa, 0xaa, 0x00, 0x01, 0x23, 0x4c, 0xaa, 0xaa};
+    int i;
+
+    asm volatile(
+        "    pack 2(4,%[data]),2(4,%[data])\n"
+        :
+        : [data] "r" (&data[0])
+        : "memory");
+    for (i = 0; i < 8; i++) {
+        if (data[i] != exp[i]) {
+            write(1, "bad data\n", 9);
+            return 1;
+        }
+    }
+    return 0;
+}
Signature · 1 line
2.18.0
Reviewed-by on v1 6/7
#13 lore raw

Re: [Qemu-devel] [PATCH 6/7] target/s390x: fix PACK reading 1 byte less and writing 1 byte more

Quoted 71 lines · Pavel Zbitskiy

PACK fails on the test from the Principles of Operation: F1F2F3F4 becomes 0000234C instead of 0001234C due to an off-by-one error. Furthermore, it overwrites one extra byte to the left of F1.

If len_dest is 0, then we only want to flip the 1st byte and never loop over the rest. Therefore, the loop condition should be > and not >=.

If len_src is 1, then we should flip the 1st byte and pack the 2nd. Since len_src is already decremented before the loop, the first condition should be >=, and not >.

Likewise for len_src == 2 and the second condition.

---
 target/s390x/mem_helper.c       |  6 +++---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/pack.c          | 21 +++++++++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/s390x/pack.c
target/s390x/mem_helper.c +3 -3
index 704d0193b5..bacae4f503 100644
@@ -1019,15 +1019,15 @@ void HELPER(pack)(CPUS390XState *env, uint32_t len, uint64_t dest, uint64_t src)
     len_src--;
 
     /* now pack every value */
-    while (len_dest >= 0) {
+    while (len_dest > 0) {
         b = 0;
 
-        if (len_src > 0) {
+        if (len_src >= 0) {
             b = cpu_ldub_data_ra(env, src, ra) & 0x0f;
             src--;
             len_src--;
         }
-        if (len_src > 0) {
+        if (len_src >= 0) {
             b |= cpu_ldub_data_ra(env, src, ra) << 4;
             src--;
             len_src--;
tests/tcg/s390x/Makefile.target +1 -0
index 7de4376f52..151dc075aa 100644
@@ -5,3 +5,4 @@ TESTS+=csst
 TESTS+=ipm
 TESTS+=exrl-trt
 TESTS+=exrl-trtr
+TESTS+=pack
tests/tcg/s390x/pack.c new file +11 -0
new file mode 100644
index 0000000000..4be36f29a7
@@ -0,0 +1,21 @@
+#include <unistd.h>
+
+int main(void)
+{
+    char data[] = {0xaa, 0xaa, 0xf1, 0xf2, 0xf3, 0xc4, 0xaa, 0xaa};
+    char exp[] = {0xaa, 0xaa, 0x00, 0x01, 0x23, 0x4c, 0xaa, 0xaa};
+    int i;
+
+    asm volatile(
+        "    pack 2(4,%[data]),2(4,%[data])\n"
+        :

tests/tcg/s390x/pack.c line 21

Quoted 10 lines
tests/tcg/s390x/pack.c new file +10 -0
+        : [data] "r" (&data[0])
+        : "memory");
+    for (i = 0; i < 8; i++) {
+        if (data[i] != exp[i]) {
+            write(1, "bad data\n", 9);
+            return 1;
+        }
+    }
+    return 0;
+}
Signature · 3 lines
Thanks,

David / dhildenb
#14 lore raw

PATCH 7/7 target/s390x: implement CVB, CVBY and CVBG

In reply to Pavel Zbitskiy

Convert to Binary - counterparts of the already implemented Convert to Decimal (CVD*) instructions.
Example from the Principles of Operation: 25594C becomes 63FA.

---
 target/s390x/helper.h           |  1 +
 target/s390x/insn-data.def      |  4 +++
 target/s390x/int_helper.c       | 50 +++++++++++++++++++++++++++++++++
 target/s390x/translate.c        | 10 +++++++
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/cvb.c           | 18 ++++++++++++
 6 files changed, 84 insertions(+)
 create mode 100644 tests/tcg/s390x/cvb.c
target/s390x/helper.h +1 -0
index 97c60ca7bc..46baaee0ab 100644
@@ -88,6 +88,7 @@ DEF_HELPER_FLAGS_4(tcxb, TCG_CALL_NO_RWG_SE, i32, env, i64, i64, i64)
 DEF_HELPER_FLAGS_2(sqeb, TCG_CALL_NO_WG, i64, env, i64)
 DEF_HELPER_FLAGS_2(sqdb, TCG_CALL_NO_WG, i64, env, i64)
 DEF_HELPER_FLAGS_3(sqxb, TCG_CALL_NO_WG, i64, env, i64, i64)
+DEF_HELPER_FLAGS_3(cvb, TCG_CALL_NO_WG, i64, env, i64, i32)
 DEF_HELPER_FLAGS_1(cvd, TCG_CALL_NO_RWG_SE, i64, s32)
 DEF_HELPER_FLAGS_4(pack, TCG_CALL_NO_WG, void, env, i32, i64, i64)
 DEF_HELPER_FLAGS_4(pka, TCG_CALL_NO_WG, void, env, i64, i64, i32)
target/s390x/insn-data.def +4 -0
index 9c7b434fca..1b29a5e044 100644
@@ -284,6 +284,10 @@
     D(0xec73, CLFIT,   RIE_a, GIE, r1_32u, i2_32u, 0, 0, ct, 0, 1)
     D(0xec71, CLGIT,   RIE_a, GIE, r1_o, i2_32u, 0, 0, ct, 0, 1)
 
+/* CONVERT TO BINARY */
+    C(0x4f00, CVB,     RX_a,  Z,   0, a2, new, r1_32, cvb, 0)
+    C(0xe306, CVBY,    RXY_a, LD,  0, a2, new, r1_32, cvb, 0)
+    C(0xe30e, CVBG,    RXY_a, Z,   0, a2, r1, 0, cvb, 0)
 /* CONVERT TO DECIMAL */
     C(0x4e00, CVD,     RX_a,  Z,   r1_o, a2, 0, 0, cvd, 0)
     C(0xe326, CVDY,    RXY_a, LD,  r1_o, a2, 0, 0, cvd, 0)
target/s390x/int_helper.c +50 -0

62 lines not on this page · raw message

target/s390x/translate.c +10 -0
index f58b36b789..b3cbfead5d 100644
@@ -2115,6 +2115,16 @@ static DisasJumpType op_csp(DisasContext *s, DisasOps *o)
 }
 #endif
 
+static DisasJumpType op_cvb(DisasContext *s, DisasOps *o)
+{
+    uint64_t n = ((s->fields->op == 0xE3) && (s->fields->op2 == 0x0E)) ?
+        /* CVBG */      2 :
+        /* CVB, CVBY */ 1;
+
+    gen_helper_cvb(o->out, cpu_env, o->in2, tcg_const_i32(n));
+    return DISAS_NEXT;
+}
+
 static DisasJumpType op_cvd(DisasContext *s, DisasOps *o)
 {
     TCGv_i64 t1 = tcg_temp_new_i64();
tests/tcg/s390x/Makefile.target +1 -0
index 151dc075aa..990dfb26ff 100644
@@ -6,3 +6,4 @@ TESTS+=ipm
 TESTS+=exrl-trt
 TESTS+=exrl-trtr
 TESTS+=pack
+TESTS+=cvb
tests/tcg/s390x/cvb.c new file +18 -0
new file mode 100644
index 0000000000..3a72e132aa
@@ -0,0 +1,18 @@
+#include <stdint.h>
+#include <unistd.h>
+
+int main(void)
+{
+    uint64_t data = 0x000000000025594cull;
+    uint64_t result = 0;
+
+    asm volatile(
+        "    cvb %[result],%[data]\n"
+        : [result] "+r" (result)
+        : [data] "m" (data));
+    if (result != 0x63fa) {
+        write(1, "bad result\n", 11);
+        return 1;
+    }
+    return 0;
+}
Signature · 1 line
2.18.0
#15 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/s390x: implement CVB, CVBY and CVBG

Quoted 32 lines · Pavel Zbitskiy

Convert to Binary - counterparts of the already implemented Convert to Decimal (CVD*) instructions.
Example from the Principles of Operation: 25594C becomes 63FA.

---
 target/s390x/helper.h           |  1 +
 target/s390x/insn-data.def      |  4 +++
 target/s390x/int_helper.c       | 50 +++++++++++++++++++++++++++++++++
 target/s390x/translate.c        | 10 +++++++
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/cvb.c           | 18 ++++++++++++
 6 files changed, 84 insertions(+)
 create mode 100644 tests/tcg/s390x/cvb.c
target/s390x/helper.h +1 -0
index 97c60ca7bc..46baaee0ab 100644
@@ -88,6 +88,7 @@ DEF_HELPER_FLAGS_4(tcxb, TCG_CALL_NO_RWG_SE, i32, env, i64, i64, i64)
 DEF_HELPER_FLAGS_2(sqeb, TCG_CALL_NO_WG, i64, env, i64)
 DEF_HELPER_FLAGS_2(sqdb, TCG_CALL_NO_WG, i64, env, i64)
 DEF_HELPER_FLAGS_3(sqxb, TCG_CALL_NO_WG, i64, env, i64, i64)
+DEF_HELPER_FLAGS_3(cvb, TCG_CALL_NO_WG, i64, env, i64, i32)
 DEF_HELPER_FLAGS_1(cvd, TCG_CALL_NO_RWG_SE, i64, s32)
 DEF_HELPER_FLAGS_4(pack, TCG_CALL_NO_WG, void, env, i32, i64, i64)
 DEF_HELPER_FLAGS_4(pka, TCG_CALL_NO_WG, void, env, i64, i64, i32)
target/s390x/insn-data.def +0 -0
index 9c7b434fca..1b29a5e044 100644

target/s390x/insn-data.def line 290

Quoted 7 lines
target/s390x/insn-data.def +4 -0
@@ -284,6 +284,10 @@
     D(0xec73, CLFIT,   RIE_a, GIE, r1_32u, i2_32u, 0, 0, ct, 0, 1)
     D(0xec71, CLGIT,   RIE_a, GIE, r1_o, i2_32u, 0, 0, ct, 0, 1)
 
+/* CONVERT TO BINARY */
+    C(0x4f00, CVB,     RX_a,  Z,   0, a2, new, r1_32, cvb, 0)
+    C(0xe306, CVBY,    RXY_a, LD,  0, a2, new, r1_32, cvb, 0)
+    C(0xe30e, CVBG,    RXY_a, Z,   0, a2, r1, 0, cvb, 0)

use in1_la2 instead, so you can use o->addr in the handler.

Quoted 25 lines
target/s390x/insn-data.def +0 -0
 /* CONVERT TO DECIMAL */
     C(0x4e00, CVD,     RX_a,  Z,   r1_o, a2, 0, 0, cvd, 0)
     C(0xe326, CVDY,    RXY_a, LD,  r1_o, a2, 0, 0, cvd, 0)
target/s390x/int_helper.c +7 -0
index abf77a94e6..66c6dc8b3a 100644
@@ -24,6 +24,7 @@
 #include "exec/exec-all.h"
 #include "qemu/host-utils.h"
 #include "exec/helper-proto.h"
+#include "exec/cpu_ldst.h"
 
 /* #define DEBUG_HELPER */
 #ifdef DEBUG_HELPER
@@ -118,6 +119,55 @@ uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al,
     return ret;
 }
 
+static void general_operand_exception(CPUS390XState *env, uintptr_t ra)
+{
+#ifndef CONFIG_USER_ONLY
+    LowCore *lowcore;
+
+    lowcore = cpu_map_lowcore(env);

target/s390x/int_helper.c uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al, · line 137

Quoted 10 lines
target/s390x/int_helper.c +10 -0
+    lowcore->data_exc_code = 0;
+    cpu_unmap_lowcore(lowcore);
+#endif
+    s390_program_interrupt(env, PGM_DATA, ILEN_AUTO, ra);
+}
+
+uint64_t HELPER(cvb)(CPUS390XState *env, uint64_t src, uint32_t n)
+{
+    int i, j;
+    uintptr_t ra = GETPC();

You could make this const

target/s390x/int_helper.c uint64_t HELPER(divu64)(CPUS390XState *env, uint64_t ah, uint64_t al, · line 140

Quoted 3 lines
target/s390x/int_helper.c +3 -0
+    int64_t dec, sign = 0, digit, val = 0, pow10 = 0;
+
+    for (i = 0; i < n; i++) {

When manually creating addresses, we should usually wrap to catch some special cases (address space wraparound).

tmpsrc = wrap_address(env, src + (n - i - 1) * 8);

Quoted 38 lines
target/s390x/int_helper.c +30 -0
+        dec = cpu_ldq_data_ra(env, src + (n - i - 1) * 8, ra);
+        for (j = 0; j < 16; j++, dec >>= 4) {
+            if (i == 0 && j == 0) {
+                sign = dec & 0xf;
+                if (sign < 0xa) {
+                    general_operand_exception(env, ra);
+                }
+                continue;
+            }
+            digit = dec & 0xf;
+            if (digit > 0x9) {
+                general_operand_exception(env, ra);
+            }
+            if (i == 0 && j == 1) {
+                if (sign == 0xb || sign == 0xd) {
+                    val = -digit;
+                    pow10 = -10;
+                } else {
+                    val = digit;
+                    pow10 = 10;
+                }
+            } else {
+                val += digit * pow10;
+                pow10 *= 10;
+            }
+        }
+    }
+    return val;
+}
+
 uint64_t HELPER(cvd)(int32_t reg)
 {
     /* positive 0 */
target/s390x/translate.c +0 -0
index f58b36b789..b3cbfead5d 100644

target/s390x/translate.c static DisasJumpType op_csp(DisasContext *s, DisasOps *o) · line 2124

Quoted 10 lines
target/s390x/translate.c +7 -0
@@ -2115,6 +2115,16 @@ static DisasJumpType op_csp(DisasContext *s, DisasOps *o)
 }
 #endif
 
+static DisasJumpType op_cvb(DisasContext *s, DisasOps *o)
+{
+    uint64_t n = ((s->fields->op == 0xE3) && (s->fields->op2 == 0x0E)) ?
+        /* CVBG */      2 :
+        /* CVB, CVBY */ 1;
+
+    gen_helper_cvb(o->out, cpu_env, o->in2, tcg_const_i32(n));

You are missing to free the tcg_const_i32() created variable.

Quoted 3 lines
target/s390x/translate.c +3 -0
+    return DISAS_NEXT;
+}
+
Signature · 3 lines
Thanks,

David / dhildenb
#16 lore raw
In reply to Pavel Zbitskiy
Quoted 9 lines · Pavel Zbitskiy

Found while attempting to run an old tool in qemu.

* BAL and BALR:    Added.
* CSST:            Qemu crashed after an accidental jump to garbage.
* IPM:             A tool produced an incorrect output.
* EX TRT/TRTR:     A tool ran quite slow.
* PACK:            A tool produced an incorrect output.

* CVB, CVBY, CVBG: Added.

Thanks again for the fixes. When you resend patches

1. Use "git format-patch ... --subject-prefix="PATCH v2" --cover-letter" in order to include a version number

2. Try to keep R-bs as part of your patches, so they don't get lost.

@Conny, can you pick up Patch 1-6? Ran kvm-unit-tests and booted the ususal fedora system

I remember there were some R-by from Thomas.

Thanks!

Quoted 47 lines

Changes since v2:
* Updated MAINTAINERS.
* Updated BAL and BAS not to overwrite high 32 bits in 24- and 31- bit modes.

Changes since v1:
* Tests.
* Call pc_to_link_info() instead of op_bas().
* Clarified CSST commit message.
* Rewrote IPM using extract/deposit.
* Clarified PACK commit message.
* Do not use LowCore for CONFIG_USER_ONLY.
* Reduce duplication in CVB code.

Pavel Zbitskiy (7):
tests/tcg: add a simple s390x test
target/s390x: add BAL and BALR instructions target/s390x: fix CSST decoding and runtime alignment check target/s390x: fix IPM polluting irrelevant bits target/s390x: add EX support for TRT and TRTR target/s390x: fix PACK reading 1 byte less and writing 1 byte more target/s390x: implement CVB, CVBY and CVBG

 MAINTAINERS                     |  1 +
 target/s390x/helper.h           |  1 +
 target/s390x/insn-data.def      |  7 +++
 target/s390x/int_helper.c       | 50 +++++++++++++++++++
 target/s390x/mem_helper.c       | 24 +++++++--
 target/s390x/translate.c        | 86 +++++++++++++++++++++++++--------
 tests/tcg/s390x/Makefile.target |  9 ++++
 tests/tcg/s390x/csst.c          | 43 +++++++++++++++++
 tests/tcg/s390x/cvb.c           | 18 +++++++
 tests/tcg/s390x/exrl-trt.c      | 48 ++++++++++++++++++
 tests/tcg/s390x/exrl-trtr.c     | 48 ++++++++++++++++++
 tests/tcg/s390x/hello-s390x.c   |  7 +++
 tests/tcg/s390x/ipm.c           | 22 +++++++++
 tests/tcg/s390x/pack.c          | 21 ++++++++
 14 files changed, 362 insertions(+), 23 deletions(-)
 create mode 100644 tests/tcg/s390x/Makefile.target
 create mode 100644 tests/tcg/s390x/csst.c
 create mode 100644 tests/tcg/s390x/cvb.c
 create mode 100644 tests/tcg/s390x/exrl-trt.c
 create mode 100644 tests/tcg/s390x/exrl-trtr.c
 create mode 100644 tests/tcg/s390x/hello-s390x.c
 create mode 100644 tests/tcg/s390x/ipm.c
 create mode 100644 tests/tcg/s390x/pack.c
Signature · 3 lines
Thanks,

David / dhildenb
#17 lore raw
Quoted 11 lines · On Tue, 21 Aug 2018 09:56:33 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 9 lines · Pavel Zbitskiy

Found while attempting to run an old tool in qemu.

* BAL and BALR:    Added.
* CSST:            Qemu crashed after an accidental jump to garbage.
* IPM:             A tool produced an incorrect output.
* EX TRT/TRTR:     A tool ran quite slow.
* PACK:            A tool produced an incorrect output.

* CVB, CVBY, CVBG: Added.

Quoted 4 lines

Thanks again for the fixes. When you resend patches

1. Use "git format-patch ... --subject-prefix="PATCH v2" --cover-letter" in order to include a version number

'-v 2' instead of --subject-prefix is even easier :)

Quoted 8 lines

2. Try to keep R-bs as part of your patches, so they don't get lost.

@Conny, can you pick up Patch 1-6? Ran kvm-unit-tests and booted the ususal fedora system

I remember there were some R-by from Thomas.

Yup, will try to track down the R-bs.

#18 lore raw
In reply to Pavel Zbitskiy
Quoted 47 lines · On Mon, 20 Aug 2018 22:50:57 -0400 Pavel Zbitskiy <[email protected]>…

Found while attempting to run an old tool in qemu.

* BAL and BALR:    Added.
* CSST:            Qemu crashed after an accidental jump to garbage.
* IPM:             A tool produced an incorrect output.
* EX TRT/TRTR:     A tool ran quite slow.
* PACK:            A tool produced an incorrect output.

* CVB, CVBY, CVBG: Added.

Changes since v2:
* Updated MAINTAINERS.
* Updated BAL and BAS not to overwrite high 32 bits in 24- and 31- bit modes.

Changes since v1:
* Tests.
* Call pc_to_link_info() instead of op_bas().
* Clarified CSST commit message.
* Rewrote IPM using extract/deposit.
* Clarified PACK commit message.
* Do not use LowCore for CONFIG_USER_ONLY.
* Reduce duplication in CVB code.

Pavel Zbitskiy (7):
tests/tcg: add a simple s390x test
target/s390x: add BAL and BALR instructions target/s390x: fix CSST decoding and runtime alignment check target/s390x: fix IPM polluting irrelevant bits target/s390x: add EX support for TRT and TRTR target/s390x: fix PACK reading 1 byte less and writing 1 byte more target/s390x: implement CVB, CVBY and CVBG

 MAINTAINERS                     |  1 +
 target/s390x/helper.h           |  1 +
 target/s390x/insn-data.def      |  7 +++
 target/s390x/int_helper.c       | 50 +++++++++++++++++++
 target/s390x/mem_helper.c       | 24 +++++++--
 target/s390x/translate.c        | 86 +++++++++++++++++++++++++--------
 tests/tcg/s390x/Makefile.target |  9 ++++
 tests/tcg/s390x/csst.c          | 43 +++++++++++++++++
 tests/tcg/s390x/cvb.c           | 18 +++++++
 tests/tcg/s390x/exrl-trt.c      | 48 ++++++++++++++++++
 tests/tcg/s390x/exrl-trtr.c     | 48 ++++++++++++++++++
 tests/tcg/s390x/hello-s390x.c   |  7 +++
 tests/tcg/s390x/ipm.c           | 22 +++++++++
 tests/tcg/s390x/pack.c          | 21 ++++++++
 14 files changed, 362 insertions(+), 23 deletions(-)
Quoted 9 lines
 create mode 100644 tests/tcg/s390x/Makefile.target
 create mode 100644 tests/tcg/s390x/csst.c
 create mode 100644 tests/tcg/s390x/cvb.c
 create mode 100644 tests/tcg/s390x/exrl-trt.c
 create mode 100644 tests/tcg/s390x/exrl-trtr.c
 create mode 100644 tests/tcg/s390x/hello-s390x.c
 create mode 100644 tests/tcg/s390x/ipm.c
 create mode 100644 tests/tcg/s390x/pack.c

Thanks, applied patches 1-6.

I hope I managed to collect all R-bs; I can still add more, however :)