From: Michel Pollet Date: Sun, 3 Jun 2012 22:46:08 +0000 (+0100) Subject: cores: Now duplicate the global structure X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=a8f5ed10cc964eb744d3d1f82e2ec27588d4e777;hp=21205cf046922476737bb97feacd33bbabe01132;p=simavr cores: Now duplicate the global structure 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 --- diff --git a/simavr/cores/sim_90usb162.c b/simavr/cores/sim_90usb162.c index 793f31a..974e280 100644 --- a/simavr/cores/sim_90usb162.c +++ b/simavr/cores/sim_90usb162.c @@ -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 = { diff --git a/simavr/cores/sim_mega128.c b/simavr/cores/sim_mega128.c index 4745ced..fd617ed 100644 --- a/simavr/cores/sim_mega128.c +++ b/simavr/cores/sim_mega128.c @@ -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 = { diff --git a/simavr/cores/sim_mega1280.c b/simavr/cores/sim_mega1280.c index e943cf9..3f60e7c 100755 --- a/simavr/cores/sim_mega1280.c +++ b/simavr/cores/sim_mega1280.c @@ -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 = { diff --git a/simavr/cores/sim_mega1281.c b/simavr/cores/sim_mega1281.c index d0bbd5b..8ec486c 100644 --- a/simavr/cores/sim_mega1281.c +++ b/simavr/cores/sim_mega1281.c @@ -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 = { diff --git a/simavr/cores/sim_mega164.c b/simavr/cores/sim_mega164.c index d9f2c91..baa59d3 100644 --- a/simavr/cores/sim_mega164.c +++ b/simavr/cores/sim_mega164.c @@ -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 = { diff --git a/simavr/cores/sim_mega168.c b/simavr/cores/sim_mega168.c index 8d0f2e4..70f1b4e 100644 --- a/simavr/cores/sim_mega168.c +++ b/simavr/cores/sim_mega168.c @@ -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 = { diff --git a/simavr/cores/sim_mega16m1.c b/simavr/cores/sim_mega16m1.c index 389e174..29fefa7 100644 --- a/simavr/cores/sim_mega16m1.c +++ b/simavr/cores/sim_mega16m1.c @@ -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 = { diff --git a/simavr/cores/sim_mega324.c b/simavr/cores/sim_mega324.c index 2bbebec..7b32be5 100644 --- a/simavr/cores/sim_mega324.c +++ b/simavr/cores/sim_mega324.c @@ -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 = { diff --git a/simavr/cores/sim_mega328.c b/simavr/cores/sim_mega328.c index 3ed50d0..83115f3 100644 --- a/simavr/cores/sim_mega328.c +++ b/simavr/cores/sim_mega328.c @@ -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 = { diff --git a/simavr/cores/sim_mega48.c b/simavr/cores/sim_mega48.c index 08771af..18fe00a 100644 --- a/simavr/cores/sim_mega48.c +++ b/simavr/cores/sim_mega48.c @@ -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 = { diff --git a/simavr/cores/sim_mega644.c b/simavr/cores/sim_mega644.c index bc20f6e..0e54e6a 100644 --- a/simavr/cores/sim_mega644.c +++ b/simavr/cores/sim_mega644.c @@ -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 = { diff --git a/simavr/cores/sim_mega8.c b/simavr/cores/sim_mega8.c index 7bd2934..cad021b 100644 --- a/simavr/cores/sim_mega8.c +++ b/simavr/cores/sim_mega8.c @@ -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 = { diff --git a/simavr/cores/sim_mega88.c b/simavr/cores/sim_mega88.c index 59bc480..84c58ea 100644 --- a/simavr/cores/sim_mega88.c +++ b/simavr/cores/sim_mega88.c @@ -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 = { diff --git a/simavr/cores/sim_megax.h b/simavr/cores/sim_megax.h index e266132..f192780 100644 --- a/simavr/cores/sim_megax.h +++ b/simavr/cores/sim_megax.h @@ -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), diff --git a/simavr/cores/sim_megax4.h b/simavr/cores/sim_megax4.h index 21f3130..030aebb 100644 --- a/simavr/cores/sim_megax4.h +++ b/simavr/cores/sim_megax4.h @@ -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), diff --git a/simavr/cores/sim_megax8.h b/simavr/cores/sim_megax8.h index 75dc835..385bc8f 100644 --- a/simavr/cores/sim_megax8.h +++ b/simavr/cores/sim_megax8.h @@ -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), diff --git a/simavr/cores/sim_megaxm1.h b/simavr/cores/sim_megaxm1.h index e39bcb4..46c72fb 100644 --- a/simavr/cores/sim_megaxm1.h +++ b/simavr/cores/sim_megaxm1.h @@ -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), diff --git a/simavr/cores/sim_tiny13.c b/simavr/cores/sim_tiny13.c index 99587ce..71a30a3 100644 --- a/simavr/cores/sim_tiny13.c +++ b/simavr/cores/sim_tiny13.c @@ -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 = { diff --git a/simavr/cores/sim_tiny2313.c b/simavr/cores/sim_tiny2313.c index faeffd1..0a8ed6c 100644 --- a/simavr/cores/sim_tiny2313.c +++ b/simavr/cores/sim_tiny2313.c @@ -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 = { diff --git a/simavr/cores/sim_tiny24.c b/simavr/cores/sim_tiny24.c index 4a424f5..7babdf9 100644 --- a/simavr/cores/sim_tiny24.c +++ b/simavr/cores/sim_tiny24.c @@ -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 = { diff --git a/simavr/cores/sim_tiny25.c b/simavr/cores/sim_tiny25.c index 5c32576..b0ff4bc 100644 --- a/simavr/cores/sim_tiny25.c +++ b/simavr/cores/sim_tiny25.c @@ -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 = { diff --git a/simavr/cores/sim_tiny44.c b/simavr/cores/sim_tiny44.c index e181eef..25f99a9 100644 --- a/simavr/cores/sim_tiny44.c +++ b/simavr/cores/sim_tiny44.c @@ -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 = { diff --git a/simavr/cores/sim_tiny45.c b/simavr/cores/sim_tiny45.c index 1500b54..4e79a1e 100644 --- a/simavr/cores/sim_tiny45.c +++ b/simavr/cores/sim_tiny45.c @@ -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 = { diff --git a/simavr/cores/sim_tiny84.c b/simavr/cores/sim_tiny84.c index a868bfe..70bae75 100644 --- a/simavr/cores/sim_tiny84.c +++ b/simavr/cores/sim_tiny84.c @@ -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 = { diff --git a/simavr/cores/sim_tiny85.c b/simavr/cores/sim_tiny85.c index 1508a4f..4ffe66d 100644 --- a/simavr/cores/sim_tiny85.c +++ b/simavr/cores/sim_tiny85.c @@ -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 = { diff --git a/simavr/cores/sim_tinyx4.h b/simavr/cores/sim_tinyx4.h index ca415cf..2ce12b3 100644 --- a/simavr/cores/sim_tinyx4.h +++ b/simavr/cores/sim_tinyx4.h @@ -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), diff --git a/simavr/cores/sim_tinyx5.h b/simavr/cores/sim_tinyx5.h index 90792df..44dbd06 100644 --- a/simavr/cores/sim_tinyx5.h +++ b/simavr/cores/sim_tinyx5.h @@ -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), diff --git a/simavr/sim/sim_avr.c b/simavr/sim/sim_avr.c index de3ea41..805c84f 100644 --- a/simavr/sim/sim_avr.c +++ b/simavr/sim/sim_avr.c @@ -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++) { diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index dcc8f5c..c9414db 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -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(