Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Global pointer _gp

Dear Forum

I'm trying to allocate some data in a new section to avoid having them zeroed during a boot.

I use __attribute__ ((section (".nv_sram"))) after the declaration of the variable and then add the following lines in the linker script to have the section output in the binary too.

.nv_sram :

{

. = ALIGN(32 / 8);

} > sram

this outputs the section after the .rwdata section but before the .bss section.

This works nicely as long as I keep the nv_sram relatively small. If I increase the size of nv_sram I get the

Unable to reach (some addr) from global pointer.

when compiling.

I've tried to output the section after the bss which compiles but chrashes in the target.

Could anybody point me to some doc on the global pointer or even better the right way of telling the startup code to leave variables untouched ?

Regards Jacob

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Jskjoet,

    I have a section of NVR like yours and use the __attribute__ to put stuff into it like this:

    unsigned short fred __attribute__ ....

    If I then try to use fred from another file with:

    extern unsigned short fred;

    then I get the same "can't reach...".

    You have to tell the compiler that the variable is in the NVR section, which may be far away:

    extern unsigned short fred __attribute__ ....

    Banx.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by banx@Nov 14 2006, 05:05 AM

    hi jskjoet,

    i have a section of nvr like yours and use the __attribute__ to put stuff into it like this:

    unsigned short fred __attribute__ ....

    if i then try to use fred from another file with:

    extern unsigned short fred;

    then i get the same "can't reach...".

    you have to tell the compiler that the variable is in the nvr section, which may be far away:

    extern unsigned short fred __attribute__ ....

    banx.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=19421)

    --- quote end ---

    --- Quote End ---

    Hi Banx

    Thank you for the reply.

    In my case the varibles are used from within the same module only - so no extern declaration.

    Initially I found that outputting the nv_sram section after the bss segment caused a crash. This was due to a conflict with the heap that starts at the _end symbol.

    After inelegantly replacing

    .flash : AT (LOADADDR (.bss) + SIZEOF (.bss)

    with

    .flash : AT (LOADADDR (.bss) + SIZEOF (.bss) + SIZEOF (.nv_sram))

    in the linker script it now works nicely as this moved the _end symbol too. Note that moving the flash segment is probably not the way to go if you&#39;re using any kind of software that rely in this.

    Regards Jacob