1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup qoriq |
---|
5 | * |
---|
6 | * @brief BSP start. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2010, 2017 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <rtems/score/percpu.h> |
---|
24 | |
---|
25 | #include <bspopts.h> |
---|
26 | |
---|
27 | #include <libcpu/powerpc-utility.h> |
---|
28 | |
---|
29 | #include <bsp/vectors.h> |
---|
30 | |
---|
31 | #if (QORIQ_INITIAL_MSR & MSR_FP) != 0 |
---|
32 | #define INITIALIZE_FPU |
---|
33 | #endif |
---|
34 | |
---|
35 | #define FIRST_TLB 0 |
---|
36 | #define SCRATCH_TLB QORIQ_TLB1_ENTRY_COUNT - 1 |
---|
37 | #define INITIAL_MSR r14 |
---|
38 | #define START_STACK r15 |
---|
39 | #define SAVED_LINK_REGISTER r16 |
---|
40 | #define FDT_REGISTER r17 |
---|
41 | |
---|
42 | .globl _start |
---|
43 | #ifdef RTEMS_SMP |
---|
44 | #if QORIQ_THREAD_COUNT > 1 |
---|
45 | .globl _start_thread |
---|
46 | #endif |
---|
47 | .globl _start_secondary_processor |
---|
48 | #endif |
---|
49 | .globl bsp_exc_vector_base |
---|
50 | |
---|
51 | .section ".bsp_start_text", "ax" |
---|
52 | |
---|
53 | _start: |
---|
54 | mr FDT_REGISTER, r3 |
---|
55 | bl .Linitearly |
---|
56 | |
---|
57 | /* Get start stack */ |
---|
58 | LA START_STACK, start_stack_end |
---|
59 | |
---|
60 | bl .Linitmore |
---|
61 | |
---|
62 | /* Copy fast text */ |
---|
63 | LA r3, bsp_section_fast_text_begin |
---|
64 | LA r4, bsp_section_fast_text_load_begin |
---|
65 | LA r5, bsp_section_fast_text_size |
---|
66 | bl .Lcopy |
---|
67 | LA r3, bsp_section_fast_text_begin |
---|
68 | LA r4, bsp_section_fast_text_size |
---|
69 | bl rtems_cache_flush_multiple_data_lines |
---|
70 | |
---|
71 | /* Copy read-only data */ |
---|
72 | LA r3, bsp_section_rodata_begin |
---|
73 | LA r4, bsp_section_rodata_load_begin |
---|
74 | LA r5, bsp_section_rodata_size |
---|
75 | bl .Lcopy |
---|
76 | |
---|
77 | /* Copy FDT into read-only data */ |
---|
78 | mr r3, FDT_REGISTER |
---|
79 | bl bsp_fdt_copy |
---|
80 | |
---|
81 | /* Flush read-only data */ |
---|
82 | LA r3, bsp_section_rodata_begin |
---|
83 | LA r4, bsp_section_rodata_size |
---|
84 | bl rtems_cache_flush_multiple_data_lines |
---|
85 | |
---|
86 | /* Copy fast data */ |
---|
87 | LA r3, bsp_section_fast_data_begin |
---|
88 | LA r4, bsp_section_fast_data_load_begin |
---|
89 | LA r5, bsp_section_fast_data_size |
---|
90 | bl .Lcopy |
---|
91 | |
---|
92 | /* Copy data */ |
---|
93 | LA r3, bsp_section_data_begin |
---|
94 | LA r4, bsp_section_data_load_begin |
---|
95 | LA r5, bsp_section_data_size |
---|
96 | bl .Lcopy |
---|
97 | |
---|
98 | /* NULL pointer access protection (only core 0 has to do this) */ |
---|
99 | mfspr r3, BOOKE_PIR |
---|
100 | cmpwi r3, 0 |
---|
101 | bne .Lnull_area_setup_done |
---|
102 | LA r3, bsp_section_start_begin |
---|
103 | srawi r3, r3, 2 |
---|
104 | mtctr r3 |
---|
105 | li r3, -4 |
---|
106 | LWI r4, 0x44000002 |
---|
107 | .Lnull_area_setup_loop: |
---|
108 | stwu r4, 4(r3) |
---|
109 | bdnz .Lnull_area_setup_loop |
---|
110 | .Lnull_area_setup_done: |
---|
111 | |
---|
112 | li r3, 1 |
---|
113 | bl .Linitmmu |
---|
114 | |
---|
115 | /* Clear SBSS */ |
---|
116 | LA r3, bsp_section_sbss_begin |
---|
117 | LA r4, bsp_section_sbss_size |
---|
118 | bl bsp_start_zero |
---|
119 | |
---|
120 | /* Clear BSS */ |
---|
121 | LA r3, bsp_section_bss_begin |
---|
122 | LA r4, bsp_section_bss_size |
---|
123 | bl bsp_start_zero |
---|
124 | |
---|
125 | #ifndef __powerpc64__ |
---|
126 | /* Set up EABI and SYSV environment */ |
---|
127 | bl __eabi |
---|
128 | #endif |
---|
129 | |
---|
130 | /* Clear command line */ |
---|
131 | li r3, 0 |
---|
132 | |
---|
133 | bl boot_card |
---|
134 | |
---|
135 | .Lcopy: |
---|
136 | PPC_REG_CMP r3, r4 |
---|
137 | beqlr |
---|
138 | b memcpy |
---|
139 | |
---|
140 | .Linitearly: |
---|
141 | #ifdef __powerpc64__ |
---|
142 | /* Enable 64-bit computation mode for exceptions */ |
---|
143 | mfspr r0, BOOKE_EPCR |
---|
144 | oris r0, r0, BOOKE_EPCR_ICM >> 16 |
---|
145 | mtspr BOOKE_EPCR, r0 |
---|
146 | |
---|
147 | /* Enable 64-bit computation mode */ |
---|
148 | mfmsr r0 |
---|
149 | oris r0, r0, MSR_CM >> 16 |
---|
150 | mtmsr r0 |
---|
151 | isync |
---|
152 | #endif |
---|
153 | |
---|
154 | /* Disable decrementer */ |
---|
155 | mfspr r0, BOOKE_TCR |
---|
156 | LWI r4, BOOKE_TCR_DIE |
---|
157 | andc r0, r0, r4 |
---|
158 | mtspr BOOKE_TCR, r0 |
---|
159 | |
---|
160 | #ifdef QORIQ_INITIAL_SPEFSCR |
---|
161 | /* SPEFSCR initialization */ |
---|
162 | LWI r0, QORIQ_INITIAL_SPEFSCR |
---|
163 | mtspr FSL_EIS_SPEFSCR, r0 |
---|
164 | #endif |
---|
165 | |
---|
166 | #ifdef QORIQ_INITIAL_BUCSR |
---|
167 | /* BUCSR initialization */ |
---|
168 | LWI r0, QORIQ_INITIAL_BUCSR |
---|
169 | mtspr FSL_EIS_BUCSR, r0 |
---|
170 | isync |
---|
171 | #endif |
---|
172 | |
---|
173 | #ifdef QORIQ_INITIAL_HID0 |
---|
174 | /* HID0 initialization */ |
---|
175 | LWI r0, QORIQ_INITIAL_HID0 |
---|
176 | mtspr HID0, r0 |
---|
177 | #endif |
---|
178 | |
---|
179 | #ifdef __powerpc64__ |
---|
180 | LA32 r2, .TOC. |
---|
181 | #else |
---|
182 | /* Invalidate TLS anchor */ |
---|
183 | li r2, 0 |
---|
184 | |
---|
185 | /* Set small-data anchor */ |
---|
186 | LA r13, _SDA_BASE_ |
---|
187 | #endif |
---|
188 | |
---|
189 | SET_SELF_CPU_CONTROL r4, r5 |
---|
190 | |
---|
191 | blr |
---|
192 | |
---|
193 | .Linitmore: |
---|
194 | mflr SAVED_LINK_REGISTER |
---|
195 | |
---|
196 | /* Invalidate all TS1 MMU entries */ |
---|
197 | li r3, 1 |
---|
198 | bl qoriq_tlb1_invalidate_all_by_ts |
---|
199 | |
---|
200 | /* Add TS1 entry for the first 4GiB of RAM */ |
---|
201 | li r3, SCRATCH_TLB |
---|
202 | li r4, FSL_EIS_MAS1_TS |
---|
203 | li r5, FSL_EIS_MAS2_M |
---|
204 | li r6, FSL_EIS_MAS3_SR | FSL_EIS_MAS3_SW | FSL_EIS_MAS3_SX |
---|
205 | li r7, 0 |
---|
206 | li r8, 0 |
---|
207 | li r9, 11 |
---|
208 | bl qoriq_tlb1_write |
---|
209 | |
---|
210 | /* MSR initialization and use TS1 for address translation */ |
---|
211 | LWI INITIAL_MSR, QORIQ_INITIAL_MSR |
---|
212 | ori r0, INITIAL_MSR, MSR_IS | MSR_DS |
---|
213 | mtmsr r0 |
---|
214 | isync |
---|
215 | |
---|
216 | /* |
---|
217 | * Initialize start stack. Make sure that we do not share a cache line |
---|
218 | * with the heap block management, since initial stacks for the |
---|
219 | * secondary processors are allocated from the workspace. |
---|
220 | */ |
---|
221 | subi r1, START_STACK, 2 * PPC_DEFAULT_CACHE_LINE_SIZE |
---|
222 | clrrwi r1, r1, PPC_DEFAULT_CACHE_LINE_POWER |
---|
223 | li r0, 0 |
---|
224 | PPC_REG_STORE r0, 0(r1) |
---|
225 | |
---|
226 | #ifdef INITIALIZE_FPU |
---|
227 | bl .Linitfpu |
---|
228 | #endif |
---|
229 | |
---|
230 | mtlr SAVED_LINK_REGISTER |
---|
231 | blr |
---|
232 | |
---|
233 | .Linitmmu: |
---|
234 | mflr SAVED_LINK_REGISTER |
---|
235 | |
---|
236 | /* Configure MMU */ |
---|
237 | li r4, FIRST_TLB |
---|
238 | li r5, SCRATCH_TLB |
---|
239 | bl qoriq_mmu_config |
---|
240 | mtmsr INITIAL_MSR |
---|
241 | isync |
---|
242 | li r3, SCRATCH_TLB |
---|
243 | bl qoriq_tlb1_invalidate |
---|
244 | |
---|
245 | mtlr SAVED_LINK_REGISTER |
---|
246 | blr |
---|
247 | |
---|
248 | #ifdef INITIALIZE_FPU |
---|
249 | /* |
---|
250 | * Write a value to the FPRs to initialize the hidden tag bits. See |
---|
251 | * also "Core Software Initialization Requirements" of the e500mc |
---|
252 | * reference manual for example. |
---|
253 | */ |
---|
254 | .Linitfpu: |
---|
255 | li r0, 0 |
---|
256 | stw r0, 0(r1) |
---|
257 | stw r0, 4(r1) |
---|
258 | lfd f0, 0(r1) |
---|
259 | fmr f1, f0 |
---|
260 | fmr f2, f0 |
---|
261 | fmr f3, f0 |
---|
262 | fmr f4, f0 |
---|
263 | fmr f5, f0 |
---|
264 | fmr f6, f0 |
---|
265 | fmr f7, f0 |
---|
266 | fmr f8, f0 |
---|
267 | fmr f9, f0 |
---|
268 | fmr f10, f0 |
---|
269 | fmr f11, f0 |
---|
270 | fmr f12, f0 |
---|
271 | fmr f13, f0 |
---|
272 | fmr f14, f0 |
---|
273 | fmr f15, f0 |
---|
274 | fmr f16, f0 |
---|
275 | fmr f17, f0 |
---|
276 | fmr f18, f0 |
---|
277 | fmr f19, f0 |
---|
278 | fmr f20, f0 |
---|
279 | fmr f21, f0 |
---|
280 | fmr f22, f0 |
---|
281 | fmr f23, f0 |
---|
282 | fmr f24, f0 |
---|
283 | fmr f25, f0 |
---|
284 | fmr f26, f0 |
---|
285 | fmr f27, f0 |
---|
286 | fmr f28, f0 |
---|
287 | fmr f29, f0 |
---|
288 | fmr f30, f0 |
---|
289 | fmr f31, f0 |
---|
290 | blr |
---|
291 | #endif |
---|
292 | |
---|
293 | #ifdef RTEMS_SMP |
---|
294 | #if QORIQ_THREAD_COUNT > 1 |
---|
295 | _start_thread: |
---|
296 | /* Adjust PIR */ |
---|
297 | mfspr r0, BOOKE_PIR |
---|
298 | srawi r0, r0, 2 |
---|
299 | ori r0, r0, 1 |
---|
300 | mtspr BOOKE_PIR, r0 |
---|
301 | |
---|
302 | bl .Linitearly |
---|
303 | |
---|
304 | /* Initialize start stack */ |
---|
305 | GET_SELF_CPU_CONTROL r3 |
---|
306 | PPC_REG_LOAD r3, PER_CPU_INTERRUPT_STACK_HIGH(r3) |
---|
307 | subi r1, r3, PPC_MINIMUM_STACK_FRAME_SIZE |
---|
308 | clrrwi r1, r1, PPC_STACK_ALIGN_POWER |
---|
309 | li r0, 0 |
---|
310 | PPC_REG_STORE r0, 0(r1) |
---|
311 | |
---|
312 | #ifdef INITIALIZE_FPU |
---|
313 | bl .Linitfpu |
---|
314 | #endif |
---|
315 | |
---|
316 | b qoriq_start_thread |
---|
317 | #endif |
---|
318 | _start_secondary_processor: |
---|
319 | bl .Linitearly |
---|
320 | |
---|
321 | /* Get start stack */ |
---|
322 | mr START_STACK, r3 |
---|
323 | |
---|
324 | bl .Linitmore |
---|
325 | li r3, 0 |
---|
326 | bl .Linitmmu |
---|
327 | b bsp_start_on_secondary_processor |
---|
328 | #endif /* RTEMS_SMP */ |
---|
329 | |
---|
330 | /* Exception vector prologues area */ |
---|
331 | .section ".bsp_start_text", "ax" |
---|
332 | .align 4 |
---|
333 | bsp_exc_vector_base: |
---|
334 | /* Critical input */ |
---|
335 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
336 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
337 | li r3, 0 |
---|
338 | b ppc_exc_fatal_critical |
---|
339 | /* Machine check */ |
---|
340 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
341 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
342 | li r3, 1 |
---|
343 | b ppc_exc_fatal_machine_check |
---|
344 | /* Data storage */ |
---|
345 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
346 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
347 | li r3, 2 |
---|
348 | b ppc_exc_fatal_normal |
---|
349 | /* Instruction storage */ |
---|
350 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
351 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
352 | li r3, 3 |
---|
353 | b ppc_exc_fatal_normal |
---|
354 | /* External input */ |
---|
355 | PPC_REG_STORE_UPDATE r1, -PPC_EXC_INTERRUPT_FRAME_SIZE(r1) |
---|
356 | b ppc_exc_interrupt |
---|
357 | nop |
---|
358 | nop |
---|
359 | /* Alignment */ |
---|
360 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
361 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
362 | li r3, 5 |
---|
363 | b ppc_exc_fatal_normal |
---|
364 | /* Program */ |
---|
365 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
366 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
367 | li r3, 6 |
---|
368 | b ppc_exc_fatal_normal |
---|
369 | #ifdef __PPC_CPU_E6500__ |
---|
370 | /* Floating-point unavailable */ |
---|
371 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
372 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
373 | li r3, 7 |
---|
374 | b ppc_exc_fatal_normal |
---|
375 | #endif |
---|
376 | /* System call */ |
---|
377 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
378 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
379 | li r3, 8 |
---|
380 | b ppc_exc_fatal_normal |
---|
381 | #ifdef __PPC_CPU_E6500__ |
---|
382 | /* APU unavailable */ |
---|
383 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
384 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
385 | li r3, 9 |
---|
386 | b ppc_exc_fatal_normal |
---|
387 | #endif |
---|
388 | /* Decrementer */ |
---|
389 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
390 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
391 | li r3, 10 |
---|
392 | b ppc_exc_fatal_normal |
---|
393 | /* Fixed-interval timer interrupt */ |
---|
394 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
395 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
396 | li r3, 11 |
---|
397 | b ppc_exc_fatal_normal |
---|
398 | /* Watchdog timer interrupt */ |
---|
399 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
400 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
401 | li r3, 12 |
---|
402 | b ppc_exc_fatal_critical |
---|
403 | /* Data TLB error */ |
---|
404 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
405 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
406 | li r3, 13 |
---|
407 | b ppc_exc_fatal_normal |
---|
408 | /* Instruction TLB error */ |
---|
409 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
410 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
411 | li r3, 14 |
---|
412 | b ppc_exc_fatal_normal |
---|
413 | /* Debug */ |
---|
414 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
415 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
416 | li r3, 15 |
---|
417 | b ppc_exc_fatal_debug |
---|
418 | /* SPE APU unavailable or AltiVec unavailable */ |
---|
419 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
420 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
421 | li r3, 32 |
---|
422 | b ppc_exc_fatal_normal |
---|
423 | /* SPE floating-point data exception or AltiVec assist */ |
---|
424 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
425 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
426 | li r3, 33 |
---|
427 | b ppc_exc_fatal_normal |
---|
428 | #ifndef __PPC_CPU_E6500__ |
---|
429 | /* SPE floating-point round exception */ |
---|
430 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
431 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
432 | li r3, 34 |
---|
433 | b ppc_exc_fatal_normal |
---|
434 | #endif |
---|
435 | /* Performance monitor */ |
---|
436 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
437 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
438 | li r3, 35 |
---|
439 | b ppc_exc_fatal_normal |
---|
440 | #ifdef __PPC_CPU_E6500__ |
---|
441 | /* Processor doorbell interrupt */ |
---|
442 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
443 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
444 | li r3, 36 |
---|
445 | b ppc_exc_fatal_normal |
---|
446 | /* Processor doorbell critical interrupt */ |
---|
447 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
448 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
449 | li r3, 37 |
---|
450 | b ppc_exc_fatal_critical |
---|
451 | /* Guest processor doorbell */ |
---|
452 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
453 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
454 | li r3, 38 |
---|
455 | b ppc_exc_fatal_normal |
---|
456 | /* Guest processor doorbell critical and machine check */ |
---|
457 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
458 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
459 | li r3, 39 |
---|
460 | b ppc_exc_fatal_critical |
---|
461 | /* Hypervisor system call */ |
---|
462 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
463 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
464 | li r3, 40 |
---|
465 | b ppc_exc_fatal_normal |
---|
466 | /* Hypervisor privilege */ |
---|
467 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
468 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
469 | li r3, 41 |
---|
470 | b ppc_exc_fatal_normal |
---|
471 | /* LRAT error */ |
---|
472 | PPC_REG_STORE_UPDATE r1, -EXC_GENERIC_SIZE(r1) |
---|
473 | PPC_REG_STORE r3, GPR3_OFFSET(r1) |
---|
474 | li r3, 42 |
---|
475 | b ppc_exc_fatal_normal |
---|
476 | #endif |
---|
477 | |
---|
478 | /* Symbol provided for debugging and tracing */ |
---|
479 | bsp_exc_vector_end: |
---|
480 | |
---|
481 | /* Start stack area */ |
---|
482 | .section ".bsp_rwextra", "aw", @nobits |
---|
483 | .align 4 |
---|
484 | .space 4096 |
---|
485 | start_stack_end: |
---|