📄 cstartup.s
字号:
;------------------------------------------------------------------------------
;- ATMEL Microcontroller Software Support - ROUSSET -
;------------------------------------------------------------------------------
; The software is delivered "AS IS" without warranty or condition of any
; kind, either express, implied or statutory. This includes without
; limitation any warranty or condition with respect to merchantability or
; fitness for any particular purpose, or against the infringements of
; intellectual property rights of others.
;-----------------------------------------------------------------------------
;- File source : Cstartup.arm
;- Object : Generic CStartup for ARM ADS 1.2 and SAM7
;- Compilation flag : None
;-
;- 1.0 12/Jul/04 JPP : Creation
;- 1.1 10/Sep/04 JPP : Change Irq Managment
;- 1.1 01/Apr/05 JPP : save SPSR
;------------------------------------------------------------------------------
;--------------------------------
;- ARM Core Mode and Status Bits
;--------------------------------
ARM_MODE_USER EQU 0x10
ARM_MODE_FIQ EQU 0x11
ARM_MODE_IRQ EQU 0x12
ARM_MODE_SVC EQU 0x13
ARM_MODE_ABORT EQU 0x17
ARM_MODE_UNDEF EQU 0x1B
ARM_MODE_SYS EQU 0x1F
I_BIT EQU 0x80
F_BIT EQU 0x40
T_BIT EQU 0x20
AT91C_BASE_AIC EQU 0xFFFFF000
AIC_FVR EQU 0x00000104
AIC_IVR EQU 0x00000100
AIC_EOICR EQU 0x00000130
;------------------------------------------------------------------------------
;- Area Definition
;------------------------------------------------------------------------------
AREA Reset, CODE, READONLY
ENTRY
EXPORT entry
entry
;------------------------------------------------------------------------------
;- Exception vectors
;--------------------
;- These vectors can be read at address 0 or at RAM address
;- They ABSOLUTELY requires to be in relative addresssing mode in order to
;- guarantee a valid jump. For the moment, all are just looping.
;- If an exception occurs before remap, this would result in an infinite loop.
;- To ensure if a exeption occurs before start application to infinite loop.
;------------------------------------------------------------------------------
B InitReset ; 0x00 Reset handler
Undefvec
B Undefvec ; 0x04 Undefined Instruction
Swivec
B Swivec ; 0x08 Software Interrupt
Pabtvec
B Pabtvec ; 0x0C Prefetch Abort
Dabtvec
B Dabtvec ; 0x10 Data Abort
Rsvdvec
B Rsvdvec ; 0x14 reserved
Irqvec
B IRQ_Handler_Entry ; 0x18 IRQ
Fiqvec ; 0x1c FIQ
;------------------------------------------------------------------------------
;- Function : FIQ_Handler_Entry
;- Treatments : FIQ Controller Interrupt Handler.
;- Called Functions : AIC_FVR[interrupt]
;------------------------------------------------------------------------------
FIQ_Handler_Entry
;- Switch in SVC/User Mode to allow User Stack access for C code
; because the FIQ is not yet acknowledged
;- Save and r0 in FIQ_Register
MOV R9,R0
LDR R0 , [R8, #AIC_FVR]
MSR CPSR_c,#I_BIT :OR: F_BIT :OR: ARM_MODE_SVC
;- Save scratch/used registers and LR in User Stack
STMFD SP!, { R1-R3, R12, LR}
;- Branch to the routine pointed by the AIC_FVR
MOV R14, PC
BX R0
;- Restore scratch/used registers and LR from User Stack
LDMIA SP!, { R1-R3, R12, LR}
;- Leave Interrupts disabled and switch back in FIQ mode
MSR CPSR_c, #I_BIT :OR: F_BIT :OR: ARM_MODE_FIQ
;- Restore the R0 ARM_MODE_SVC register
MOV R0,R9
;- Restore the Program Counter using the LR_fiq directly in the PC
SUBS PC,LR,#4
;--------------------
;- The Reset handler
;--------------------
InitReset
;------------------------------------------------------------------------------
;- Low level Init (APMC, AIC, EBI, ....) by C function AT91F_LowLevelInit
;------------------------------------------------------------------------------
IMPORT AT91F_LowLevelInit
;- minimum C initialization
LDR R13,=0x00204000 ; temporary stack in internal Ram
LDR R0,=AT91F_LowLevelInit
MOV LR, PC
BX R0
;------------------------------------------------------------------------------
;- Stack Sizes Definition
;------------------------
;- Interrupt Stack requires 2 words x 8 priority level x 4 bytes when using
;- the vectoring. This assume that the IRQ_ENTRY/IRQ_EXIT macro are used.
;- The Interrupt Stack must be adjusted depending on the interrupt handlers.
;- Fast Interrupt not requires stack If in your application it required you must
;- be define here.
;- Other stacks are defined by default to save one word each.
;- The System stack size is not defined and is limited by the free internal
;- SRAM.
;- User stack size is not defined and is limited by the free external SRAM.
;------------------------------------------------------------------------------
IRQ_STACK_SIZE EQU (3*8*4) ; 2 words per interrupt priority level
;------------------------------------------------------------------------------
;- Setup the stack for each mode
;-------------------------------
LDR R0, =0x00204000
;- Set up Fast Interrupt Mode and set FIQ Mode Stack
MSR CPSR_c, #ARM_MODE_FIQ:OR:I_BIT:OR:F_BIT
;- Init the FIQ register
LDR R8, =AT91C_BASE_AIC
;- Set up Interrupt Mode and set IRQ Mode Stack
MSR CPSR_c, #ARM_MODE_IRQ:OR:I_BIT:OR:F_BIT
MOV R13, r0 ; Init stack IRQ
sub r0, R0, #IRQ_STACK_SIZE
;- Set up Supervisor Mode and set Supervisor Mode Stack
MSR CPSR_c, #ARM_MODE_SVC
MOV R13, R0 ; Init stack Sup
;------------------------------------------------------------------------------
;- Branch on C code Main function (with interworking)
;----------------------------------------------------
;- Branch must be performed by an interworking call as either an ARM or Thumb
;- main C function must be supported. This makes the code not position-
;- independent. A Branch with link would generate errors
;------------------------------------------------------------------------------
IMPORT __main
LDR R0, =__main
MOV LR, PC
BX R0
;------------------------------------------------------------------------------
;- Loop for ever
;---------------
;- End of application. Normally, never occur.
;- Could jump on Software Reset ( B 0x0 ).
;------------------------------------------------------------------------------
End
B End
;------------------------------------------------------------------------------
;- Manage exception
;---------------
;- This module The exception must be ensure in ARM mode
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;- Function : IRQ_Handler_Entry
;- Treatments : IRQ Controller Interrupt Handler.
;- Called Functions : AIC_IVR[interrupt]
;------------------------------------------------------------------------------
IRQ_Handler_Entry
;- Manage Exception Entry
;- Adjust and save LR_irq in IRQ stack
SUB LR, LR, #4
STMFD SP!, {LR}
;- Save SPSR need to be saved for nested interrupt
MRS R14, SPSR
STMFD SP!, {R14}
;- Save and r0 in IRQ stack
STMFD SP!, {R0}
;- Write in the IVR to support Protect Mode
;- No effect in Normal Mode
;- De-assert the NIRQ and clear the source in Protect Mode
LDR R14, =AT91C_BASE_AIC
LDR R0 , [R14, #AIC_IVR]
STR R14, [R14, #AIC_IVR]
;- Enable Interrupt and Switch in Supervisor Mode
MSR CPSR_c, #ARM_MODE_SVC
;- Save scratch/used registers and LR in User Stack
STMFD SP!, { R1-R3, R12, R14}
;- Branch to the routine pointed by the AIC_IVR
MOV R14, PC
BX R0
;- Restore scratch/used registers and LR from User Stack
LDMIA SP!, { R1-R3, R12, R14}
;- Disable Interrupt and switch back in IRQ mode
MSR CPSR_c, #I_BIT :OR: ARM_MODE_IRQ
;- Mark the End of Interrupt on the AIC
LDR R14, =AT91C_BASE_AIC
STR R14, [R14, #AIC_EOICR]
;- Restore SPSR_irq and r0 from IRQ stack
LDMIA SP!, {R0}
;- Restore SPSR_irq and r0 from IRQ stack
LDMIA SP!, {R14}
MSR SPSR_cxsf, R14
;- Restore adjusted LR_irq from IRQ stack directly in the PC
LDMIA SP!, {PC}^
;------------------------------------------------------------------------------
;- Manage exception
;---------------
;- The exception must be ensure in ARM mode
;------------------------------------------------------------------------------
EXPORT AT91F_Default_FIQ_handler
AT91F_Default_FIQ_handler
B AT91F_Default_FIQ_handler
EXPORT AT91F_Default_IRQ_handler
AT91F_Default_IRQ_handler
B AT91F_Default_IRQ_handler
EXPORT AT91F_Spurious_handler
AT91F_Spurious_handler
B AT91F_Spurious_handler
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -