1 ;* ----------------------------------------------------------------------------
2 ;* ATMEL Microcontroller Software Support - ROUSSET -
3 ;* ----------------------------------------------------------------------------
4 ;* Copyright (c) 2006, Atmel Corporation
6 ;* All rights reserved.
8 ;* Redistribution and use in source and binary forms, with or without
9 ;* modification, are permitted provided that the following conditions are met:
11 ;* - Redistributions of source code must retain the above copyright notice,
12 ;* this list of conditions and the disclaimer below.
14 ;* - Redistributions in binary form must reproduce the above copyright notice,
15 ;* this list of conditions and the disclaimer below in the documentation and/or
16 ;* other materials provided with the distribution.
18 ;* Atmel's name may not be used to endorse or promote products derived from
19 ;* this software without specific prior written permission.
21 ;* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
22 ;* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 ;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
24 ;* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ;* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 ;* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 ;* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 ;* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 ;* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 ;* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ;* ----------------------------------------------------------------------------
33 ;------------------------------------------------------------------------------
34 ; Include your AT91 Library files
35 ;------------------------------------------------------------------------------
36 #include "AT91SAM7X256_inc.h"
37 ;------------------------------------------------------------------------------
39 #define TOP_OF_MEMORY (AT91C_ISRAM + AT91C_ISRAM_SIZE)
40 #define IRQ_STACK_SIZE 200
41 ; 3 words to be saved per interrupt priority level
43 ; Mode, correspords to bits 0-5 in CPSR
44 MODE_BITS DEFINE 0x1F ; Bit mask for mode bits in CPSR
45 USR_MODE DEFINE 0x10 ; User mode
46 FIQ_MODE DEFINE 0x11 ; Fast Interrupt Request mode
47 IRQ_MODE DEFINE 0x12 ; Interrupt Request mode
48 SVC_MODE DEFINE 0x13 ; Supervisor mode
49 ABT_MODE DEFINE 0x17 ; Abort mode
50 UND_MODE DEFINE 0x1B ; Undefined Instruction mode
51 SYS_MODE DEFINE 0x1F ; System mode
56 ;------------------------------------------------------------------------------
59 ; Normally, segment INTVEC is linked at address 0.
60 ; For debugging purposes, INTVEC may be placed at other addresses.
61 ; A debugger that honors the entry point will start the
62 ; program in a normal way even if INTVEC is not at address 0.
63 ;------------------------------------------------------------------------------
64 SECTION .intvec:CODE:NOROOT(2)
66 PUBLIC __iar_program_start
67 EXTERN vPortYieldProcessor
71 ldr pc,[pc,#+24] ;; Reset
73 ldr pc,[pc,#+24] ;; Undefined instructions
75 ldr pc,[pc,#+24] ;; Software interrupt (SWI/SVC)
77 ldr pc,[pc,#+24] ;; Prefetch abort
79 ldr pc,[pc,#+24] ;; Data abort
80 DC32 0xFFFFFFFF ;; RESERVED
84 ldr pc,[pc,#+24] ;; FIQ
86 DC32 __iar_program_start
88 DC32 vPortYieldProcessor
89 DC32 __prefetch_handler
92 DC32 IRQ_Handler_Entry
93 DC32 FIQ_Handler_Entry
95 ;------------------------------------------------------------------------------
96 ;- Manage exception: The exception must be ensure in ARM mode
97 ;------------------------------------------------------------------------------
98 SECTION text:CODE:NOROOT(2)
100 ;------------------------------------------------------------------------------
101 ;- Function : FIQ_Handler_Entry
102 ;- Treatments : FIQ Controller Interrupt Handler.
103 ;- R8 is initialize in Cstartup
104 ;- Called Functions : None only by FIQ
105 ;------------------------------------------------------------------------------
108 ;- Switch in SVC/User Mode to allow User Stack access for C code
109 ; because the FIQ is not yet acknowledged
111 ;- Save and r0 in FIQ_Register
113 ldr r0 , [r8, #AIC_FVR]
114 msr CPSR_c,#I_BIT | F_BIT | SVC_MODE
115 ;- Save scratch/used registers and LR in User Stack
116 stmfd sp!, { r1-r3, r12, lr}
118 ;- Branch to the routine pointed by the AIC_FVR
122 ;- Restore scratch/used registers and LR from User Stack
123 ldmia sp!, { r1-r3, r12, lr}
125 ;- Leave Interrupts disabled and switch back in FIQ mode
126 msr CPSR_c, #I_BIT | F_BIT | FIQ_MODE
128 ;- Restore the R0 ARM_MODE_SVC register
131 ;- Restore the Program Counter using the LR_fiq directly in the PC
133 ;------------------------------------------------------------------------------
134 ;- Function : IRQ_Handler_Entry
135 ;- Treatments : IRQ Controller Interrupt Handler.
136 ;- Called Functions : AIC_IVR[interrupt]
137 ;------------------------------------------------------------------------------
139 ;-------------------------
140 ;- Manage Exception Entry
141 ;-------------------------
142 ;- Adjust and save LR_irq in IRQ stack
146 ;- Save r0 and SPSR (need to be saved for nested interrupt)
150 ;- Write in the IVR to support Protect Mode
151 ;- No effect in Normal Mode
152 ;- De-assert the NIRQ and clear the source in Protect Mode
153 ldr r14, =AT91C_BASE_AIC
154 ldr r0 , [r14, #AIC_IVR]
155 str r14, [r14, #AIC_IVR]
157 ;- Enable Interrupt and Switch in Supervisor Mode
158 msr CPSR_c, #SVC_MODE
160 ;- Save scratch/used registers and LR in User Stack
161 stmfd sp!, { r1-r3, r12, r14}
163 ;----------------------------------------------
164 ;- Branch to the routine pointed by the AIC_IVR
165 ;----------------------------------------------
169 ;----------------------------------------------
170 ;- Manage Exception Exit
171 ;----------------------------------------------
172 ;- Restore scratch/used registers and LR from User Stack
173 ldmia sp!, { r1-r3, r12, r14}
175 ;- Disable Interrupt and switch back in IRQ mode
176 msr CPSR_c, #I_BIT | IRQ_MODE
178 ;- Mark the End of Interrupt on the AIC
179 ldr r14, =AT91C_BASE_AIC
180 str r14, [r14, #AIC_EOICR]
182 ;- Restore SPSR_irq and r0 from IRQ stack
186 ;- Restore adjusted LR_irq from IRQ stack directly in the PC
189 ;------------------------------------------------------------------------------
191 ;------------------------------------------------------------------------------
192 PUBLIC AT91F_Default_FIQ_handler
193 PUBLIC AT91F_Default_IRQ_handler
194 PUBLIC AT91F_Spurious_handler
196 ARM ; Always ARM mode after exeption
198 AT91F_Default_FIQ_handler
199 b AT91F_Default_FIQ_handler
201 AT91F_Default_IRQ_handler
202 b AT91F_Default_IRQ_handler
204 AT91F_Spurious_handler
205 b AT91F_Spurious_handler
208 ;------------------------------------------------------------------------------
211 ;------------------------------------------------------------------------------
213 SECTION FIQ_STACK:DATA:NOROOT(3)
214 SECTION IRQ_STACK:DATA:NOROOT(3)
215 SECTION SVC_STACK:DATA:NOROOT(3)
216 SECTION ABT_STACK:DATA:NOROOT(3)
217 SECTION UND_STACK:DATA:NOROOT(3)
218 SECTION CSTACK:DATA:NOROOT(3)
219 SECTION text:CODE:NOROOT(2)
222 PUBLIC __iar_program_start
223 EXTERN AT91F_LowLevelInit
228 ;------------------------------------------------------------------------------
229 ;- Low level Init is performed in a C function: AT91F_LowLevelInit
230 ;- Init Stack Pointer to a valid memory area before calling AT91F_LowLevelInit
231 ;------------------------------------------------------------------------------
233 ;- Retrieve end of RAM address
235 ldr r13,=TOP_OF_MEMORY ;- Temporary stack in internal RAM for Low Level Init execution
236 ldr r0,=AT91F_LowLevelInit
238 bx r0 ;- Branch on C function (with interworking)
240 ; Initialize the stack pointers.
241 ; The pattern below can be used for any of the exception stacks:
242 ; FIQ, IRQ, SVC, ABT, UND, SYS.
243 ; The USR mode uses the same stack as SYS.
244 ; The stack segments must be defined in the linker command file,
245 ; and be declared above.
247 mrs r0,cpsr ; Original PSR value
248 bic r0,r0,#MODE_BITS ; Clear the mode bits
249 orr r0,r0,#SVC_MODE ; Set SVC mode bits
250 msr cpsr_c,r0 ; Change the mode
251 ldr sp,=SFE(SVC_STACK) ; End of SVC_STACK
253 bic r0,r0,#MODE_BITS ; Clear the mode bits
254 orr r0,r0,#UND_MODE ; Set UND mode bits
255 msr cpsr_c,r0 ; Change the mode
256 ldr sp,=SFE(UND_STACK) ; End of UND_STACK
258 bic r0,r0,#MODE_BITS ; Clear the mode bits
259 orr r0,r0,#ABT_MODE ; Set ABT mode bits
260 msr cpsr_c,r0 ; Change the mode
261 ldr sp,=SFE(ABT_STACK) ; End of ABT_STACK
263 bic r0,r0,#MODE_BITS ; Clear the mode bits
264 orr r0,r0,#FIQ_MODE ; Set FIQ mode bits
265 msr cpsr_c,r0 ; Change the mode
266 ldr sp,=SFE(FIQ_STACK) ; End of FIQ_STACK
267 ;- Init the FIQ register
268 ldr r8, =AT91C_BASE_AIC
270 bic r0,r0,#MODE_BITS ; Clear the mode bits
271 orr r0,r0,#IRQ_MODE ; Set IRQ mode bits
272 msr cpsr_c,r0 ; Change the mode
273 ldr sp,=SFE(IRQ_STACK) ; End of IRQ_STACK
275 bic r0,r0,#MODE_BITS ; Clear the mode bits
276 orr r0,r0,#SYS_MODE ; Set System mode bits
277 msr cpsr_c,r0 ; Change the mode
278 ldr sp,=SFE(CSTACK) ; End of CSTACK
282 ; Enable the VFP coprocessor.
283 mov r0, #0x40000000 ; Set EN bit in VFP
284 fmxr fpexc, r0 ; FPEXC, clear others.
286 ; Disable underflow exceptions by setting flush to zero mode.
287 ; For full IEEE 754 underflow compliance this code should be removed
288 ; and the appropriate exception handler installed.
289 mov r0, #0x01000000 ; Set FZ bit in VFP
290 fmxr fpscr, r0 ; FPSCR, clear others.
293 ; Add more initialization here
294 msr CPSR_c,#I_BIT | F_BIT | SVC_MODE
297 ; Continue to ?main for more IAR specific system startup
302 END ;- Terminates the assembly of the last module in a file