##-----------------------------------------------------------------------------
## Hardware supplied vectors
.set noreorder
.section ".reset_vector","ax"
# Reset vector at 0xBFC00000
>>cpu从这里开始执行
FUNC_START(reset_vector)
>>cpu vendor 添加一些初始化,比如一些clock,reset;
>>在CYG_HAL_STARTUP_RAM不需要,因为在_ROMRAM,_ROM才需要
#ifndef CYG_HAL_STARTUP_RAM
# if defined(CYGPKG_HAL_RESET_VECTOR_FIRST_CODE)
hal_reset_vector_first_code
# endif
# if defined(CYGPKG_HAL_EARLY_INIT)
hal_early_init
# endif
# Decide whether this is an NMI, cold or warm boot.
>>这里英文注释已经很清楚了
mfc0 k0,status # get status reg
lui k1,0x0008 # isolate NMI bit
and k1,k1,k0
beqz k1,1f # skip if zero
nop
lar k1,__nmi_entry # jump to ROM nmi code
jalr k1
nop
1:
lui k1,0x0010 # isolate soft reset bit
and k1,k1,k0
beqz k1,2f # skip if zero
nop
lar k1,__warm_start # jump to ROM warm_start code
jr k1
nop
2:
la k0,INITIAL_CONFIG0 # Set up config0 register
mtc0 k0,config0 # to disable cache
#endif
lar v0,_start # jump to start
#ifdef CYGARC_START_FUNC_UNCACHED
CYGARC_ADDRESS_REG_UNCACHED(v0)
#endif
jr v0
nop # (delay slot)
FUNC_END(reset_vector)
>>这里几个*_vector是mips exception 的入口,详细的去看mips的书籍
>>值得提出的是,这几个位置会被前面的code比如hal_reset_vector_first_code
>>挤出正确的位置,不过后面还会有些code会把这些*_vector复制到ram里的相应的位置
>>只要保证在code切换到ram exception mode之前,不要产生任何exception就可以了
.section ".debug_vector","ax"
# Debug vector at 0xBFC00200
FUNC_START(debug_vector)
la k0,32*4
la k1,hal_vsr_table # Get VSR table
lw k1,32*4(k1) # load debug vector
jr k1 # go there
nop # (delay slot)
FUNC_END(debug_vector)
.section ".other_vector","ax"
# Common vector at 0x80000080 or 0xBFC00180
FUNC_START(other_vector)
mfc0 k0,cause # K0 = exception cause
nop
andi k0,k0,0x7F # isolate exception code
la k1,hal_vsr_table # address of VSR table
add k1,k1,k0 # offset of VSR entry
lw k1,0(k1) # k1 = pointer to VSR
jr k1 # go there
nop # (delay slot)
FUNC_END(other_vector)
.section ".utlb_vector","ax"
FUNC_START(utlb_vector)
mfc0 k0,cause # K0 = exception cause
nop
andi k0,k0,0x7F # isolate exception code
la k1,hal_vsr_table # address of VSR table
add k1,k1,k0 # offset of VSR entry
lw k1,0(k1) # k1 = pointer to VSR
jr k1 # go there
nop # (delay slot)
FUNC_END(utlb_vector)
##-----------------------------------------------------------------------------
## Startup code
.text
FUNC_START(_start)
# Initialize hardware
>>cpu core 初始化
hal_cpu_init
hal_diag_init
hal_mmu_init
hal_fpu_init
>>如果是_ROMRAM类型,在hal_memc_init里会把text段复制到ram
hal_memc_init
hal_intc_init
hal_cache_init
hal_timer_init
#if 0
## Spin to allow ejtag gdb to attach
1:
li t0, 1
bnez t0, 1b
nop
#endif
#ifdef CYG_HAL_STARTUP_RAM
hal_serial_init
#endif
#ifdef CYGARC_START_FUNC_UNCACHED
# switch to cached execution address if necessary
# assumption is that hal_cache_init makes this safe
lar v0,1f
jr v0
nop
1:
#endif
# Load Global Pointer register.
la gp,_gp
# load initial stack pointer
la a0,__interrupt_stack
move sp,a0
>>填充hal_vsr_table里面的内容
hal_mon_init
#ifdef CYG_HAL_STARTUP_ROM
# Copy data from ROM to RAM
>>复制data段
.extern hal_copy_data
jal hal_copy_data
nop
#endif
# Zero BSS
>>清除bss段
.extern hal_zero_bss
jal hal_zero_bss
nop
# Call variant and platform HAL
# initialization routines.
.extern hal_variant_init
jal hal_variant_init
nop
>>平台上的初始化,比如GPIO
.extern hal_platform_init
jal hal_platform_init
nop
>>调用c++ 类的初始化函数
# Call constructors
.extern cyg_hal_invoke_constructors
jal cyg_hal_invoke_constructors
nop
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
.extern initialize_stub
jal initialize_stub
nop
#endif
#if defined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT)
.extern hal_ctrlc_isr_init
jal hal_ctrlc_isr_init
nop
#endif
# Call cyg_start
>>进入主程序
.extern cyg_start
j cyg_start
lui ra,0
FUNC_END(_start )
## Hardware supplied vectors
.set noreorder
.section ".reset_vector","ax"
# Reset vector at 0xBFC00000
>>cpu从这里开始执行
FUNC_START(reset_vector)
>>cpu vendor 添加一些初始化,比如一些clock,reset;
>>在CYG_HAL_STARTUP_RAM不需要,因为在_ROMRAM,_ROM才需要
#ifndef CYG_HAL_STARTUP_RAM
# if defined(CYGPKG_HAL_RESET_VECTOR_FIRST_CODE)
hal_reset_vector_first_code
# endif
# if defined(CYGPKG_HAL_EARLY_INIT)
hal_early_init
# endif
# Decide whether this is an NMI, cold or warm boot.
>>这里英文注释已经很清楚了
mfc0 k0,status # get status reg
lui k1,0x0008 # isolate NMI bit
and k1,k1,k0
beqz k1,1f # skip if zero
nop
lar k1,__nmi_entry # jump to ROM nmi code
jalr k1
nop
1:
lui k1,0x0010 # isolate soft reset bit
and k1,k1,k0
beqz k1,2f # skip if zero
nop
lar k1,__warm_start # jump to ROM warm_start code
jr k1
nop
2:
la k0,INITIAL_CONFIG0 # Set up config0 register
mtc0 k0,config0 # to disable cache
#endif
lar v0,_start # jump to start
#ifdef CYGARC_START_FUNC_UNCACHED
CYGARC_ADDRESS_REG_UNCACHED(v0)
#endif
jr v0
nop # (delay slot)
FUNC_END(reset_vector)
>>这里几个*_vector是mips exception 的入口,详细的去看mips的书籍
>>值得提出的是,这几个位置会被前面的code比如hal_reset_vector_first_code
>>挤出正确的位置,不过后面还会有些code会把这些*_vector复制到ram里的相应的位置
>>只要保证在code切换到ram exception mode之前,不要产生任何exception就可以了
.section ".debug_vector","ax"
# Debug vector at 0xBFC00200
FUNC_START(debug_vector)
la k0,32*4
la k1,hal_vsr_table # Get VSR table
lw k1,32*4(k1) # load debug vector
jr k1 # go there
nop # (delay slot)
FUNC_END(debug_vector)
.section ".other_vector","ax"
# Common vector at 0x80000080 or 0xBFC00180
FUNC_START(other_vector)
mfc0 k0,cause # K0 = exception cause
nop
andi k0,k0,0x7F # isolate exception code
la k1,hal_vsr_table # address of VSR table
add k1,k1,k0 # offset of VSR entry
lw k1,0(k1) # k1 = pointer to VSR
jr k1 # go there
nop # (delay slot)
FUNC_END(other_vector)
.section ".utlb_vector","ax"
FUNC_START(utlb_vector)
mfc0 k0,cause # K0 = exception cause
nop
andi k0,k0,0x7F # isolate exception code
la k1,hal_vsr_table # address of VSR table
add k1,k1,k0 # offset of VSR entry
lw k1,0(k1) # k1 = pointer to VSR
jr k1 # go there
nop # (delay slot)
FUNC_END(utlb_vector)
##-----------------------------------------------------------------------------
## Startup code
.text
FUNC_START(_start)
# Initialize hardware
>>cpu core 初始化
hal_cpu_init
hal_diag_init
hal_mmu_init
hal_fpu_init
>>如果是_ROMRAM类型,在hal_memc_init里会把text段复制到ram
hal_memc_init
hal_intc_init
hal_cache_init
hal_timer_init
#if 0
## Spin to allow ejtag gdb to attach
1:
li t0, 1
bnez t0, 1b
nop
#endif
#ifdef CYG_HAL_STARTUP_RAM
hal_serial_init
#endif
#ifdef CYGARC_START_FUNC_UNCACHED
# switch to cached execution address if necessary
# assumption is that hal_cache_init makes this safe
lar v0,1f
jr v0
nop
1:
#endif
# Load Global Pointer register.
la gp,_gp
# load initial stack pointer
la a0,__interrupt_stack
move sp,a0
>>填充hal_vsr_table里面的内容
hal_mon_init
#ifdef CYG_HAL_STARTUP_ROM
# Copy data from ROM to RAM
>>复制data段
.extern hal_copy_data
jal hal_copy_data
nop
#endif
# Zero BSS
>>清除bss段
.extern hal_zero_bss
jal hal_zero_bss
nop
# Call variant and platform HAL
# initialization routines.
.extern hal_variant_init
jal hal_variant_init
nop
>>平台上的初始化,比如GPIO
.extern hal_platform_init
jal hal_platform_init
nop
>>调用c++ 类的初始化函数
# Call constructors
.extern cyg_hal_invoke_constructors
jal cyg_hal_invoke_constructors
nop
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
.extern initialize_stub
jal initialize_stub
nop
#endif
#if defined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT)
.extern hal_ctrlc_isr_init
jal hal_ctrlc_isr_init
nop
#endif
# Call cyg_start
>>进入主程序
.extern cyg_start
j cyg_start
lui ra,0
FUNC_END(_start )