Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: How to setup Stacks in GNU

2004-12-28 by Karl Olsen

--- In lpc2000@yahoogroups.com, "sig5534" <sig5534@h...> wrote:

> I assume that "r13" is the same as "sp" ?

Yes.
 
> They also have some RAM init code after stack setups.  I guess they 
> are zeroing memory.  Do I need to zero RAM?  Does it really matter 
to 
> anything?

It zeroes the .bss section and copies initialization values for 
the .data section.  GCC assumes that the startup code does this for 
code like this:

int a;
int *pa;

which must be zero initialized according to the C standard.  GCC also 
places explicitly zero initialized variables in .bss:

int b = 0;
int *pb = NULL;

Variables explicitly initialized to other than zero are placed 
in .data:

int c = 1234;
int *pc = &c;

Your startup code should also have code to copy the initialization 
values for .data from flash to RAM.

If you write all the code of your program yourself, you may of course 
skip the startup initialization so that all globals/statics are 
indeterminate at startup.  But if you link in other code, such as 
standard C library functions, you better be absolutely sure that the 
indetermination of their statics/globals won't break anything.
 
If you are concerned with the speed of the startup initialization, 
you can speed it up by using LDM/STM to load/store e.g. 8 words at a 
time instead of the normal LDR/STR loop which only does 1 word at a 
time.  In the .ld file, you should then make the start and end of the 
sections 32-byte aligned instead of just 4-byte aligned.

If you have large arrays that you don't need or have time to zero 
initialize at startup, you can invent a special section name and put 
the variables into that section:

char buffer[10000] __attribute__ ((section ("my_noinit")));

and process the section appropriately in the .ld file.  In any case, 
prepare for a deep dive into the .ld file syntax...

And before deciding all this, first examine the linker map file to 
see the actual size of the sections.  

Karl Olsen

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.