这个文件相当于RTS库里的_c_int00,初始化各种模式的stack,然后切换到system mode,再clear BSS段,跳转到main。这里没有对cinit段的初始化,可能是因为这个原始工程本身没有初始化的全局变量,所以没做这一步。
有兴趣可以对比一下编译器带的boot.asm文件的_c_int00函数,它在初始化stack后调用了__TI_auto_init初始化cinit段再跳到main。
对于自己的工程除非在系统初始化阶段有什么特殊要求,而且了解初始化要做什么样的处理,否则就用编译器自带的RTS库的入口函数吧。
Entry:
;
; Set up the Stack for Undefined mode
;
LDR r0, _stackptr ; Read the stack address
MSR cpsr_c, #MODE_UND|I_F_BIT ; switch to undef mode
MOV sp,r0 ; write the stack pointer
SUB r0, r0, #UND_STACK_SIZE ; give stack space
;
; Set up the Stack for abort mode
;
MSR cpsr_c, #MODE_ABT|I_F_BIT ; Change to abort mode
MOV sp, r0 ; write the stack pointer
SUB r0,r0, #ABT_STACK_SIZE ; give stack space
;
; Set up the Stack for FIQ mode
;
MSR cpsr_c, #MODE_FIQ|I_F_BIT ; change to FIQ mode
MOV sp,r0 ; write the stack pointer
SUB r0,r0, #FIQ_STACK_SIZE ; give stack space
;
; Set up the Stack for IRQ mode
;
MSR cpsr_c, #MODE_IRQ|I_F_BIT ; change to IRQ mode
MOV sp,r0 ; write the stack pointer
SUB r0,r0, #IRQ_STACK_SIZE ; give stack space
;
; Set up the Stack for SVC mode
;
MSR cpsr_c, #MODE_SVC|I_F_BIT ; change to SVC mode
MOV sp,r0 ; write the stack pointer
SUB r0,r0, #SVC_STACK_SIZE ; give stack space
;
; Set up the Stack for USer/System mode
;
MSR cpsr_c, #MODE_SYS|I_F_BIT ; change to system mode
MOV sp,r0 ; write the stack pointer
;
; Clear the BSS section here
;
Clear_Bss_Section:
LDR r0, _bss_start ; Start address of BSS
LDR r1, _bss_end ; End address of BSS
SUB r1,r1,#4
MOV r2, #0
Loop:
STR r2, [r0], #4 ; Clear one word in BSS
CMP r0, r1
BLE Loop ; Clear till BSS end
;
; Enter the start_boot function. The execution still happens in system mode
;
LDR r10, _main ; Get the address of main
MOV lr,pc ; Dummy return to main
BX r10 ; Branch to main
SUB pc, pc, #0x08 ; looping