Fix EXECUTE of relative long instructions
PATCH v3 1/2 target/s390x: Fix EXECUTE of relative long instructions
In reply to Ilya LeoshkevichThe code uses the wrong base for relative addressing: it should use the target instruction address and not the EXECUTE's address.
Fix by storing the target instruction address in the new CPUS390XState member and loading it from the code generated by gen_ri2().
--- target/s390x/cpu.h | 1 + target/s390x/tcg/mem_helper.c | 1 + target/s390x/tcg/translate.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-)
target/s390x/cpu.h +1 -0
@@ -87,6 +87,7 @@ struct CPUArchState {uint64_t cc_vr;uint64_t ex_value; +uint64_t ex_target;uint64_t __excp_addr;uint64_t psa;
target/s390x/tcg/mem_helper.c +1 -0
@@ -2530,6 +2530,7 @@ void HELPER(ex)(CPUS390XState *env, uint32_t ilen, uint64_t r1, uint64_t addr)that ex_value is non-zero, which flags that we are in a state that requires such execution. */ env->ex_value = insn | ilen; + env->ex_target = addr; } uint32_t HELPER(mvcos)(CPUS390XState *env, uint64_t dest, uint64_t src,
target/s390x/tcg/translate.c +12 -1
@@ -5747,7 +5747,18 @@ static void in2_a2(DisasContext *s, DisasOps *o)static TCGv gen_ri2 (DisasContext *s) { -return tcg_constant_i64 (s->base.pc_next + (int64_t )get_field (s, i2) *2 ); +int64_t delta = (int64_t )get_field (s, i2) *2 ; +TCGv ri2; + +if (unlikely (s->ex_value)) { + ri2 =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (ri2, cpu_env, offsetof(CPUS390XState , ex_target)); +tcg_gen_addi_i64 (ri2, ri2, delta); + }else { + ri2 =tcg_constant_i64 (s->base.pc_next + delta); + } + +return ri2; }static void in2_ri2 (DisasContext *s,DisasOps *o)
Signature · 1 line
2.39.2
PATCH v3 2/2 tests/tcg/s390x: Add ex-relative-long.c
In reply to Ilya LeoshkevichTest EXECUTE and EXECUTE RELATIVE LONG with relative long instructions as targets.
--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/ex-relative-long.c | 156 +++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 tests/tcg/s390x/ex-relative-long.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -29,6 +29,7 @@ TESTS+=clst TESTS+=long-double TESTS+=cdsg TESTS+=chrl +TESTS+=ex-relative-long cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/ex-relative-long.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.39.2
v3 cover Fix EXECUTE of relative long instructions
v2: https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04499.html
v2 -> v3: Make mem static (Nina).
Initialize cc with cr (Nina).
Drop long casts (Nina).
Move mask assignment outside of asm.
Use "a" constraints instead of "r" where necessary. Drop unnecessary earlyclobbers.
v1: https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04316.html
v1 -> v2: Address the middle of an array in the test (Richard).
Rebase - not 100% trivial, so not carrying Reviewed-bys.
Hi,
This series fixes EXECUTE of instructions like LARL, LGLR, etc. Currently the address calculation uses EXECUTE's address as a base, while it should be using that of the target instruction. Patch 1 fixes the issue, patch 2 adds a test.
Best regards,
Ilya
Ilya Leoshkevich (2):
target/s390x: Fix EXECUTE of relative long instructions tests/tcg/s390x: Add ex-relative-long.c
target/s390x/cpu.h | 1 + target/s390x/tcg/mem_helper.c | 1 + target/s390x/tcg/translate.c | 13 ++- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/ex-relative-long.c | 156 +++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/ex-relative-long.c
Signature · 1 line
2.39.2