Slim the BootLoader of ZLG: Startup.s
;/***************************************************************************** ;定义堆栈大小 ;初始化系统,跳转到C程序接口 ;*****************************************************************************/ SVC_STACK_LENGTH EQU 0 FIQ_STACK_LENGTH EQU 0 IRQ_STACK_LENGTH EQU 256 ABT_STACK_LENGTH EQU 0 UND_STACK_LENGTH EQU 0
NOIRQ EQU 0x80 NOFIQ EQU 0x40 USRMD EQU 0x10 FIQMD EQU 0x11 IRQMD EQU 0x12 SVCMD EQU 0x13 ABTMD EQU 0x17 NDEFMD EQU 0x1b OSMD EQU 0x1f
;引入要调用的全局变量或函数 IMPORT __use_no_semihosting_swi IMPORT __main IMPORT TargetINI IMPORT FIQFunction
EXPORT __user_initial_stackheap EXPORT UsrStack EXPORT Reset EXPORT bottom_of_heap
CODE32 AREA vectors, CODE, READONLY ENTRY
;中断向量表 Reset B RST_Handler B Undef_Handler B SWI_Handler B PreABT_Handler B DABT_Handler DCD 0xb9295f80 LDR PC, [PC,#-0xff0] ;PC=0x20,PC-0xff0=0xfffff030 B FIQ_Handler ;既是IRQ中断的寄存器地址,加载PC ;RSTadr DCD RST_Handler ;Undefadr DCD Undef_Handler ;SWIadr DCD SWI_Handler ;PreABTadr DCD PreABT_Handler ;DABTadr DCD DABT_Handler ;FIQadr DCD FIQ_Handler RST_Handler BL StackINI ;初始化系统堆栈分配 BL TargetINI ;跳转C语言目标板初始化函数 B __main ;跳转到C语言main函数 Undef_Handler B Undef_Handler SWI_Handler CMP R0, #4 ;判断软件中断的类型号,实现跳转 LDRLO PC, [PC, R0, LSL#2] MOVS PC, LR SWIFunction DCD IRQDisable ;软件中断跳转向量表 DCD IRQEnable DCD FIQDisable DCD FIQEnable IRQDisable MRS R0, SPSR ORR R0, R0, #NOIRQ MSR SPSR_c, R0 MOVS PC, LR IRQEnable MRS R0, SPSR BIC R0, R0, #NOIRQ MSR SPSR_c, R0 MOVS PC, LR FIQDisable MRS R0, SPSR ORR R0, R0, #NOFIQ MSR SPSR_c, R0 MOVS PC, LR FIQEnable MRS R0, SPSR BIC R0, R0, #NOFIQ MSR SPSR_c, R0 MOVS PC, LR PreABT_Handler B PreABT_Handler DABT_Handler B DABT_Handler ;快速中断跳转处理 FIQ_Handler STMFD SP!, {R0-R3,LR} BL FIQFunction LDMFD SP!, {R0-R3,LR} SUBS PC, LR, #4 StackINI ;设置快速中断堆栈 ;芯片复位后是管理模式,管理模式可以进行处理器模式切换 ;但不适合运行程序,必须在用户/系统模式下运行程序, ;保存堆栈初始化子程序,因为此时的LR是管理模式下的LR MOV R0, LR MSR CPSR_c, #0xd1 LDR SP, Stack_fiq ;设置IRQ中断堆栈 MSR CPSR_c, #0xd2 LDR SP, Stack_irq MSR CPSR_c, #0xd3 LDR SP, Stack_svc MSR CPSR_c, #0xd7 LDR SP, Stack_abt MSR CPSR_c, #0xdb LDR SP, Stack_und MSR CPSR_c, #0xdf LDR SP, =UsrStack ;返回 MOV PC, R0 ;加载返回地址
;设置堆栈起始地址和长度 ;R0--HEAP BASE R1--STACK BASE ;R2--HEAP LENGTH R3--STACK LENGTH __user_initial_stackheap LDR R0, =bottom_of_heap MOV PC, LR
;定义堆栈空间大小 Stack_svc DCD SvcSpace + (SVC_STACK_LENGTH-1)*4 Stack_fiq DCD FiqSpace + (FIQ_STACK_LENGTH-1)*4 Stack_irq DCD IrqSpace + (IRQ_STACK_LENGTH-1)*4 Stack_abt DCD AbtSpace + (ABT_STACK_LENGTH-1)*4 Stack_und DCD UndSpace + (UND_STACK_LENGTH-1)*4 AREA mystack, DATA, NOINIT, ALIGN=2 ;分配堆栈空间 SvcSpace SPACE SVC_STACK_LENGTH*4 FiqSpace SPACE FIQ_STACK_LENGTH*4 IrqSpace SPACE IRQ_STACK_LENGTH*4 AbtSpace SPACE ABT_STACK_LENGTH*4 UndSpace SPACE UND_STACK_LENGTH*4
;定义堆的RAM空间 AREA HEAP, DATA, NOINIT bottom_of_heap SPACE 1
;定义栈的RAM空间 AREA STACKS, DATA, NOINIT UsrStack
END |