Initialization of BSS section to zero in the Linker command file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Initialization of BSS section to zero in the Linker command file

2,891 Views
chr
Contributor I
Hi,
I am working with MCF5282 Controller.
The problem is :
 
  I need to initialize the total bss section to zero(default  data)in the Linker command file
 I used the FILL attribute for output section but it is giving error.
  Section
  {
     data :
     {
      *(.bss)
      *(COMMON)
 
     }> Data_Memory = 0x0000
 }
  
  How to use that?
 can anybody give the correct syntax?
 
Labels (1)
0 Kudos
2 Replies

728 Views
sjmelnikoff
Contributor III
The FILL attribute is used primarily to fill unused areas of flash and EEPROM when the device is programmed; it won't work for RAM.
 
If you want to zero the RAM at startup, you need to write some code to do it. To avoid messing up the stack, it may be best to do it right at the start of initialisation, and in assembler so you can ensure that any variables you use are stored in registers, not RAM.
 
In any case, the default startup code already does this, so you might want to have a look at that.
 
Steve.
0 Kudos

728 Views
Kremer
Contributor I
 You need something like:
 
register uint32 n;
register uint8  *sp;
 
 if (__BSS_START != __BSS_END)
 {
  sp = (uint8 *)__BSS_START;
  n = (uint32)(__BSS_END - __BSS_START);
  while (n--)
   *sp++ = 0;
 }
 
 Courtesy code by freescale.
 
 Regards
 
0 Kudos