Skip to content

Commit a2a254e

Browse files
committed
Refine rv_step function prototype
After refinement of riscv.[ch] public APIs in commit 820cd9b, cycle_per_step is specified in vm_attr_t, the argument cycles in the function prototype of rv_step is no longer required.
1 parent 2935d30 commit a2a254e

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/emulate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,11 @@ static bool runtime_profiler(riscv_t *rv, block_t *block)
10741074
typedef void (*exec_block_func_t)(riscv_t *rv, uintptr_t);
10751075
#endif
10761076

1077-
void rv_step(riscv_t *rv, int32_t cycles)
1077+
void rv_step(riscv_t *rv)
10781078
{
10791079
assert(rv);
1080+
vm_attr_t *attr = PRIV(rv);
1081+
uint32_t cycles = attr->cycle_per_step;
10801082

10811083
/* find or translate a block for starting PC */
10821084
const uint64_t cycles_target = rv->csr_cycle + cycles;

src/gdbstub.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ static inline bool rv_is_interrupt(riscv_t *rv)
7979
static gdb_action_t rv_cont(void *args)
8080
{
8181
riscv_t *rv = (riscv_t *) args;
82-
const uint32_t cycles_per_step = 1;
82+
assert(rv);
83+
vm_attr_t *attr = PRIV(rv);
84+
attr->cycle_per_step = 1;
8385

8486
for (; !rv_has_halted(rv) && !rv_is_interrupt(rv);) {
8587
if (breakpoint_map_find(rv->breakpoint_map, rv_get_pc(rv)))
8688
break;
8789

88-
rv_step(rv, cycles_per_step);
90+
rv_step(rv);
8991
}
9092

9193
/* Clear the interrupt if it's pending */
@@ -97,7 +99,11 @@ static gdb_action_t rv_cont(void *args)
9799
static gdb_action_t rv_stepi(void *args)
98100
{
99101
riscv_t *rv = (riscv_t *) args;
100-
rv_step(rv, 1);
102+
assert(rv);
103+
vm_attr_t *attr = PRIV(rv);
104+
attr->cycle_per_step = 1;
105+
106+
rv_step(rv);
101107
return ACT_RESUME;
102108
}
103109

src/riscv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,19 @@ static void rv_run_and_trace(riscv_t *rv)
276276

277277
vm_attr_t *attr = PRIV(rv);
278278
assert(attr && attr->data.user && attr->data.user->elf_program);
279+
attr->cycle_per_step = 1;
279280

280281
const char *prog_name = attr->data.user->elf_program;
281282
elf_t *elf = elf_new();
282283
assert(elf && elf_open(elf, prog_name));
283-
const uint32_t cycles_per_step = 1;
284284

285285
for (; !rv_has_halted(rv);) { /* run until the flag is done */
286286
/* trace execution */
287287
uint32_t pc = rv_get_pc(rv);
288288
const char *sym = elf_find_symbol(elf, pc);
289289
printf("%08x %s\n", pc, (sym ? sym : ""));
290290

291-
rv_step(rv, cycles_per_step); /* step instructions */
291+
rv_step(rv); /* step instructions */
292292
}
293293

294294
elf_delete(elf);
@@ -316,8 +316,8 @@ void rv_run(riscv_t *rv)
316316
#endif
317317
else {
318318
/* default main loop */
319-
for (; !rv_has_halted(rv);) /* run until the flag is done */
320-
rv_step(rv, attr->cycle_per_step); /* step instructions */
319+
for (; !rv_has_halted(rv);) /* run until the flag is done */
320+
rv_step(rv); /* step instructions */
321321
}
322322

323323
if (attr->run_flag & RV_RUN_PROFILE) {

src/riscv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void rv_debug(riscv_t *rv);
166166
#endif
167167

168168
/* step the RISC-V emulator */
169-
void rv_step(riscv_t *rv, int32_t cycles);
169+
void rv_step(riscv_t *rv);
170170

171171
/* set the program counter of a RISC-V emulator */
172172
bool rv_set_pc(riscv_t *rv, riscv_word_t pc);

0 commit comments

Comments
 (0)