cores: Now duplicate the global structure
authorMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 22:46:08 +0000 (23:46 +0100)
committerMichel Pollet <buserror@gmail.com>
Sun, 3 Jun 2012 22:46:08 +0000 (23:46 +0100)
Strangely, it didn't, so you could not allocate 2 cores even tho nothing else
is there to stop it...

Signed-off-by: Michel Pollet <buserror@gmail.com>
29 files changed:
simavr/cores/sim_90usb162.c
simavr/cores/sim_mega128.c
simavr/cores/sim_mega1280.c
simavr/cores/sim_mega1281.c
simavr/cores/sim_mega164.c
simavr/cores/sim_mega168.c
simavr/cores/sim_mega16m1.c
simavr/cores/sim_mega324.c
simavr/cores/sim_mega328.c
simavr/cores/sim_mega48.c
simavr/cores/sim_mega644.c
simavr/cores/sim_mega8.c
simavr/cores/sim_mega88.c
simavr/cores/sim_megax.h
simavr/cores/sim_megax4.h
simavr/cores/sim_megax8.h
simavr/cores/sim_megaxm1.h
simavr/cores/sim_tiny13.c
simavr/cores/sim_tiny2313.c
simavr/cores/sim_tiny24.c
simavr/cores/sim_tiny25.c
simavr/cores/sim_tiny44.c
simavr/cores/sim_tiny45.c
simavr/cores/sim_tiny84.c
simavr/cores/sim_tiny85.c
simavr/cores/sim_tinyx4.h
simavr/cores/sim_tinyx5.h
simavr/sim/sim_avr.c
simavr/sim/sim_avr.h

index 793f31a..974e280 100644 (file)
@@ -40,7 +40,7 @@ void usb162_reset(struct avr_t * avr);
 #define __ASSEMBLER__
 #include "avr/iousb162.h"
 
