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

Terminate the simulation on exit() from firmware #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions simavr/sim/sim_avr.c
Expand Up @@ -282,6 +282,16 @@ avr_callback_sleep_gdb(
;
}

static void
gracefully_quit(
avr_t * avr,
const char * reason)
{
if (avr->log)
AVR_LOG(avr, LOG_TRACE, "simavr: %s, quitting gracefully\n", reason);
avr->state = cpu_Done;
}

void
avr_callback_run_gdb(
avr_t * avr)
Expand Down Expand Up @@ -309,13 +319,16 @@ avr_callback_run_gdb(
// until the next timer is due
avr_cycle_count_t sleep = avr_cycle_timer_process(avr);

if (avr->state == cpu_Running && new_pc == avr->pc && avr->flash[new_pc] == 0xff && avr->flash[new_pc+1] == 0xcf && !avr->sreg[S_I]) {
gracefully_quit(avr, "rjmp .-2 with interrupts off");
return;
}

avr->pc = new_pc;

if (avr->state == cpu_Sleeping) {
if (!avr->sreg[S_I]) {
if (avr->log)
AVR_LOG(avr, LOG_TRACE, "simavr: sleeping with interrupts off, quitting gracefully\n");
avr->state = cpu_Done;
gracefully_quit(avr, "sleeping with interrupts off");
return;
}
/*
Expand Down Expand Up @@ -372,13 +385,16 @@ avr_callback_run_raw(
// until the next timer is due
avr_cycle_count_t sleep = avr_cycle_timer_process(avr);

if (avr->state == cpu_Running && new_pc == avr->pc && avr->flash[new_pc] == 0xff && avr->flash[new_pc+1] == 0xcf && !avr->sreg[S_I]) {
gracefully_quit(avr, "rjmp .-2 with interrupts off");
return;
}

avr->pc = new_pc;

if (avr->state == cpu_Sleeping) {
if (!avr->sreg[S_I]) {
if (avr->log)
AVR_LOG(avr, LOG_TRACE, "simavr: sleeping with interrupts off, quitting gracefully\n");
avr->state = cpu_Done;
gracefully_quit(avr, "sleeping with interrupts off");
return;
}
/*
Expand Down