I use Code Composer Studio for an AM1808. CCS does not have an option to define the stack sizes of the different ARM modes (USR/FIQ/IRQ/SVC/...) so this is done in an init.asm assembler file.
My init.asm defines a routine named "Entry" that setups the stack pointers for each mode. The routine "Entry" is defined as entry-point of the program. After setting up the stacks "Entry" calls _c_int00 to initialize the C/C++ library. Then _c_int00 in turn calls the main routine.
Now I have seen some example where the entry-point routine sets up the stack, then clears the BSS section in a loop and calls __TI_auto_init afterwards.
Is clearing the BSS section manually and then calling __TI_auto_init an appropriate substitution for _c_int00? I tried this solution but as it seems it does not initialize the virtual method tables of C++ classes correctly so calling the base class constructor sometimes fails.
What about calling _c_int00 at the end of the entry-routine? Does it destroy the stack layout that was previously setup or is it ok to call this routine after the stack setup?
So my questions are:
1. What is the correct routine to initialize C/C++ after stack setup: _c_int00 or __TI_auto_init?
2. Does __TI_auto_init work with C++ code as it seems to not initialize the VMTs of virtual classes correctly.
Thanks in advance.
Here the __TI_auto_init solution (at least the concept of it):
====================================================
Entry:
LDR r0, _stackptr
MSR cpsr_c, #MODE_UND|I_F_BIT
MOV sp,r0
SUB r0, r0, #UND_STACK_SIZE
; setup ABT, FIQ, IRQ, SVC, USR/SYS
...
Clear_Bss:
LDR r0, _bss_start
LDR r1, _bss_end
SUB r1,r1,#4
MOV r2, #0
Loop:
STR r2, [r0], #4
CMP r0, r1
BLE Loop
LDR r10, __TI_auto_init
BLX r10
; jump to main()
...
====================================================
The _c_int00 solution:
====================================================
Entry:
LDR r0, _stackptr
MSR cpsr_c, #MODE_UND|I_F_BIT
MOV sp,r0
SUB r0, r0, #UND_STACK_SIZE
; setup ABT, FIQ, IRQ, SVC, USR/SYS
...
LDR r0, __c_int00
BX r0
====================================================