Commit 76666724ab05f8b0a1d2dbac9aa11b571810503c
authorga <ga@oldell.fish>
Fri, 2 Apr 2021 17:19:02 +0000 (18:19 +0100)
committerga <ga@oldell.fish>
Fri, 2 Apr 2021 18:00:28 +0000 (19:00 +0100)
Remove call to memset() in sim_elf.c that destroyed initialisations
and initialise the firmware structure everywhere.
Add comments to say initialisation is required.

9 files changed:
examples/board_ds1338/ds1338demo.c
examples/board_hd44780/charlcd.c
examples/board_i2ctest/i2ctest.c
examples/board_ledramp/ledramp.c
examples/board_rotenc/rotenc_test.c
examples/board_timer_64led/timer_64led.c
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h
tests/tests.c

index 565d02fadeaa6131f75b8496fd19347c3fdff6db..266fd7eae4498e44c13f56af6c6cede22123e984 100644 (file)
@@ -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);
index 100cd34c121430dcd87ad398604af87b84997320..4b69964c2d907eaf74012b3f8b1d7f76faff1427 100644 (file)
@@ -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);
index a8ccca9e5c9cec72a139372e09f1ecfcefff4d4c..233d86e0738990dc323dd666976d0020462e86cc 100644 (file)
@@ -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);
index 4e765ba3dc39fc4584bff59d9cc2756c62c07920..77ea689257590ad5c59ae3e6b83cb7683d3fc18c 100644 (file)
@@ -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];
 
index fdde75468384d3ad0eaa274ca8478d5535728536..a538ba0253835b950689b9688fd532a83a0c4396 100644 (file)
@@ -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(
index c5f4e26edd2e9e53826b07f23c78fa228e2da07d..589f2969db4288f87aaa9d33e82c4a4956b18c66 100644 (file)
@@ -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];
 
index 4c289593152af2373b53d2abd56d90cd93f9e209..fa49a59926a15df20fc7a7278ffbfc17a702a2f8 100644 (file)
@@ -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;
index 174a4402789d6739657e6d891a306d17e1eb80a0..37d61d70353f58d66263be0844b1f42c0c7556b8 100644 (file)
@@ -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,
index 7f83657cc2eac9960ab09995a4aff664dd39c49b..db18153e0f01b84186935182a8b2e48b1d370650 100644 (file)
@@ -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);