📄 startup.s
字号:
;/******************************************************************************************************
;** File name: Startup.s
;** Descriptions: The start up codes for LPC2200, including the initializing codes for the entry
; point of exceptions and the stacks of user tasks.Every project should have a
; independent copy of this file for related modifications.
;********************************************************************************************************/
;define the stack size
;定义堆栈的大小,根据需要改变
SVC_STACK_LEGTH EQU 0
FIQ_STACK_LEGTH EQU 0
IRQ_STACK_LEGTH EQU 256
ABT_STACK_LEGTH EQU 0
UND_STACK_LEGTH EQU 0
;用于置位程序状态寄存器的I位(IRQ中断屏蔽位)
NoInt EQU 0x80 ;Bit7,I位
USR32Mode EQU 0x10 ;M[4:0]=10000,用户模式
SVC32Mode EQU 0x13 ;M[4:0]=10011,管理模式
SYS32Mode EQU 0x1f ;M[4:0]=1ffff,系统模式
IRQ32Mode EQU 0x12 ;M[4:0]=10010,IRQ中断模式
FIQ32Mode EQU 0x11 ;M[4:0]=10001,快速中断模式
PINSEL2 EQU 0xE002C014
BCFG0 EQU 0xFFE00000
BCFG1 EQU 0xFFE00004
BCFG2 EQU 0xFFE00008
BCFG3 EQU 0xFFE0000C
IMPORT __use_no_semihosting_swi
IMPORT __use_two_region_memory
;The imported labels
;引入的外部标号在这声明
IMPORT FIQ_Exception ;Fast interrupt exceptions handler 快速中断异常处理程序
IMPORT __main ;The entry point to the main function C语言主程序入口
IMPORT TargetResetInit ;initialize the target board 目标板基本初始化,在Target.c中
;The exported labels
;给外部使用的标号在这声明
EXPORT bottom_of_heap
EXPORT bottom_of_Stacks
EXPORT top_of_heap
EXPORT StackUsr
EXPORT Reset
EXPORT __user_initial_stackheap
;以下为异常向量表,声明代码段vectors
CODE32
AREA vectors,CODE,READONLY
ENTRY
;interrupt vectors
;中断向量表
Reset
LDR PC, ResetAddr ;0x00,复位
LDR PC, UndefinedAddr ;0x04,未定义地址
LDR PC, SWI_Addr ;0x08,软件中断
LDR PC, PrefetchAddr ;0x0C,预取指中止
LDR PC, DataAbortAddr ;0x10,数据中止
DCD 0xb9205f80 ;0x14,保留,
LDR PC, [PC, #-0xff0] ;0x18,IRQ中断
LDR PC, FIQ_Addr ;0x1C,快速中断
ResetAddr DCD ResetInit ;复位初始化处理程序地址
UndefinedAddr DCD Undefined ;未定义指令处理程序地址
SWI_Addr DCD SoftwareInterrupt ;软件中断处理程序地址
PrefetchAddr DCD PrefetchAbort ;预取指中止处理程序地址
DataAbortAddr DCD DataAbort ;数据中止处理程序地址
Nouse DCD 0 ;未使用
IRQ_Addr DCD 0 ;IRQ中断,已在LDR PC, [PC, #-0xff0]中处理
FIQ_Addr DCD FIQ_Handler ;快速中断处理程序地址
;异常向量表结束
;未定义指令
Undefined
B Undefined ;死循环
;软中断
SoftwareInterrupt
B SoftwareInterrupt ;死循环
;取指令中止
PrefetchAbort
B PrefetchAbort ;死循环
;取数据中止
DataAbort
B DataAbort ;死循环
;快速中断
FIQ_Handler
STMFD SP!, {R0-R3, LR} ;寄存器R0~R3,LR入栈
BL FIQ_Exception ;调用FIQ处理程序(在Target.c中)
LDMFD SP!, {R0-R3, LR} ;寄存器R0~R3,LR出栈
SUBS PC, LR, #4 ;计算返回地址
;/*********************************************************************************************************
;** unction name 函数名称: InitStack
;** Descriptions 功能描述: Initialize the stacks 初始化堆栈,此时禁止IRQ(I=1)、禁止FIQ(F=1)、ARM状态(T=0)
;** input parameters 输 入: None 无
;** Returned value 输 出 : None 无
;** Used global variables 全局变量: None 无
;** Calling modules 调用模块: None 无
;********************************************************************************************************/
InitStack
MOV R0, LR
;Build the SVC stack
;设置管理模式堆栈
MSR CPSR_c, #0xd3
LDR SP, StackSvc
;Build the IRQ stack
;设置中断模式堆栈
MSR CPSR_c, #0xd2
LDR SP, StackIrq
;Build the FIQ stack
;设置快速中断模式堆栈
MSR CPSR_c, #0xd1
LDR SP, StackFiq
;Build the DATAABORT stack
;设置中止模式堆栈
MSR CPSR_c, #0xd7
LDR SP, StackAbt
;Build the UDF stack
;设置未定义模式堆栈
MSR CPSR_c, #0xdb
LDR SP, StackUnd
;Build the SYS stack
;设置系统模式堆栈
MSR CPSR_c, #0xdf ;切换到系统模式,之后将在系统模式下运行
LDR SP, =StackUsr ;除非进行模式切换
MOV PC, R0
;/*********************************************************************************************************
;** unction name 函数名称: ResetInit
;** Descriptions 功能描述: RESET 复位入口
;** input parameters 输 入: None 无
;** Returned value 输 出 : None 无
;** Used global variables 全局变量: None 无
;** Calling modules 调用模块: None 无
;********************************************************************************************************/
ResetInit
;Initial extenal bus controller.
;初始化外部总线控制器,根据目标板决定配置
LDR R0, =PINSEL2
IF :DEF: EN_CRP
LDR R1, =0x0f814910
ELSE
LDR R1, =0x0f814914
ENDIF
STR R1, [R0]
LDR R0, =BCFG0
LDR R1, =0x1000ffef
STR R1, [R0]
LDR R0, =BCFG1
LDR R1, =0x1000ffef
STR R1, [R0]
; LDR R0, =BCFG2
; LDR R1, =0x2000ffef
; STR R1, [R0]
; LDR R0, =BCFG3
; LDR R1, =0x2000ffef
; STR R1, [R0]
BL InitStack ;初始化堆栈 Initialize the stack
BL TargetResetInit ;目标板基本初始化 Initialize the target board
;跳转到c语言入口 Jump to the entry point of C program
B __main
;/*********************************************************************************************************
;** unction name 函数名称: __user_initial_stackheap
;** Descriptions 功能描述: Initial the function library stacks and heaps, can not deleted! 库函数初始化堆和栈,不能删除
;** input parameters 输 入: reference by function library 参考库函数手册
;** Returned value 输 出 : reference by function library 参考库函数手册
;** Used global variables 全局变量: None 无
;** Calling modules 调用模块: None 无
;********************************************************************************************************/
__user_initial_stackheap
LDR r0,=bottom_of_heap
; LDR r1,=StackUsr
LDR r2,=top_of_heap
LDR r3,=bottom_of_Stacks
MOV pc,lr
StackSvc DCD SvcStackSpace + (SVC_STACK_LEGTH - 1)* 4
StackIrq DCD IrqStackSpace + (IRQ_STACK_LEGTH - 1)* 4
StackFiq DCD FiqStackSpace + (FIQ_STACK_LEGTH - 1)* 4
StackAbt DCD AbtStackSpace + (ABT_STACK_LEGTH - 1)* 4
StackUnd DCD UndtStackSpace + (UND_STACK_LEGTH - 1)* 4
;/*********************************************************************************************************
;** unction name 函数名称: CrpData
;** Descriptions 功能描述: encrypt the chip
;** input parameters 输 入: None 无
;** Returned value 输 出 : None 无
;** Used global variables 全局变量: None 无
;** Calling modules 调用模块: None 无
;********************************************************************************************************/
;芯片加密
IF :DEF: EN_CRP
IF . >= 0x1fc
INFO 1,"\nThe data at 0x000001fc must be 0x87654321.\nPlease delete some source before this line."
ENDIF
CrpData
WHILE . < 0x1fc
NOP ;/*循环用NOP填充,直到0x1FC*/
WEND
CrpData1
DCD 0x87654321 ;/*When the Data is 为0x87654321,user code be protected. 当此数为0x87654321时,用户程序被保护 */
ENDIF
;/* 分配堆栈空间 */
AREA MyStacks, DATA, NOINIT, ALIGN=2 ;MyStacks通过分散加载文件定位
SvcStackSpace SPACE SVC_STACK_LEGTH * 4 ;Stack spaces for Administration Mode 管理模式堆栈空间
IrqStackSpace SPACE IRQ_STACK_LEGTH * 4 ;Stack spaces for Interrupt ReQuest Mode 中断模式堆栈空间
FiqStackSpace SPACE FIQ_STACK_LEGTH * 4 ;Stack spaces for Fast Interrupt reQuest Mode 快速中断模式堆栈空间
AbtStackSpace SPACE ABT_STACK_LEGTH * 4 ;Stack spaces for Suspend Mode 中止义模式堆栈空间
UndtStackSpace SPACE UND_STACK_LEGTH * 4 ;Stack spaces for Undefined Mode 未定义模式堆栈
AREA Heap, DATA, NOINIT ;Heap通过分散加载文件定位
bottom_of_heap SPACE 1
AREA StackBottom, DATA, NOINIT
bottom_of_Stacks SPACE 1
AREA HeapTop, DATA, NOINIT
top_of_heap
AREA Stacks, DATA, NOINIT ;Stacks通过分散加载文件定位
StackUsr
END
;/*********************************************************************************************************
;** End Of File
;********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -