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.

Initializing BSS Section

Other Parts Discussed in Thread: AM3358, SYSBIOS

Hello!

I'm on a Windows 7 64-bit PC, developing code for an AM3358 on the AM335x Starter Kit, using CCS Version: 6.1.2.00015, and have recently installed Processor SDK RTOS AM335x v2.00.02.11, and SYS/BIOS 6.45.01.29  (installs with the PDK), and am using XDCtools 3.32.00.06.

If I am understanding correctly something I read about TI-RTOS a couple of weeks ago (and which I can't find now), global and static variables in an application are NOT initialized to contain all zero (0) bits as is is done by most default  CRT0  start-up sequences I have worked with.  Part of the advice I read with this was to initialize all global and variables to the value you want them to contain when your application hits main.

Unfortunately, I have a few libraries I will likely be using that were originally written in an environment where minimizing program size was important (initialization values for the  .data  [initialized variables] section were stored as part of program space and copied into RAM by CRT0 code), and so they were written by ASSUMING (by design) that the  CRT0  start-up code is being used was the one that zero'd the  .bss  section (that environment offered a choice of start-up code libraries to use), and therefore all variables that were not assigned an initial value were guaranteed to contain all zero (0) bits when the application entered its  main()  function.

Question #1:

Thinking about this for a bit, since  __bss_start__  and  __bss_end__  symbols are being created in the generated linker command file, wouldn't it be possible to achieve this initialization by writing a quick loop using those symbols to initialize pointers, and writing 0's across the section myself?

Question #2:

Would I need to do this in a  "firstFxns"  function in order to preserve any other variables SYS/BIOS might have initialized?

Kind regards,
Vic

  • Victor,

    Are you using GNU tool chain? If so, then the target boot code will zero-initialize the .bss section for you (just as you suggested above). Have a look at the following file.

    bios_6_45_01_29/packages/gnu/targets/arm/rtsv7A/startup.c

    Make sure you are using this target in your configuration.

    One word of caution. A float variable value of zero is not necessarily all zero bits. It is best to explicitly initialize your floats to zero in the source code.

    You are also correct, that you cannot do this in main. That would be too late. By then, the boot code has probably set runtime values to variables in .bss. Clearing .bss in main would wipe out their values. I think using the xdc.runtime.Startup.firstFxns would be fine. If that does not work, then using xdc.runtime.Reset.fxns would do the job.

    Have a look at the RTSC runtime startup description in the ti.sysbios.BIOS documentation.

    ~Ramsey