There are two types of constants with ARM: rodata and literal pools.
The rodata is used for stuff marked "const" in C, and the literal
pool is used for large immediate values.
Consider the code:
const char hello[] = "hello";
void fn(void)
{
x = 5;
y = 0x12345678;
}
hello is stored in rodata
The 5 in x = 5 is small enough that this can fit in an immediate
value and will compile to something like:
mov r4,#5
The value 0x12345678 is too large to store in an immediate
instruction so the emmittted code becomes something like:
ldr r4,[pc,xxxx]
...
.word 0x12345678
The actual data for 0x12345678 is stored as a literal value in
the .text section along with the code and is loaded indirectly using
the offset from the pc. This is called a literal pool.
BTW The assembler will do this for us automatically. All you need to
do is write:
ldr r4,=0x12345678
The assmebler will look at the value and determine if it can be done
with a mov. If not then a suitable literal pool is made.
At 11:33 PM 4/22/05 +0200, Anton Erasmus wrote: >On 22 Apr 2005 at 15:07, Robert Adsett wrote:
<much snipped>
> > OK, I'll bite. Why would you copy the
.rodata section to RAM? I
> > haven't seen any need to. From one of my linker files
>Sorry, an artifact from working with the AVR. There the .rodata section is
>handled the
>same as the .data section. The variables are placed in RAM and their
>initial value
>copied from flash memory by the startup code. Of course the ARM does not
>need this and the .rodata section can be kept in flash.
That makes sense. After a while all the different architectures do tend to
blur.
Robert
" 'Freedom' has no meaning of itself. There are always
restrictions, be
they legal, genetic, or physical. If you don't believe me, try to chew a
radio signal. " -- Kelvin Throop, III http://www.aeolusdevelopment.com/
Reply by Anton Erasmus●April 22, 20052005-04-22
On 22 Apr 2005 at 15:07, Robert Adsett wrote:
>
> At 07:15 PM 4/22/05 +0200, Anton Erasmus wrote:
> >On 22 Apr 2005 at 8:52, Richard Duits wrote:
> > > Anything you define as const is allocated in the flash (at
least
> > > gcc does this, have no experience with other compilers yet).
> > > Because the arm has only one address space, all memory (flash
and
> > > ram) is the same, except you cannot write to the flash
directly.
> > > The only reason you may want to copy to ram is because ram is
> > > faster than flash is some cases.
> >
> >In which version of arm-gcc does const put the variable in the text
> >section. I have checked with arm-elf-gcc v3.4.3, and the variable is
> >not put into the .test section when const is used. One must
> >explicitly use a __attribute__((section (".text"))).
> >
> >const int gConstVar=5; /* Put in .rodata section */
> >const int gConstVar1 __attribute__((section (".text")))=6; /*
Put in
> >.text section */
> >
> >The .rodata section is in flash, and then copied to RAM in the
> >startup code. So if the intention of using varaibles in flash is to
> >save memory ( Which is usually the case), then just declaring the
> >variables const does not suffice.
> OK, I'll bite. Why would you copy the .rodata section to RAM? I
> haven't seen any need to. From one of my linker files
>
> prog : { /* Program (.text) sections
> */
> *(.text) /* are next, then constant
> data.*/ *(.rodata) *(.rodata*) *(.glue_7) *(.glue_7t) }
> >flash
> __end_of_text__ = .; /* Used by startup to find
> */
> /* initialized vars. */
>
> And no, my startup doesn't copy any of the above to RAM
>
> I'm running 3.3.2 (I generally like to stay off the compilers
bleeding
> edge :), but I can't imagine they've gone backwards on this
particular
> issue.
Sorry, an artifact from working with the AVR. There the .rodata section is
handled the
same as the .data section. The variables are placed in RAM and their initial
value
copied from flash memory by the startup code. Of course the ARM does not
need this and the .rodata section can be kept in flash.
Regards
Anton Erasmus
> Yahoo! Groups Links
>
>
--
A J Erasmus
Reply by Robert Adsett●April 22, 20052005-04-22
At 07:15 PM 4/22/05 +0200, Anton Erasmus wrote: >On 22 Apr 2005 at 8:52, Richard Duits wrote:
> > Anything you define as const is allocated in the flash (at least
gcc
> > does this, have no experience with other compilers yet). Because
the
> > arm has only one address space, all memory (flash and ram) is the
> > same, except you cannot write to the flash directly. The only
reason
> > you may want to copy to ram is because ram is faster than flash is
> > some cases.
>
>In which version of arm-gcc does const put the variable in the text
>section. I have
>checked with arm-elf-gcc v3.4.3, and the variable is not put into the
>.test section
>when const is used. One must explicitly use a __attribute__((section
>(".text"))).
>
>const int gConstVar=5; /* Put in .rodata section */
>const int gConstVar1 __attribute__((section (".text")))=6; /* Put
in .text
>section */
>
>The .rodata section is in flash, and then copied to RAM in the startup
>code. So if
>the intention of using varaibles in flash is to save memory ( Which is
>usually the case),
>then just declaring the variables const does not suffice.
OK, I'll bite. Why would you copy the .rodata section to RAM? I
haven't
seen any need to. From one of my linker files
prog : { /* Program (.text) sections */
*(.text) /* are next, then constant data.*/
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
} >flash
__end_of_text__ = .; /* Used by startup to find */
/* initialized vars. */
And no, my startup doesn't copy any of the above to RAM
I'm running 3.3.2 (I generally like to stay off the compilers bleeding edge
:), but I can't imagine they've gone backwards on this particular
issue.
Robert
" 'Freedom' has no meaning of itself. There are always
restrictions, be
they legal, genetic, or physical. If you don't believe me, try to chew a
radio signal. " -- Kelvin Throop, III http://www.aeolusdevelopment.com/
Reply by Anton Erasmus●April 22, 20052005-04-22
On 22 Apr 2005 at 8:52, Richard Duits wrote:
>
> Anything you define as const is allocated in the flash (at least gcc
> does this, have no experience with other compilers yet). Because the
> arm has only one address space, all memory (flash and ram) is the
> same, except you cannot write to the flash directly. The only reason
> you may want to copy to ram is because ram is faster than flash is
> some cases.
In which version of arm-gcc does const put the variable in the text section. I
have
checked with arm-elf-gcc v3.4.3, and the variable is not put into the .test
section
when const is used. One must explicitly use a __attribute__((section
(".text"))).
const int gConstVar=5; /* Put in .rodata section */
const int gConstVar1 __attribute__((section (".text")))=6; /* Put in
.text section */
The .rodata section is in flash, and then copied to RAM in the startup code. So
if
the intention of using varaibles in flash is to save memory ( Which is usually
the case),
then just declaring the variables const does not suffice.
Regards
Anton Erasmus
> Richard.
> Jaromir wrote:
>
> > Hello,
> >
> > how can i keep long strings(or fonts,bitmaps) only in flash memory,
> > and later read. I use gcc - is something like read_flash_byte()
> > function? or can i use memcpy ?
> >
> > Jaromir
> > _________________________________________________________________
> > List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )
> >
> >
> >
> >
> >
> > --------------------------------
> > ---- *>.
> >
>
>
>
> Yahoo! Groups Links
>
>
--
A J Erasmus
Reply by Michael Anburaj●April 22, 20052005-04-22
Jaromir,
Its true for all compilers, as long as the .text
region (RO section in ADS) is located in Flash (in the
link step) all constants & literals will go along
with the code. If the code is located in Flash, so
will constants & literals.
void myfunc()
{
char *ptr = "my string";
}
In this case my string will be placed along with
code.
Cheers,
-Mike.
--- Richard Duits <yahoo@yaho...> wrote: > Anything you define as const is allocated in
the
> flash (at least gcc
> does this, have no experience with other compilers
> yet). Because the arm
> has only one address space, all memory (flash and
> ram) is the same,
> except you cannot write to the flash directly. The
> only reason you may
> want to copy to ram is because ram is faster than
> flash is some cases.
>
> Richard.
> Jaromir wrote:
>
> > Hello,
> >
> > how can i keep long strings(or fonts,bitmaps) only
> in flash memory,
> > and later read.
> > I use gcc - is something like read_flash_byte()
> function?
> > or can i use memcpy ?
> >
> > Jaromir
> >
> _________________________________________________________________ > > List sprawdzony skanerem poczty mks_vir (
> http://www.mks.com.pl )
> >
> >
> > [Non-text portions of this message have been
> removed]
> >
> >
> >
>
Anything you define as const is allocated in the flash (at least gcc
does this, have no experience with other compilers yet). Because the arm
has only one address space, all memory (flash and ram) is the same,
except you cannot write to the flash directly. The only reason you may
want to copy to ram is because ram is faster than flash is some cases.
Richard.
Jaromir wrote:
> Hello,
>
> how can i keep long strings(or fonts,bitmaps) only in flash memory,
> and later read.
> I use gcc - is something like read_flash_byte() function?
> or can i use memcpy ?
>
> Jaromir
> _________________________________________________________________
> List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )
>
> *>.
Reply by Jaromir●April 22, 20052005-04-22
Hello,
how can i keep long strings(or fonts,bitmaps) only in flash memory, and later
read.
I use gcc - is something like read_flash_byte() function?
or can i use memcpy ?
Jaromir
_________________________________________________________________
List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )