target-mips: correct DERET instruction
PATCH 1/1 target-mips: correct DERET instruction
Fix Debug Mode flag clearing, and when DERET is placed between LL and SC do not make SC fail.
--- target-mips/op_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target-mips/op_helper.c +1 -2
@@ -2154,10 +2154,9 @@ void helper_deret(CPUMIPSState *env)debug_pre_eret (env);set_pc (env, env->CP0_DEPC); - env->hflags &=MIPS_HFLAG_DM ; + env->hflags &= ~MIPS_HFLAG_DM ;compute_hflags (env); debug_post_eret(env); - env->lladdr = 1; }#endif /* !CONFIG_USER_ONLY */
Signature · 1 line
2.1.0
PATCH 1/1 target-mips: fix resource leak reported by Coverity
UHI assert and link operations call lock_user_string() twice to obtain two strings pointed by gpr[4] and gpr[5]. If the second lock_user_string() fails, then the first one won't get freed. Fix this by introducing another macro responsible for obtaining two strings and handling allocation failure.
--- target-mips/mips-semi.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
target-mips/mips-semi.c +19 -4
@@ -220,6 +220,23 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, } \ } while (0) +#define GET_TARGET_STRINGS_2 (p, addr, p2, addr2) \ + do { \ + p = lock_user_string(addr); \ + if (!p) { \ + gpr[2] = -1; \ + gpr[3] = EFAULT; \ + goto uhi_done; \ + } \ + p2 = lock_user_string(addr2); \ + if (!p2) { \ + unlock_user(p, addr, 0); \ + gpr[2] = -1; \ + gpr[3] = EFAULT; \ + goto uhi_done; \ + } \ + } while (0) +#define FREE_TARGET_STRING (p, gpr) \ do { \ unlock_user(p, gpr, 0); \
@@ -322,8 +339,7 @@ void helper_do_semihosting(CPUMIPSState *env)FREE_TARGET_STRING (p, gpr[4 ]);break ;case UHI_assert: -GET_TARGET_STRING (p, gpr[4 ]); -GET_TARGET_STRING (p2, gpr[5 ]); +GET_TARGET_STRINGS_2 (p, gpr[4 ], p2, gpr[5 ]);printf ("assertion '" );printf ("\"%s\"" , p);printf ("': file \"%s\", line %d\n" , p2, (int )gpr[6 ]);
@@ -341,8 +357,7 @@ void helper_do_semihosting(CPUMIPSState *env)break ;#ifndef _WIN32case UHI_link: -GET_TARGET_STRING (p, gpr[4 ]); -GET_TARGET_STRING (p2, gpr[5 ]); +GET_TARGET_STRINGS_2 (p, gpr[4 ], p2, gpr[5 ]); gpr[2 ] =link (p, p2); gpr[3 ] =errno_mips (errno);FREE_TARGET_STRING (p2, gpr[5 ]);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH] target-mips: fix resource leak reported by Coverity
Quoted 50 lines · Leon Alrae
UHI assert and link operations call
lock_user_string()twice to obtain two strings pointed by gpr[4] and gpr[5]. If the secondlock_user_string()fails, then the first one won't get freed. Fix this by introducing another macro responsible for obtaining two strings and handling allocation failure.Signed-off-by Leon Alrae <[email protected]>--- target-mips/mips-semi.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)target-mips/mips-semi.c +18
-2@@ -220,6 +220,23 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, } \ } while (0) +#define GET_TARGET_STRINGS_2 (p, addr, p2, addr2) \ + do { \ + p = lock_user_string(addr); \ + if (!p) { \ + gpr[2] = -1; \ + gpr[3] = EFAULT; \ + goto uhi_done; \ + } \ + p2 = lock_user_string(addr2); \ + if (!p2) { \ + unlock_user(p, addr, 0); \ + gpr[2] = -1; \ + gpr[3] = EFAULT; \ + goto uhi_done; \ + } \ + } while (0) +#define FREE_TARGET_STRING (p, gpr) \ do { \ unlock_user(p, gpr, 0); \@@ -322,8 +339,7 @@ void helper_do_semihosting(CPUMIPSState *env)FREE_TARGET_STRING (p, gpr[4 ]);break ;case UHI_assert: -GET_TARGET_STRING (p, gpr[4 ]); -GET_TARGET_STRING (p2, gpr[5 ]); +GET_TARGET_STRINGS_2 (p, gpr[4 ], p2, gpr[5 ]);printf ("assertion '" );printf ("\"%s\"" , p);printf ("': file \"%s\", line %d\n" , p2, (int )gpr[6 ]);
target-mips/mips-semi.c void helper_do_semihosting(CPUMIPSState *env) · line 363
Quoted 9 lines
target-mips/mips-semi.c +1
-2@@ -341,8 +357,7 @@ void helper_do_semihosting(CPUMIPSState *env)break ;#ifndef _WIN32case UHI_link: -GET_TARGET_STRING (p, gpr[4 ]); -GET_TARGET_STRING (p2, gpr[5 ]); +GET_TARGET_STRINGS_2 (p, gpr[4 ], p2, gpr[5 ]); gpr[2 ] =link (p, p2); gpr[3 ] =errno_mips (errno);FREE_TARGET_STRING (p2, gpr[5 ]);
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
PATCH 1/1 target-mips: fix logically dead code reported by Coverity
In reply to Leon AlraeMake use of CMPOP in floating-point compare instructions.
--- target-mips/translate.c | 3 +++ 1 file changed, 3 insertions(+)
target-mips/translate.c +3 -0
@@ -9552,6 +9552,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_s (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;case OPC_ADD_D :check_cp1_registers (ctx, fs | ft | fd);
@@ -10036,6 +10037,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_d (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;case OPC_CVT_S_D :check_cp1_registers (ctx, fs);
@@ -10461,6 +10463,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_ps (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;default :MIPS_INVAL (opn);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH] target-mips: fix logically dead code reported by Coverity
Quoted 28 lines · Leon Alrae
Make use of CMPOP in floating-point compare instructions.
Signed-off-by Leon Alrae <[email protected]>--- target-mips/translate.c | 3 +++ 1 file changed, 3 insertions(+)target-mips/translate.c +2
-0@@ -9552,6 +9552,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_s (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;case OPC_ADD_D :check_cp1_registers (ctx, fs | ft | fd);@@ -10036,6 +10037,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_d (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;case OPC_CVT_S_D :check_cp1_registers (ctx, fs);
target-mips/translate.c static void gen_farith (DisasContext *ctx, enum fopcode op1, · line 10469
Quoted 7 lines
target-mips/translate.c +1
-0@@ -10461,6 +10463,7 @@ static void gen_farith (DisasContext *ctx, enum fopcode op1,gen_cmp_ps (ctx, func-48 , ft, fs, cc); opn = condnames[func-48 ]; } + optype =CMPOP ;break ;default :MIPS_INVAL (opn);
By the way, is this debug code really useful? I think by looking at the TCG code (-d in_asm,op), it's easy to determine if an instruction is correctly disassembled or not.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH] target-mips: fix logically dead code reported by Coverity
Quoted 4 lines · Aurelien Jarno
By the way, is this debug code really useful? I think by looking at the TCG code (-d in_asm,op), it's easy to determine if an instruction is correctly disassembled or not.
For me this debug code doesn't seem to be useful at all and it only clutters translate.c :) In this patch I just wanted to make Coverity happy so I followed the existing code but generally would vote for removal all of MIPS_DEBUG.
Leon
Re: [Qemu-devel] [PATCH] target-mips: fix logically dead code reported by Coverity
Quoted 9 lines · Leon Alrae
Quoted 4 lines · Aurelien Jarno
By the way, is this debug code really useful? I think by looking at the TCG code (-d in_asm,op), it's easy to determine if an instruction is correctly disassembled or not.
For me this debug code doesn't seem to be useful at all and it only clutters
translate.c:) In this patch I just wanted to make Coverity happy so I followed the existing code but generally would vote for removal all ofMIPS_DEBUG.
Ok, I'll work on a patch for 2.5. That said I think we should still merge the patch for 2.4.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Quoted 13 lines · Leon Alrae
Fix Debug Mode flag clearing, and when DERET is placed between LL and SC do not make SC fail.
Signed-off-by Leon Alrae <[email protected]>--- target-mips/op_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)target-mips/op_helper.c +0
-0
target-mips/op_helper.c void helper_deret(CPUMIPSState *env) · line 2161
Quoted 10 lines
target-mips/op_helper.c +1
-2@@ -2154,10 +2154,9 @@ void helper_deret(CPUMIPSState *env)debug_pre_eret (env);set_pc (env, env->CP0_DEPC); - env->hflags &=MIPS_HFLAG_DM ; + env->hflags &= ~MIPS_HFLAG_DM ;compute_hflags (env); debug_post_eret(env); - env->lladdr = 1; }#endif /* !CONFIG_USER_ONLY */
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net