m68k: More bug fixes for translation code
Hi Laurent!
As promised, here are the fixes for the two recently discovered bugs in the m68k translation code.
The first patch fixes the opcode mask for the fbcc instruction which is currently incorrect as it masks the 6th bit as constant (0xffc0). However, according to the ColdFire reference manual, this bit is used to determine the size of the displacement for the jump, either 16 or 32 bits:
Quoted 1 line
http://www.nxp.com/files/dsp/doc/ref_manual/CFPRM.pdf (p. 229)
Looking at DISAS_INSN(fbcc), the emulated instruction actually tests for the 6th bit and sets the offset accordingly. However, since the current opcode mask ignores this bit, long jumps can never work. In fact, what we actually see is an illegal instruction: 0xf2e0.
Changing the opcode mask to 0xff80 makes the 6th bit variable and allows long jumps to work as expected.
The second patch addresses a problem with the thread safety of register_m68k_insns(). It turns out, that the opcode table is rebuild for every thread that is started which means that in a multithreaded environment, one thread can destroy the opcode table of a concurrent thread which makes this thread crash with an illegal instruction.
This patch changes register_m68k_insns() such that it returns without doing anything in case the opcode table has already been built and re-registering the instructions is therefore not necessary but rather harmful.
Credits go to Michael Karcher for helping to debug these issues!
Cheers,
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
PATCH 1/2 m68k: Fix opcode mask for fbcc instruction
--- target-m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-m68k/translate.c +1 -1
@@ -2940,7 +2940,7 @@ void register_m68k_insns (CPUM68KState *env)INSN (shift_reg, e0a0, f0f0,CF_ISA_A );INSN (undef_fpu, f000, f000,CF_ISA_A );INSN (fpu, f200, ffc0,CF_FPU ); -INSN (fbcc, f280, ffc0,CF_FPU ); +INSN (fbcc, f280, ff80,CF_FPU );INSN (frestore, f340, ffc0,CF_FPU );INSN (fsave, f340, ffc0,CF_FPU );INSN (intouch, f340, ffc0,CF_ISA_A );
Signature · 1 line
2.7.0
Re: [Qemu-devel] [PATCH 1/2] m68k: Fix opcode mask for fbcc instruction
Quoted 11 lines · John Paul Adrian Glaubitz
Signed-off-by John Paul Adrian Glaubitz <[email protected]>--- target-m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-m68k/translate.c +0
-0
target-m68k/translate.c void register_m68k_insns (CPUM68KState *env) · line 2946
Quoted 8 lines
target-m68k/translate.c +1
-1@@ -2940,7 +2940,7 @@ void register_m68k_insns (CPUM68KState *env)INSN (shift_reg, e0a0, f0f0,CF_ISA_A );INSN (undef_fpu, f000, f000,CF_ISA_A );INSN (fpu, f200, ffc0,CF_FPU ); -INSN (fbcc, f280, ffc0,CF_FPU ); +INSN (fbcc, f280, ff80,CF_FPU );INSN (frestore, f340, ffc0,CF_FPU );INSN (fsave, f340, ffc0,CF_FPU );INSN (intouch, f340, ffc0,CF_ISA_A );
Re: [Qemu-devel] [PATCH 1/2] m68k: Fix opcode mask for fbcc instruction
Quoted 1 line · Laurent Vivier
Reviewed-by Laurent Vivier <[email protected]>
Any chance to get this merged quickly?
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [Qemu-devel] [PATCH 1/2] m68k: Fix opcode mask for fbcc instruction
In reply to John Paul Adrian GlaubitzStrange. There should be a cover letter coming along as well which explains my changes. Did you get it?
Quoted 19 lines · John Paul Adrian Glaubitz
Signed-off-by John Paul Adrian Glaubitz <[email protected]>--- target-m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-m68k/translate.c +1
-1@@ -2940,7 +2940,7 @@ void register_m68k_insns (CPUM68KState *env)INSN (shift_reg, e0a0, f0f0,CF_ISA_A );INSN (undef_fpu, f000, f000,CF_ISA_A );INSN (fpu, f200, ffc0,CF_FPU ); -INSN (fbcc, f280, ffc0,CF_FPU ); +INSN (fbcc, f280, ff80,CF_FPU );INSN (frestore, f340, ffc0,CF_FPU );INSN (fsave, f340, ffc0,CF_FPU );INSN (intouch, f340, ffc0,CF_ISA_A );
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [Qemu-devel] [PATCH 1/2] m68k: Fix opcode mask for fbcc instruction
Quoted 2 lines · John Paul Adrian Glaubitz
Strange. There should be a cover letter coming along as well which explains my changes. Did you get it?
We have the cover letter, but it is never sent to the sender :)
Laurent
Quoted 23 lines · John Paul Adrian Glaubitz
Quoted 19 lines
Signed-off-by John Paul Adrian Glaubitz <[email protected]>--- target-m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-m68k/translate.c +1
-1@@ -2940,7 +2940,7 @@ void register_m68k_insns (CPUM68KState *env)INSN (shift_reg, e0a0, f0f0,CF_ISA_A );INSN (undef_fpu, f000, f000,CF_ISA_A );INSN (fpu, f200, ffc0,CF_FPU ); -INSN (fbcc, f280, ffc0,CF_FPU ); +INSN (fbcc, f280, ff80,CF_FPU );INSN (frestore, f340, ffc0,CF_FPU );INSN (fsave, f340, ffc0,CF_FPU );INSN (intouch, f340, ffc0,CF_ISA_A );
PATCH 2/2 m68k: Build the opcode table only once to avoid multithreading issues
In reply to John Paul Adrian Glaubitz--- target-m68k/translate.c | 4 ++++ 1 file changed, 4 insertions(+)
target-m68k/translate.c +4 -0
@@ -2828,6 +2828,10 @@ register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask)Later insn override earlier ones. */ void register_m68k_insns (CPUM68KState *env) { +/* Build the opcode table only once to avoid +issues with multithreading. */ +if (opcode_table[0 ] !=NULL ) +return ;#define INSN (name, opcode, mask, feature) do { \ if (m68k_feature(env, M68K_FEATURE_##feature)) \ register_opcode(disas_##name, 0x##opcode, 0x##mask); \
Signature · 1 line
2.7.0
Re: [Qemu-devel] [PATCH 2/2] m68k: Build the opcode table only once to avoid multithreading issues
Quoted 11 lines · John Paul Adrian Glaubitz
Signed-off-by John Paul Adrian Glaubitz <[email protected]>--- target-m68k/translate.c | 4 ++++ 1 file changed, 4 insertions(+)target-m68k/translate.c +0
-0
target-m68k/translate.c register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask) · line 2837
Quoted 10 lines
target-m68k/translate.c +4
-0@@ -2828,6 +2828,10 @@ register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask)Later insn override earlier ones. */ void register_m68k_insns (CPUM68KState *env) { +/* Build the opcode table only once to avoid +issues with multithreading. */ +if (opcode_table[0 ] !=NULL ) +return ;#define INSN (name, opcode, mask, feature) do { \ if (m68k_feature(env, M68K_FEATURE_##feature)) \ register_opcode(disas_##name, 0x##opcode, 0x##mask); \
Re: [Qemu-devel] [PATCH 2/2] m68k: Build the opcode table only once to avoid multithreading issues
Quoted 17 lines · Laurent Vivier
Quoted 14 lines · John Paul Adrian Glaubitz
Signed-off-by John Paul Adrian Glaubitz <[email protected]>--- target-m68k/translate.c | 4 ++++ 1 file changed, 4 insertions(+)target-m68k/translate.c +1
-0@@ -2828,6 +2828,10 @@ register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask)Later insn override earlier ones. */ void register_m68k_insns (CPUM68KState *env) { +/* Build the opcode table only once to avoid
Quoted 8 lines
target-m68k/translate.c register_opcode (disas_proc proc, uint16_t opcode, uint16_t mask) · line 2837
Quoted 7 lines
target-m68k/translate.c +3
-0+issues with multithreading. */ +if (opcode_table[0 ] !=NULL ) +return ;#define INSN (name, opcode, mask, feature) do { \ if (m68k_feature(env, M68K_FEATURE_##feature)) \ register_opcode(disas_##name, 0x##opcode, 0x##mask); \Reviewed-by Laurent Vivier <[email protected]>
In fact, the line should be:
+ if (opcode_table[0] != NULL)
+ return;
thanks to scripts/checkpatch.pl.
Laurent
Re: [Qemu-devel] [PATCH 2/2] m68k: Build the opcode table only once to avoid multithreading issues
Quoted 6 lines · Laurent Vivier
In fact, the line should be:
(quoted diff) +2
-0+ if (opcode_table[0] != NULL) + return;thanks to
scripts/checkpatch.pl.
Want me to re-send it?
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [Qemu-devel] [PATCH 2/2] m68k: Build the opcode table only once to avoid multithreading issues
Quoted 10 lines · John Paul Adrian Glaubitz
Quoted 6 lines · Laurent Vivier
In fact, the line should be:
(quoted diff) +2
-0+ if (opcode_table[0] != NULL) + return;thanks to
scripts/checkpatch.pl.Want me to re-send it?
I don't know if the one who will commit this to the tree will want to update this.
BTW, Peter, perhaps it's the time to add me as m68k maintainer ? (so I will manage that :) )
Laurent
Re: [Qemu-devel] [PATCH 2/2] m68k: Build the opcode table only once to avoid multithreading issues
Quoted 2 lines · Laurent Vivier
I don't know if the one who will commit this to the tree will want to update this.
Just sent an updated one, just in case :).
Quoted 2 lines
BTW, Peter, perhaps it's the time to add me as m68k maintainer ? (so I will manage that :) )
Yes, please. I'm all for that! I'm really motivated to get m68k support into best shape. qemu-m68k is fun to hack on!
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913