This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: m68k cross: problems with crt0
- To: gcc-help at gcc dot gnu dot org
- Subject: RE: m68k cross: problems with crt0
- From: "paul andrews" <paulwandrews at hotmail dot com>
- Date: Mon, 29 Nov 1999 16:21:02 NZDT
- Reply-To: paul dot andrews at smartmove dot co dot nz
>hi,
>i have installed gcc as cross compiler for an mc68332 embedded system. but
>i failed with this initialization stuff. i also wonder about this
>__main, __do_global_ctors() function and the __INIT_SECTION__ in
>the linker script.
>i hope that someone can help me with this stuff.
__main, __do_global_ctors etc is the generic gcc startup code, which is
actually initialising global c++ constructors. This is fairly harmless
if you only use c. These routines are found in libgcc - hunt around for
it and include it in your link.
>modified the crt0.S file which comes with newlib.
>small programs work. but global and static variables are
>uninitialized. also library function like sprintf() don't
>work.
I completely re-wrote the crt0.s for use in our system as I didn't
need much of the stuff it was doing. I also noticed that you don't need
to specify it on your link line: ld seems to magically find it.
>what's about the function __do_global_ctors(). is that
>the place where this stuff should be done?
No. This function is part of the gcc helper library. crt0.s is the place.
I also re-wrote the ld script, again because I though it was overly complex.
Below are both my crt0.s and .ld script which may help you...or may not :-)
Paul Andrews
Software Engineer
Smartmove (NZ) Ltd
Auckland, New Zealand
http://www.smartmove.co.nz
----------------------------------------------------------------------------
-----
crt0.s
----------------------------------------------------------------------------
-----
.extern main
.extern _etext
.extern _edata
.extern _sdata
.global start
/*--------------------------------------------------------------------------
--*/
.section .bss
stkbot:
.ds.b 4096
stktop:
/*--------------------------------------------------------------------------
--*/
.section .sig
.ascii "The quick brown fox jumps over the lazy dog"
/*--------------------------------------------------------------------------
--*/
.section .vectors
.long _etext
.long start
/*--------------------------------------------------------------------------
--*/
.text
start:
move.l #stktop,%a7 /* set up the stack */
move.l #_etext,%a0 /* copy initialised data back to ram */
move.l #_sdata,%a1
loop:
move.b (%a0)+,(%a1)+
cmp.l #_edata,%a1
blt.s loop
jmp main
/*--------------------------------------------------------------------------
--*/
/* EOF */
----------------------------------------------------------------------------
-----
cad.ld
----------------------------------------------------------------------------
-----
/*
CAD3 linker script.
*/
STARTUP(crt0.o)
OUTPUT_ARCH(m68k)
/* formats: srec coff-m68k */
OUTPUT_FORMAT(coff-m68k)
SEARCH_DIR(D:\gnu\gcc-m68k\m68k-coff\lib\m68000)
/* for libgcc.a */
SEARCH_DIR(D:\GNU\gcc-m68k\lib\gcc-lib\m68k-coff\2.95.2)
MEMORY
{
ram(RWX) : ORIGIN = 0, LENGTH = 512K
flash(RX) : ORIGIN = 0x400000, LENGTH = 512K
}
SECTIONS
{
/* RAM */
.vectorspace 0x000000:
{
*(.vectorspace)
} > ram
.data 0x8000:
AT( ADDR(.text) + SIZEOF(.text) )
{
_sdata = .; /* store start address as symbol*/
*(.data)
_edata = .; /* store end address as symbol */
} > ram /* the >ram and >flash do nothing but provide extra
checking */
.bss :
{
*(.bss)
} > ram /* use '> ram' to see if it all still fits */
.stack :
{
*(.stack)
end = .; /* sbrk.c in libnosys wants this for some
reason */
} > ram
/* ROM */
.vectors 0x408000:
{
*(.vectors)
} > flash
.signature 0x408400 :
{
*(.sig)
} > flash
.text 0x408500 :
{
*(.text)
. = ALIGN(4); /* this keep the __do_global_ctors happy */
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(.ctors)
LONG(0)
__CTOR_END__ = .;
_etext = ABSOLUTE(.) ;
} > flash
}
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com