ProcessorInit
;
; Copy the code image from flash to SRAM.
;
movs r0, #0x0000
movs r1, #0x0000
movt r1, #0x2000--->movt把0x2000放到r1的高16bit
import ||Image$$SRAM$$ZI$$Base||--->.BSS段的开始地址
ldr r2, =||Image$$SRAM$$ZI$$Base||
copy_loop
ldr r3, [r0], #4
str r3, [r1], #4
cmp r1, r2
blt copy_loop
;
; Zero fill the .bss section.
;
movs r0, #0x0000
import ||Image$$SRAM$$ZI$$Limit||
ldr r2, =||Image$$SRAM$$ZI$$Limit||
zero_loop
str r0, [r1], #4
cmp r1, r2
blt zero_loop
;
; Set the vector table pointer to the beginning of SRAM.
;
movw r0, #(NVIC_VTABLE & 0xffff)
movt r0, #(NVIC_VTABLE >> 16)
movs r1, #0x0000
movt r1, #0x2000
str r1, [r0]
;
; Set the return address to the code just copied into SRAM.
;
//此刻lr寄存器中已经存放了返回地址
// 此操作为lr=lr+SRAM address,所以程序直接返回到SRAM中继续运行
orr lr, lr, #0x20000000
;
; Return to the caller.
;
bx lr
;******************************************************************************
;
; The reset handler, which gets called when the processor starts.
;
;******************************************************************************
export Reset_Handler
程序是从这里开始的
Reset_Handler
;
; Initialize the processor.
;
//bl指令会把下条指令的地址存放到lr寄存器中
bl ProcessorInit
//程序运行到这里已经被拷贝到SRAM中了
;
; Call the user-supplied low level hardware initialization function
; if provided.
;
if :def:_BL_HW_INIT_FN_HOOK
import $_BL_HW_INIT_FN_HOOK
bl $_BL_HW_INIT_FN_HOOK
endif
;
; See if an update should be performed.
;
import CheckForceUpdate
bl CheckForceUpdate
//r0保存CheckForceUpdate函数的返回值
//如果为0表示启动APP程序
cbz r0, CallApplication
CallApplication
;
; Copy the application's vector table to the target address if necessary.
; Note that incorrect boot loader configuration could cause this to
; corrupt the code! Setting VTABLE_START_ADDRESS to 0x20000000 (the start
; of SRAM) is safe since this will use the same memory that the boot loader
; already uses for its vector table. Great care will have to be taken if
; other addresses are to be used.
;
//把APP的VTABLE拷贝到指定addr
//一般来说_APP_START_ADDRESS == _VTABLE_START_ADDRESS==0x1000=4K
//一般来说程序的开始是VTABLE表,所以程序开始地址肯定是VTABLE地址
//处理不相等的情况
//把APP开始处得VTABLE拷贝到指定地址
if (_APP_START_ADDRESS != _VTABLE_START_ADDRESS)
movw r0, #(_VTABLE_START_ADDRESS & 0xffff)
if (_VTABLE_START_ADDRESS > 0xffff)
movt r0, #(_VTABLE_START_ADDRESS >> 16)
endif
movw r1, #(_APP_START_ADDRESS & 0xffff)
if (_APP_START_ADDRESS > 0xffff)
movt r1, #(_APP_START_ADDRESS >> 16)
endif
;
; Calculate the end add