]> rtime.felk.cvut.cz Git - arc.git/blob - arch/arm/arm_cr4/kernel/startup_cr4.s
Added MCU driver to Cortex-R4
[arc.git] / arch / arm / arm_cr4 / kernel / startup_cr4.s
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15     \r
16 \r
17         .syntax unified\r
18         .cpu cortex-r4\r
19         .fpu softvfp\r
20         .thumb\r
21 \r
22 .global Default_Handler\r
23 \r
24 /* Addresses used to setup RAM */\r
25 .word   _sidata\r
26 .word   _sdata\r
27 .word   _edata\r
28 .word   _sbss\r
29 .word   _ebss\r
30 \r
31 /* The address of the stack to use in all modes. */\r
32 .word _estack\r
33 \r
34 \r
35 /**\r
36  * @brief  This is the code that gets called when the processor first\r
37  *          starts execution following a reset event. Only the absolutely\r
38  *          necessary set is performed, after which the application\r
39  *          supplied main() routine is called. \r
40  * @param  None\r
41  * @retval : None\r
42 */\r
43     .section    .text.Reset_Handler\r
44         .weak   Reset_Handler\r
45         .type   Reset_Handler, %function\r
46 \r
47 Reset_Handler:  \r
48 \r
49 /* Set big endian state */\r
50         SETEND BE\r
51 \r
52 /* Initialize core registers.\r
53    This is done to avoid mismatch between lockstep CPU and ordinary CPU\r
54 */\r
55     mov   r0,         #0x0000\r
56     mov   r1,         #0x0000\r
57     mov   r2,         #0x0000\r
58     mov   r3,         #0x0000\r
59     mov   r4,         #0x0000\r
60     mov   r5,         #0x0000\r
61     mov   r6,         #0x0000\r
62     mov   r7,         #0x0000\r
63     mov   r8,         #0x0000\r
64     mov   r9,         #0x0000\r
65     mov   r10,        #0x0000\r
66     mov   r11,        #0x0000\r
67     mov   r12,        #0x0000\r
68     mov   r1,         #0x03D0\r
69     orr   r2,        r1,     #0x0001\r
70     msr   cpsr_cxsf,  r2\r
71     msr   spsr_cxsf,  r2\r
72     mov   r8,         #0x0000\r
73     mov   r9,         #0x0000\r
74     mov   r10,        #0x0000\r
75     mov   r11,        #0x0000\r
76     mov   r12,        #0x0000\r
77     orr   r12,        r1,     #0x0002\r
78     msr   cpsr_c,     r12\r
79     msr   spsr_cxsf,  r12\r
80     orr   r12,        r1,     #0x0007\r
81     msr   cpsr_c,     r12\r
82     msr   spsr_cxsf,  r12\r
83     orr   r12,        r1,     #0x000B\r
84     msr   cpsr_c,     r12\r
85     msr   spsr_cxsf,  r12\r
86     orr   r12,        r1,     #0x0003\r
87     msr   cpsr_c,     r12\r
88     msr   spsr_cxsf,  r12\r
89 \r
90 /* System level configuration\r
91    This mainly involves setting instruction mode for exceptions and interrupts.\r
92 */\r
93     mrc   p15,0,r11,c1,c0,0       /* Read current system configuration */\r
94     mov   r12,            #0x40000000 /* Set THUMB instruction set mode for interrupts and exceptions */\r
95     orr   r12, r12, r11\r
96     mcr   p15,0,r12,c1,c0,0       /* Write new configuration */\r
97 \r
98 \r
99 /* Initialize stack pointers.\r
100    This is done for all processor modes. Note that we only use one stack pointer.\r
101    In reality this means that no mode except USER and SYS is allowed to do anythin on the stack.\r
102    IRQ mode handles its own stack in the interrupt routine.\r
103 */\r
104         mov   r2,               #0xD1\r
105     msr   cpsr_c,   r2\r
106     ldr   sp,           =_estack\r
107 \r
108     mov   r2,           #0xD2\r
109     msr   cpsr_c,   r2\r
110     ldr   sp,           =_estack\r
111 \r
112     mov   r2,           #0xD7\r
113     msr   cpsr_c,   r2\r
114     ldr   sp,           =_estack\r
115 \r
116     mov   r2,           #0xDB\r
117     msr   cpsr_c,   r2\r
118     ldr   sp,           =_estack\r
119 \r
120     mov   r2,           #0xDF\r
121     msr   cpsr_c,   r2\r
122     ldr   sp,           =_estack\r
123 \r
124     mov   r2,           #0xD3\r
125     msr   cpsr_c,   r2\r
126     ldr   sp,           =_estack\r
127 \r
128 \r
129 /* Initialize RAM.\r
130    First the initialized RAM is copied from flash to RAM.\r
131    Then the zeroed RAM is erased.\r
132 */\r
133         ldr     r0, =_sdata       /* r0 holds start of data in ram */\r
134         ldr     r3, =_edata       /* r3 holds end of data in ram */\r
135         ldr     r5, =_sidata      /* r5 start of data in flash */\r
136         movs  r1,       #0    /* r1 is the counter */\r
137         b       LoopCopyDataInit\r
138 \r
139 CopyDataInit:\r
140         ldr     r4, [r5, r1]          /* read current position in flash */\r
141         str     r4, [r0, r1]          /* store current position in ram */\r
142         adds    r1, r1, #4        /* increment counter */\r
143     \r
144 LoopCopyDataInit:\r
145         adds    r2, r0, r1        /* are we at the final position? */\r
146         cmp     r2, r3                /* ... */\r
147         bcc     CopyDataInit          /* nope, continue */\r
148 \r
149 /* Fill zero areas */\r
150         ldr     r2, =_sbss            /* r2 holds the start address */\r
151         ldr r5, =_ebss            /* r5 holds the end address */\r
152         bl      LoopFillZero\r
153 \r
154         ldr     r2, =_sstack            /* r2 holds the start address */\r
155         ldr r5, =_estack            /* r5 holds the end address */\r
156         bl      LoopFillZero\r
157 \r
158 /* Call the application's entry point.*/\r
159         mov   r2,               #0xDF\r
160     msr   cpsr_c,   r2\r
161         bl      main\r
162         bx      lr\r
163 \r
164 /* Zero fill the bss segment. */  \r
165 FillZero:\r
166         movs    r3, #0\r
167         str         r3, [r2], #4\r
168     \r
169 LoopFillZero:\r
170         cmp     r2, r5\r
171         bcc     FillZero\r
172         bx  lr\r
173 \r
174 /* Interrupt routine used to catch unused interrupts and exceptions */\r
175 Dummy_Irq:\r
176         /* Go back to sys mode for easier debugging.\r
177          Save link register*/\r
178         mov   r3, lr\r
179         /* We don't want to use the IRQ mode\r
180            so swich back to sys mode. */\r
181         mov   r2,               #0xDF\r
182     msr   cpsr_c,   r2\r
183     /* Restore link register again */\r
184     mov   lr, r3\r
185         b Dummy_Irq\r
186 \r
187 .size   Reset_Handler, .-Reset_Handler\r
188 \r
189 /**\r
190  * @brief  This is the code that gets called when the processor receives an \r
191  *         unexpected interrupt.  This simply enters an infinite loop, preserving\r
192  *         the system state for examination by a debugger.\r
193  *\r
194  * @param  None     \r
195  * @retval : None       \r
196 */\r
197     .section    .text.Default_Handler,"ax",%progbits\r
198 Default_Handler:\r
199 Infinite_Loop:\r
200         b       Infinite_Loop\r
201         .size   Default_Handler, .-Default_Handler\r
202 \r
203 \r
204 \r
205 /******************************************************************************\r
206 * Interrupt and exception vectors. Vectors start at addr 0x0.\r
207 ******************************************************************************/    \r
208         .section        .int_vecs,"ax",%progbits\r
209         .extern Irq_Handler\r
210 \r
211         b   Reset_Handler      /* Reset? */\r
212         b   Dummy_Irq          /* Undefined instruction exception */\r
213         b   Irq_Handler        /* SVC, to be able to use software interrupt instruction. */\r
214         b   Dummy_Irq          /* Prefetch exception */\r
215         b   Dummy_Irq          /* Data exception */\r
216         b   Dummy_Irq          /* Reserved */\r
217         b   Irq_Handler        /* Ordinary interrupts (IRQ) */\r
218             b   Irq_Handler        /* Fast interrupts (FIR) */\r
219 \r