This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
As discussed in this thread, one needs to implement a work-around in order to zero-initialize undefined global and static variables.
My first try was to use the FILL directive in the linker file, which seemed to work at first, but did not work when running from flash. If I understand correctly, this is because the FILL directive only causes the memory to be initialized when running from JTAG, however, please explain if there is more I should know.
I got a tip about using memcpy to zero .ebss, but this would overwrite initialized variables. Is there a convenient method to run this before cinit?
Any other suggestions? It would be very nice if the various methods of accomplishing this was explained on the Wiki, together with the implications or pros/cons of each method.
Stian Soevik said:I got a tip about using memcpy to zero .ebss, but this would overwrite initialized variables. Is there a convenient method to run this before cinit?
assuming you have a 28x device you could put something like
movl XAR0,#_start_ebss
mov AL,#0
mov AH,#(_end_ebss - _start_ebss - 1)
rpt AH || mov *XAR0++,AL
in your CodeStartBranch.asm just before _c_int00 is called. The symbols _start_ebss and _end_ebss need to be associated with the .ebss section in your linker command file.
Johannes,
I have attempted your method to initialize large structures in legacy code and I am a little green on the Linking process. My problem lies in the fact that I don't seem to know how to create the symbols _start_ebss and _end_ebss in my linker CMD file properly. I have attempted adding the following to the end of the .ebss line:
START(_start_ebss), END(_end_ebss)
However, the compiler gives me an error of undefined symbols. I am using CCS 5.1.
-Mark
Mark,
I don't see what's wrong with what you tried. I have the following in my linker command file:
.ebss : > ZONE6 PAGE = 1
START(_start_ebss),
END(_end_ebss)
You need
.ref _start_ebss
.ref _end_ebss
in your assembly code.
My proposed code doesn't work when the .ebss section is too large (size > 0xffff). Then you'll need to write a loop instead of using the rpt AH || mov ... instruction.
Regards
Johannes