AnsweredAssumed Answered

use linker to reinitialize data again

Question asked by M B on Nov 25, 2009
Latest reply on Dec 7, 2009 by M B

Hello,

 

I really need your help.

I want to reinit all global initialized variables in my C-Sourcecode again after start of the S12P microcontroller (like "int example = 8").

I thought I would know how to do this, but I have lots of problems.

The only thing I need to know is the adress in ROM where the initial values are stored, right?

After I know that, I would be able to write a function to get these values again and reinitialize the variables any time I want to... thats my plan, if you have better suggestions tell me please.

 

I read the linker manual today and thought the adress of my global initialized data is representated by .copy, so the ELF name is COPY.

Problem: I always get a linker warning that there is no information about the segment COPY !?

 

My prm-file looks like:

 

PLACEMENT /* here all predefined and user segments are placed into the SEGMENTS defined above. */
      _PRESTART,              /* Used in HIWARE format: jump to _Startup at the code start */
      STARTUP,                /* startup data structures */
      ROM_VAR,                /* constant variables */
      STRINGS,                /* string literals */
      VIRTUAL_TABLE_SEGMENT,  /* C++ virtual table segment */
    //.ostext,                /* OSEK */
      NON_BANKED,             /* runtime routines which must not be banked */
      COPY                    /* copy down information: how to initialize variables */
                              /* in case you want to use ROM_4000 here as well, make sure
                                 that all files (incl. library files) are compiled with the
                                 option: -OnB=b */
                        INTO  ROM_C000/*, ROM_1400, ROM_4000*/;

      DEFAULT_ROM       INTO  PAGE_08, PAGE_09, PAGE_0A, PAGE_0B, PAGE_0C, PAGE_0C_A800, PAGE_0E                  ;

    //.stackstart,            /* eventually used for OSEK kernel awareness: Main-Stack Start */
      SSTACK,                 /* allocate stack first to avoid overwriting variables on overflow */
    //.stackend,              /* eventually used for OSEK kernel awareness: Main-Stack End */
    DEFAULT_RAM         INTO  RAM;

  //.vectors            INTO  OSVECTORS; /* OSEK */
END

 

 

What I do in the Sourcecode (like the example in the linker manual):

 

char *test;

#define __SEG_START_REF(a) __SEG_START_ ## a
#define __SEG_START_DEF(a) extern char __SEG_START_REF(a) []
__SEG_START_DEF(COPY);

 

test= (char*)__SEG_START_REF(COPY);  /* this should be the startaddress of the segment COPY! */

 

If I try to do the same with SSTACK instead of COPY, everythings ok and I DO get the begin of the stack at the address 0x2800!

 

Where's the failure???

Thanks for any hints!

fireas

Outcomes