Hi Steve,
Ok, I think you 're missing the point a bit...
There are a couple of regions of ram which are called 'sections'.
.data - the section where _initialized_ data are located. Actually this
section initialy situated in ROM on a top of '.text' (the one where
executable code and initialized constants live) and then reflects to RAM.
So, if you have initialized global like
int a = 3;
you'll have something like:
.global a
.data ;; <-- NOTE the section!
.p2align 1,0
.type a,@object
.size a,4
a:
.long 3 ;; <-- note the value.
So, the startup code just copies data from ROM (which covers '.data' section
range) to RAM.
'__data_start' points to the '.data' section start in RAM, '_edata' points to
the end of .data section in RAM.
Data being copied from '_etext' location with length (_edata-__data_start).
Another section of RAM is '.bss' one. This section accomodates uninitialized
globals. This section being cleared in strartup code - from '__bss_start'
till '__bss_end'.
The startup code is (section '.init' is not described anywhere, yet a part of
'elf' file and always located at entry address - rom start):
.extern _etext ;; Names of this variables are stupid
.extern __data_start ;; but they appear in any elf file
.extern _edata ;; and there is no any reason to change
.extern __bss_start ;; them.
.extern __bss_end
.extern __stack
.section .init, "ax", @progbits
.global _reset_vector__
.func _reset_vector__
_reset_vector__:
mov #23168, &288 ;DISABLE watchdog.Why people do it in their
code?
mov #_etext, r15 ; load r15 with end of .text segment
mov #__data_start, r14 ; load ram start
mov #_edata, r13 ; end of data segment
cmp r14, r13
jeq .Lend_of_data_loop
.Lcopy_data_loop:
/* copy data from @r15 to @r14 */
mov.b @r15+, @r14 ; move one byte
inc r14
cmp r13, r14 ; check if end of data reached
jlo .Lcopy_data_loop
.Lend_of_data_loop:
mov #__bss_start, r15
mov #__bss_end, r13
cmp r15, r13
jeq .Lend_of_bss_loop
.Lzero_bss:
clr.b @r15
inc r15
cmp r13, r15 ; check if r15 < r13
jlo .Lzero_bss
.Lend_of_bss_loop:
br #main ; jump to main procedure
.endfunc
Obviously, during compilation, the size of thar regions is not known. So, the
startup code should handle any situation. And it does.
Another section '.noinit' is intended for uninitialized globals which will not
be initialized at all during startup.
--------------------------------------
I think this should be clear now :)
The everything above is described in doc.txt, #line 333.
Merry Christmas to everyone.
~d
On Tuesday 24 December 2002 18:41, Steve Underwood wrote:
> I just noticed that RAM is not initialise properly at startup, when the
> default startup code is used. It tries looping between __data_start and
> _edata, but these are both pointing to the same location - the start of
> RAM. If I compile something like:
>
> #include <io.h>
>
> int i;
> int j;
> int k;
>
> int main(int argc, char *argv[])
> {
> extern int __data_start;
> extern int _edata;
> extern int _etext;
>
> i = __data_start;
> j = _edata;
> k = _etext;
> return 0;
> }
>
>
> and look at the code (eg with objdump) the location of __data_start and
> _edata are both 0x200, although _edata should clearly be somewhere
> higher. I think this is not a new problem, but I am suprised I haven't
> noticed it before. I'm not clear if the intention is that _edata should
> point to the end of RAM or the end of used RAM. The related _etext
> symbol points to the end of the code, rather than the end of the code
> space.
>
> I looked at the files in binutils/binutils-2.11/ld/, but I don't really
> understand the syntax that is used (and, yes, I'm too lazy to work it
> out right now).
>
> A happy Christmas to anyone that solves this...... Oh, lets be generous.
> A happy Christmas to everyone. :-)
>
> Regards,
> Steve
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
--
/********************************************************************
("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
`6_ 6 ) `-. ( ).`-.__.`) Enterprise Information Sys
(_Y_.)' ._ ) `._ `. ``-..-' Nevsky prospekt, 20 / 44
_..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
(il),-'' (li),' ((!.-' +7 (812) 3468202, 5585314
********************************************************************/