C Startup Code
Andrew Pines
apines@cosmodog.com
Tue Apr 17 21:20:00 GMT 2001
.text -- code
.rodata -- read-only data (constants)
.data -- initialized data
.bss -- uninitialized data (cleared to zeroes on startup)
have a link file containing something like this:
SECTIONS
{
.text :
{
_text = .; /* start of text */
*(.rodata) /* read only data (in ROM) */
*(.text) /* code */
_etext = .; /* end of text */
} >ROM
.data : AT (ADDR(.text) + SIZEOF(.text)) /* place initialized
data after read only data in ROM, but reference to it in RAM */
{
_data = .; /* RAM location of initialized data */
*(.data)
_edata = .; /* end of data, used to copy initialized
data at start up */
} >RAM
.bss :
{
_bss = .; /* start of uninitialized data (clear to
0 at program start) */
*(.bss) *(COMMON) /* uninitilized data goes in RAM after
initialized data */
_ebss = .; /* end of uninitialized data */
} >RAM
}
your reset vector should then point to something like this:
void _start() // jump here on reset
{
extern int main();
extern char _etext;
extern char _data;
extern char _edata;
extern char _bss;
extern char _ebss;
char *src;
char *dst;
// copy initialized data from ROM to RAM
src=&_etext;
for(dst=&_data;dst<&_edata;dst++)
{
*dst=*src++;
}
// zero-out the bss segment (uninitialized data)
for(dst=&_bss;dst<&_ebss;dst++)
{
*dst=0;
}
// run the main program
main();
}
Hope that's useful. Good luck.
-Andrew
Rohit Prasad wrote:
>
> Hi,
> Since this question has been asked let me announce my need to understand or get hold of working example/ sample code for the startup routines for knowing what the .bss and .data contains. (in context of GCC )
>
> Waiting ,with my fingers crossed,
> Rohit S Prasad
>
> Desg Engg
> Future Software Ltd
> India
>
> -----Original Message-----
> From: Joel Dierks saxofon@musician.net
> Sent: 17 Apr 2001 18:15:24 -0000
> To: crossgcc@sourceware.cygnus.com
> Subject: C Startup Code
>
> Joel R. Dierks
> Digital Design Engineer
> Spectrian Corporation
>
> ___________________________________________________________________________
> Visit http://www.visto.com/info , your free web-based communications center.
> Visto.com. Life on the Dot.
>
> ------
> Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
--
Andrew Pines
apines@cosmodog.com
http://www.cosmodog.com
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list