[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] tests/tcg/s390x: Test BRASL and BRCL with large negative off
From: |
Ilya Leoshkevich |
Subject: |
[PATCH 3/3] tests/tcg/s390x: Test BRASL and BRCL with large negative offsets |
Date: |
Fri, 11 Mar 2022 19:49:11 +0100 |
Add a small test in order to prevent regressions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/s390x/Makefile.target | 1 +
tests/tcg/s390x/branch-relative-long.c | 29 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 tests/tcg/s390x/branch-relative-long.c
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 257c568c58..fd34b130f7 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -15,6 +15,7 @@ TESTS+=mvc
TESTS+=shift
TESTS+=trap
TESTS+=signals-s390x
+TESTS+=branch-relative-long
ifneq ($(HAVE_GDB_BIN),)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
diff --git a/tests/tcg/s390x/branch-relative-long.c
b/tests/tcg/s390x/branch-relative-long.c
new file mode 100644
index 0000000000..b9fcee9873
--- /dev/null
+++ b/tests/tcg/s390x/branch-relative-long.c
@@ -0,0 +1,29 @@
+#include <assert.h>
+#include <stddef.h>
+#include <sys/mman.h>
+
+int main(void)
+{
+ const unsigned short opcodes[] = {
+ 0xc005, /* brasl %r0 */
+ 0xc0f4, /* brcl 0xf */
+ };
+ size_t length = 0x100000006;
+ unsigned char *buf;
+ int i;
+
+ buf = mmap(NULL, length, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(buf != MAP_FAILED);
+
+ *(unsigned short *)&buf[0] = 0x07fe; /* br %r14 */
+ *(unsigned int *)&buf[0x100000002] = 0x80000000;
+ for (i = 0; i < sizeof(opcodes) / sizeof(opcodes[0]); i++) {
+ *(unsigned short *)&buf[0x100000000] = opcodes[i];
+ ((void (*)(void))&buf[0x100000000])();
+ }
+
+ munmap(buf, length);
+
+ return 0;
+}
--
2.35.1