1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
31 //------------------------------------------------------------------------------
\r
33 //------------------------------------------------------------------------------
\r
36 #define AIC 0xFFFFF000
\r
37 #define AIC_IVR 0x10
\r
38 #define AIC_EOICR 0x38
\r
40 #define IRQ_STACK_SIZE 8*3*4
\r
42 #define ARM_MODE_ABT 0x17
\r
43 #define ARM_MODE_FIQ 0x11
\r
44 #define ARM_MODE_IRQ 0x12
\r
45 #define ARM_MODE_SVC 0x13
\r
46 #define ARM_MODE_SYS 0x1F
\r
51 //------------------------------------------------------------------------------
\r
53 //------------------------------------------------------------------------------
\r
58 /* Exception vectors
\r
59 *******************/
\r
60 .section .vectors, "a", %progbits
\r
63 ldr pc, =resetHandler /* Reset */
\r
65 b undefVector /* Undefined instruction */
\r
67 b swiVector /* Software interrupt */
\r
68 prefetchAbortVector:
\r
69 b prefetchAbortVector /* Prefetch abort */
\r
71 b dataAbortVector /* Data abort */
\r
73 b reservedVector /* Reserved for future use */
\r
75 b irqHandler /* Interrupt */
\r
77 /* Fast interrupt */
\r
78 //------------------------------------------------------------------------------
\r
79 /// Handles a fast interrupt request by branching to the address defined in the
\r
81 //------------------------------------------------------------------------------
\r
85 //------------------------------------------------------------------------------
\r
86 /// Handles incoming interrupt requests by branching to the corresponding
\r
87 /// handler, as defined in the AIC. Supports interrupt nesting.
\r
88 //------------------------------------------------------------------------------
\r
90 /* Save interrupt context on the stack to allow nesting */
\r
96 /* Write in the IVR to support Protect Mode */
\r
98 LDR r0, [r14, #AIC_IVR]
\r
99 STR lr, [r14, #AIC_IVR]
\r
101 /* Branch to interrupt handler in Supervisor mode */
\r
102 MSR CPSR_c, #ARM_MODE_SVC
\r
103 STMFD sp!, {r1-r3, r4, r12, lr}
\r
105 /* Check for 8-byte alignment and save lr plus a */
\r
106 /* word to indicate the stack adjustment used (0 or 4) */
\r
109 STMFD sp!, {r1, lr}
\r
113 LDMIA sp!, {r1, lr}
\r
116 LDMIA sp!, {r1-r3, r4, r12, lr}
\r
117 MSR CPSR_c, #ARM_MODE_IRQ | I_BIT
\r
119 /* Acknowledge interrupt */
\r
121 STR lr, [r14, #AIC_EOICR]
\r
123 /* Restore interrupt context and branch back to calling code */
\r
124 LDMIA sp!, {r0, lr}
\r
129 //------------------------------------------------------------------------------
\r
130 /// Initializes the chip and branches to the main() function.
\r
131 //------------------------------------------------------------------------------
\r
132 .section .textEntry
\r
141 /* - Enable access to CP10 and CP11 in CP15.CACR */
\r
142 mrc p15, 0, r0, c1, c0, 2
\r
143 orr r0, r0, #0xf00000
\r
144 mcr p15, 0, r0, c1, c0, 2
\r
145 /* - Enable access to CP10 and CP11 in CP15.NSACR */
\r
146 /* - Set FPEXC.EN (B30) */
\r
148 orr r0, r0, #0x40000000
\r
151 /* Useless instruction for referencing the .vectors section */
\r
152 ldr r0, =resetVector
\r
154 /* Set pc to actual code location (i.e. not in remap zone) */
\r
157 /* Initialize the prerelocate segment */
\r
160 ldr r1, =_sprerelocate
\r
161 ldr r2, =_eprerelocate
\r
168 /* Perform low-level initialization of the chip using LowLevelInit() */
\r
171 ldr r0, =LowLevelInit
\r
174 /* Initialize the postrelocate segment */
\r
177 ldr r1, =_spostrelocate
\r
178 ldr r2, =_epostrelocate
\r
185 /* Clear the zero segment */
\r
197 msr CPSR_c, #ARM_MODE_IRQ | I_BIT | F_BIT
\r
199 sub r4, sp, #IRQ_STACK_SIZE
\r
201 /* Supervisor mode (interrupts enabled) */
\r
202 msr CPSR_c, #ARM_MODE_SVC | F_BIT
\r
205 /*Initialize the C library */
\r
206 ldr r3, =__libc_init_array
\r
210 /* Branch to main()
\r
211 ******************/
\r
215 /* Loop indefinitely when program is finished */
\r