aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tcg')
-rw-r--r--tests/tcg/s390x/Makefile.target14
-rw-r--r--tests/tcg/s390x/gdbstub/test-svc.py64
-rw-r--r--tests/tcg/s390x/hello-s390x-asm.S20
-rw-r--r--tests/tcg/s390x/lcbb.c51
-rw-r--r--tests/tcg/s390x/locfhr.c29
-rw-r--r--tests/tcg/s390x/mxdb.c30
6 files changed, 207 insertions, 1 deletions
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 23dc8b6..85abfbb 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -35,6 +35,7 @@ TESTS+=chrl
TESTS+=rxsbg
TESTS+=ex-relative-long
TESTS+=ex-branch
+TESTS+=mxdb
cdsg: CFLAGS+=-pthread
cdsg: LDFLAGS+=-pthread
@@ -47,6 +48,8 @@ $(PGM_SPECIFICATION_TESTS): LDFLAGS+=pgm-specification-user.o
TESTS += $(PGM_SPECIFICATION_TESTS)
Z13_TESTS=vistr
+Z13_TESTS+=lcbb
+Z13_TESTS+=locfhr
$(Z13_TESTS): CFLAGS+=-march=z13 -O2
TESTS+=$(Z13_TESTS)
@@ -75,7 +78,16 @@ run-gdbstub-signals-s390x: signals-s390x
--bin $< --test $(S390X_SRC)/gdbstub/test-signals-s390x.py, \
mixing signals and debugging)
-EXTRA_RUNS += run-gdbstub-signals-s390x
+hello-s390x-asm: CFLAGS+=-nostdlib
+
+run-gdbstub-svc: hello-s390x-asm
+ $(call run-test, $@, $(GDB_SCRIPT) \
+ --gdb $(HAVE_GDB_BIN) \
+ --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+ --bin $< --test $(S390X_SRC)/gdbstub/test-svc.py, \
+ single-stepping svc)
+
+EXTRA_RUNS += run-gdbstub-signals-s390x run-gdbstub-svc
endif
# MVX versions of sha512
diff --git a/tests/tcg/s390x/gdbstub/test-svc.py b/tests/tcg/s390x/gdbstub/test-svc.py
new file mode 100644
index 0000000..7851ca7
--- /dev/null
+++ b/tests/tcg/s390x/gdbstub/test-svc.py
@@ -0,0 +1,64 @@
+"""Test single-stepping SVC.
+
+This runs as a sourced script (via -x, via run-test.py)."""
+from __future__ import print_function
+import gdb
+import sys
+
+
+n_failures = 0
+
+
+def report(cond, msg):
+ """Report success/fail of a test"""
+ if cond:
+ print("PASS: {}".format(msg))
+ else:
+ print("FAIL: {}".format(msg))
+ global n_failures
+ n_failures += 1
+
+
+def run_test():
+ """Run through the tests one by one"""
+ report("lghi\t" in gdb.execute("x/i $pc", False, True), "insn #1")
+ gdb.execute("si")
+ report("larl\t" in gdb.execute("x/i $pc", False, True), "insn #2")
+ gdb.execute("si")
+ report("lghi\t" in gdb.execute("x/i $pc", False, True), "insn #3")
+ gdb.execute("si")
+ report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #4")
+ gdb.execute("si")
+ report("xgr\t" in gdb.execute("x/i $pc", False, True), "insn #5")
+ gdb.execute("si")
+ report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #6")
+ gdb.execute("si")
+
+
+def main():
+ """Prepare the environment and run through the tests"""
+ try:
+ inferior = gdb.selected_inferior()
+ print("ATTACHED: {}".format(inferior.architecture().name()))
+ except (gdb.error, AttributeError):
+ print("SKIPPING (not connected)")
+ exit(0)
+
+ if gdb.parse_and_eval('$pc') == 0:
+ print("SKIP: PC not set")
+ exit(0)
+
+ try:
+ # These are not very useful in scripts
+ gdb.execute("set pagination off")
+ gdb.execute("set confirm off")
+
+ # Run the actual tests
+ run_test()
+ except gdb.error:
+ report(False, "GDB Exception: {}".format(sys.exc_info()[0]))
+ print("All tests complete: %d failures" % n_failures)
+ exit(n_failures)
+
+
+main()
diff --git a/tests/tcg/s390x/hello-s390x-asm.S b/tests/tcg/s390x/hello-s390x-asm.S
new file mode 100644
index 0000000..2e9faa1
--- /dev/null
+++ b/tests/tcg/s390x/hello-s390x-asm.S
@@ -0,0 +1,20 @@
+/*
+ * Hello, World! in assembly.
+ */
+
+.globl _start
+_start:
+
+/* puts("Hello, World!"); */
+lghi %r2,1
+larl %r3,foo
+lghi %r4,foo_end-foo
+svc 4
+
+/* exit(0); */
+xgr %r2,%r2
+svc 1
+
+.align 2
+foo: .asciz "Hello, World!\n"
+foo_end:
diff --git a/tests/tcg/s390x/lcbb.c b/tests/tcg/s390x/lcbb.c
new file mode 100644
index 0000000..8d368e0
--- /dev/null
+++ b/tests/tcg/s390x/lcbb.c
@@ -0,0 +1,51 @@
+/*
+ * Test the LCBB instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+static inline __attribute__((__always_inline__)) void
+lcbb(long *r1, void *dxb2, int m3, int *cc)
+{
+ asm("lcbb %[r1],%[dxb2],%[m3]\n"
+ "ipm %[cc]"
+ : [r1] "+r" (*r1), [cc] "=r" (*cc)
+ : [dxb2] "R" (*(char *)dxb2), [m3] "i" (m3)
+ : "cc");
+ *cc = (*cc >> 28) & 3;
+}
+
+static char buf[0x1000] __attribute__((aligned(0x1000)));
+
+static inline __attribute__((__always_inline__)) void
+test_lcbb(void *p, int m3, int exp_r1, int exp_cc)
+{
+ long r1 = 0xfedcba9876543210;
+ int cc;
+
+ lcbb(&r1, p, m3, &cc);
+ assert(r1 == (0xfedcba9800000000 | exp_r1));
+ assert(cc == exp_cc);
+}
+
+int main(void)
+{
+ test_lcbb(&buf[0], 0, 16, 0);
+ test_lcbb(&buf[63], 0, 1, 3);
+ test_lcbb(&buf[0], 1, 16, 0);
+ test_lcbb(&buf[127], 1, 1, 3);
+ test_lcbb(&buf[0], 2, 16, 0);
+ test_lcbb(&buf[255], 2, 1, 3);
+ test_lcbb(&buf[0], 3, 16, 0);
+ test_lcbb(&buf[511], 3, 1, 3);
+ test_lcbb(&buf[0], 4, 16, 0);
+ test_lcbb(&buf[1023], 4, 1, 3);
+ test_lcbb(&buf[0], 5, 16, 0);
+ test_lcbb(&buf[2047], 5, 1, 3);
+ test_lcbb(&buf[0], 6, 16, 0);
+ test_lcbb(&buf[4095], 6, 1, 3);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/tcg/s390x/locfhr.c b/tests/tcg/s390x/locfhr.c
new file mode 100644
index 0000000..ab9ff6e
--- /dev/null
+++ b/tests/tcg/s390x/locfhr.c
@@ -0,0 +1,29 @@
+/*
+ * Test the LOCFHR instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+static inline __attribute__((__always_inline__)) long
+locfhr(long r1, long r2, int m3, int cc)
+{
+ cc <<= 28;
+ asm("spm %[cc]\n"
+ "locfhr %[r1],%[r2],%[m3]\n"
+ : [r1] "+r" (r1)
+ : [cc] "r" (cc), [r2] "r" (r2), [m3] "i" (m3)
+ : "cc");
+ return r1;
+}
+
+int main(void)
+{
+ assert(locfhr(0x1111111122222222, 0x3333333344444444, 8, 0) ==
+ 0x3333333322222222);
+ assert(locfhr(0x5555555566666666, 0x7777777788888888, 11, 1) ==
+ 0x5555555566666666);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/tcg/s390x/mxdb.c b/tests/tcg/s390x/mxdb.c
new file mode 100644
index 0000000..ae92255
--- /dev/null
+++ b/tests/tcg/s390x/mxdb.c
@@ -0,0 +1,30 @@
+/*
+ * Test the MXDB and MXDBR instructions.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+int main(void)
+{
+ union {
+ double d[2];
+ long double ld;
+ } a;
+ double b;
+
+ a.d[0] = 1.2345;
+ a.d[1] = 999;
+ b = 6.789;
+ asm("mxdb %[a],%[b]" : [a] "+f" (a.ld) : [b] "R" (b));
+ assert(a.ld > 8.38 && a.ld < 8.39);
+
+ a.d[0] = 1.2345;
+ a.d[1] = 999;
+ b = 6.789;
+ asm("mxdbr %[a],%[b]" : [a] "+f" (a.ld) : [b] "f" (b));
+ assert(a.ld > 8.38 && a.ld < 8.39);
+
+ return EXIT_SUCCESS;
+}