target-s390 tcg improvements
cover target-s390 tcg improvements
With this patch set we can boot the fedora 19 kernel, and make it all the way to /bin/init. At which point the process either hangs or crashes; in either case the kernel winds up with no runnable processes and spends its time in the idle loop.
The choice of z9-109 for the facilities is because that appears to be what fedora 19 is targeting as the minimum.
That said, a debian install can make it all the way through to completion, so the fedora crash/hang must be related to something in the extra z9-109 insns.
r~
Richard Henderson (10):
target-s390: Move facilities bits to env
target-s390: Implement STFLE
target-s390: Add facilities bits and sets
target-s390: Raise OPERATION exception for disabled insns
target-s390: Implement SAM31 and SAM64
target-s390: Implement EPSW
target-s390: Fix STIDP
target-s390: Fix STURA
target-s390: Implement LURA, LURAG, STURG
target-s390: Implement ECAG
target-s390x/cpu.c | 78 ++++++++++++++++++++++ target-s390x/cpu.h | 74 ++++++++++++++++++++- target-s390x/helper.h | 4 ++ target-s390x/insn-data.def | 18 +++-- target-s390x/mem_helper.c | 18 ++++- target-s390x/misc_helper.c | 13 ++++ target-s390x/translate.c | 161 ++++++++++++++++++++++++++++++++++++--------- 7 files changed, 329 insertions(+), 37 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/10 target-s390: Move facilities bits to env
Rather than simply hard-coding them in STFL instruction.
--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)
target-s390x/cpu.c +3 -0
@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; + env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ; +if (tcg_enabled () && !inited) { inited = true;s390x_translate_init ();
target-s390x/cpu.h +1 -0
@@ -136,6 +136,7 @@ typedef struct CPUS390XState {CPU_COMMON /* reset does memset(0) up to here */ + uint64_t facilities[2];int cpu_num;uint8_t *storage_keys;
target-s390x/translate.c +5 -5
@@ -3230,12 +3230,12 @@ static ExitStatus op_spt(DisasContext *s, DisasOps *o)static ExitStatus op_stfl (DisasContext *s,DisasOps *o) { -TCGv_i64 f, a; -/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );tcg_gen_qemu_st32 (f, a,get_mem_index (s));tcg_temp_free_i64 (f);tcg_temp_free_i64 (a);
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 14 lines · Richard Henderson
Rather than simply hard-coding them in STFL instruction.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)target-s390x/cpu.c +0
-0
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 185
Quoted 5 lines
target-s390x/cpu.c +2
-0@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; + env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ;
Could we add CPU definitions along the way here? I'm fine with making z9 the default CPU type, but we should make this explicit :).
Quoted 25 lines
target-s390x/cpu.c +1
-0+if (tcg_enabled ()&& !inited) { inited = true;s390x_translate_init ();target-s390x/cpu.h +1
-0@@ -136,6 +136,7 @@ typedef struct CPUS390XState {CPU_COMMON /* reset does memset(0) up to here */ + uint64_t facilities[2];int cpu_num;uint8_t *storage_keys;target-s390x/translate.c +0
-1@@ -3230,12 +3230,12 @@ static ExitStatus op_spt(DisasContext *s, DisasOps *o)static ExitStatus op_stfl (DisasContext *s,DisasOps *o) { -TCGv_i64 f, a;
target-s390x/translate.c static ExitStatus op_spt(DisasContext *s, DisasOps *o) · line 3238
Quoted 10 lines
target-s390x/translate.c +5
-4-/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );
IMHO the facility list should be stored in DisasContext. That way we can check whether we're generating code against the correct target.
Alex
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 18 lines · Alexander Graf
Quoted 17 lines · Richard Henderson
Rather than simply hard-coding them in STFL instruction.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)target-s390x/cpu.c +0
-0@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ;
Quoted 5 lines
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 185
Quoted 2 lines
target-s390x/cpu.c +2
-0+ env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ;Could we add CPU definitions along the way here? I'm fine with making z9 the default CPU type, but we should make this explicit :).
Certainly that's what we should do. I just hadn't yet researched the currently correct way to do that. I know there's some amount of out-of-date examples in the current source base.
Pointers?
Quoted 14 lines
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj)
Quoted 13 lines
target-s390x/cpu.c +5
-5static ExitStatus op_stfl (DisasContext *s,DisasOps *o) { -TCGv_i64 f, a; -/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );
Quoted 2 lines
IMHO the facility list should be stored in DisasContext. That way we can check whether we're generating code against the correct target.
See patch 4.
As for the code we generate here, does it really matter if we load the value from env, or have it encoded as a constant? It still has to get stored to memory, so it's not like the TCG optimizer is going to do anything with the constant.
r~
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 19 lines · Richard Henderson
Quoted 18 lines · Alexander Graf
Quoted 17 lines · Richard Henderson
Rather than simply hard-coding them in STFL instruction.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)target-s390x/cpu.c +0
-0@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ;
Quoted 7 lines
Quoted 4 lines
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 185
Quoted 2 lines
target-s390x/cpu.c +2
-0+ env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ;Could we add CPU definitions along the way here? I'm fine with making z9 the default CPU type, but we should make this explicit :).
Certainly that's what we should do. I just hadn't yet researched the currently correct way to do that. I know there's some amount of out-of-date examples in the current source base.
I'll leave the answer to that to Andreas :).
Quoted 16 lines
Pointers?
Quoted 13 lines
Quoted 13 lines
target-s390x/cpu.c +5
-5static ExitStatus op_stfl (DisasContext *s,DisasOps *o) { -TCGv_i64 f, a; -/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );
Quoted 8 lines
Quoted 2 lines
IMHO the facility list should be stored in DisasContext. That way we can check whether we're generating code against the correct target.
See patch 4.
As for the code we generate here, does it really matter if we load the value from env, or have it encoded as a constant? It still has to get stored to memory, so it's not like the TCG optimizer is going to do anything with the constant.
No, it only seemed more straight forward to me from a "single source of information" point of view. But it really doesn't matter. Shifting in C seems to be easier to read :).
Alex
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 24 lines · Alexander Graf
Quoted 23 lines · Richard Henderson
Quoted 22 lines · Alexander Graf
Quoted 14 lines · Richard Henderson
Rather than simply hard-coding them in STFL instruction.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)target-s390x/cpu.c +0
-0target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 185
Quoted 5 lines
target-s390x/cpu.c +2
-0@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; + env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ;Could we add CPU definitions along the way here? I'm fine with making z9 the default CPU type, but we should make this explicit :).
Quoted 5 lines
Quoted 3 lines
Certainly that's what we should do. I just hadn't yet researched the currently correct way to do that. I know there's some amount of out-of-date examples in the current source base.
I'll leave the answer to that to Andreas :).
Can we leave that for a separate patch series then?
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj)
Quoted 11 lines
target-s390x/cpu.c +5
-5-TCGv_i64 f, a; -/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );Quoted 2 lines
IMHO the facility list should be stored in DisasContext. That way we can check whether we're generating code against the correct target.
See patch 4.
Quoted 8 lines
Quoted 4 lines
As for the code we generate here, does it really matter if we load the value from env, or have it encoded as a constant? It still has to get stored to memory, so it's not like the TCG optimizer is going to do anything with the constant.
No, it only seemed more straight forward to me from a "single source of information" point of view. But it really doesn't matter. Shifting in C seems to be easier to read :).
Fair enough. I'll rearrange the order of the patches so that we can update STFL to use the DisasContext data.
r~
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 25 lines · Richard Henderson
Quoted 24 lines · Alexander Graf
Quoted 23 lines · Richard Henderson
Quoted 22 lines · Alexander Graf
Quoted 14 lines · Richard Henderson
Rather than simply hard-coding them in STFL instruction.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 3 +++ target-s390x/cpu.h | 1 + target-s390x/translate.c | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-)target-s390x/cpu.c +0
-0target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 185
Quoted 5 lines
target-s390x/cpu.c +2
-0@@ -181,6 +181,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; + env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[1 ] =0 ;Could we add CPU definitions along the way here? I'm fine with making z9 the default CPU type, but we should make this explicit :).
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Certainly that's what we should do. I just hadn't yet researched the currently correct way to do that. I know there's some amount of out-of-date examples in the current source base.
I'll leave the answer to that to Andreas :).
Can we leave that for a separate patch series then?
Just make sure you actually check for feature bits on every instruction (which I think you do, but the current code is way too magical to me to really understand it anymore) so that we can always implement a z900 cpu type later on.
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 12 lines
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj)
Quoted 12 lines
target-s390x/cpu.c +5
-5-TCGv_i64 f, a; -/* We really ought to have more complete indication of facilities -that we implement. Address this when STFLE is implemented. */ +TCGv_i64 f =tcg_temp_new_i64 (); +TCGv_i64 a =tcg_const_i64 (200 ); +check_privileged (s); - f =tcg_const_i64 (0xc0000000 ); - a =tcg_const_i64 (200 ); + tcg_gen_ld_i64(f, cpu_env, offsetof(CPUS390XState, facilities[0])); +tcg_gen_shri_i64 (f, f,32 );Quoted 2 lines
IMHO the facility list should be stored in DisasContext. That way we can check whether we're generating code against the correct target.
See patch 4.
As for the code we generate here, does it really matter if we load the value from env, or have it encoded as a constant? It still has to get stored to memory, so it's not like the TCG optimizer is going to do anything with the constant.
Quoted 5 lines
Quoted 3 lines
No, it only seemed more straight forward to me from a "single source of information" point of view. But it really doesn't matter. Shifting in C seems to be easier to read :).
Fair enough. I'll rearrange the order of the patches so that we can update STFL to use the DisasContext data.
Thanks :)
Alex
Re: [Qemu-devel] [PATCH 01/10] target-s390: Move facilities bits to env
Quoted 3 lines · Alexander Graf
Just make sure you actually check for feature bits on every instruction (which I think you do, but the current code is way too magical to me to really understand it anymore) so that we can always implement a z900 cpu type later on.
Yes, the code to check is in "translate_one". Which, as you might imagine, translates one instruction. ;-)
r~
PATCH 2/10 target-s390: Implement STFLE
In reply to Richard Henderson--- target-s390x/helper.h | 1 + target-s390x/insn-data.def | 2 ++ target-s390x/misc_helper.c | 13 +++++++++++++ target-s390x/translate.c | 8 ++++++++ 4 files changed, 24 insertions(+)
target-s390x/helper.h +1 -0
@@ -85,6 +85,7 @@ DEF_HELPER_FLAGS_5(calc_cc, TCG_CALL_NO_RWG_SE, i32, env, i32, i64, i64, i64) DEF_HELPER_FLAGS_2(sfpc, TCG_CALL_NO_RWG, void, env, i64) DEF_HELPER_FLAGS_2(sfas, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_1(popcnt, TCG_CALL_NO_RWG_SE, i64, i64) +DEF_HELPER_2(stfle, i32, env, i64)#ifndef CONFIG_USER_ONLY DEF_HELPER_3 (servc, i32, env, i64, i64)
target-s390x/insn-data.def +2 -0
@@ -639,6 +639,8 @@ C(0xe33e, STRV, RXY_a, Z, la2, r1_32u, new, m1_32, rev32, 0) C(0xe32f, STRVG, RXY_a, Z, la2, r1_o, new, m1_64, rev64, 0) +/* STORE FACILITY LIST EXTENDED */ + C(0xb2b0, STFLE, S, SFLE, 0, a2, 0, 0, stfle, 0) /* STORE FPC */ C(0xb29c, STFPC, S, Z, 0, a2, new, m2_32, efpc, 0)
target-s390x/misc_helper.c +13 -0
@@ -518,3 +518,16 @@ uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1, return cc; }#endif + +uint32_t HELPER (stfle )(CPUS390XState *env,uint64_t addr) +{ +int max_m1 = (env->facilities[1 ] !=0 ); +int count_m1 = env->regs[0 ] &0xff ; + +cpu_stq_data (env, addr, env->facilities[0 ]); +if (count_m1 >0 ) { +cpu_stq_data (env, addr +8 , env->facilities[1 ]); + } + env->regs[0 ] = max_m1; +return (count_m1 >= max_m1 ?0 :3 ); +}
target-s390x/translate.c +8 -0
@@ -3314,6 +3314,14 @@ static ExitStatus op_stura(DisasContext *s, DisasOps *o) }#endif +static ExitStatus op_stfle (DisasContext *s,DisasOps *o) +{ +potential_page_fault (s); +gen_helper_stfle (cc_op, cpu_env, o->in2); +set_cc_static (s); +return NO_EXIT ; +} +static ExitStatus op_st8 (DisasContext *s,DisasOps *o) {tcg_gen_qemu_st8 (o->in1, o->in2,get_mem_index (s));
Signature · 1 line
1.8.1.4
PATCH 3/10 target-s390: Add facilities bits and sets
In reply to Richard HendersonName the facilities bits, collect the set of bits for tcg and the various real processor revisions. Update the set of facilities reported for TCG.
--- target-s390x/cpu.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++- target-s390x/cpu.h | 59 +++++++++++++++++++++++++++++++++++++ target-s390x/translate.c | 49 ++++++++++++++++--------------- 3 files changed, 157 insertions(+), 26 deletions(-)
target-s390x/cpu.c +74 -1
@@ -152,6 +152,70 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) scc->parent_realize (dev, errp); } +#define FAC0_TCG \ + ( FAC_BIT(0, FAC_N3) \ + | FAC_BIT(0, FAC_ZARCH) \ + | FAC_BIT(0, FAC_ZARCH_ACTIVE) \ + | FAC_BIT(0, FAC_STFLE) \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT) \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT_FAST) \ + | FAC_BIT(0, FAC_EXTENDED_IMMEDIATE) \ + | FAC_BIT(0, FAC_GENERAL_INSTRUCTIONS_EXT) \ + | FAC_BIT(0, FAC_FLOATING_POINT_EXT) \ + | FAC_BIT(0, FAC_FLOATING_POINT_SUPPPORT_ENH)) +/* ??? We may have most of the collection of facilities at bit 45. */ + +/* ??? These lists of facilities gleaned from arch/s390/kernel/head.S. */ +#define FAC0_Z900 \ + ( FAC_BIT(0, FAC_N3) \ + | FAC_BIT(0, FAC_ZARCH) \ + | FAC_BIT(0, FAC_ZARCH_ACTIVE)) + +#define FAC0_Z990 \ + ( FAC0_Z900 \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT) \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT_FAST)) + +#define FAC0_Z9_109 \ + ( FAC0_Z990 \ + | FAC_BIT(0, FAC_STFLE) \ + | FAC_BIT(0, FAC_EXTENDED_TRANSLATION_2) \ + | FAC_BIT(0, FAC_MESSAGE_SECURITY_ASSIST) \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT) \ + | FAC_BIT(0, FAC_LONG_DISPLACEMENT_FAST) \ + | FAC_BIT(0, FAC_HFP_MADDSUB) \ + | FAC_BIT(0, FAC_EXTENDED_IMMEDIATE) \ + | FAC_BIT(0, FAC_EXTENDED_TRANSLATION_3) \ + | FAC_BIT(0, FAC_HFP_UNNORMALIZED_EXT) \ + | FAC_BIT(0, FAC_ETF2_ENH) \ + | FAC_BIT(0, FAC_STORE_CLOCK_FAST) \ + | FAC_BIT(0, FAC_ETF3_ENH) \ + | FAC_BIT(0, FAC_EXTRACT_CPU_TIME)) + +#define FAC0_Z10 \ + ( FAC0_Z9_109 \ + | FAC_BIT(0, FAC_COMPARE_AND_SWAP_AND_STORE) \ + | FAC_BIT(0, FAC_COMPARE_AND_SWAP_AND_STORE_2) \ + | FAC_BIT(0, FAC_GENERAL_INSTRUCTIONS_EXT) \ + | FAC_BIT(0, FAC_EXECUTE_EXT) \ + | FAC_BIT(0, FAC_FLOATING_POINT_SUPPPORT_ENH) \ + | FAC_BIT(0, FAC_DFP) \ + | FAC_BIT(0, FAC_PFPO)) + +#define FAC0_Z196 \ + ( FAC0_Z10 \ + | FAC_BIT(0, FAC_FLOATING_POINT_EXT) \ + | FAC_BIT(0, FAC_MULTI_45)) + +#define FAC0_ZEC12 \ + ( FAC0_Z196 \ + | FAC_BIT(0, FAC_DFP_ZONED_CONVERSION) \ + | FAC_BIT(0, FAC_MULTI_49) \ + | FAC_BIT(0, FAC_CONSTRAINT_TRANSACTIONAL_EXE)) +#define FAC1_ZEC12 \ + FAC_BIT(1, FAC_TRANSACTIONAL_EXE) + +static void s390_cpu_initfn (Object *obj) {CPUState *cs =CPU (obj);
@@ -181,9 +245,18 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; - env->facilities[0 ] =0xc000000000000000ull ; + env->facilities[0 ] =FAC0_TCG ; env->facilities[1 ] =0 ; +/* ??? Current distros are targeting Z9-109 as the minimum. TCG +supports most of the Z9-109 facilities but not all. Sadly, the +kernel checks for facilities it doesn't actually need, minor stuff +like hex floating point and translation. For now, include all +that the kernel requires we support. */ +#ifndef CONFIG_USER_ONLY + env->facilities[0 ] |=FAC0_Z9_109 ; +#endif +if (tcg_enabled () && !inited) { inited = true;s390x_translate_init ();
target-s390x/cpu.h +59 -0
65 lines not on this page · raw message
target-s390x/translate.c +24 -25
70 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 4/10 target-s390: Raise OPERATION exception for disabled insns
In reply to Richard Henderson--- target-s390x/translate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target-s390x/translate.c +12 -0
@@ -53,6 +53,7 @@ struct DisasContext {const DisasInsn *insn;DisasFields *fields;uint64_t pc, next_pc; +uint64_t fac0;enum cc_op cc_op;bool singlestep_enabled; };
@@ -4651,6 +4652,16 @@ static ExitStatus translate_one(CPUS390XState *env, DisasContext *s)return EXIT_NORETURN ; } +/* Check for operation exceptions for insns that have been disabled. +Do this by shifting the facilities word0 up by the IBM big-endian +bit numbering, leaving the bit to be tested in the sign bit. +Note that TCG does not currently support any facilities in word1. */ +assert (insn->fac <64 ); +if ((int64_t )(s->fac0 << insn->fac) >=0 ) { +gen_program_exception (s,PGM_OPERATION ); +return EXIT_NORETURN ; + } +/* Check for insn specification exceptions. */ if (insn->spec) {int spec = insn->spec, excp =0 , r;
@@ -4769,6 +4780,7 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, dc.tb = tb; dc.pc = pc_start; dc.cc_op =CC_OP_DYNAMIC ; + dc.fac0 = env->facilities[0 ]; do_debug = dc.singlestep_enabled = cs->singlestep_enabled; gen_opc_end = tcg_ctx.gen_opc_buf +OPC_MAX_SIZE ;
Signature · 1 line
1.8.1.4
PATCH 5/10 target-s390: Implement SAM31 and SAM64
In reply to Richard Henderson--- target-s390x/insn-data.def | 8 ++++---- target-s390x/translate.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-)
target-s390x/insn-data.def +4 -4
@@ -566,6 +566,10 @@ /* SET ACCESS */ C(0xb24e, SAR, RRE, Z, 0, r2_o, 0, 0, sar, 0) +/* SET ADDRESSING MODE */ + /* We only do 32 and 64-bit. Let SAM24 signal illegal instruction. */ + C(0x010d, SAM31, E, Z, 0, 0, 0, 0, sam31, 0) + C(0x010e, SAM64, E, Z, 0, 0, 0, 0, sam64, 0) /* SET FPC */ C(0xb384, SFPC, RRE, Z, 0, r1_o, 0, 0, sfpc, 0) /* SET FPC AND SIGNAL */
@@ -745,10 +749,6 @@ C(0xb22a, RRBE, RRE, Z, 0, r2_o, 0, 0, rrbe, 0) /* SERVICE CALL LOGICAL PROCESSOR (PV hypercall) */ C(0xb220, SERVC, RRE, Z, r1_o, r2_o, 0, 0, servc, 0) -/* SET ADDRESSING MODE */ - /* We only do 64-bit, so accept this as a no-op. - Let SAM24 and SAM31 signal illegal instruction. */ - C(0x010e, SAM64, E, Z, 0, 0, 0, 0, 0, 0) /* SET ADDRESS SPACE CONTROL FAST */ C(0xb279, SACF, S, Z, 0, a2, 0, 0, sacf, 0) /* SET CLOCK */
target-s390x/translate.c +29 -0
@@ -2912,6 +2912,35 @@ static ExitStatus op_sacf(DisasContext *s, DisasOps *o) }#endif +static ExitStatus op_sam31 (DisasContext *s,DisasOps *o) +{ +/* Bizzare but true, we check the address of the current insn for the +specification exception, not the next to be executed. Thus the PoO +documents that Bad Things Happen at 0x7ffffffe. */ +if (s->pc & ~0x7ffffff ) { +gen_program_exception (s,PGM_SPECIFICATION ); +return EXIT_NORETURN ; + } + +tcg_gen_andi_i64 (psw_mask, psw_mask, ~PSW_MASK_64 ); +tcg_gen_ori_i64 (psw_mask, psw_mask,PSW_MASK_32 ); + +/* Always exit the TB, since we (may have) changed execution mode. */ + s->pc = s->next_pc &0x7fffffff ; +update_psw_addr (s); +return EXIT_PC_UPDATED ; +} + +static ExitStatus op_sam64 (DisasContext *s,DisasOps *o) +{ +tcg_gen_ori_i64 (psw_mask, psw_mask,PSW_MASK_32 |PSW_MASK_64 ); + +/* Always exit the TB, since we (may have) changed execution mode. */ + s->pc = s->next_pc; +update_psw_addr (s); +return EXIT_PC_UPDATED ; +} +static ExitStatus op_sar (DisasContext *s,DisasOps *o) {int r1 =get_field (s->fields, r1);
Signature · 1 line
1.8.1.4
PATCH 6/10 target-s390: Implement EPSW
In reply to Richard Henderson--- target-s390x/insn-data.def | 2 ++ target-s390x/translate.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+)
target-s390x/insn-data.def +2 -0
@@ -287,6 +287,8 @@ C(0xb24f, EAR, RRE, Z, 0, 0, new, r1_32, ear, 0) /* EXTRACT FPC */ C(0xb38c, EFPC, RRE, Z, 0, 0, new, r1_32, efpc, 0) +/* EXTRACT PSW */ + C(0xb98d, EPSW, RRE, Z, 0, 0, 0, 0, epsw, 0) /* FIND LEFTMOST ONE */ C(0xb983, FLOGR, RRE, EI, 0, r2_o, r1_P, 0, flogr, 0)
target-s390x/translate.c +18 -0
@@ -2036,6 +2036,24 @@ static ExitStatus op_efpc(DisasContext *s, DisasOps *o)return NO_EXIT ; } +static ExitStatus op_epsw (DisasContext *s,DisasOps *o) +{ +int r1 =get_field (s->fields, r1); +int r2 =get_field (s->fields, r2); +TCGv_i64 t =tcg_temp_new_i64 (); + +/* Note the "subsequently" in the PoO, which implies a defined result +if r1 == r2. Thus we cannot defer these writes to an output hook. */ +tcg_gen_shri_i64 (t, psw_mask,32 ); +store_reg32_i64 (r1, t); +if (r2 !=0 ) { +store_reg32_i64 (r2, psw_mask); + } + +tcg_temp_free_i64 (t); +return NO_EXIT ; +} +static ExitStatus op_ex (DisasContext *s,DisasOps *o) {/* ??? Perhaps a better way to implement EXECUTE is to set a bit in
Signature · 1 line
1.8.1.4
PATCH 7/10 target-s390: Fix STIDP
In reply to Richard HendersonThe implementation had been incomplete, as we did not store the machine type.
--- target-s390x/cpu.c | 2 ++ target-s390x/cpu.h | 14 +++++++++++++- target-s390x/translate.c | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-)
target-s390x/cpu.c +2 -0
@@ -257,6 +257,8 @@ static void s390_cpu_initfn(Object *obj) env->facilities[0 ] |=FAC0_Z9_109 ;#endif + env->machine_type =0x20940000 ;/* ??? Also Z9-109. */ +if (tcg_enabled () && !inited) { inited = true;s390x_translate_init ();
target-s390x/cpu.h +13 -1
@@ -197,7 +197,19 @@ typedef struct CPUS390XState {/* reset does memset(0) up to here */ uint64_t facilities[2 ]; -int cpu_num; +union { +uint64_t cpuid; +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint32_t cpu_num; +uint32_t machine_type; +#else +uint32_t machine_type; +uint32_t cpu_num; +#endif + }; + }; +uint8_t *storage_keys;uint64_t tod_offset;
target-s390x/translate.c +1 -1
@@ -3242,7 +3242,7 @@ static ExitStatus op_stctl(DisasContext *s, DisasOps *o)static ExitStatus op_stidp (DisasContext *s,DisasOps *o) {check_privileged (s); -tcg_gen_ld32u_i64 (o->out, cpu_env, offsetof(CPUS390XState , cpu_num)); +tcg_gen_ld_i64 (o->out, cpu_env, offsetof(CPUS390XState , cpuid));return NO_EXIT ; }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 07/10] target-s390: Fix STIDP
Quoted 15 lines · Richard Henderson
The implementation had been incomplete, as we did not store the machine type.
Signed-off-by Richard Henderson<[email protected]>--- target-s390x/cpu.c | 2 ++ target-s390x/cpu.h | 14 +++++++++++++- target-s390x/translate.c | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-)target-s390x/cpu.c +0
-0
target-s390x/cpu.c static void s390_cpu_initfn(Object *obj) · line 260
Quoted 4 lines
target-s390x/cpu.c +1
-0@@ -257,6 +257,8 @@ static void s390_cpu_initfn(Object *obj) env->facilities[0 ] |=FAC0_Z9_109 ;#endif + env->machine_type =0x20940000 ;/* ??? Also Z9-109. */
This really wants to be selected by -cpu.
Quoted 13 lines
target-s390x/cpu.c +1
-0+if (tcg_enabled ()&& !inited) { inited = true;s390x_translate_init ();target-s390x/cpu.h +0
-1@@ -197,7 +197,19 @@ typedef struct CPUS390XState {/* reset does memset(0) up to here */ uint64_t facilities[2 ]; -int cpu_num;
target-s390x/cpu.h typedef struct CPUS390XState { · line 209
Quoted 10 lines
target-s390x/cpu.h +10
-0+union { +uint64_t cpuid; +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint32_t cpu_num; +uint32_t machine_type; +#else +uint32_t machine_type; +uint32_t cpu_num; +#endif
Are we guaranteed that we don't need to pack? Also anonymous unions/structs are a gcc extension IIRC. And why do you swap endianness here, but not above when defining the machine_type value?
Alex
Quoted 19 lines
target-s390x/cpu.h +3
-0+ }; + }; +uint8_t *storage_keys;uint64_t tod_offset;target-s390x/translate.c +1
-1@@ -3242,7 +3242,7 @@ static ExitStatus op_stctl(DisasContext *s, DisasOps *o)static ExitStatus op_stidp (DisasContext *s,DisasOps *o) {check_privileged (s); -tcg_gen_ld32u_i64 (o->out, cpu_env, offsetof(CPUS390XState , cpu_num)); +tcg_gen_ld_i64 (o->out, cpu_env, offsetof(CPUS390XState , cpuid));return NO_EXIT ; }
Re: [Qemu-devel] [PATCH 07/10] target-s390: Fix STIDP
Quoted 7 lines · Alexander Graf
Quoted 7 lines
target-s390x/cpu.h +6
-1-int cpu_num; +union { +uint64_t cpuid; +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint32_t cpu_num; +uint32_t machine_type;
Quoted 8 lines
target-s390x/cpu.h typedef struct CPUS390XState { · line 209
Quoted 4 lines
target-s390x/cpu.h +4
-0+#else +uint32_t machine_type; +uint32_t cpu_num; +#endif Are we guaranteed that we don't need to pack? Also anonymous unions/structs are a gcc extension IIRC. And why do you swap endianness here, but not above when defining the
machine_typevalue?
(1) I can't imagine that we would; such struct/unions are used all over.
(2) Sure, but we've so many other gcc extensions I figured it didn't matter.
(3) Of course. I want host endianness, not target endianness.
r~
Re: [Qemu-devel] [PATCH 07/10] target-s390: Fix STIDP
Quoted 15 lines · Richard Henderson
Quoted 6 lines · Alexander Graf
Quoted 6 lines
target-s390x/cpu.h +5
-1-int cpu_num; +union { +uint64_t cpuid; +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint32_t cpu_num;Quoted 8 lines
target-s390x/cpu.h typedef struct CPUS390XState { · line 209
Quoted 5 lines
target-s390x/cpu.h +5
-0+uint32_t machine_type; +#else +uint32_t machine_type; +uint32_t cpu_num; +#endif Are we guaranteed that we don't need to pack? Also anonymous unions/structs are a gcc extension IIRC. And why do you swap endianness here, but not above when defining the
machine_typevalue?
Quoted 1 line
(1) I can't imagine that we would; such struct/unions are used all over.
*shrug* you're the expert :).
Quoted 1 line
(2) Sure, but we've so many other gcc extensions I figured it didn't matter.
Avi complained about it to me in Linux patches. Not sure how much we care in QEMU.
Quoted 1 line
(3) Of course. I want host endianness, not target endianness.
Phew. I think I'm slowly starting to grasp what you're trying to do here. Any way you could make this more explicit through shifts and ors and other explicit operations? This feels like too much magic to "just understand on a glimpse" to me.
Alex
Re: [Qemu-devel] [PATCH 07/10] target-s390: Fix STIDP
Quoted 22 lines · Alexander Graf
Quoted 15 lines · Richard Henderson
Quoted 6 lines · Alexander Graf
Quoted 6 lines
target-s390x/cpu.h +5
-1-int cpu_num; +union { +uint64_t cpuid; +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint32_t cpu_num;Quoted 8 lines
target-s390x/cpu.h typedef struct CPUS390XState { · line 209
Quoted 5 lines
target-s390x/cpu.h +5
-0+uint32_t machine_type; +#else +uint32_t machine_type; +uint32_t cpu_num; +#endif Are we guaranteed that we don't need to pack? Also anonymous unions/structs are a gcc extension IIRC. And why do you swap endianness here, but not above when defining the
machine_typevalue?Quoted 1 line
(1) I can't imagine that we would; such struct/unions are used all over.
*shrug* you're the expert :).
Quoted 1 line
(2) Sure, but we've so many other gcc extensions I figured it didn't matter.
Quoted 8 lines
Avi complained about it to me in Linux patches. Not sure how much we care in QEMU.
Quoted 1 line
(3) Of course. I want host endianness, not target endianness.
Phew. I think I'm slowly starting to grasp what you're trying to do here. Any way you could make this more explicit through shifts and ors and other explicit operations? This feels like too much magic to "just understand on a glimpse" to me.
Yes, I could arrange for it to be two loads and assembled at runtime.
It's not like this insn is used on any hot path... or indeed, apparently more than once in the whole lifetime of the system.
r~
PATCH 8/10 target-s390: Fix STURA
In reply to Richard HendersonWe were storing 16 bits instead of 32.
--- target-s390x/mem_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-s390x/mem_helper.c +1 -1
@@ -1041,7 +1041,7 @@ void HELPER(ptlb)(CPUS390XState *env)/* store using real address */ void HELPER (stura )(CPUS390XState *env,uint64_t addr,uint64_t v1) { -stw_phys (get_address (env,0 ,0 , addr), (uint32_t )v1); +stl_phys (get_address (env,0 ,0 , addr), (uint32_t )v1); }/* load real address */
Signature · 1 line
1.8.1.4
PATCH 9/10 target-s390: Implement LURA, LURAG, STURG
In reply to Richard Henderson--- target-s390x/helper.h | 3 +++ target-s390x/insn-data.def | 4 ++++ target-s390x/mem_helper.c | 16 ++++++++++++++++ target-s390x/translate.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+)
target-s390x/helper.h +3 -0
@@ -114,7 +114,10 @@ DEF_HELPER_FLAGS_2(sacf, TCG_CALL_NO_WG, void, env, i64) DEF_HELPER_FLAGS_3(ipte, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_1(ptlb, TCG_CALL_NO_RWG, void, env) DEF_HELPER_2(lra, i64, env, i64) +DEF_HELPER_FLAGS_2(lura, TCG_CALL_NO_WG, i64, env, i64) +DEF_HELPER_FLAGS_2(lurag, TCG_CALL_NO_WG, i64, env, i64) DEF_HELPER_FLAGS_3(stura, TCG_CALL_NO_WG, void, env, i64, i64) +DEF_HELPER_FLAGS_3(sturg, TCG_CALL_NO_WG, void, env, i64, i64)#endif #include "exec/def-helper.h"
target-s390x/insn-data.def +4 -0
@@ -741,6 +741,9 @@ C(0xb100, LRA, RX_a, Z, 0, a2, r1, 0, lra, 0) C(0xe313, LRAY, RXY_a, LD, 0, a2, r1, 0, lra, 0) C(0xe303, LRAG, RXY_a, Z, 0, a2, r1, 0, lra, 0) +/* LOAD USING REAL ADDRESS */ + C(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0) + C(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0) /* MOVE TO PRIMARY */ C(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0) /* MOVE TO SECONDARY */
@@ -798,6 +801,7 @@ C(0xad00, STOSM, SI, Z, la1, 0, 0, 0, stnosm, 0) /* STORE USING REAL ADDRESS */ C(0xb246, STURA, RRE, Z, r1_o, r2_o, 0, 0, stura, 0) + C(0xb925, STURG, RRE, Z, r1_o, r2_o, 0, 0, sturg, 0) /* TEST PROTECTION */ C(0xe501, TPROT, SSE, Z, la1, a2, 0, 0, tprot, 0)
target-s390x/mem_helper.c +16 -0
@@ -1038,12 +1038,28 @@ void HELPER(ptlb)(CPUS390XState *env)tlb_flush (env,1 ); } +/* load using real address */ +uint64_t HELPER (lura )(CPUS390XState *env,uint64_t addr) +{ +return (uint32_t )ldl_phys (get_address (env,0 ,0 , addr)); +} + +uint64_t HELPER (lurag )(CPUS390XState *env,uint64_t addr) +{ +return ldq_phys (get_address (env,0 ,0 , addr)); +} +/* store using real address */ void HELPER (stura )(CPUS390XState *env,uint64_t addr,uint64_t v1) {stl_phys (get_address (env,0 ,0 , addr), (uint32_t )v1); } +void HELPER (sturg )(CPUS390XState *env,uint64_t addr,uint64_t v1) +{ +stq_phys (get_address (env,0 ,0 , addr), v1); +} +/* load real address */ uint64_t HELPER (lra )(CPUS390XState *env,uint64_t addr) {
target-s390x/translate.c +26 -0
@@ -2463,6 +2463,24 @@ static ExitStatus op_lm64(DisasContext *s, DisasOps *o)return NO_EXIT ; } +#ifndef CONFIG_USER_ONLY +static ExitStatus op_lura (DisasContext *s,DisasOps *o) +{ +check_privileged (s); +potential_page_fault (s); +gen_helper_lura (o->out, cpu_env, o->in2); +return NO_EXIT ; +} + +static ExitStatus op_lurag (DisasContext *s,DisasOps *o) +{ +check_privileged (s); +potential_page_fault (s); +gen_helper_lurag (o->out, cpu_env, o->in2); +return NO_EXIT ; +} +#endif +static ExitStatus op_mov2 (DisasContext *s,DisasOps *o) { o->out = o->in2;
@@ -3337,6 +3355,14 @@ static ExitStatus op_stura(DisasContext *s, DisasOps *o)gen_helper_stura (cpu_env, o->in2, o->in1); return NO_EXIT; } + +static ExitStatus op_sturg (DisasContext *s,DisasOps *o) +{ +check_privileged (s); +potential_page_fault (s); +gen_helper_sturg (cpu_env, o->in2, o->in1); +return NO_EXIT ; +}#endif static ExitStatus op_stfle (DisasContext *s,DisasOps *o)
Signature · 1 line
1.8.1.4
PATCH 10/10 target-s390: Implement ECAG
In reply to Richard Henderson--- target-s390x/insn-data.def | 2 ++ target-s390x/translate.c | 7 +++++++ 2 files changed, 9 insertions(+)
target-s390x/insn-data.def +2 -0
@@ -285,6 +285,8 @@ /* EXTRACT ACCESS */ C(0xb24f, EAR, RRE, Z, 0, 0, new, r1_32, ear, 0) +/* EXTRACT CPU ATTRIBUTE */ + C(0xeb4c, ECAG, RSY_a, GIE, 0, a2, r1, 0, ecag, 0) /* EXTRACT FPC */ C(0xb38c, EFPC, RRE, Z, 0, 0, new, r1_32, efpc, 0) /* EXTRACT PSW */
target-s390x/translate.c +7 -0
@@ -2030,6 +2030,13 @@ static ExitStatus op_ear(DisasContext *s, DisasOps *o)return NO_EXIT ; } +static ExitStatus op_ecag (DisasContext *s,DisasOps *o) +{ +/* No cache information provided. */ +tcg_gen_movi_i64 (o->out,-1 ); +return NO_EXIT ; +} +static ExitStatus op_efpc (DisasContext *s,DisasOps *o) {tcg_gen_ld32u_i64 (o->out, cpu_env, offsetof(CPUS390XState , fpc));
Signature · 1 line
1.8.1.4
Quoted 11 lines · Richard Henderson
With this patch set we can boot the fedora 19 kernel, and make it all the way to
/bin/init. At which point the process either hangs or crashes; in either case the kernel winds up with no runnable processes and spends its time in the idle loop.The choice of z9-109 for the facilities is because that appears to be what fedora 19 is targeting as the minimum.
That said, a debian install can make it all the way through to completion, so the fedora crash/hang must be related to something in the extra z9-109 insns.
I couldn't spot anything obviously wrong.
Alex
Quoted 27 lines
r~
Richard Henderson (10):
target-s390: Move facilities bits to env
target-s390: Implement STFLE
target-s390: Add facilities bits and sets
target-s390: Raise OPERATION exception for disabled insns
target-s390: Implement SAM31 and SAM64
target-s390: Implement EPSW
target-s390: Fix STIDP
target-s390: Fix STURA
target-s390: Implement LURA, LURAG, STURG
target-s390: Implement ECAGtarget-s390x/cpu.c | 78 ++++++++++++++++++++++ target-s390x/cpu.h | 74 ++++++++++++++++++++- target-s390x/helper.h | 4 ++ target-s390x/insn-data.def | 18 +++-- target-s390x/mem_helper.c | 18 ++++- target-s390x/misc_helper.c | 13 ++++ target-s390x/translate.c | 161 ++++++++++++++++++++++++++++++++++++--------- 7 files changed, 329 insertions(+), 37 deletions(-)