Hi,

I found a workaround for the .data initialization problem
that does not require a custom patch to the compiler.

1. Change the linker scripts back like they were in the old compiler -
to place .data initialization in ROM, and runtime data in RAM

example:

> <snip>
--- msp430f5437a.ld.ram 2014-12-05 15:28:35.000000000 +0100
+++ msp430f5437a.ld.rom 2014-12-05 14:06:31.000000000 +0100
@@ -265,11 +265,11 @@
     . = ALIGN(2);
 
     _edata = .;
     PROVIDE (edata = .);
     PROVIDE (__dataend = .);
-  } > RAM
+  } > RAM AT > ROM
 
   /* Note that crt0 assumes this is a multiple of two; all the
      start/stop symbols are also assumed word-aligned.  */
   PROVIDE(__romdatastart = LOADADDR(.data));
   PROVIDE (__romdatacopysize = SIZEOF(.data));
> </snip>

2. Luckily the symbols __datastart and __romdatastart are still
present in the ld templates, only the crt0 code to copy over
data from ROM to RAM is no longer there. This can be worked around with
the following stand alone C code:

copydata.c
> #include <stdint.h>
> #include <string.h>
> 
> extern char __datastart;
> extern char __romdatastart;
> extern char __romdatacopysize;
> static void* const datastart=&__datastart;
> static void* const romdatastart=&__romdatastart;
> static uint16_t const romdatacopysize=(uint16_t)&__romdatacopysize;
> 
> __attribute__((constructor)) void __data_move() {
>         if (datastart!=romdatastart) {
>                 memmove(datastart,romdatastart,romdatacopysize);
>         }
> }

this does not require changes to existing programs per se, as that code
can be compiled separately and linked together with any existing or
even precompiled code to get the desired result, as crt0 will call the
__attribute__((constructor)) function before it calls main()

cheers


Eric


-- 
Eric Price
TTI GmbH - TGU Smartmote
Pfaffenwaldring 4
D-70569 Stuttgart

Tel.: +49 0711 - 6856 5369
Fax.: +49 0711 - 6856 6818
E-mail: pr...@smartmote.de
Homepage: http://www.smartmote.de

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to