target-s390 tcg improvements
v2 cover target-s390 tcg improvements
Changes v1-v2:
* Squashed patches 1, 2, 4. The feedback from patch 1 called for a re-ordering of the patch set to better deal with STFL, but I could not find an ordering that worked well. I think this is probably just as clear as 3 separate patches.
* STFL and STIDP implementations adjusted for feedback.
* Minor tweaks to SAM implementations.
* Split out z9-109 hack to a separate patch.
r~
Richard Henderson (9):
target-s390: Add facilities data to env
target-s390: Implement STFLE
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-s390: Force TCG to report Z9-109
target-s390x/cpu.c | 77 ++++++++++++++++++++++ target-s390x/cpu.h | 64 +++++++++++++++++- 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 | 157 +++++++++++++++++++++++++++++++++++++-------- 7 files changed, 317 insertions(+), 34 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/9 target-s390: Add facilities data to env
Name the facilities bits, collect the set of bits for tcg and the various real processor revisions. Update the set of facilities reported for TCG. Validate the insns we execute against the facilities enabled. Report the correct facilities via STFL.
--- target-s390x/cpu.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu.h | 60 +++++++++++++++++++++++++++++++++++++++++++ target-s390x/translate.c | 66 +++++++++++++++++++++++++++-------------------- 3 files changed, 165 insertions(+), 28 deletions(-)
target-s390x/cpu.c +67 -0
@@ -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,6 +245,9 @@ static void s390_cpu_initfn(Object *obj) env->cpu_num = cpu_num++; env->ext_index =-1 ; + env->facilities[0 ] =FAC0_TCG ; + env->facilities[1 ] =0 ; +if (tcg_enabled () && !inited) { inited = true;s390x_translate_init ();
target-s390x/cpu.h +60 -0
72 lines not on this page · raw message
target-s390x/translate.c +38 -28
112 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v2 2/9 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_FLAGS_2(stfle, TCG_CALL_NO_WG, 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
@@ -465,3 +465,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
@@ -3291,6 +3291,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 v2 3/9 target-s390: Implement SAM31 and SAM64
In reply to Richard Henderson--- target-s390x/insn-data.def | 8 ++++---- target-s390x/translate.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 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 +26 -0
@@ -2912,6 +2912,32 @@ 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 ; + } + s->next_pc &=0x7fffffff ; + +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. */ +return EXIT_PC_STALE ; +} + +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. */ +return EXIT_PC_STALE ; +} +static ExitStatus op_sar (DisasContext *s,DisasOps *o) {int r1 =get_field (s->fields, r1);
Signature · 1 line
1.8.1.4
PATCH v2 4/9 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 v2 5/9 target-s390: Fix STIDP
In reply to Richard HendersonThe implementation had been incomplete, as we did not store the machine type. Note that the machine_type member is still unset during initialization, so this has no effect yet.
--- target-s390x/cpu.h | 4 +++- target-s390x/translate.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
target-s390x/cpu.h +3 -1
@@ -197,7 +197,9 @@ typedef struct CPUS390XState {/* reset does memset(0) up to here */ uint64_t facilities[2 ]; -int cpu_num; +uint32_t cpu_num; +uint32_t machine_type; +uint8_t *storage_keys;uint64_t tod_offset;
target-s390x/translate.c +6 -0
@@ -3238,8 +3238,14 @@ static ExitStatus op_stctl(DisasContext *s, DisasOps *o)static ExitStatus op_stidp (DisasContext *s,DisasOps *o) { +TCGv_i64 t1 =tcg_temp_new_i64 (); +check_privileged (s);tcg_gen_ld32u_i64 (o->out, cpu_env, offsetof(CPUS390XState , cpu_num)); +tcg_gen_ld32u_i64 (t1, cpu_env, offsetof(CPUS390XState , machine_type)); +tcg_gen_deposit_i64 (o->out, o->out, t1,32 ,32 ); +tcg_temp_free_i64 (t1); +return NO_EXIT ; }
Signature · 1 line
1.8.1.4
PATCH v2 6/9 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 v2 7/9 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;
@@ -3339,6 +3357,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 v2 8/9 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
PATCH v2 9/9 target-s390: Force TCG to report Z9-109
In reply to Richard HendersonFedora 19 targets Z9-109 as the minimum supported cpu, and the kernel will exit very early in the boot process if facilities do not match.
This is a hack until we properly implement distinct qom cpu types.
--- target-s390x/cpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
target-s390x/cpu.c +10 -0
@@ -248,6 +248,16 @@ static void s390_cpu_initfn(Object *obj) 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 ; + env->machine_type =0x20940000 ; +#endif +if (tcg_enabled () && !inited) { inited = true;s390x_translate_init ();
Signature · 1 line
1.8.1.4
Quoted 11 lines · Richard Henderson
Changes v1-v2:
* Squashed patches 1, 2, 4. The feedback from patch 1 called for a re-ordering of the patch set to better deal with STFL, but I could not find an ordering that worked well. I think this is probably just as clear as 3 separate patches.* STFL and STIDP implementations adjusted for feedback.
* Minor tweaks to SAM implementations.
* Split out z9-109 hack to a separate patch.
Alex
Quoted 11 lines · Richard Henderson
Changes v1-v2:
* Squashed patches 1, 2, 4. The feedback from patch 1 called for a re-ordering of the patch set to better deal with STFL, but I could not find an ordering that worked well. I think this is probably just as clear as 3 separate patches.* STFL and STIDP implementations adjusted for feedback.
* Minor tweaks to SAM implementations.
* Split out z9-109 hack to a separate patch.
Any movement on the KVM STFLE changes? I'd rebase this set on that if I knew it was going to go in unchanged...
r~