Fix EXECUTE of relative long instructions
cover Fix EXECUTE of relative long instructions
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 | 10 +- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/ex-relative-long.c | 149 +++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/ex-relative-long.c
Signature · 1 line
2.39.2
PATCH 1/2 target/s390x: Fix EXECUTE of relative long instructions
The 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 in2_ri2().
--- target/s390x/cpu.h | 1 + target/s390x/tcg/mem_helper.c | 1 + target/s390x/tcg/translate.c | 10 +++++++++- 3 files changed, 11 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 +9 -1
@@ -5888,7 +5888,15 @@ static void in2_a2(DisasContext *s, DisasOps *o)static void in2_ri2 (DisasContext *s,DisasOps *o) { - o->in2 =tcg_const_i64 (s->base.pc_next + (int64_t )get_field (s, i2) *2 ); +int64_t delta = (int64_t )get_field (s, i2) *2 ; + +if (unlikely (s->ex_value)) { + o->in2 =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (o->in2, cpu_env, offsetof(CPUS390XState , ex_target)); +tcg_gen_addi_i64 (o->in2, o->in2, delta); + }else { + o->in2 =tcg_const_i64 (s->base.pc_next + delta); + } }#define SPEC_in2_ri2 0
Signature · 1 line
2.39.2
Re: [PATCH 1/2] target/s390x: Fix EXECUTE of relative long instructions
Quoted 49 lines · Ilya Leoshkevich
The 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
in2_ri2().Reported-by Nina Schoetterl-Glausch <[email protected]>Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/cpu.h | 1 + target/s390x/tcg/mem_helper.c | 1 + target/s390x/tcg/translate.c | 10 +++++++++- 3 files changed, 11 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 +2
-1@@ -5888,7 +5888,15 @@ static void in2_a2(DisasContext *s, DisasOps *o)static void in2_ri2 (DisasContext *s,DisasOps *o) { - o->in2 =tcg_const_i64 (s->base.pc_next + (int64_t )get_field (s, i2) *2 ); +int64_t delta = (int64_t )get_field (s, i2) *2 ; +
target/s390x/tcg/translate.c static void in2_a2(DisasContext *s, DisasOps *o) · line 5902
Quoted 10 lines
target/s390x/tcg/translate.c +7
-0+if (unlikely (s->ex_value)) { + o->in2 =tcg_temp_new_i64 (); +tcg_gen_ld_i64 (o->in2, cpu_env, offsetof(CPUS390XState , ex_target)); +tcg_gen_addi_i64 (o->in2, o->in2, delta); + }else { + o->in2 =tcg_const_i64 (s->base.pc_next + delta); + } }#define SPEC_in2_ri2 0
LGTM, hopefully Richard can have another look. Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 1/2] target/s390x: Fix EXECUTE of relative long instructions
In reply to Ilya LeoshkevichQuoted 6 lines · Ilya Leoshkevich
The 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
in2_ri2().
Quoted 7 lines
Reported-by Nina Schoetterl-Glausch<[email protected]>Signed-off-by Ilya Leoshkevich<[email protected]>--- target/s390x/cpu.h | 1 + target/s390x/tcg/mem_helper.c | 1 + target/s390x/tcg/translate.c | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-)
Good solution, reading the value from env.
r~
PATCH 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 | 149 +++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 tests/tcg/s390x/ex-relative-long.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -28,6 +28,7 @@ TESTS+=div TESTS+=clst TESTS+=long-double TESTS+=cdsg +TESTS+=ex-relative-long cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthread
tests/tcg/s390x/ex-relative-long.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 2/2] tests/tcg/s390x: Add ex-relative-long.c
Quoted 32 lines · Ilya Leoshkevich
Test EXECUTE and EXECUTE RELATIVE LONG with relative long instructions as targets.
Signed-off-by Ilya Leoshkevich <[email protected]>--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/ex-relative-long.c | 149 +++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+)create mode 100644
tests/tcg/s390x/ex-relative-long.ctests/tcg/s390x/Makefile.target +1
-0@@ -28,6 +28,7 @@ TESTS+=div TESTS+=clst TESTS+=long-double TESTS+=cdsg +TESTS+=ex-relative-long cdsg: CFLAGS+=-pthread cdsg: LDFLAGS+=-pthreadtests/tcg/s390x/ex-relative-long.c new file +4
-0@@ -0,0 +1,149 @@ +/* Check EXECUTE with relative long instructions as targets. */ +#include <stdlib.h> +#include <stdio.h> +
tests/tcg/s390x/ex-relative-long.c line 14
Quoted 10 lines
tests/tcg/s390x/ex-relative-long.c new file +10
-0+struct test { +const char *name; +long (*func)(long reg,long *cc); +long exp_reg; +long exp_mem; +long exp_cc; +}; + +/* Variable targeted by relative long instructions. */ +long mem;
I guess you're assuming that the adjacent memory, which the buggy qemu would address, contains something other than
tests/tcg/s390x/ex-relative-long.c line 20
Quoted 2 lines
tests/tcg/s390x/ex-relative-long.c new file +2
-0+/* Initial "mem" value. */ +#define MEM 0xfedcba9889abcdef
this? Perhaps better to use an array, and address the middle of it?
r~