Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine rv_step function prototype #380

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,11 @@ static bool runtime_profiler(riscv_t *rv, block_t *block)
typedef void (*exec_block_func_t)(riscv_t *rv, uintptr_t);
#endif

void rv_step(riscv_t *rv, int32_t cycles)
void rv_step(riscv_t *rv)
{
assert(rv);
vm_attr_t *attr = PRIV(rv);
uint32_t cycles = attr->cycle_per_step;

/* find or translate a block for starting PC */
const uint64_t cycles_target = rv->csr_cycle + cycles;
Expand Down
12 changes: 9 additions & 3 deletions src/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ static inline bool rv_is_interrupt(riscv_t *rv)
static gdb_action_t rv_cont(void *args)
{
riscv_t *rv = (riscv_t *) args;
const uint32_t cycles_per_step = 1;
assert(rv);
vm_attr_t *attr = PRIV(rv);
attr->cycle_per_step = 1;

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

rv_step(rv, cycles_per_step);
rv_step(rv);
}

/* Clear the interrupt if it's pending */
Expand All @@ -97,7 +99,11 @@ static gdb_action_t rv_cont(void *args)
static gdb_action_t rv_stepi(void *args)
{
riscv_t *rv = (riscv_t *) args;
rv_step(rv, 1);
assert(rv);
vm_attr_t *attr = PRIV(rv);
attr->cycle_per_step = 1;

rv_step(rv);
return ACT_RESUME;
}

Expand Down
8 changes: 4 additions & 4 deletions src/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ static void rv_run_and_trace(riscv_t *rv)

vm_attr_t *attr = PRIV(rv);
assert(attr && attr->data.user && attr->data.user->elf_program);
attr->cycle_per_step = 1;

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

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

rv_step(rv, cycles_per_step); /* step instructions */
rv_step(rv); /* step instructions */
}

elf_delete(elf);
Expand Down Expand Up @@ -316,8 +316,8 @@ void rv_run(riscv_t *rv)
#endif
else {
/* default main loop */
for (; !rv_has_halted(rv);) /* run until the flag is done */
rv_step(rv, attr->cycle_per_step); /* step instructions */
for (; !rv_has_halted(rv);) /* run until the flag is done */
rv_step(rv); /* step instructions */
}

if (attr->run_flag & RV_RUN_PROFILE) {
Expand Down
2 changes: 1 addition & 1 deletion src/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void rv_debug(riscv_t *rv);
#endif

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

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