target-arm: add feature flag for ARMv8
PATCH 1/3 target-arm: add feature flag for ARMv8
--- target-arm/cpu.c | 5 ++++- target-arm/cpu.h | 1 + target-arm/translate.c | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)
target-arm/cpu.c +4 -1
@@ -162,6 +162,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)CPUARMState *env = &cpu->env;/* Some features automatically imply others: */ +if (arm_feature (env,ARM_FEATURE_V8 )) { +set_feature (env,ARM_FEATURE_V7 ); + }if (arm_feature (env,ARM_FEATURE_V7 )) {set_feature (env,ARM_FEATURE_VAPA );set_feature (env,ARM_FEATURE_THUMB2 );
@@ -748,7 +751,7 @@ static void pxa270c5_initfn(Object *obj)static void arm_any_initfn (Object *obj) {ARMCPU *cpu =ARM_CPU (obj); -set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_V8 );set_feature (&cpu->env,ARM_FEATURE_VFP4 );set_feature (&cpu->env,ARM_FEATURE_VFP_FP16 );set_feature (&cpu->env,ARM_FEATURE_NEON );
target-arm/cpu.h +1 -0
@@ -392,6 +392,7 @@ enum arm_features {ARM_FEATURE_MPIDR ,/* has cp15 MPIDR */ ARM_FEATURE_PXN ,/* has Privileged Execute Never bit */ ARM_FEATURE_LPAE ,/* has Large Physical Address Extension */ + ARM_FEATURE_V8, };static inline int arm_feature (CPUARMState *env,int feature)
target-arm/translate.c +1 -0
@@ -42,6 +42,7 @@#define ENABLE_ARCH_6K arm_feature(env, ARM_FEATURE_V6K)#define ENABLE_ARCH_6T2 arm_feature(env, ARM_FEATURE_THUMB2)#define ENABLE_ARCH_7 arm_feature(env, ARM_FEATURE_V7) +#define ENABLE_ARCH_8 arm_feature(env, ARM_FEATURE_V8)#define ARCH (x) do { if (!ENABLE_ARCH_##x) goto illegal_op; } while(0)
Signature · 1 line
1.8.2.1
PATCH 2/3 target-arm: implement LDA/STL instructions
This adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
--- target-arm/translate.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 6 deletions(-)
target-arm/translate.c +85 -6
@@ -7274,14 +7274,54 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) rd = (insn >>12 ) &0xf ;if (insn & (1 <<23 )) {/* load/store exclusive */ +int excl = (insn >>9 ) &1 ; op1 = (insn >>21 ) &0x3 ; -if (op1) +if (!excl) +ARCH (8 ); +else if (op1) ARCH(6K);else ARCH (6 ); addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if (!excl) { +if (op1 ==1 ) + goto illegal_op; + tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op1) { +case 0 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 3 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rd, tmp); + }else { + rm = insn &0xf ; + tmp =load_reg (s, rm); +switch (op1) { +case 0 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 3 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {switch (op1) {case 0 :/* ldrex */ gen_load_exclusive (s, rd,15 , addr,2 );
@@ -8126,7 +8166,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwgen_store_exclusive (s, rd, rs,15 , addr,2 ); }tcg_temp_free_i32 (addr); - }else if ((insn & (1 <<6 )) ==0 ) { + }else if ((insn & (3 <<6 )) ==0 ) {/* Table Branch. */ if (rn ==15 ) { addr =tcg_temp_new_i32 ();
@@ -8153,14 +8193,53 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwstore_reg (s,15 , tmp); }else {/* Load/store exclusive byte/halfword/doubleword. */ -ARCH (7 ); +if (((insn >>6 ) &3 ) !=1 ) +ARCH (8 ); +else +ARCH (7 ); op = (insn >>4 ) &0x3 ; -if (op ==2 ) { +if (((insn >>7 ) &1 ) ==0 && op ==2 ) { goto illegal_op; } addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if ((insn & (1 <<6 )) ==0 ) { +if (op ==3 ) + goto illegal_op; + tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op) { +case 0 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 1 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rs, tmp); + }else { + tmp =load_reg (s, rs); +switch (op) { +case 0 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 1 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {gen_load_exclusive (s, rs, rd, addr, op); }else {gen_store_exclusive (s, rm, rs, rd, addr, op);
Signature · 1 line
1.8.2.1
PATCH 3/3 target-arm: explicitly decode SEVL instruction
In reply to Mans RullgardThe ARMv8 SEVL instruction is in the architectural hint space already emulated as nop. This makes the decoding of SEVL explicit for clarity.
--- target-arm/translate.c | 1 + 1 file changed, 1 insertion(+)
target-arm/translate.c +1 -0
@@ -3501,6 +3501,7 @@ static void gen_nop_hint(DisasContext *s, int val)break ;case 2 :/* wfe */ case 4 :/* sev */ +case 5 :/* sevl */ /* TODO: Implement SEV and WFE. May help SMP performance. */ default :/* nop */ break ;
Signature · 1 line
1.8.2.1
Quoted 12 lines · Mans Rullgard
Signed-off-by Mans Rullgard <[email protected]>--- target-arm/cpu.c | 5 ++++- target-arm/cpu.h | 1 + target-arm/translate.c | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)target-arm/cpu.c +0
-0
target-arm/cpu.c static void arm_cpu_realizefn(DeviceState *dev, Error **errp) · line 167
Quoted 6 lines
target-arm/cpu.c +3
-0@@ -162,6 +162,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)CPUARMState *env = &cpu->env;/* Some features automatically imply others: */ +if (arm_feature (env,ARM_FEATURE_V8 )) { +set_feature (env,ARM_FEATURE_V7 ); + }
This should also imply ARM_FEATURE_ARM_DIV and ARM_FEATURE_LPAE.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 3/3] target-arm: explicitly decode SEVL instruction
In reply to Mans RullgardQuoted 4 lines · Mans Rullgard
The ARMv8 SEVL instruction is in the architectural hint space already emulated as nop. This makes the decoding of SEVL explicit for clarity.
Signed-off-by Mans Rullgard <[email protected]>
-- PMM
Re: [Qemu-devel] [PATCH 3/3] target-arm: explicitly decode SEVL instruction
In reply to Mans RullgardAm 07.06.2013 14:06, schrieb Mans Rullgard:
Quoted 13 lines
The ARMv8 SEVL instruction is in the architectural hint space already emulated as nop. This makes the decoding of SEVL explicit for clarity.
Signed-off-by Mans Rullgard <[email protected]>--- target-arm/translate.c | 1 + 1 file changed, 1 insertion(+)target-arm/translate.c +0
-0
target-arm/translate.c static void gen_nop_hint(DisasContext *s, int val) · line 3507
Quoted 7 lines
target-arm/translate.c +1
-0@@ -3501,6 +3501,7 @@ static void gen_nop_hint(DisasContext *s, int val)break ;case 2 :/* wfe */ case 4 :/* sev */ +case 5 :/* sevl */ /* TODO: Implement SEV and WFE. May help SMP performance. */ default :/* nop */ break ;
So does SEVL need to be implemented? Then the TODO should be updated. Otherwise moving it a line down may be clearer.
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH v2 1/1 target-arm: add feature flag for ARMv8
In reply to Peter Maydell---
Make V8 imply ARM_DIV and LPAE.
--- target-arm/cpu.c | 7 ++++++- target-arm/cpu.h | 1 + target-arm/translate.c | 1 + 3 files changed, 8 insertions(+), 1 deletion(-)
target-arm/cpu.c +6 -1
@@ -162,6 +162,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)CPUARMState *env = &cpu->env;/* Some features automatically imply others: */ +if (arm_feature (env,ARM_FEATURE_V8 )) { +set_feature (env,ARM_FEATURE_V7 ); +set_feature (env,ARM_FEATURE_ARM_DIV ); +set_feature (env,ARM_FEATURE_LPAE ); + }if (arm_feature (env,ARM_FEATURE_V7 )) {set_feature (env,ARM_FEATURE_VAPA );set_feature (env,ARM_FEATURE_THUMB2 );
@@ -748,7 +753,7 @@ static void pxa270c5_initfn(Object *obj)static void arm_any_initfn (Object *obj) {ARMCPU *cpu =ARM_CPU (obj); -set_feature (&cpu->env,ARM_FEATURE_V7 ); +set_feature (&cpu->env,ARM_FEATURE_V8 );set_feature (&cpu->env,ARM_FEATURE_VFP4 );set_feature (&cpu->env,ARM_FEATURE_VFP_FP16 );set_feature (&cpu->env,ARM_FEATURE_NEON );
target-arm/cpu.h +1 -0
@@ -392,6 +392,7 @@ enum arm_features {ARM_FEATURE_MPIDR ,/* has cp15 MPIDR */ ARM_FEATURE_PXN ,/* has Privileged Execute Never bit */ ARM_FEATURE_LPAE ,/* has Large Physical Address Extension */ + ARM_FEATURE_V8, };static inline int arm_feature (CPUARMState *env,int feature)
target-arm/translate.c +1 -0
@@ -42,6 +42,7 @@#define ENABLE_ARCH_6K arm_feature(env, ARM_FEATURE_V6K)#define ENABLE_ARCH_6T2 arm_feature(env, ARM_FEATURE_THUMB2)#define ENABLE_ARCH_7 arm_feature(env, ARM_FEATURE_V7) +#define ENABLE_ARCH_8 arm_feature(env, ARM_FEATURE_V8)#define ARCH (x) do { if (!ENABLE_ARCH_##x) goto illegal_op; } while(0)
Signature · 1 line
1.8.2.1
Re: [Qemu-devel] [PATCH 3/3] target-arm: explicitly decode SEVL instruction
In reply to Andreas FärberQuoted 9 lines · Andreas Färber
Am 07.06.2013 14:06, schrieb Mans Rullgard:
Quoted 8 lines
The ARMv8 SEVL instruction is in the architectural hint space already emulated as nop. This makes the decoding of SEVL explicit for clarity.
Signed-off-by Mans Rullgard <[email protected]>--- target-arm/translate.c | 1 + 1 file changed, 1 insertion(+)
Quoted 15 lines
target-arm/translate.c static void gen_nop_hint(DisasContext *s, int val) · line 3507
Quoted 12 lines
target-arm/translate.c +1
-0@@ -3501,6 +3501,7 @@ static void gen_nop_hint(DisasContext *s, int val)break ;case 2 :/* wfe */ case 4 :/* sev */ +case 5 :/* sevl */ /* TODO: Implement SEV and WFE. May help SMP performance. */ default :/* nop */ break ;So does SEVL need to be implemented? Then the TODO should be updated. Otherwise moving it a line down may be clearer.
It needs to be implemented when/if SEV and WFE are.
Signature · 2 lines
Måns Rullgård [email protected]
Re: [Qemu-devel] [PATCH 2/3] target-arm: implement LDA/STL instructions
In reply to Mans RullgardQuoted 3 lines · Mans Rullgard
This adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
A brief comment to this effect in the appropriate parts of the code as well as the commit message would be good.
Quoted 13 lines
Signed-off-by Mans Rullgard <[email protected]>--- target-arm/translate.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 6 deletions(-)target-arm/translate.c +0
-0@@ -7274,14 +7274,54 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) rd = (insn >>12 ) &0xf ;if (insn & (1 <<23 )) {
target-arm/translate.c static void disas_arm_insn(CPUARMState * env, DisasContext *s) · line 7284
Quoted 10 lines
target-arm/translate.c +4
-1/* load/store exclusive */ +int excl = (insn >>9 ) &1 ; op1 = (insn >>21 ) &0x3 ; -if (op1) +if (!excl) +ARCH (8 ); +else if (op1) ARCH(6K);else ARCH (6 );
This if statement needs braces on all its arms. (QEMU coding style mandates braces, though some existing code is not in line with this; our general policy is that where patches touch such existing code they update it accordingly.)
You can use scripts/checkpatch.pl to check for this.
This is also continuing to underdecode this space: some of the new exclusive insns are ARCH(8) only but will be allowed on ARCH(6) or 6K by this check. I know we've historically underdecoded, but if we're touching this bit of the decoder I'd prefer it if we tightened it up in the process.
target-arm/translate.c static void disas_arm_insn(CPUARMState * env, DisasContext *s) · line 7289
Quoted 6 lines
target-arm/translate.c +3
-1addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if (!excl) { +if (op1 ==1 ) + goto illegal_op;
This check needs to happen earlier to avoid leaking a tcg temp.
Quoted 39 lines
target-arm/translate.c +35
-0+ tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op1) { +case 0 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 3 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rd, tmp); + }else { + rm = insn &0xf ; + tmp =load_reg (s, rm); +switch (op1) { +case 0 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 3 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {switch (op1) {case 0 :/* ldrex */ gen_load_exclusive (s, rd,15 , addr,2 );
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8169
Quoted 5 lines
target-arm/translate.c +1
-1@@ -8126,7 +8166,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwgen_store_exclusive (s, rd, rs,15 , addr,2 ); }tcg_temp_free_i32 (addr); - }else if ((insn & (1 <<6 )) ==0 ) { + }else if ((insn & (3 <<6 )) ==0 ) {
While we're fiddling with the decode here let's actually narrow it down completely, by making this condition
((insn & (7 << 5)) == 0)
...
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8199
Quoted 12 lines
target-arm/translate.c +4
-1/* Table Branch. */ if (rn ==15 ) { addr =tcg_temp_new_i32 ();@@ -8153,14 +8193,53 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwstore_reg (s,15 , tmp); }else {/* Load/store exclusive byte/halfword/doubleword. */ -ARCH (7 ); +if (((insn >>6 ) &3 ) !=1 ) +ARCH (8 ); +else +ARCH (7 );
...and then here do something like:
switch ((insn >> 6) & 3) {
case 0:
goto illegal_op;
case 1:
/* Load/store exclusive byte/halfword/doubleword */
ARCH(7);
break;
case 2:
case 3:
/* Load-acquire/store-release */
ARCH(8);
break;
}target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8203
Quoted 5 lines
target-arm/translate.c +1
-1op = (insn >>4 ) &0x3 ; -if (op ==2 ) { +if (((insn >>7 ) &1 ) ==0 && op ==2 ) { goto illegal_op; }
It might be better to just pull out the op3 field and then do tests on it rather than combinations of testing op (op3's lower 2 bits) and bits directly from insn.
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8208
Quoted 6 lines
target-arm/translate.c +3
-1addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if ((insn & (1 <<6 )) ==0 ) { +if (op ==3 ) + goto illegal_op;
This check needs to go earlier, otherwise we leak a tcg temp if we take the illegal_op path. You might be able to roll all the illegal-op checks and ARCH checks into a single switch on the whole op3 field.
Quoted 27 lines
target-arm/translate.c +27
-0+ tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op) { +case 0 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 1 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rs, tmp); + }else { + tmp =load_reg (s, rs); +switch (op) { +case 0 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 1 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s));
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8245
Quoted 10 lines
target-arm/translate.c +7
-0+break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {gen_load_exclusive (s, rs, rd, addr, op); }else {gen_store_exclusive (s, rm, rs, rd, addr, op);
Have you tested these with risu yet?
thanks
-- PMM
Quoted 3 lines · Mans Rullgard
Signed-off-by Mans Rullgard <[email protected]>---
Make V8 implyARM_DIVand LPAE.
-- PMM
PATCH v2 1/1 target-arm: implement LDA/STL instructions
In reply to Peter MaydellThis adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
---
Not thoroughly tested.
--- target-arm/translate.c | 126 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 10 deletions(-)
target-arm/translate.c +116 -10
@@ -7274,14 +7274,72 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) rd = (insn >>12 ) &0xf ;if (insn & (1 <<23 )) {/* load/store exclusive */ +int op2 = (insn >>8 ) &3 ; op1 = (insn >>21 ) &0x3 ; -if (op1) - ARCH(6K); -else -ARCH (6 ); + +switch (op2) { +case 0 :/* lda/stl */ +if (op1 ==1 ) { + goto illegal_op; + } +ARCH (8 ); +break ; +case 1 :/* reserved */ + goto illegal_op; +case 2 :/* ldaex/stlex */ +ARCH (8 ); +break ; +case 3 :/* ldrex/strex */ +if (op1) { + ARCH(6K); + }else { +ARCH (6 ); + } +break ; + } + addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { + +/* Since the emulation does not have barriers, +the acquire/release semantics need no special +handling */ +if (op2 ==0 ) { + tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op1) { +case 0 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 3 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rd, tmp); + }else { + rm = insn &0xf ; + tmp =load_reg (s, rm); +switch (op1) { +case 0 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 3 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {switch (op1) {case 0 :/* ldrex */ gen_load_exclusive (s, rd,15 , addr,2 );
@@ -8126,7 +8184,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwgen_store_exclusive (s, rd, rs,15 , addr,2 ); }tcg_temp_free_i32 (addr); - }else if ((insn & (1 <<6 )) ==0 ) { + }else if ((insn & (7 <<5 )) ==0 ) {/* Table Branch. */ if (rn ==15 ) { addr =tcg_temp_new_i32 ();
@@ -8152,15 +8210,63 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwtcg_gen_addi_i32 (tmp, tmp, s->pc);store_reg (s,15 , tmp); }else { -/* Load/store exclusive byte/halfword/doubleword. */ -ARCH (7 ); +int op2 = (insn >>6 ) &0x3 ; op = (insn >>4 ) &0x3 ; -if (op ==2 ) { +switch (op2) { +case 0 : goto illegal_op; +case 1 : +/* Load/store exclusive byte/halfword/doubleword */ +ARCH (7 ); +break ; +case 2 : +/* Load-acquire/store-release */ +if (op ==3 ) { + goto illegal_op; + } +/* Fall through */ +case 3 : +/* Load-acquire/store-release exclusive */ +ARCH (8 ); +break ; } addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if (!(op2 &1 )) { + tmp =tcg_temp_new_i32 (); +if (insn & (1 <<20 )) { +switch (op) { +case 0 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 1 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rs, tmp); + }else { + tmp =load_reg (s, rs); +switch (op) { +case 0 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 1 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {gen_load_exclusive (s, rs, rd, addr, op); }else {gen_store_exclusive (s, rm, rs, rd, addr, op);
Signature · 1 line
1.8.2.1
Re: [Qemu-devel] [PATCH v2] target-arm: implement LDA/STL instructions
Quoted 3 lines · Mans Rullgard
This adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
Couple more minor issues, otherwise looks good.
target-arm/translate.c static void disas_arm_insn(CPUARMState * env, DisasContext *s) · line 7308
Quoted 9 lines
addr = tcg_temp_local_new_i32(); load_reg_var(s, addr, rn);target-arm/translate.c +6
-1-if (insn & (1 <<20 )) { + +/* Since the emulation does not have barriers, +the acquire/release semantics need no special +handling */ +if (op2 ==0 ) { + tmp =tcg_temp_new_i32 ();
This line needs to go inside the next if(), otherwise we leak a temp in the stl/stlb/stlh case. (load_reg() does a temp_new for you, so you need to pair temp_new/store_reg and load_reg/temp_free.)
Quoted 55 lines
target-arm/translate.c +42
-3+if (insn & (1 <<20 )) { +switch (op1) { +case 0 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 3 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rd, tmp); + }else { + rm = insn &0xf ; + tmp =load_reg (s, rm); +switch (op1) { +case 0 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 3 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {switch (op1) {case 0 :/* ldrex */ gen_load_exclusive (s, rd,15 , addr,2 );@@ -8152,15 +8210,63 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwtcg_gen_addi_i32 (tmp, tmp, s->pc);store_reg (s,15 , tmp); }else { -/* Load/store exclusive byte/halfword/doubleword. */ -ARCH (7 ); +int op2 = (insn >>6 ) &0x3 ; op = (insn >>4 ) &0x3 ; -if (op ==2 ) { +switch (op2) { +case 0 : goto illegal_op; +case 1 : +/* Load/store exclusive byte/halfword/doubleword */ +ARCH (7 ); +break ; +case 2 :
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8232
Quoted 10 lines
target-arm/translate.c +9
-0+/* Load-acquire/store-release */ +if (op ==3 ) { + goto illegal_op; + } +/* Fall through */ +case 3 : +/* Load-acquire/store-release exclusive */ +ARCH (8 ); +break ; }
This change has lost the check for op==2 being illegal in the load/store exclusive case (ie case op2==1).
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8236
Quoted 5 lines
target-arm/translate.c +2
-1addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if (!(op2 &1 )) { + tmp =tcg_temp_new_i32 ();
This needs to be inside the following if(), otherwise we leak a temp in the stlb/stlh/stl case.
Quoted 26 lines
target-arm/translate.c +26
-0+if (insn & (1 <<20 )) { +switch (op) { +case 0 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 1 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rs, tmp); + }else { + tmp =load_reg (s, rs); +switch (op) { +case 0 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 1 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s));
target-arm/translate.c static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw · line 8272
Quoted 10 lines
target-arm/translate.c +7
-0+break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {gen_load_exclusive (s, rs, rd, addr, op); }else {gen_store_exclusive (s, rm, rs, rd, addr, op);
thanks
-- PMM
PATCH v3 1/1 target-arm: implement LDA/STL instructions
This adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
---
Fixed issues found in v2.
Could use more testing.
--- target-arm/translate.c | 129 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 10 deletions(-)
target-arm/translate.c +119 -10
@@ -7274,14 +7274,72 @@ static void disas_arm_insn(CPUARMState * env, DisasContext *s) rd = (insn >>12 ) &0xf ;if (insn & (1 <<23 )) {/* load/store exclusive */ +int op2 = (insn >>8 ) &3 ; op1 = (insn >>21 ) &0x3 ; -if (op1) - ARCH(6K); -else -ARCH (6 ); + +switch (op2) { +case 0 :/* lda/stl */ +if (op1 ==1 ) { + goto illegal_op; + } +ARCH (8 ); +break ; +case 1 :/* reserved */ + goto illegal_op; +case 2 :/* ldaex/stlex */ +ARCH (8 ); +break ; +case 3 :/* ldrex/strex */ +if (op1) { + ARCH(6K); + }else { +ARCH (6 ); + } +break ; + } + addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { + +/* Since the emulation does not have barriers, +the acquire/release semantics need no special +handling */ +if (op2 ==0 ) { +if (insn & (1 <<20 )) { + tmp =tcg_temp_new_i32 (); +switch (op1) { +case 0 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 3 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rd, tmp); + }else { + rm = insn &0xf ; + tmp =load_reg (s, rm); +switch (op1) { +case 0 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 3 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {switch (op1) {case 0 :/* ldrex */ gen_load_exclusive (s, rd,15 , addr,2 );
@@ -8126,7 +8184,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwgen_store_exclusive (s, rd, rs,15 , addr,2 ); }tcg_temp_free_i32 (addr); - }else if ((insn & (1 <<6 )) ==0 ) { + }else if ((insn & (7 <<5 )) ==0 ) {/* Table Branch. */ if (rn ==15 ) { addr =tcg_temp_new_i32 ();
@@ -8152,15 +8210,66 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hwtcg_gen_addi_i32 (tmp, tmp, s->pc);store_reg (s,15 , tmp); }else { -/* Load/store exclusive byte/halfword/doubleword. */ -ARCH (7 ); +int op2 = (insn >>6 ) &0x3 ; op = (insn >>4 ) &0x3 ; -if (op ==2 ) { +switch (op2) { +case 0 : goto illegal_op; +case 1 : +/* Load/store exclusive byte/halfword/doubleword */ +if (op ==2 ) { + goto illegal_op; + } +ARCH (7 ); +break ; +case 2 : +/* Load-acquire/store-release */ +if (op ==3 ) { + goto illegal_op; + } +/* Fall through */ +case 3 : +/* Load-acquire/store-release exclusive */ +ARCH (8 ); +break ; } addr =tcg_temp_local_new_i32 ();load_reg_var (s, addr, rn); -if (insn & (1 <<20 )) { +if (!(op2 &1 )) { +if (insn & (1 <<20 )) { + tmp =tcg_temp_new_i32 (); +switch (op) { +case 0 :/* ldab */ +tcg_gen_qemu_ld8u (tmp, addr,IS_USER (s)); +break ; +case 1 :/* ldah */ +tcg_gen_qemu_ld16u (tmp, addr,IS_USER (s)); +break ; +case 2 :/* lda */ +tcg_gen_qemu_ld32u (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +store_reg (s, rs, tmp); + }else { + tmp =load_reg (s, rs); +switch (op) { +case 0 :/* stlb */ +tcg_gen_qemu_st8 (tmp, addr,IS_USER (s)); +break ; +case 1 :/* stlh */ +tcg_gen_qemu_st16 (tmp, addr,IS_USER (s)); +break ; +case 2 :/* stl */ +tcg_gen_qemu_st32 (tmp, addr,IS_USER (s)); +break ; +default : +abort (); + } +tcg_temp_free_i32 (tmp); + } + }else if (insn & (1 <<20 )) {gen_load_exclusive (s, rs, rd, addr, op); }else {gen_store_exclusive (s, rm, rs, rd, addr, op);
Signature · 1 line
1.8.2.1
Re: [Qemu-devel] [PATCH 3/3] target-arm: explicitly decode SEVL instruction
In reply to Andreas FärberQuoted 10 lines · Andreas Färber
Am 07.06.2013 14:06, schrieb Mans Rullgard:
Quoted 6 lines
case 2: /* wfe */ case 4: /* sev */ + case 5: /* sevl */ /* TODO: Implement SEV and WFE. May help SMP performance. */ default: /* nop */ break;So does SEVL need to be implemented? Then the TODO should be updated. Otherwise moving it a line down may be clearer.
I updated the comment to mention SEVL as part of taking this patch into target-arm.next.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v3] target-arm: implement LDA/STL instructions
In reply to Mans RullgardQuoted 5 lines · Mans Rullgard
This adds support for the ARMv8 load acquire/store release instructions. Since qemu does nothing special for memory barriers, these can be emulated like their non-acquire/release counterparts.
Signed-off-by Mans Rullgard <[email protected]>
Thanks; applied to target-arm.next (together with the other 2 patches in the series.)
-- PMM