From 90ff09bc10c5652396fabef39a969713ffc45afb Mon Sep 17 00:00:00 2001 From: fridtjof Date: Fri, 8 May 2026 19:08:49 +0200 Subject: [PATCH] add runtime printing for call/return this makes it easier to follow execution and figure out what's currently running --- target/cr16c/helper.c | 4 ++++ target/cr16c/helper.h | 1 + target/cr16c/translate.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/target/cr16c/helper.c b/target/cr16c/helper.c index 0f43a2ab28..9a558ae947 100644 --- a/target/cr16c/helper.c +++ b/target/cr16c/helper.c @@ -29,3 +29,7 @@ void helper_dump_regs(CPUCR16CState* env) { qemu_printf("State dump requested:\n"); cr16c_debug_dump_state(env_cpu(env)); } + +void helper_print_addr(const void * insn, uint32_t addr) { + qemu_printf("%s to: 0x%x\n", (const char *) insn, addr); +} diff --git a/target/cr16c/helper.h b/target/cr16c/helper.h index a5d74d1ca9..8c7d4da74a 100644 --- a/target/cr16c/helper.h +++ b/target/cr16c/helper.h @@ -2,3 +2,4 @@ DEF_HELPER_1(raise_illegal_instruction, void, env); DEF_HELPER_1(raise_unimplemented_instruction, void, env); DEF_HELPER_1(exit, void, env); DEF_HELPER_1(dump_regs, void, env); +DEF_HELPER_2(print_addr, void, cptr, i32); diff --git a/target/cr16c/translate.c b/target/cr16c/translate.c index 72d75768fb..a46c4c1a71 100644 --- a/target/cr16c/translate.c +++ b/target/cr16c/translate.c @@ -1367,6 +1367,10 @@ static bool trans_JCOND(DisasContext* ctx, arg_JCOND *a) { gen_set_label(l); + if (a->cond == CR16C_COND_ALWAYS && a->ra == CR16C_REGNO_RA) { + gen_helper_print_addr(tcg_constant_ptr("JUMP ra"), r[a->ra]); + } + tcg_gen_mov_i32(pc, r[a->ra]); tcg_gen_lookup_and_goto_ptr(); @@ -1395,6 +1399,8 @@ static bool trans_JAL(DisasContext* ctx, arg_JAL *a) { tcg_gen_extract2_i32(pc, r[a->destrp], r[a->destrp+1], 0); tcg_gen_andi_i32(pc, pc, 0xffffff); tcg_gen_shli_i32(pc, pc, 1); + + gen_helper_print_addr(tcg_constant_ptr("JAL"), pc); tcg_gen_lookup_and_goto_ptr(); // TODO CFG.SR handling @@ -1723,6 +1729,8 @@ static bool trans_BAL_ra(DisasContext *ctx, arg_BAL_ra *a) { // 2) sign extend from 23 -> "25" bits int32_t dest_sextend = sextract32(dest_offset, 0, 23); + gen_helper_print_addr(tcg_constant_ptr("BAL"), tcg_constant_i32(pc_this + dest_sextend)); + ctx->base.is_jmp = DISAS_NORETURN; gen_goto(&ctx->base, pc_this + dest_sextend, 0); @@ -1759,6 +1767,7 @@ static bool trans_pop(DisasContext *ctx, arg_pop *a) { if (a->rt) { // basically, JUMP RA + gen_helper_print_addr(tcg_constant_ptr("POPRET"), r[CR16C_REGNO_RA]); ctx->base.is_jmp = DISAS_NORETURN; tcg_gen_mov_i32(pc, r[CR16C_REGNO_RA]);