1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup mpc55xx_asm |
---|
5 | * |
---|
6 | * @brief Boot and system start code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008 |
---|
11 | * Embedded Brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * D-82178 Puchheim |
---|
14 | * Germany |
---|
15 | * rtems@embedded-brains.de |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be found in the file |
---|
18 | * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | /** |
---|
22 | * @defgroup mpc55xx_asm Assembler files |
---|
23 | * |
---|
24 | * @ingroup mpc55xx |
---|
25 | */ |
---|
26 | |
---|
27 | #include <libcpu/powerpc-utility.h> |
---|
28 | #include <mpc55xx/reg-defs.h> |
---|
29 | #include <bspopts.h> |
---|
30 | |
---|
31 | .section ".bsp_start_text", "ax" |
---|
32 | #ifdef MPC55XX_BOOTFLAGS |
---|
33 | PUBLIC_VAR (mpc55xx_bootflag_0) |
---|
34 | PUBLIC_VAR (mpc55xx_bootflag_1) |
---|
35 | #endif |
---|
36 | PUBLIC_VAR (start) |
---|
37 | .globl fmpll_syncr_vals |
---|
38 | bam_rchw: |
---|
39 | /* |
---|
40 | * BAM |
---|
41 | */ |
---|
42 | |
---|
43 | /* BAM: RCHW */ |
---|
44 | .int 0x005a0000 |
---|
45 | |
---|
46 | #ifdef MPC55XX_BOOTFLAGS |
---|
47 | /* BAM: Address of start instruction |
---|
48 | * We skip over the next two boot flag words to the next |
---|
49 | * 64-bit aligned start address. It is 64-bit aligned |
---|
50 | * to play well with FLASH programming. |
---|
51 | * These boot flags can be set by debuggers and emulators to |
---|
52 | * customize boot. |
---|
53 | * Currently bit0 of bootflag_0 means to "skip setting up the MMU", |
---|
54 | * allowing external MMU setup in a debugger before branching |
---|
55 | * to 0x10. This can be used e.g., to map FLASH into RAM. |
---|
56 | */ |
---|
57 | .int 0x00000010 /* Start address is 0x10. */ |
---|
58 | |
---|
59 | mpc55xx_bootflag_0: |
---|
60 | .int 0xffffffff |
---|
61 | mpc55xx_bootflag_1: |
---|
62 | .int 0xffffffff |
---|
63 | |
---|
64 | #else |
---|
65 | .int 0x00000008 /* Start address is 0x08. */ |
---|
66 | #endif |
---|
67 | |
---|
68 | /* |
---|
69 | * Enable time base |
---|
70 | */ |
---|
71 | start: |
---|
72 | li r0, 0 |
---|
73 | mtspr TBWU, r0 |
---|
74 | mtspr TBWL, r0 |
---|
75 | mfspr r2, HID0 |
---|
76 | ori r2, r2, 0x4000 |
---|
77 | mtspr HID0, r2 |
---|
78 | |
---|
79 | /* |
---|
80 | * System clock |
---|
81 | */ |
---|
82 | |
---|
83 | LWI r3,fmpll_syncr_vals |
---|
84 | bl SYM (mpc55xx_fmpll_reset_config) |
---|
85 | |
---|
86 | /* |
---|
87 | * Enable branch prediction |
---|
88 | */ |
---|
89 | |
---|
90 | LWI r2, BUCSR_BBFI | BUCSR_BPEN |
---|
91 | mtspr BUCSR, r2 |
---|
92 | |
---|
93 | /* |
---|
94 | * Basics |
---|
95 | */ |
---|
96 | |
---|
97 | /* Set stack start to end of ram */ |
---|
98 | LA r1, bsp_ram_end |
---|
99 | addi r1, r1, -8 |
---|
100 | |
---|
101 | /* Enable SPE */ |
---|
102 | mfmsr r2 |
---|
103 | oris r2, r2, 0x200 |
---|
104 | mtmsr r2 |
---|
105 | |
---|
106 | /* Config internal flash */ |
---|
107 | bl SYM (mpc55xx_flash_config) |
---|
108 | |
---|
109 | #if BSP_DATA_CACHE_ENABLED || BSP_INSTRUCTION_CACHE_ENABLED |
---|
110 | /* FIXME: Config cache */ |
---|
111 | bl config_cache |
---|
112 | #endif /* BSP_DATA_CACHE_ENABLED || BSP_INSTRUCTION_CACHE_ENABLED */ |
---|
113 | |
---|
114 | /* |
---|
115 | * TODO, FIXME: Enable cache in the MMU for the SRAM |
---|
116 | */ |
---|
117 | |
---|
118 | .equ MAS0, 624 |
---|
119 | .equ MAS1, 625 |
---|
120 | .equ MAS2, 626 |
---|
121 | .equ MAS3, 627 |
---|
122 | |
---|
123 | /* Read back MMU TLB1 entry 3 (internal SRAM) and enable the cache. |
---|
124 | */ |
---|
125 | LWI r3, 0x10030000 |
---|
126 | mtspr MAS0, r3 |
---|
127 | tlbre |
---|
128 | LWI r4, ~0x00000008 |
---|
129 | mfspr r3, MAS2 |
---|
130 | and r3, r3, r4 |
---|
131 | mtspr MAS2, r3 |
---|
132 | tlbwe |
---|
133 | |
---|
134 | /* |
---|
135 | * TODO, FIXME: Set MMU for the external SRAM |
---|
136 | */ |
---|
137 | |
---|
138 | /* Read back MMU TLB1 entry 2 (external SRAM) and set the |
---|
139 | * logical address to the external RAM start. |
---|
140 | */ |
---|
141 | LWI r3, 0x10020000 |
---|
142 | mtspr MAS0, r3 |
---|
143 | tlbre |
---|
144 | LWI r4, 0xfff |
---|
145 | mfspr r3, MAS3 |
---|
146 | and r3, r3, r4 |
---|
147 | LA r4, bsp_external_ram_start |
---|
148 | or r3, r3, r4 |
---|
149 | mtspr MAS3, r3 |
---|
150 | tlbwe |
---|
151 | |
---|
152 | /* Read back MMU TLB1 entry 1 (internal flash) and disable |
---|
153 | * write access. |
---|
154 | */ |
---|
155 | LWI r3, 0x10010000 |
---|
156 | mtspr MAS0, r3 |
---|
157 | tlbre |
---|
158 | LWI r4, ~0x0000000C |
---|
159 | mfspr r3, MAS3 |
---|
160 | and r3, r3, r4 |
---|
161 | mtspr MAS3, r3 |
---|
162 | tlbwe |
---|
163 | |
---|
164 | /* |
---|
165 | * Zero RAM (needed to get proper ECC) |
---|
166 | */ |
---|
167 | |
---|
168 | /* Addresses */ |
---|
169 | LA r3, bsp_ram_start |
---|
170 | LA r4, bsp_ram_size |
---|
171 | |
---|
172 | /* Zero */ |
---|
173 | bl SYM (bsp_start_zero) |
---|
174 | |
---|
175 | /* |
---|
176 | * Copy data |
---|
177 | */ |
---|
178 | |
---|
179 | /* Addresses */ |
---|
180 | LA r3, bsp_section_text_end |
---|
181 | LA r4, bsp_section_data_start |
---|
182 | LA r5, bsp_section_data_end |
---|
183 | |
---|
184 | /* Assert: Proper alignment of source start */ |
---|
185 | andi. r6, r3, 0x7 |
---|
186 | bne twiddle |
---|
187 | |
---|
188 | /* Assert: Proper alignment of destination start */ |
---|
189 | andi. r6, r4, 0x7 |
---|
190 | bne twiddle |
---|
191 | |
---|
192 | /* Assert: Proper alignment of destination end */ |
---|
193 | andi. r6, r5, 0x7 |
---|
194 | bne twiddle |
---|
195 | |
---|
196 | /* Data size = destination end - destination start */ |
---|
197 | subf r5, r4, r5 |
---|
198 | |
---|
199 | /* Copy */ |
---|
200 | bl SYM (mpc55xx_copy_8) |
---|
201 | |
---|
202 | /* Save time and get time delta */ |
---|
203 | mftb r26 |
---|
204 | subf r25, r25, r26 |
---|
205 | |
---|
206 | /* |
---|
207 | * Prepare high level initialization |
---|
208 | */ |
---|
209 | |
---|
210 | /* Create NULL */ |
---|
211 | li r0, 0 |
---|
212 | |
---|
213 | /* Return address */ |
---|
214 | stw r0, 4(r1) |
---|
215 | |
---|
216 | /* Back chain */ |
---|
217 | stw r0, 0(r1) |
---|
218 | |
---|
219 | /* Read-only small data */ |
---|
220 | LA r2, _SDA2_BASE_ |
---|
221 | |
---|
222 | /* Read-write small data */ |
---|
223 | LA r13, _SDA_BASE_ |
---|
224 | |
---|
225 | /* |
---|
226 | * Start RTEMS |
---|
227 | */ |
---|
228 | |
---|
229 | /* Clear command line */ |
---|
230 | xor r3, r3, r3 |
---|
231 | |
---|
232 | /* Start RTEMS */ |
---|
233 | bl SYM (boot_card) |
---|
234 | |
---|
235 | /* Spin around */ |
---|
236 | b twiddle |
---|
237 | |
---|
238 | .equ L1CSR0, 1010 |
---|
239 | .equ L1CSR0_CINV, 0x2 |
---|
240 | .equ L1CSR0_CABT, 0x4 |
---|
241 | /* FIXME: CORG??? .equ L1CSR0_SETTINGS, 0x00180011 */ |
---|
242 | .equ L1CSR0_SETTINGS, 0x00100001 |
---|
243 | |
---|
244 | /* |
---|
245 | * Configure cache |
---|
246 | */ |
---|
247 | config_cache: |
---|
248 | /* Start cache invalidation */ |
---|
249 | LWI r5, L1CSR0_CINV |
---|
250 | mtspr L1CSR0, r5 |
---|
251 | |
---|
252 | /* Bit masks to test and clear invalidation abortion (CABT) */ |
---|
253 | LWI r6, L1CSR0_CABT |
---|
254 | not r7, r6 |
---|
255 | |
---|
256 | /* Wait for cache invalidation to complete */ |
---|
257 | check_cache_invalidation: |
---|
258 | mfspr r9, L1CSR0 |
---|
259 | |
---|
260 | /* Check if the invalidate was aborted */ |
---|
261 | and. r10, r9, r6 |
---|
262 | beq no_chache_invalidation_abort |
---|
263 | |
---|
264 | /* Clear CABT bit */ |
---|
265 | and r10, r9, r7 |
---|
266 | mtspr L1CSR0, r10 |
---|
267 | |
---|
268 | /* Retry invalidation */ |
---|
269 | b config_cache |
---|
270 | |
---|
271 | no_chache_invalidation_abort: |
---|
272 | /* Check CINV bit */ |
---|
273 | and. r10, r5, r9 |
---|
274 | |
---|
275 | /* Wait? */ |
---|
276 | bne check_cache_invalidation |
---|
277 | |
---|
278 | /* Enable cache */ |
---|
279 | LWI r6, L1CSR0_SETTINGS |
---|
280 | mfspr r5, L1CSR0 |
---|
281 | or r5, r5, r6 |
---|
282 | msync |
---|
283 | isync |
---|
284 | mtspr L1CSR0, r5 |
---|
285 | |
---|
286 | /* Return */ |
---|
287 | blr |
---|
288 | |
---|
289 | twiddle: |
---|
290 | b twiddle |
---|