> Hi,
>
> I want to initialize global variables from ROM,
>
The easiest way to do this is to look at the standard crt0.s and linker
files for your compiler, and base your versions on that. But the normal
way to set up a linker file is to have memory areas defined at the top
of the linker file, and put your .text, .data and .bss output sections
into the ROM and RAM memory areas as appropriate. The initialised data
section is put into "> ROM AT> RAM" (or something similar - now you have
the hint, you can look up the exact syntax) which sets the link-time
addresses for data items to a ram address, but puts their contents in
rom. You need to be careful to get the init_data_start and data_start
symbols from the correct area - again, look at the standard linker files
for examples.
You can also drop all the "copy byte" stuff in your startup routines -
use . = ALIGN(4) liberally in your linker file, and everything will be
aligned to 32-bit boundaries.
Reply by Stan●December 5, 20072007-12-05
"Ted" <tedwood@btinternet.com> a �crit dans le message de
news:e268833f-5cc8-4218-be5e-a13356c21de8@j20g2000hsi.googlegroups.com...
> You might want to tell us whose linker this is a script for.
>
> TW
>
I use GNU ld version 2.16.1 ( arm-elf-ld ).
--
-Stan
Reply by Ted●December 5, 20072007-12-05
You might want to tell us whose linker this is a script for.
TW
Reply by Stan●December 5, 20072007-12-05
Hi,
I want to initialize global variables from ROM,
my crt0.s is same as :
[...]
start:
_start:
/* select user mode */
mrs r0, cpsr
bic r0, r0, #0x1F /* clear mode flags */
orr r0, r0, #0x10 /* set user mode */
msr cpsr, r0
/* init stack */
ldr sp,_Lstack_end
/* copy data */
_Lcopy_data:
ldr r0, _Linit_data_start
ldr r1, _Ldata_start
ldr r2, _Ldata_end
cmp r1,r2
beq _Lzero_bss
/* copy byte by byte if not aligned */
tst r0, #0x3
bne _Lcopy_bytes
tst r1, #0x3
bne _Lcopy_bytes
tst r2, #0x3
bne _Lcopy_bytes
_Lcopy_words:
ldr r3, [r0], #0x4
str r3, [r1], #0x4
cmp r1,r2
bne _Lcopy_words
b _Lzero_bss
_Lcopy_bytes:
ldr r3, [r0], #0x1
str r3, [r1], #0x1
cmp r1,r2
bne _Lcopy_bytes
/* zero bss */
_Lzero_bss:
ldr r0, _Lbss_start
ldr r1, _Lbss_end
[...]
at present my linker script is :
----------------------------------------------------
__TEXT_START__ = 0x00000400;
__DATA_START__ = 0x40003000;
__STACK_END__ = 0x40004000;
SECTIONS
{
/* Read-only sections, merged into text segment */
.text0 0x0:
{
*intvec.o(.text)
}
.text2 __TEXT_START__ :
{
*(.text)
*(.text.*)
}
PROVIDE (__etext = .);
.rodata :
{
*(.rodata)
*(.rodata.*)
}
/* append .data; it will be copied by crt0 to final __DATA_START__ */
. = ALIGN(4);
__INIT_DATA_START__ = .;
.data __DATA_START__ : AT ( __INIT_DATA_START__ )
{
*(.data)
*(.data.*)
SORT(CONSTRUCTORS)
}
. = ALIGN(4);
__DATA_END__ = .;
/* noninitialized data; will be zeroed by crt0*/
__bss_start__ = .;
.bss :
{
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(4);
}
. = ALIGN(4);
__bss_end__ = . ;
PROVIDE (end = .);
}
----------------------------------------------------
how to modify this script for initialize global variables from ROM ?
Thanks a lot .
--
-Stan