From: ga Date: Fri, 2 Apr 2021 17:19:02 +0000 (+0100) Subject: Fix run-avr's --output and --add-trace options (upstream issue #400). X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=76666724ab05f8b0a1d2dbac9aa11b571810503c;p=sx%2Fsimavr.git Fix run-avr's --output and --add-trace options (upstream issue #400). Remove call to memset() in sim_elf.c that destroyed initialisations and initialise the firmware structure everywhere. Add comments to say initialisation is required. --- diff --git a/examples/board_ds1338/ds1338demo.c b/examples/board_ds1338/ds1338demo.c index 565d02f..266fd7e 100644 --- a/examples/board_ds1338/ds1338demo.c +++ b/examples/board_ds1338/ds1338demo.c @@ -35,7 +35,7 @@ ds1338_virt_t ds1338_virt; int main(int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}}; const char * fname = "atmega32_ds1338.axf"; printf("Firmware pathname is %s\n", fname); diff --git a/examples/board_hd44780/charlcd.c b/examples/board_hd44780/charlcd.c index 100cd34..4b69964 100644 --- a/examples/board_hd44780/charlcd.c +++ b/examples/board_hd44780/charlcd.c @@ -145,7 +145,7 @@ main( int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}}; const char * fname = "atmega48_charlcd.axf"; // char path[256]; // sprintf(path, "%s/%s", dirname(argv[0]), fname); diff --git a/examples/board_i2ctest/i2ctest.c b/examples/board_i2ctest/i2ctest.c index a8ccca9..233d86e 100644 --- a/examples/board_i2ctest/i2ctest.c +++ b/examples/board_i2ctest/i2ctest.c @@ -38,7 +38,7 @@ i2c_eeprom_t ee; int main(int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}}; const char * fname = "atmega1280_i2ctest.axf"; printf("Firmware pathname is %s\n", fname); diff --git a/examples/board_ledramp/ledramp.c b/examples/board_ledramp/ledramp.c index 4e765ba..77ea689 100644 --- a/examples/board_ledramp/ledramp.c +++ b/examples/board_ledramp/ledramp.c @@ -141,7 +141,7 @@ static void * avr_run_thread(void * oaram) int main(int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}};; const char * fname = "atmega48_ledramp.axf"; //char path[256]; diff --git a/examples/board_rotenc/rotenc_test.c b/examples/board_rotenc/rotenc_test.c index fdde754..a538ba0 100644 --- a/examples/board_rotenc/rotenc_test.c +++ b/examples/board_rotenc/rotenc_test.c @@ -155,7 +155,7 @@ avr_run_thread(void * ignore) int main(int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}}; const char * fname = "atmega32_rotenc_test.axf"; printf( diff --git a/examples/board_timer_64led/timer_64led.c b/examples/board_timer_64led/timer_64led.c index c5f4e26..589f296 100644 --- a/examples/board_timer_64led/timer_64led.c +++ b/examples/board_timer_64led/timer_64led.c @@ -211,7 +211,7 @@ static void * avr_run_thread(void * ignore) int main(int argc, char *argv[]) { - elf_firmware_t f; + elf_firmware_t f = {{0}}; const char * fname = "atmega168_timer_64led.axf"; //char path[256]; diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index 4c28959..fa49a59 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -290,6 +290,10 @@ elf_copy_section( } +/* The structure *firmware must be pre-initialised to zero, then optionally + * with tracing and VCD information. + */ + int elf_read_firmware( const char * file, @@ -313,7 +317,6 @@ elf_read_firmware( Elf_Data *data_fuse = NULL; Elf_Data *data_lockbits = NULL; - memset(firmware, 0, sizeof(*firmware)); #if ELF_SYMBOLS firmware->symbolcount = 0; firmware->symbol = NULL; diff --git a/simavr/sim/sim_elf.h b/simavr/sim/sim_elf.h index 174a440..37d61d7 100644 --- a/simavr/sim/sim_elf.h +++ b/simavr/sim/sim_elf.h @@ -78,10 +78,14 @@ typedef struct elf_firmware_t { #if ELF_SYMBOLS avr_symbol_t ** symbol; - uint32_t symbolcount; + uint32_t symbolcount; #endif } elf_firmware_t ; +/* The structure *firmware must be pre-initialised to zero, then optionally + * with tracing and VCD information. + */ + int elf_read_firmware( const char * file, diff --git a/tests/tests.c b/tests/tests.c index 7f83657..db18153 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -103,7 +103,7 @@ avr_t *tests_init_avr(const char *elfname) { tests_cycle_count = 0; map_stderr(); - elf_firmware_t fw; + elf_firmware_t fw = {{0}}; if (elf_read_firmware(elfname, &fw)) fail("Failed to read ELF firmware \"%s\"", elfname); avr_t *avr = avr_make_mcu_by_name(fw.mmcu);