target/rx: Define exception vector constants
v2 cover target/rx: Define exception vector constants
Since v1: Repost as a series (not buried in thread)
Unify BRK/INT0, replace magic values by exception vector constants.
Philippe Mathieu-Daudé (1):
target/rx: Unify BRK and INT trap handling
Yonggang Luo (1):
target/rx: Define exception vector constants
target/rx/cpu.h | 13 +++++++++++++ target/rx/helper.h | 3 +-- target/rx/helper.c | 21 +++++++++++---------- target/rx/op_helper.c | 17 ++++++----------- target/rx/translate.c | 23 +++++++++++------------ 5 files changed, 42 insertions(+), 35 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/2 target/rx: Unify BRK and INT trap handling
BRK is equivalent to INT #0, so route both instructions through the same trap helper.
--- target/rx/helper.h | 3 +-- target/rx/op_helper.c | 7 +------ target/rx/translate.c | 21 ++++++++++----------- 3 files changed, 12 insertions(+), 19 deletions(-)
target/rx/helper.h +1 -2
@@ -2,8 +2,7 @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) DEF_HELPER_1(raise_access_fault, noreturn, env) DEF_HELPER_1(raise_privilege_violation, noreturn, env) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) +DEF_HELPER_2(trap, noreturn, env, i32) DEF_HELPER_3(fadd, f32, env, f32, f32) DEF_HELPER_3(fsub, f32, env, f32, f32)DEF_HELPER_3 (fmul, f32, env, f32, f32)
target/rx/op_helper.c +1 -6
@@ -455,12 +455,7 @@ G_NORETURN void helper_wait(CPURXState *env)raise_exception (env,EXCP_HLT ,0 ); } -G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) +G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) {raise_exception (env,0x100 + vec,0 ); } - -G_NORETURN void helper_rxbrk(CPURXState *env) -{ -raise_exception (env,0x100 ,0 ); -}
target/rx/translate.c +10 -11
@@ -2170,26 +2170,25 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)return true; } +static bool do_trap (DisasContext *ctx,uint8_t vec) +{ +tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); +gen_helper_trap (tcg_env,tcg_constant_i32 (vec)); + ctx->base.is_jmp =DISAS_NORETURN ; +return true; +} +/* brk */ static bool trans_BRK (DisasContext *ctx,arg_BRK *a) { -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxbrk (tcg_env); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx,0 ); }/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -TCGv_i32 vec; -tcg_debug_assert (a->imm <0x100 ); - vec =tcg_constant_i32 (a->imm); -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxint (tcg_env, vec); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx, a->imm); }/* wait */
Signature · 1 line
2.53.0
Re: [PATCH v2 1/2] target/rx: Unify BRK and INT trap handling
Quoted 10 lines · Philippe Mathieu-Daudé
BRK is equivalent to INT #0, so route both instructions through the same trap helper.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/rx/helper.h | 3 +-- target/rx/op_helper.c | 7 +------ target/rx/translate.c | 21 ++++++++++----------- 3 files changed, 12 insertions(+), 19 deletions(-)
thanks
-- PMM
Re: [PATCH v2 1/2] target/rx: Unify BRK and INT trap handling
In reply to Philippe Mathieu-DaudéQuoted 87 lines · Philippe Mathieu-Daudé
BRK is equivalent to INT #0, so route both instructions through the same trap helper.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/rx/helper.h | 3 +-- target/rx/op_helper.c | 7 +------ target/rx/translate.c | 21 ++++++++++----------- 3 files changed, 12 insertions(+), 19 deletions(-)target/rx/helper.h +1
-2@@ -2,8 +2,7 @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) DEF_HELPER_1(raise_access_fault, noreturn, env) DEF_HELPER_1(raise_privilege_violation, noreturn, env) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) +DEF_HELPER_2(trap, noreturn, env, i32) DEF_HELPER_3(fadd, f32, env, f32, f32) DEF_HELPER_3(fsub, f32, env, f32, f32)DEF_HELPER_3 (fmul, f32, env, f32, f32)target/rx/op_helper.c +1
-6@@ -455,12 +455,7 @@ G_NORETURN void helper_wait(CPURXState *env)raise_exception (env,EXCP_HLT ,0 ); } -G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) +G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) {raise_exception (env,0x100 + vec,0 ); } - -G_NORETURN void helper_rxbrk(CPURXState *env) -{ -raise_exception (env,0x100 ,0 ); -}target/rx/translate.c +10
-11@@ -2170,26 +2170,25 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)return true; } +static bool do_trap (DisasContext *ctx,uint8_t vec) +{ +tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); +gen_helper_trap (tcg_env,tcg_constant_i32 (vec)); + ctx->base.is_jmp =DISAS_NORETURN ; +return true; +} +/* brk */ static bool trans_BRK (DisasContext *ctx,arg_BRK *a) { -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxbrk (tcg_env); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx,0 ); }/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -TCGv_i32 vec; -tcg_debug_assert (a->imm <0x100 ); - vec =tcg_constant_i32 (a->imm); -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxint (tcg_env, vec); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx, a->imm); }/* wait */ Signature · 1 line
2.53.0
Signature · 1 line
Yosinori Sato
PATCH v2 2/2 target/rx: Define exception vector constants
In reply to Philippe Mathieu-DaudéFrom: Yonggang Luo <[email protected]>
Name RX exception vectors and trap ranges, and use the definitions throughout exception handling and exception raising.
Assert that exception indexes remain within the defined range before accessing their vector tables.
--- target/rx/cpu.h | 13 +++++++++++++ target/rx/helper.c | 21 +++++++++++---------- target/rx/op_helper.c | 10 +++++----- target/rx/translate.c | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-)
target/rx/cpu.h +13 -0
@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +#define RX_EXCP_TRAP_COUNT 0x100 + +enum { +RX_EXCP_PRIVILEGE_VIOLATION =20 , +RX_EXCP_ACCESS =21 , +RX_EXCP_ILLEGAL_INSTRUCTION =23 , +RX_EXCP_FPU =25 , +RX_EXCP_NMI =30 , +RX_EXCP_TRAP_BASE =0x100 ,/* Up to RX_EXCP_TRAP_COUNT */ +}; + +#define RX_EXCP_COUNT (RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT) + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */
target/rx/helper.c +11 -10
@@ -86,13 +86,14 @@ void rx_cpu_do_interrupt(CPUState *cs) env->isp -=4 ;cpu_stl_le_data (env, env->isp, env->pc); -if (vec <0x100 ) { - env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); - }else { +assert (vec <RX_EXCP_COUNT ); +if (vec >=RX_EXCP_TRAP_BASE ) { env->pc =cpu_ldl_le_data (env, env->intb + (vec &0xff ) *4 ); + }else { + env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); } -if (vec ==30 ) { +if (vec ==RX_EXCP_NMI ) {/* Non-maskable interrupt */ qemu_plugin_vcpu_interrupt_cb (cs, last_pc); }else {
@@ -100,22 +101,22 @@ void rx_cpu_do_interrupt(CPUState *cs) }switch (vec) { -case 20 : +case RX_EXCP_PRIVILEGE_VIOLATION : expname ="privilege violation" ;break ; -case 21 : +case RX_EXCP_ACCESS : expname ="access exception" ;break ; -case 23 : +case RX_EXCP_ILLEGAL_INSTRUCTION : expname ="illegal instruction" ;break ; -case 25 : +case RX_EXCP_FPU : expname ="fpu exception" ;break ; -case 30 : +case RX_EXCP_NMI : expname ="non-maskable interrupt" ;break ; - case 0x100 ... 0x1ff: + case RX_EXCP_TRAP_BASE ... RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT - 1: expname ="unconditional trap" ; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n",
target/rx/op_helper.c +5 -5
@@ -115,7 +115,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable =FIELD_EX32 (env->fpsw,FPSW ,ENABLE ); enable |=1 <<5 ;/* CE always enabled */ if (cause & enable) { -raise_exception (env,21 , retaddr); +raise_exception (env,RX_EXCP_ACCESS , retaddr); } } }
@@ -432,17 +432,17 @@ void raise_exception(CPURXState *env, int index, G_NORETURN void helper_raise_privilege_violation(CPURXState *env) { -raise_exception (env,20 ,GETPC ()); +raise_exception (env,RX_EXCP_PRIVILEGE_VIOLATION ,GETPC ()); } G_NORETURN void helper_raise_access_fault(CPURXState *env) { -raise_exception (env,21 ,GETPC ()); +raise_exception (env,RX_EXCP_ACCESS ,GETPC ()); } G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) { -raise_exception (env,23 ,GETPC ()); +raise_exception (env,RX_EXCP_ILLEGAL_INSTRUCTION ,GETPC ()); } G_NORETURN void helper_wait(CPURXState *env)
@@ -457,5 +457,5 @@ G_NORETURN void helper_wait(CPURXState *env) G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) { -raise_exception (env,0x100 + vec,0 ); +raise_exception (env,RX_EXCP_TRAP_BASE + vec,0 ); }
target/rx/translate.c +1 -1
@@ -2187,7 +2187,7 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a)/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -tcg_debug_assert (a->imm <0x100 ); +tcg_debug_assert (a->imm <RX_EXCP_TRAP_COUNT );return do_trap (ctx, a->imm); }
Signature · 1 line
2.53.0
Quoted 7 lines · Philippe Mathieu-Daudé
From: Yonggang Luo <[email protected]>
Name RX exception vectors and trap ranges, and use the definitions throughout exception handling and exception raising.
Quoted 6 lines
Assert that exception indexes remain within the defined range before accessing their vector tables.
Signed-off-by Yonggang Luo <[email protected]>Co-developed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
thanks
-- PMM
Quoted 153 lines · Philippe Mathieu-Daudé
From: Yonggang Luo <[email protected]>
Name RX exception vectors and trap ranges, and use the definitions throughout exception handling and exception raising.
Assert that exception indexes remain within the defined range before accessing their vector tables.
Signed-off-by Yonggang Luo <[email protected]>Co-developed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/rx/cpu.h | 13 +++++++++++++ target/rx/helper.c | 21 +++++++++++---------- target/rx/op_helper.c | 10 +++++----- target/rx/translate.c | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-)target/rx/cpu.h +13
-0@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +#define RX_EXCP_TRAP_COUNT 0x100 + +enum { +RX_EXCP_PRIVILEGE_VIOLATION =20 , +RX_EXCP_ACCESS =21 , +RX_EXCP_ILLEGAL_INSTRUCTION =23 , +RX_EXCP_FPU =25 , +RX_EXCP_NMI =30 , +RX_EXCP_TRAP_BASE =0x100 ,/* Up to RX_EXCP_TRAP_COUNT */ +}; + +#define RX_EXCP_COUNT (RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT) + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */target/rx/helper.c +11
-10@@ -86,13 +86,14 @@ void rx_cpu_do_interrupt(CPUState *cs) env->isp -=4 ;cpu_stl_le_data (env, env->isp, env->pc); -if (vec <0x100 ) { - env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); - }else { +assert (vec <RX_EXCP_COUNT ); +if (vec >=RX_EXCP_TRAP_BASE ) { env->pc =cpu_ldl_le_data (env, env->intb + (vec &0xff ) *4 ); + }else { + env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); } -if (vec ==30 ) { +if (vec ==RX_EXCP_NMI ) {/* Non-maskable interrupt */ qemu_plugin_vcpu_interrupt_cb (cs, last_pc); }else {@@ -100,22 +101,22 @@ void rx_cpu_do_interrupt(CPUState *cs) }switch (vec) { -case 20 : +case RX_EXCP_PRIVILEGE_VIOLATION : expname ="privilege violation" ;break ; -case 21 : +case RX_EXCP_ACCESS : expname ="access exception" ;break ; -case 23 : +case RX_EXCP_ILLEGAL_INSTRUCTION : expname ="illegal instruction" ;break ; -case 25 : +case RX_EXCP_FPU : expname ="fpu exception" ;break ; -case 30 : +case RX_EXCP_NMI : expname ="non-maskable interrupt" ;break ; - case 0x100 ... 0x1ff: + case RX_EXCP_TRAP_BASE ... RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT - 1: expname ="unconditional trap" ; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n",target/rx/op_helper.c +5
-5@@ -115,7 +115,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable =FIELD_EX32 (env->fpsw,FPSW ,ENABLE ); enable |=1 <<5 ;/* CE always enabled */ if (cause & enable) { -raise_exception (env,21 , retaddr); +raise_exception (env,RX_EXCP_ACCESS , retaddr); } } }@@ -432,17 +432,17 @@ void raise_exception(CPURXState *env, int index, G_NORETURN void helper_raise_privilege_violation(CPURXState *env) { -raise_exception (env,20 ,GETPC ()); +raise_exception (env,RX_EXCP_PRIVILEGE_VIOLATION ,GETPC ()); } G_NORETURN void helper_raise_access_fault(CPURXState *env) { -raise_exception (env,21 ,GETPC ()); +raise_exception (env,RX_EXCP_ACCESS ,GETPC ()); } G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) { -raise_exception (env,23 ,GETPC ()); +raise_exception (env,RX_EXCP_ILLEGAL_INSTRUCTION ,GETPC ()); } G_NORETURN void helper_wait(CPURXState *env)@@ -457,5 +457,5 @@ G_NORETURN void helper_wait(CPURXState *env) G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) { -raise_exception (env,0x100 + vec,0 ); +raise_exception (env,RX_EXCP_TRAP_BASE + vec,0 ); }target/rx/translate.c +1
-1@@ -2187,7 +2187,7 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a)/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -tcg_debug_assert (a->imm <0x100 ); +tcg_debug_assert (a->imm <RX_EXCP_TRAP_COUNT );return do_trap (ctx, a->imm); }Signature · 1 line
2.53.0
Signature · 1 line
Yosinori Sato