From: Michel Pollet Date: Fri, 29 Nov 2013 16:25:52 +0000 (+0000) Subject: avr: Make vector trace work X-Git-Tag: v1.2~50 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b66ed500234bfcac1387742f2e7e07c6ac471db5;p=sx%2Fsimavr.git avr: Make vector trace work Somehow the vector list was erased at avr_reset time, luckily only the trace code in run_avr was using it. Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/run_avr.c b/simavr/sim/run_avr.c index e18f1cd..57fa05e 100644 --- a/simavr/sim/run_avr.c +++ b/simavr/sim/run_avr.c @@ -161,9 +161,11 @@ int main(int argc, char *argv[]) } avr->log = (log > LOG_TRACE ? LOG_TRACE : log); avr->trace = trace; - for (int ti = 0; ti < trace_vectors_count; ti++) - if (avr->interrupts.vector[trace_vectors[ti]]) - avr->interrupts.vector[trace_vectors[ti]]->trace = 1; + for (int ti = 0; ti < trace_vectors_count; ti++) { + for (int vi = 0; vi < avr->interrupts.vector_count; vi++) + if (avr->interrupts.vector[vi]->vector == trace_vectors[ti]) + avr->interrupts.vector[vi]->trace = 1; + } // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index fe53d18..d020a72 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -81,6 +81,7 @@ int avr_init(avr_t * avr) // cpu is in limbo before init is finished. avr->state = cpu_Limbo; avr->frequency = 1000000; // can be overridden via avr_mcu_section + avr_interrupt_init(avr); if (avr->special_init) avr->special_init(avr); if (avr->init) @@ -122,10 +123,10 @@ void avr_reset(avr_t * avr) avr->pc = 0; for (int i = 0; i < 8; i++) avr->sreg[i] = 0; - if (avr->reset) - avr->reset(avr); avr_interrupt_reset(avr); avr_cycle_timer_reset(avr); + if (avr->reset) + avr->reset(avr); avr_io_t * port = avr->io_port; while (port) { if (port->reset) diff --git a/simavr/sim/sim_interrupts.c b/simavr/sim/sim_interrupts.c index a2f3758..7f21b8a 100644 --- a/simavr/sim/sim_interrupts.c +++ b/simavr/sim/sim_interrupts.c @@ -33,13 +33,25 @@ #define INT_FIFO_MOD(_v) ((_v) & (INT_FIFO_SIZE - 1)) void -avr_interrupt_reset( +avr_interrupt_init( avr_t * avr ) { avr_int_table_p table = &avr->interrupts; memset(table, 0, sizeof(*table)); } +void +avr_interrupt_reset( + avr_t * avr ) +{ + printf("%s\n", __func__); + avr_int_table_p table = &avr->interrupts; + table->pending_r = table->pending_w = 0; + table->pending_wait = 0; + for (int i = 0; i < table->vector_count; i++) + table->vector[i]->pending = 0; +} + void avr_register_vector( avr_t *avr, diff --git a/simavr/sim/sim_interrupts.h b/simavr/sim/sim_interrupts.h index 2e86882..f86dfb1 100644 --- a/simavr/sim/sim_interrupts.h +++ b/simavr/sim/sim_interrupts.h @@ -99,6 +99,11 @@ avr_get_interrupt_irq( struct avr_t * avr, uint8_t v); +// Initializes the interrupt table +void +avr_interrupt_init( + struct avr_t * avr ); + // reset the interrupt table and the fifo void avr_interrupt_reset(