EmbDev.net

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


von Amit C. (aseem)


Rate this post
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

von Martin T. (mthomas) (Moderator)


Rate this post
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;

von Clifford S. (clifford)


Rate this post
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/Variable-Attributes.html#Variable-Attributes

Clifford

von Amit C. (aseem)


Rate this post
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/Variable-Attributes.html#Variable-Attributes
>
> 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

von Clifford S. (clifford)


Rate this post
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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.