Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 2b7899d

Browse files
committed
riscv_debug: Step over ebreak instructions
1 parent 4898a32 commit 2b7899d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/target/riscv_debug.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,19 @@ static void riscv_halt_resume(target_s *target, const bool step)
11321132
}
11331133
if (!riscv_csr_write(hart, RV_DCSR | RV_CSR_FORCE_32_BIT, &stepping_config))
11341134
return;
1135+
/* Step over coded breakpoints */
1136+
uint32_t dcsr_cause = 0U;
1137+
riscv_csr_read(hart, RV_DCSR, &dcsr_cause);
1138+
dcsr_cause &= RV_DCSR_CAUSE_MASK;
1139+
if (dcsr_cause == RV_HALT_CAUSE_EBREAK) {
1140+
/* Read the instruction to resume on */
1141+
uint32_t program_counter = riscv_pc_read(hart);
1142+
/* If it actually is a breakpoint instruction, update the program counter one past it. */
1143+
if (target_mem32_read32(target, program_counter) == RV_EBREAK) {
1144+
program_counter += 4U;
1145+
riscv_csr_write(hart, RV_DPC, &program_counter);
1146+
}
1147+
}
11351148
/* Request the hart to resume */
11361149
if (!riscv_dm_write(hart->dbg_module, RV_DM_CONTROL, hart->hartsel | RV_DM_CTRL_RESUME_REQ))
11371150
return;

0 commit comments

Comments
 (0)