-struct mcu_t {
+const struct mcu_t {
        avr_t                    core;
        avr_eeprom_t    eeprom;
        avr_flash_t     selfprog;
@@ -261,7 +261,7 @@ struct mcu_t {
 
 static avr_t * make()
 {
-       return &mcu_usb162.core;
+       return avr_core_allocate(&mcu_usb162.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t usb162 = {
index 4745ced..fd617ed 100644 (file)
@@ -43,7 +43,7 @@ void m128_reset(struct avr_t * avr);
 /*
  * This is a template for all of the 128 devices, hopefuly
  */
-struct mcu_t {
+const struct mcu_t {
        avr_t          core;
        avr_eeprom_t    eeprom;
        avr_flash_t     selfprog;
@@ -481,7 +481,7 @@ struct mcu_t {
 
 static avr_t * make()
 {
-        return &mcu_mega128.core;
+       return avr_core_allocate(&mcu_mega128.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega128 = {
index e943cf9..3f60e7c 100755 (executable)
@@ -46,7 +46,7 @@ void m1280_reset(struct avr_t * avr);
 /*
  * This is a template for all of the 1280 devices, hopefully
  */
-struct mcu_t {
+const struct mcu_t {
        avr_t          core;
        avr_eeprom_t    eeprom;
        avr_flash_t     selfprog;
@@ -596,7 +596,7 @@ struct mcu_t {
 
 static avr_t * make()
 {
-        return &mcu_mega1280.core;
+       return avr_core_allocate(&mcu_mega1280.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega1280 = {
index d0bbd5b..8ec486c 100644 (file)
@@ -43,7 +43,7 @@ void m1281_reset(struct avr_t * avr);
 /*
  * This is a template for all of the 1281 devices, hopefully
  */
-struct mcu_t {
+const struct mcu_t {
        avr_t          core;
        avr_eeprom_t    eeprom;
        avr_flash_t     selfprog;
@@ -509,7 +509,7 @@ struct mcu_t {
 
 static avr_t * make()
 {
-        return &mcu_mega1281.core;
+       return avr_core_allocate(&mcu_mega1281.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega1281 = {
index d9f2c91..baa59d3 100644 (file)
@@ -32,7 +32,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega164 = {
index 8d0f2e4..70f1b4e 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega168 = {
index 389e174..29fefa7 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega16m1 = {
index 2bbebec..7b32be5 100644 (file)
@@ -32,7 +32,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega324 = {
index 3ed50d0..83115f3 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega328 = {
index 08771af..18fe00a 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega48 = {
index bc20f6e..0e54e6a 100644 (file)
@@ -32,7 +32,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega644 = {
index 7bd2934..cad021b 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega8 = {
index 59bc480..84c58ea 100644 (file)
@@ -33,7 +33,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t mega88 = {
index e266132..f192780 100644 (file)
@@ -70,7 +70,7 @@ struct mcu_t {
 #define EIMSK GICR
 #define EIFR GIFR
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
        .core = {
                .mmcu = SIM_MMCU,
                DEFAULT_CORE(SIM_VECTOR_SIZE),
index 21f3130..030aebb 100644 (file)
@@ -61,7 +61,7 @@ struct mcu_t {
 #error SIM_MMCU is not declared
 #endif
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
        .core = {
                .mmcu = SIM_MMCU,
                DEFAULT_CORE(4),
index 75dc835..385bc8f 100644 (file)
@@ -64,7 +64,7 @@ struct mcu_t {
 #error SIM_MMCU is not declared
 #endif
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
        .core = {
                .mmcu = SIM_MMCU,
                DEFAULT_CORE(SIM_VECTOR_SIZE),
index e39bcb4..46c72fb 100644 (file)
@@ -63,7 +63,7 @@ struct mcu_t {
 #error SIM_MMCU is not declared
 #endif
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
        .core = {
                .mmcu = SIM_MMCU,
                DEFAULT_CORE(SIM_VECTOR_SIZE),
index 99587ce..71a30a3 100644 (file)
@@ -37,7 +37,7 @@ static void init(struct avr_t * avr);
 static void reset(struct avr_t * avr);
 
 
-static struct mcu_t {
+const static struct mcu_t {
        avr_t core;
        avr_eeprom_t    eeprom;
        avr_watchdog_t  watchdog;
@@ -122,7 +122,7 @@ static struct mcu_t {
 
 static avr_t * make()
 {
-       return &mcu.core;
+       return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny13 = {
index faeffd1..0a8ed6c 100644 (file)
@@ -38,7 +38,7 @@ static void reset(struct avr_t * avr);
 /*
  * This is a template for all of the tinyx5 devices, hopefully
  */
-static struct mcu_t {
+const static struct mcu_t {
        avr_t core;
        avr_eeprom_t    eeprom;
        avr_watchdog_t  watchdog;
@@ -214,7 +214,7 @@ static struct mcu_t {
 
 static avr_t * make()
 {
-       return &mcu.core;
+       return avr_core_allocate(&mcu.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny2313 = {
index 4a424f5..7babdf9 100644 (file)
@@ -34,7 +34,7 @@
 
 static avr_t * make()
 {
-    return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny24 = {
index 5c32576..b0ff4bc 100644 (file)
@@ -34,7 +34,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny25 = {
index e181eef..25f99a9 100644 (file)
@@ -34,7 +34,7 @@
 
 static avr_t * make()
 {
-    return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny44 = {
index 1500b54..4e79a1e 100644 (file)
@@ -34,7 +34,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny45 = {
index a868bfe..70bae75 100644 (file)
@@ -35,7 +35,7 @@
 
 static avr_t * make()
 {
-    return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny84 = {
index 1508a4f..4ffe66d 100644 (file)
@@ -34,7 +34,7 @@
 
 static avr_t * make()
 {
-       return &SIM_CORENAME.core;
+       return avr_core_allocate(&SIM_CORENAME.core, sizeof(struct mcu_t));
 }
 
 avr_kind_t tiny85 = {
index ca415cf..2ce12b3 100644 (file)
@@ -57,7 +57,7 @@ struct mcu_t {
 #error SIM_MMCU is not declared
 #endif
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
     .core = {
         .mmcu = SIM_MMCU,
         DEFAULT_CORE(SIM_VECTOR_SIZE),
index 90792df..44dbd06 100644 (file)
@@ -57,7 +57,7 @@ struct mcu_t {
 #error SIM_MMCU is not declared
 #endif
 
-struct mcu_t SIM_CORENAME = {
+const struct mcu_t SIM_CORENAME = {
        .core = {
                .mmcu = SIM_MMCU,
                DEFAULT_CORE(SIM_VECTOR_SIZE),
index de3ea41..805c84f 100644 (file)
@@ -292,36 +292,19 @@ int avr_run(avr_t * avr)
        return avr->state;
 }
 
-#if 0
-extern avr_kind_t tiny13;
-extern avr_kind_t tiny2313;
-extern avr_kind_t tiny25,tiny45,tiny85;
-extern avr_kind_t tiny24,tiny44,tiny84;
-extern avr_kind_t mega8;
-extern avr_kind_t mega48,mega88,mega168,mega328;
-extern avr_kind_t mega164,mega324,mega644;
-extern avr_kind_t mega128;
-extern avr_kind_t mega1281;
-extern avr_kind_t mega16m1;
-extern avr_kind_t usb162;
-
-avr_kind_t * avr_kind[] = {
-       &tiny13,
-       &tiny2313,
-       &tiny25, &tiny45, &tiny85,
-       &tiny24, &tiny44, &tiny84,
-       &mega8,
-       &mega48, &mega88, &mega168, &mega328,
-       &mega164, &mega324, &mega644,
-       &mega128,
-       &mega1281,
-       &mega16m1,
-       &usb162,
-       NULL
-};
-#endif
+avr_t *
+avr_core_allocate(
+               const avr_t * core,
+               uint32_t coreLen)
+{
+       uint8_t * b = malloc(coreLen);
+       memcpy(b, core, coreLen);
+       return (avr_t *)b;
+}
 
-avr_t * avr_make_mcu_by_name(const char *name)
+avr_t *
+avr_make_mcu_by_name(
+               const char *name)
 {
        avr_kind_t * maker = NULL;
        for (int i = 0; avr_kind[i] && !maker; i++) {
index dcc8f5c..c9414db 100644 (file)
@@ -281,6 +281,12 @@ avr_make_mcu_by_name(
 int
 avr_init(
                avr_t * avr);
+// Used by the cores, allocated a mutable avr_t from the const global
+avr_t *
+avr_core_allocate(
+               const avr_t * core,
+               uint32_t coreLen);
+
 // resets the AVR, and the IO modules
 void
 avr_reset(