EmbDev.net

Forum: ARM programming with GCC/GNU tools Variable Storage area


Author: Amit Chatre (aseem)
Posted on:

Rate this post
0 useful
not useful
Hi,

        I assign a variable int x=55; please tell me storage area in
memory.

if it will store in data memory,please what is the way to store it in
code memroy?

Thanks,
Aseem

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Amit Chatre wrote:
> Hi,
>
>         I assign a variable int x=55; please tell me storage area in
> memory.

Generate a map-file (-Wl,-Map=mymapfile.map when linking with gcc), it
shows the location.

> if it will store in data memory,please what is the way to store it in
> code memroy?

Test with const int x=55;

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
Amit Chatre wrote:
> Hi,
>
>         I assign a variable int x=55; please tell me storage area in
> memory.

That depends on the storage class of the variable. Non-static local
variables are stored on the stack so are non-deterministic. Either way
you can determine the address at run-time with &x


>
> if it will store in data memory,please what is the way to store it in
> code memroy?
>
> Thanks,
> Aseem

What is it you are actually trying to achieve. Neither the
compiler/linker not the ARM architecture have any concept of 'code' or
'data' memory, code may be executed from ROM or RAM. Did you simply want
to store the data in read-only memory?

It has been suggested that you use the const keyword, but the compiler
is not obliged to store such data in ROM. The semantics of const is
merely that the code cannot modify the data.

To place variables in specific memory areas in GCC you myst use a
section attribute to place the data in a section defined in the linker
script.
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variab...

Clifford

Author: Amit Chatre (aseem)
Posted on:

Rate this post
0 useful
not useful
Thank you for all this,

Clifford Slocombe wrote:
> Amit Chatre wrote:
>> Hi,
>>
>>         I assign a variable int x=55; please tell me storage area in
>> memory.
>
> That depends on the storage class of the variable. Non-static local
> variables are stored on the stack so are non-deterministic. Either way
> you can determine the address at run-time with &x
>
by using const keyword I'm able to save data in read only memeory.
>
>>
>> if it will store in data memory,please what is the way to store it in
>> code memroy?
>>
>> Thanks,
>> Aseem
>
> What is it you are actually trying to achieve. Neither the
> compiler/linker not the ARM architecture have any concept of 'code' or
> 'data' memory, code may be executed from ROM or RAM. Did you simply want
> to store the data in read-only memory?
>
Actually I wanted to store const defined variables in ROM.
now suppose if I have a variable array of int
const unsigned int i[1024]={
                              ....
                              ....
                           };
then it should be store in flash memroy.

> It has been suggested that you use the const keyword, but the compiler
> is not obliged to store such data in ROM. The semantics of const is
> merely that the code cannot modify the data.
>
> To place variables in specific memory areas in GCC you myst use a
> section attribute to place the data in a section defined in the linker
> script.
> 
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Variab...
>
> Clifford

Again ther is one problem,
how can I define a variable external memroy by default.

means if i defined a variable
const int XL[10];

its memory address would be 0xA0000000.
Please tell me how can I do this?

Or any suggestion or link about memory interfacing and samples codes.
I'm totally new for memory interfacing.....

Thanks in Advance.
Aseem

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
The answer to your question is as I suggested - use a linker section
attribute.

const unsigned int i[1024] _attribute_ ((section ("ROMDATA"))) =
               {
                  ...
                  ...
               };


const int XL[10] = _attribute_ ((section ("MYLOCATION"))) =
               {
                  ...
                  ...
               };

Note that here ROMDATA and MYLOCATION must be defined in the linker
script. You can define them as absolute addresses or a relocatable
section. As described here:
http://www.math.utah.edu/docs/info/ld_3.html#SEC14

Clifford

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.