Fixes for target/m68k
v2 cover Fixes for target/m68k
This is a series of fixes for target/m68k found:
- with RISU (bit operation with immediate)
- while debugging package build under chroot
(gen_flush_flags() and CAS address modes)
- while I was working on the softmmu mode
(CAS alignment and SP address modes)
v2:
- Don't align stack access on coldfire.
Laurent Vivier (5):
target-m68k: fix bit operation with immediate value
target-m68k: fix gen_flush_flags()
target-m68k: manage pre-dec et post-inc in CAS
target-m68k: CAS doesn't need aligned access
target-m68k: increment/decrement with SP
target/m68k/translate.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/5 target-m68k: fix bit operation with immediate value
M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.
--- target/m68k/translate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
target/m68k/translate.c +10 -3
@@ -1801,9 +1801,16 @@ DISAS_INSN(bitop_im) op = (insn >>6 ) &3 ; bitnum =read_im16 (env, s); -if (bitnum &0xff00 ) { -disas_undef (env, s, insn); -return ; +if (m68k_feature (s->env,M68K_FEATURE_M68000 )) { +if (bitnum &0xfe00 ) { +disas_undef (env, s, insn); +return ; + } + }else { +if (bitnum &0xff00 ) { +disas_undef (env, s, insn); +return ; + } }SRC_EA (env, src1, opsize,0 , op ? &addr:NULL );
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value
Quoted 2 lines · Laurent Vivier
M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.
I don't see that in the reference manual. Where do you get this from?
r~
Re: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Laurent Vivier
M680x0 bit operations with an immediate value use 9 bits of the 16bit value, while coldfire ones use only 8 bits.
I don't see that in the reference manual. Where do you get this from?
See "BSET Instruction Format:BIT NUMBER STATIC, SPECIFIED AS IMMEDIATE DATA", p. 4.58 of "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", "BIT NUMBER" is bits 0 to 8 of extended word.
See "Test a Bit and Set", p. 4-22 of "ColdFire Family Programmer’s Reference Manual, Rev. 3" (link given by Thomas), "Bit Number" is bits 0 to 7 of extended word.
I've found the problem with RISU.
Thanks,
Laurent
Richard Henderson
Reviewed-byRe: [Qemu-devel] [PATCH v2 1/5] target-m68k: fix bit operation with immediate value
Quoted 3 lines · Laurent Vivier
See "BSET Instruction Format:BIT NUMBER STATIC, SPECIFIED AS IMMEDIATE DATA", p. 4.58 of "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", "BIT NUMBER" is bits 0 to 8 of extended word.
Oops, yep. I misread that.
r~
PATCH v2 2/5 target-m68k: fix gen_flush_flags()
In reply to Laurent Viviergen_flush_flags() is setting unconditionally cc_op_synced to 1 and s->cc_op to CC_OP_FLAGS, whereas env->cc_op can be set to something else by a previous tcg fragment.
We fix that by not setting cc_op_synced to 1 (except for gen_helper_flush_flags() that updates env->cc_op)
FIX: https://github.com/vivier/qemu-m68k/issues/19
--- target/m68k/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/m68k/translate.c +2 -1
@@ -595,18 +595,19 @@ static void gen_flush_flags(DisasContext *s)case CC_OP_DYNAMIC :gen_helper_flush_flags (cpu_env,QREG_CC_OP ); + s->cc_op_synced =1 ;break ;default : t0 =tcg_const_i32 (s->cc_op);gen_helper_flush_flags (cpu_env, t0);tcg_temp_free (t0); + s->cc_op_synced =1 ;break ; }/* Note that flush_flags also assigned to env->cc_op. */ s->cc_op =CC_OP_FLAGS ; - s->cc_op_synced =1 ; }static inline TCGv gen_extend (TCGv val,int opsize,int sign)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 2/5] target-m68k: fix gen_flush_flags()
Quoted 7 lines · Laurent Vivier
gen_flush_flags()is setting unconditionallycc_op_syncedto 1 ands->cc_optoCC_OP_FLAGS, whereasenv->cc_opcan be set to something else by a previous tcg fragment.We fix that by not setting
cc_op_syncedto 1 (except forgen_helper_flush_flags()that updatesenv->cc_op)
Quoted 6 lines
FIX: https://github.com/vivier/qemu-m68k/issues/19
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
r~
PATCH v2 3/5 target-m68k: manage pre-dec et post-inc in CAS
In reply to Laurent VivierIn these cases we must update the address register after the operation.
--- target/m68k/translate.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/m68k/translate.c +9 -0
@@ -1963,6 +1963,15 @@ DISAS_INSN(cas)gen_partset_reg (opsize,DREG (ext,0 ), load);tcg_temp_free (load); + +switch (extract32 (insn,3 ,3 )) { +case 3 :/* Indirect postincrement. */ +tcg_gen_addi_i32 (AREG (insn,0 ), addr,opsize_bytes (opsize)); +break ; +case 4 :/* Indirect predecrememnt. */ +tcg_gen_mov_i32 (AREG (insn,0 ), addr); +break ; + } }DISAS_INSN (cas2w)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 3/5] target-m68k: manage pre-dec et post-inc in CAS
Quoted 7 lines · Laurent Vivier
In these cases we must update the address register after the operation.
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 9 +++++++++ 1 file changed, 9 insertions(+)
r~
PATCH v2 4/5 target-m68k: CAS doesn't need aligned access
In reply to Laurent Vivier--- target/m68k/translate.c | 1 - 1 file changed, 1 deletion(-)
target/m68k/translate.c +0 -1
@@ -1934,7 +1934,6 @@ DISAS_INSN(cas)default :g_assert_not_reached (); } - opc |=MO_ALIGN ; ext =read_im16 (env, s);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 4/5] target-m68k: CAS doesn't need aligned access
Quoted 4 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 1 - 1 file changed, 1 deletion(-)
Huh. Wow. Ok.
r~
PATCH v2 5/5 target-m68k: increment/decrement with SP
In reply to Laurent VivierOn 680x0 family only.
Address Register indirect With postincrement:
When using the stack pointer (A7) with byte size data, the register is incremented by two.
Address Register indirect With predecrement:
When using the stack pointer (A7) with byte size data, the register is decremented by two.
--- target/m68k/translate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
target/m68k/translate.c +12 -2
@@ -725,7 +725,12 @@ static TCGv gen_lea_mode(CPUM68KState *env, DisasContext *s, } reg =get_areg (s, reg0); tmp =tcg_temp_new (); -tcg_gen_subi_i32 (tmp, reg,opsize_bytes (opsize)); +if (reg0 ==7 && opsize ==OS_BYTE && +m68k_feature (s->env,M68K_FEATURE_M68000 )) { +tcg_gen_subi_i32 (tmp, reg,2 ); + }else { +tcg_gen_subi_i32 (tmp, reg,opsize_bytes (opsize)); + }return tmp;case 5 :/* Indirect displacement. */ reg =get_areg (s, reg0);
@@ -801,7 +806,12 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, result =gen_ldst (s, opsize, reg, val, what);if (what ==EA_STORE || !addrp) {TCGv tmp =tcg_temp_new (); -tcg_gen_addi_i32 (tmp, reg,opsize_bytes (opsize)); +if (reg0 ==7 && opsize ==OS_BYTE && +m68k_feature (s->env,M68K_FEATURE_M68000 )) { +tcg_gen_subi_i32 (tmp, reg,2 ); + }else { +tcg_gen_addi_i32 (tmp, reg,opsize_bytes (opsize)); + }delay_set_areg (s, reg0, tmp, true); }return result;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v2 5/5] target-m68k: increment/decrement with SP
Quoted 40 lines · Laurent Vivier
On 680x0 family only.
Address Register indirect With postincrement:
When using the stack pointer (A7) with byte size data, the register is incremented by two.
Address Register indirect With predecrement:
When using the stack pointer (A7) with byte size data, the register is decremented by two.
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)target/m68k/translate.c +6
-1@@ -725,7 +725,12 @@ static TCGv gen_lea_mode(CPUM68KState *env, DisasContext *s, } reg =get_areg (s, reg0); tmp =tcg_temp_new (); -tcg_gen_subi_i32 (tmp, reg,opsize_bytes (opsize)); +if (reg0 ==7 && opsize ==OS_BYTE && +m68k_feature (s->env,M68K_FEATURE_M68000 )) { +tcg_gen_subi_i32 (tmp, reg,2 ); + }else { +tcg_gen_subi_i32 (tmp, reg,opsize_bytes (opsize)); + }return tmp;case 5 :/* Indirect displacement. */ reg =get_areg (s, reg0);@@ -801,7 +806,12 @@ static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, result =gen_ldst (s, opsize, reg, val, what);if (what ==EA_STORE || !addrp) {TCGv tmp =tcg_temp_new ();
target/m68k/translate.c static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, · line 817
Quoted 10 lines
target/m68k/translate.c +6
-1-tcg_gen_addi_i32 (tmp, reg,opsize_bytes (opsize)); +if (reg0 ==7 && opsize ==OS_BYTE && +m68k_feature (s->env,M68K_FEATURE_M68000 )) { +tcg_gen_subi_i32 (tmp, reg,2 ); + }else { +tcg_gen_addi_i32 (tmp, reg,opsize_bytes (opsize)); + }delay_set_areg (s, reg0, tmp, true); }return result;
Re: [Qemu-devel] [PATCH v2 5/5] target-m68k: increment/decrement with SP
In reply to Laurent Viviertarget/m68k/translate.c static TCGv gen_ea_mode(CPUM68KState *env, DisasContext *s, int mode, int reg0, · line 814
Quoted 6 lines · Laurent Vivier
target/m68k/translate.c +6
-0+if (reg0 ==7 && opsize ==OS_BYTE && +m68k_feature (s->env,M68K_FEATURE_M68000 )) { +tcg_gen_subi_i32 (tmp, reg,2 ); + }else { +tcg_gen_addi_i32 (tmp, reg,opsize_bytes (opsize)); + }
post-increment add.
r~