Linux and We use the code of conditional trap instructions to emit signals other than simple SIGTRAP. Currently, code 6 (overflow), 7 (div by zero) are supported. It means that if code 7 is used with a conditional trap instruction, a SIGFPE instead of SIGTRAP will emit.
But when `gen_trap` we didn't pass the code as we use `generate_exception`, which has no info about the code. Let's introduce a new function `generate_exception_code` for it. --- target/mips/tcg/translate.c | 8 +++++++- target/mips/tcg/translate.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 333469b268..e680a1c2f2 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -1353,6 +1353,12 @@ void generate_exception(DisasContext *ctx, int excp) gen_helper_raise_exception(tcg_env, tcg_constant_i32(excp)); } +void generate_exception_with_code(DisasContext *ctx, int excp, int code) +{ + gen_helper_raise_exception_err(tcg_env, tcg_constant_i32(excp), + tcg_constant_i32(code)); +} + void generate_exception_end(DisasContext *ctx, int excp) { generate_exception_err(ctx, excp, 0); @@ -4553,7 +4559,7 @@ static void gen_trap(DisasContext *ctx, uint32_t opc, if (ctx->hflags != ctx->saved_hflags) { tcg_gen_movi_i32(hflags, ctx->hflags); } - generate_exception(ctx, EXCP_TRAP); + generate_exception_with_code(ctx, EXCP_TRAP, code); gen_set_label(l1); } } diff --git a/target/mips/tcg/translate.h b/target/mips/tcg/translate.h index 2b6646b339..e3d544b478 100644 --- a/target/mips/tcg/translate.h +++ b/target/mips/tcg/translate.h @@ -134,6 +134,7 @@ enum { } while (0) void generate_exception(DisasContext *ctx, int excp); +void generate_exception_with_code(DisasContext *ctx, int excp, int code); void generate_exception_err(DisasContext *ctx, int excp, int err); void generate_exception_end(DisasContext *ctx, int excp); void generate_exception_break(DisasContext *ctx, int code); -- 2.39.3 (Apple Git-146)