diff options
Diffstat (limited to 'arch/arm64/kernel/head.S')
-rw-r--r-- | arch/arm64/kernel/head.S | 434 |
1 files changed, 228 insertions, 206 deletions
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 0a6e4f924df8..8ce88e08c030 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S | |||
@@ -132,6 +132,8 @@ efi_head: | |||
132 | #endif | 132 | #endif |
133 | 133 | ||
134 | #ifdef CONFIG_EFI | 134 | #ifdef CONFIG_EFI |
135 | .globl stext_offset | ||
136 | .set stext_offset, stext - efi_head | ||
135 | .align 3 | 137 | .align 3 |
136 | pe_header: | 138 | pe_header: |
137 | .ascii "PE" | 139 | .ascii "PE" |
@@ -155,12 +157,12 @@ optional_header: | |||
155 | .long 0 // SizeOfInitializedData | 157 | .long 0 // SizeOfInitializedData |
156 | .long 0 // SizeOfUninitializedData | 158 | .long 0 // SizeOfUninitializedData |
157 | .long efi_stub_entry - efi_head // AddressOfEntryPoint | 159 | .long efi_stub_entry - efi_head // AddressOfEntryPoint |
158 | .long stext - efi_head // BaseOfCode | 160 | .long stext_offset // BaseOfCode |
159 | 161 | ||
160 | extra_header_fields: | 162 | extra_header_fields: |
161 | .quad 0 // ImageBase | 163 | .quad 0 // ImageBase |
162 | .long 0x20 // SectionAlignment | 164 | .long 0x1000 // SectionAlignment |
163 | .long 0x8 // FileAlignment | 165 | .long PECOFF_FILE_ALIGNMENT // FileAlignment |
164 | .short 0 // MajorOperatingSystemVersion | 166 | .short 0 // MajorOperatingSystemVersion |
165 | .short 0 // MinorOperatingSystemVersion | 167 | .short 0 // MinorOperatingSystemVersion |
166 | .short 0 // MajorImageVersion | 168 | .short 0 // MajorImageVersion |
@@ -172,7 +174,7 @@ extra_header_fields: | |||
172 | .long _end - efi_head // SizeOfImage | 174 | .long _end - efi_head // SizeOfImage |
173 | 175 | ||
174 | // Everything before the kernel image is considered part of the header | 176 | // Everything before the kernel image is considered part of the header |
175 | .long stext - efi_head // SizeOfHeaders | 177 | .long stext_offset // SizeOfHeaders |
176 | .long 0 // CheckSum | 178 | .long 0 // CheckSum |
177 | .short 0xa // Subsystem (EFI application) | 179 | .short 0xa // Subsystem (EFI application) |
178 | .short 0 // DllCharacteristics | 180 | .short 0 // DllCharacteristics |
@@ -217,16 +219,24 @@ section_table: | |||
217 | .byte 0 | 219 | .byte 0 |
218 | .byte 0 // end of 0 padding of section name | 220 | .byte 0 // end of 0 padding of section name |
219 | .long _end - stext // VirtualSize | 221 | .long _end - stext // VirtualSize |
220 | .long stext - efi_head // VirtualAddress | 222 | .long stext_offset // VirtualAddress |
221 | .long _edata - stext // SizeOfRawData | 223 | .long _edata - stext // SizeOfRawData |
222 | .long stext - efi_head // PointerToRawData | 224 | .long stext_offset // PointerToRawData |
223 | 225 | ||
224 | .long 0 // PointerToRelocations (0 for executables) | 226 | .long 0 // PointerToRelocations (0 for executables) |
225 | .long 0 // PointerToLineNumbers (0 for executables) | 227 | .long 0 // PointerToLineNumbers (0 for executables) |
226 | .short 0 // NumberOfRelocations (0 for executables) | 228 | .short 0 // NumberOfRelocations (0 for executables) |
227 | .short 0 // NumberOfLineNumbers (0 for executables) | 229 | .short 0 // NumberOfLineNumbers (0 for executables) |
228 | .long 0xe0500020 // Characteristics (section flags) | 230 | .long 0xe0500020 // Characteristics (section flags) |
229 | .align 5 | 231 | |
232 | /* | ||
233 | * EFI will load stext onwards at the 4k section alignment | ||
234 | * described in the PE/COFF header. To ensure that instruction | ||
235 | * sequences using an adrp and a :lo12: immediate will function | ||
236 | * correctly at this alignment, we must ensure that stext is | ||
237 | * placed at a 4k boundary in the Image to begin with. | ||
238 | */ | ||
239 | .align 12 | ||
230 | #endif | 240 | #endif |
231 | 241 | ||
232 | ENTRY(stext) | 242 | ENTRY(stext) |
@@ -238,7 +248,13 @@ ENTRY(stext) | |||
238 | mov x0, x22 | 248 | mov x0, x22 |
239 | bl lookup_processor_type | 249 | bl lookup_processor_type |
240 | mov x23, x0 // x23=current cpu_table | 250 | mov x23, x0 // x23=current cpu_table |
241 | cbz x23, __error_p // invalid processor (x23=0)? | 251 | /* |
252 | * __error_p may end up out of range for cbz if text areas are | ||
253 | * aligned up to section sizes. | ||
254 | */ | ||
255 | cbnz x23, 1f // invalid processor (x23=0)? | ||
256 | b __error_p | ||
257 | 1: | ||
242 | bl __vet_fdt | 258 | bl __vet_fdt |
243 | bl __create_page_tables // x25=TTBR0, x26=TTBR1 | 259 | bl __create_page_tables // x25=TTBR0, x26=TTBR1 |
244 | /* | 260 | /* |
@@ -250,13 +266,214 @@ ENTRY(stext) | |||
250 | */ | 266 | */ |
251 | ldr x27, __switch_data // address to jump to after | 267 | ldr x27, __switch_data // address to jump to after |
252 | // MMU has been enabled | 268 | // MMU has been enabled |
253 | adr lr, __enable_mmu // return (PIC) address | 269 | adrp lr, __enable_mmu // return (PIC) address |
270 | add lr, lr, #:lo12:__enable_mmu | ||
254 | ldr x12, [x23, #CPU_INFO_SETUP] | 271 | ldr x12, [x23, #CPU_INFO_SETUP] |
255 | add x12, x12, x28 // __virt_to_phys | 272 | add x12, x12, x28 // __virt_to_phys |
256 | br x12 // initialise processor | 273 | br x12 // initialise processor |
257 | ENDPROC(stext) | 274 | ENDPROC(stext) |
258 | 275 | ||
259 | /* | 276 | /* |
277 | * Determine validity of the x21 FDT pointer. | ||
278 | * The dtb must be 8-byte aligned and live in the first 512M of memory. | ||
279 | */ | ||
280 | __vet_fdt: | ||
281 | tst x21, #0x7 | ||
282 | b.ne 1f | ||
283 | cmp x21, x24 | ||
284 | b.lt 1f | ||
285 | mov x0, #(1 << 29) | ||
286 | add x0, x0, x24 | ||
287 | cmp x21, x0 | ||
288 | b.ge 1f | ||
289 | ret | ||
290 | 1: | ||
291 | mov x21, #0 | ||
292 | ret | ||
293 | ENDPROC(__vet_fdt) | ||
294 | /* | ||
295 | * Macro to create a table entry to the next page. | ||
296 | * | ||
297 | * tbl: page table address | ||
298 | * virt: virtual address | ||
299 | * shift: #imm page table shift | ||
300 | * ptrs: #imm pointers per table page | ||
301 | * | ||
302 | * Preserves: virt | ||
303 | * Corrupts: tmp1, tmp2 | ||
304 | * Returns: tbl -> next level table page address | ||
305 | */ | ||
306 | .macro create_table_entry, tbl, virt, shift, ptrs, tmp1, tmp2 | ||
307 | lsr \tmp1, \virt, #\shift | ||
308 | and \tmp1, \tmp1, #\ptrs - 1 // table index | ||
309 | add \tmp2, \tbl, #PAGE_SIZE | ||
310 | orr \tmp2, \tmp2, #PMD_TYPE_TABLE // address of next table and entry type | ||
311 | str \tmp2, [\tbl, \tmp1, lsl #3] | ||
312 | add \tbl, \tbl, #PAGE_SIZE // next level table page | ||
313 | .endm | ||
314 | |||
315 | /* | ||
316 | * Macro to populate the PGD (and possibily PUD) for the corresponding | ||
317 | * block entry in the next level (tbl) for the given virtual address. | ||
318 | * | ||
319 | * Preserves: tbl, next, virt | ||
320 | * Corrupts: tmp1, tmp2 | ||
321 | */ | ||
322 | .macro create_pgd_entry, tbl, virt, tmp1, tmp2 | ||
323 | create_table_entry \tbl, \virt, PGDIR_SHIFT, PTRS_PER_PGD, \tmp1, \tmp2 | ||
324 | #if SWAPPER_PGTABLE_LEVELS == 3 | ||
325 | create_table_entry \tbl, \virt, TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2 | ||
326 | #endif | ||
327 | .endm | ||
328 | |||
329 | /* | ||
330 | * Macro to populate block entries in the page table for the start..end | ||
331 | * virtual range (inclusive). | ||
332 | * | ||
333 | * Preserves: tbl, flags | ||
334 | * Corrupts: phys, start, end, pstate | ||
335 | */ | ||
336 | .macro create_block_map, tbl, flags, phys, start, end | ||
337 | lsr \phys, \phys, #BLOCK_SHIFT | ||
338 | lsr \start, \start, #BLOCK_SHIFT | ||
339 | and \start, \start, #PTRS_PER_PTE - 1 // table index | ||
340 | orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry | ||
341 | lsr \end, \end, #BLOCK_SHIFT | ||
342 | and \end, \end, #PTRS_PER_PTE - 1 // table end index | ||
343 | 9999: str \phys, [\tbl, \start, lsl #3] // store the entry | ||
344 | add \start, \start, #1 // next entry | ||
345 | add \phys, \phys, #BLOCK_SIZE // next block | ||
346 | cmp \start, \end | ||
347 | b.ls 9999b | ||
348 | .endm | ||
349 | |||
350 | /* | ||
351 | * Setup the initial page tables. We only setup the barest amount which is | ||
352 | * required to get the kernel running. The following sections are required: | ||
353 | * - identity mapping to enable the MMU (low address, TTBR0) | ||
354 | * - first few MB of the kernel linear mapping to jump to once the MMU has | ||
355 | * been enabled, including the FDT blob (TTBR1) | ||
356 | * - pgd entry for fixed mappings (TTBR1) | ||
357 | */ | ||
358 | __create_page_tables: | ||
359 | pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses | ||
360 | mov x27, lr | ||
361 | |||
362 | /* | ||
363 | * Invalidate the idmap and swapper page tables to avoid potential | ||
364 | * dirty cache lines being evicted. | ||
365 | */ | ||
366 | mov x0, x25 | ||
367 | add x1, x26, #SWAPPER_DIR_SIZE | ||
368 | bl __inval_cache_range | ||
369 | |||
370 | /* | ||
371 | * Clear the idmap and swapper page tables. | ||
372 | */ | ||
373 | mov x0, x25 | ||
374 | add x6, x26, #SWAPPER_DIR_SIZE | ||
375 | 1: stp xzr, xzr, [x0], #16 | ||
376 | stp xzr, xzr, [x0], #16 | ||
377 | stp xzr, xzr, [x0], #16 | ||
378 | stp xzr, xzr, [x0], #16 | ||
379 | cmp x0, x6 | ||
380 | b.lo 1b | ||
381 | |||
382 | ldr x7, =MM_MMUFLAGS | ||
383 | |||
384 | /* | ||
385 | * Create the identity mapping. | ||
386 | */ | ||
387 | mov x0, x25 // idmap_pg_dir | ||
388 | ldr x3, =KERNEL_START | ||
389 | add x3, x3, x28 // __pa(KERNEL_START) | ||
390 | create_pgd_entry x0, x3, x5, x6 | ||
391 | ldr x6, =KERNEL_END | ||
392 | mov x5, x3 // __pa(KERNEL_START) | ||
393 | add x6, x6, x28 // __pa(KERNEL_END) | ||
394 | create_block_map x0, x7, x3, x5, x6 | ||
395 | |||
396 | /* | ||
397 | * Map the kernel image (starting with PHYS_OFFSET). | ||
398 | */ | ||
399 | mov x0, x26 // swapper_pg_dir | ||
400 | mov x5, #PAGE_OFFSET | ||
401 | create_pgd_entry x0, x5, x3, x6 | ||
402 | ldr x6, =KERNEL_END | ||
403 | mov x3, x24 // phys offset | ||
404 | create_block_map x0, x7, x3, x5, x6 | ||
405 | |||
406 | /* | ||
407 | * Map the FDT blob (maximum 2MB; must be within 512MB of | ||
408 | * PHYS_OFFSET). | ||
409 | */ | ||
410 | mov x3, x21 // FDT phys address | ||
411 | and x3, x3, #~((1 << 21) - 1) // 2MB aligned | ||
412 | mov x6, #PAGE_OFFSET | ||
413 | sub x5, x3, x24 // subtract PHYS_OFFSET | ||
414 | tst x5, #~((1 << 29) - 1) // within 512MB? | ||
415 | csel x21, xzr, x21, ne // zero the FDT pointer | ||
416 | b.ne 1f | ||
417 | add x5, x5, x6 // __va(FDT blob) | ||
418 | add x6, x5, #1 << 21 // 2MB for the FDT blob | ||
419 | sub x6, x6, #1 // inclusive range | ||
420 | create_block_map x0, x7, x3, x5, x6 | ||
421 | 1: | ||
422 | /* | ||
423 | * Since the page tables have been populated with non-cacheable | ||
424 | * accesses (MMU disabled), invalidate the idmap and swapper page | ||
425 | * tables again to remove any speculatively loaded cache lines. | ||
426 | */ | ||
427 | mov x0, x25 | ||
428 | add x1, x26, #SWAPPER_DIR_SIZE | ||
429 | bl __inval_cache_range | ||
430 | |||
431 | mov lr, x27 | ||
432 | ret | ||
433 | ENDPROC(__create_page_tables) | ||
434 | .ltorg | ||
435 | |||
436 | .align 3 | ||
437 | .type __switch_data, %object | ||
438 | __switch_data: | ||
439 | .quad __mmap_switched | ||
440 | .quad __bss_start // x6 | ||
441 | .quad __bss_stop // x7 | ||
442 | .quad processor_id // x4 | ||
443 | .quad __fdt_pointer // x5 | ||
444 | .quad memstart_addr // x6 | ||
445 | .quad init_thread_union + THREAD_START_SP // sp | ||
446 | |||
447 | /* | ||
448 | * The following fragment of code is executed with the MMU on in MMU mode, and | ||
449 | * uses absolute addresses; this is not position independent. | ||
450 | */ | ||
451 | __mmap_switched: | ||
452 | adr x3, __switch_data + 8 | ||
453 | |||
454 | ldp x6, x7, [x3], #16 | ||
455 | 1: cmp x6, x7 | ||
456 | b.hs 2f | ||
457 | str xzr, [x6], #8 // Clear BSS | ||
458 | b 1b | ||
459 | 2: | ||
460 | ldp x4, x5, [x3], #16 | ||
461 | ldr x6, [x3], #8 | ||
462 | ldr x16, [x3] | ||
463 | mov sp, x16 | ||
464 | str x22, [x4] // Save processor ID | ||
465 | str x21, [x5] // Save FDT pointer | ||
466 | str x24, [x6] // Save PHYS_OFFSET | ||
467 | mov x29, #0 | ||
468 | b start_kernel | ||
469 | ENDPROC(__mmap_switched) | ||
470 | |||
471 | /* | ||
472 | * end early head section, begin head code that is also used for | ||
473 | * hotplug and needs to have the same protections as the text region | ||
474 | */ | ||
475 | .section ".text","ax" | ||
476 | /* | ||
260 | * If we're fortunate enough to boot at EL2, ensure that the world is | 477 | * If we're fortunate enough to boot at EL2, ensure that the world is |
261 | * sane before dropping to EL1. | 478 | * sane before dropping to EL1. |
262 | * | 479 | * |
@@ -331,7 +548,8 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems | |||
331 | msr vttbr_el2, xzr | 548 | msr vttbr_el2, xzr |
332 | 549 | ||
333 | /* Hypervisor stub */ | 550 | /* Hypervisor stub */ |
334 | adr x0, __hyp_stub_vectors | 551 | adrp x0, __hyp_stub_vectors |
552 | add x0, x0, #:lo12:__hyp_stub_vectors | ||
335 | msr vbar_el2, x0 | 553 | msr vbar_el2, x0 |
336 | 554 | ||
337 | /* spsr */ | 555 | /* spsr */ |
@@ -492,183 +710,6 @@ ENDPROC(__calc_phys_offset) | |||
492 | .quad PAGE_OFFSET | 710 | .quad PAGE_OFFSET |
493 | 711 | ||
494 | /* | 712 | /* |
495 | * Macro to create a table entry to the next page. | ||
496 | * | ||
497 | * tbl: page table address | ||
498 | * virt: virtual address | ||
499 | * shift: #imm page table shift | ||
500 | * ptrs: #imm pointers per table page | ||
501 | * | ||
502 | * Preserves: virt | ||
503 | * Corrupts: tmp1, tmp2 | ||
504 | * Returns: tbl -> next level table page address | ||
505 | */ | ||
506 | .macro create_table_entry, tbl, virt, shift, ptrs, tmp1, tmp2 | ||
507 | lsr \tmp1, \virt, #\shift | ||
508 | and \tmp1, \tmp1, #\ptrs - 1 // table index | ||
509 | add \tmp2, \tbl, #PAGE_SIZE | ||
510 | orr \tmp2, \tmp2, #PMD_TYPE_TABLE // address of next table and entry type | ||
511 | str \tmp2, [\tbl, \tmp1, lsl #3] | ||
512 | add \tbl, \tbl, #PAGE_SIZE // next level table page | ||
513 | .endm | ||
514 | |||
515 | /* | ||
516 | * Macro to populate the PGD (and possibily PUD) for the corresponding | ||
517 | * block entry in the next level (tbl) for the given virtual address. | ||
518 | * | ||
519 | * Preserves: tbl, next, virt | ||
520 | * Corrupts: tmp1, tmp2 | ||
521 | */ | ||
522 | .macro create_pgd_entry, tbl, virt, tmp1, tmp2 | ||
523 | create_table_entry \tbl, \virt, PGDIR_SHIFT, PTRS_PER_PGD, \tmp1, \tmp2 | ||
524 | #if SWAPPER_PGTABLE_LEVELS == 3 | ||
525 | create_table_entry \tbl, \virt, TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2 | ||
526 | #endif | ||
527 | .endm | ||
528 | |||
529 | /* | ||
530 | * Macro to populate block entries in the page table for the start..end | ||
531 | * virtual range (inclusive). | ||
532 | * | ||
533 | * Preserves: tbl, flags | ||
534 | * Corrupts: phys, start, end, pstate | ||
535 | */ | ||
536 | .macro create_block_map, tbl, flags, phys, start, end | ||
537 | lsr \phys, \phys, #BLOCK_SHIFT | ||
538 | lsr \start, \start, #BLOCK_SHIFT | ||
539 | and \start, \start, #PTRS_PER_PTE - 1 // table index | ||
540 | orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry | ||
541 | lsr \end, \end, #BLOCK_SHIFT | ||
542 | and \end, \end, #PTRS_PER_PTE - 1 // table end index | ||
543 | 9999: str \phys, [\tbl, \start, lsl #3] // store the entry | ||
544 | add \start, \start, #1 // next entry | ||
545 | add \phys, \phys, #BLOCK_SIZE // next block | ||
546 | cmp \start, \end | ||
547 | b.ls 9999b | ||
548 | .endm | ||
549 | |||
550 | /* | ||
551 | * Setup the initial page tables. We only setup the barest amount which is | ||
552 | * required to get the kernel running. The following sections are required: | ||
553 | * - identity mapping to enable the MMU (low address, TTBR0) | ||
554 | * - first few MB of the kernel linear mapping to jump to once the MMU has | ||
555 | * been enabled, including the FDT blob (TTBR1) | ||
556 | * - pgd entry for fixed mappings (TTBR1) | ||
557 | */ | ||
558 | __create_page_tables: | ||
559 | pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses | ||
560 | mov x27, lr | ||
561 | |||
562 | /* | ||
563 | * Invalidate the idmap and swapper page tables to avoid potential | ||
564 | * dirty cache lines being evicted. | ||
565 | */ | ||
566 | mov x0, x25 | ||
567 | add x1, x26, #SWAPPER_DIR_SIZE | ||
568 | bl __inval_cache_range | ||
569 | |||
570 | /* | ||
571 | * Clear the idmap and swapper page tables. | ||
572 | */ | ||
573 | mov x0, x25 | ||
574 | add x6, x26, #SWAPPER_DIR_SIZE | ||
575 | 1: stp xzr, xzr, [x0], #16 | ||
576 | stp xzr, xzr, [x0], #16 | ||
577 | stp xzr, xzr, [x0], #16 | ||
578 | stp xzr, xzr, [x0], #16 | ||
579 | cmp x0, x6 | ||
580 | b.lo 1b | ||
581 | |||
582 | ldr x7, =MM_MMUFLAGS | ||
583 | |||
584 | /* | ||
585 | * Create the identity mapping. | ||
586 | */ | ||
587 | mov x0, x25 // idmap_pg_dir | ||
588 | ldr x3, =KERNEL_START | ||
589 | add x3, x3, x28 // __pa(KERNEL_START) | ||
590 | create_pgd_entry x0, x3, x5, x6 | ||
591 | ldr x6, =KERNEL_END | ||
592 | mov x5, x3 // __pa(KERNEL_START) | ||
593 | add x6, x6, x28 // __pa(KERNEL_END) | ||
594 | create_block_map x0, x7, x3, x5, x6 | ||
595 | |||
596 | /* | ||
597 | * Map the kernel image (starting with PHYS_OFFSET). | ||
598 | */ | ||
599 | mov x0, x26 // swapper_pg_dir | ||
600 | mov x5, #PAGE_OFFSET | ||
601 | create_pgd_entry x0, x5, x3, x6 | ||
602 | ldr x6, =KERNEL_END | ||
603 | mov x3, x24 // phys offset | ||
604 | create_block_map x0, x7, x3, x5, x6 | ||
605 | |||
606 | /* | ||
607 | * Map the FDT blob (maximum 2MB; must be within 512MB of | ||
608 | * PHYS_OFFSET). | ||
609 | */ | ||
610 | mov x3, x21 // FDT phys address | ||
611 | and x3, x3, #~((1 << 21) - 1) // 2MB aligned | ||
612 | mov x6, #PAGE_OFFSET | ||
613 | sub x5, x3, x24 // subtract PHYS_OFFSET | ||
614 | tst x5, #~((1 << 29) - 1) // within 512MB? | ||
615 | csel x21, xzr, x21, ne // zero the FDT pointer | ||
616 | b.ne 1f | ||
617 | add x5, x5, x6 // __va(FDT blob) | ||
618 | add x6, x5, #1 << 21 // 2MB for the FDT blob | ||
619 | sub x6, x6, #1 // inclusive range | ||
620 | create_block_map x0, x7, x3, x5, x6 | ||
621 | 1: | ||
622 | /* | ||
623 | * Since the page tables have been populated with non-cacheable | ||
624 | * accesses (MMU disabled), invalidate the idmap and swapper page | ||
625 | * tables again to remove any speculatively loaded cache lines. | ||
626 | */ | ||
627 | mov x0, x25 | ||
628 | add x1, x26, #SWAPPER_DIR_SIZE | ||
629 | bl __inval_cache_range | ||
630 | |||
631 | mov lr, x27 | ||
632 | ret | ||
633 | ENDPROC(__create_page_tables) | ||
634 | .ltorg | ||
635 | |||
636 | .align 3 | ||
637 | .type __switch_data, %object | ||
638 | __switch_data: | ||
639 | .quad __mmap_switched | ||
640 | .quad __bss_start // x6 | ||
641 | .quad __bss_stop // x7 | ||
642 | .quad processor_id // x4 | ||
643 | .quad __fdt_pointer // x5 | ||
644 | .quad memstart_addr // x6 | ||
645 | .quad init_thread_union + THREAD_START_SP // sp | ||
646 | |||
647 | /* | ||
648 | * The following fragment of code is executed with the MMU on in MMU mode, and | ||
649 | * uses absolute addresses; this is not position independent. | ||
650 | */ | ||
651 | __mmap_switched: | ||
652 | adr x3, __switch_data + 8 | ||
653 | |||
654 | ldp x6, x7, [x3], #16 | ||
655 | 1: cmp x6, x7 | ||
656 | b.hs 2f | ||
657 | str xzr, [x6], #8 // Clear BSS | ||
658 | b 1b | ||
659 | 2: | ||
660 | ldp x4, x5, [x3], #16 | ||
661 | ldr x6, [x3], #8 | ||
662 | ldr x16, [x3] | ||
663 | mov sp, x16 | ||
664 | str x22, [x4] // Save processor ID | ||
665 | str x21, [x5] // Save FDT pointer | ||
666 | str x24, [x6] // Save PHYS_OFFSET | ||
667 | mov x29, #0 | ||
668 | b start_kernel | ||
669 | ENDPROC(__mmap_switched) | ||
670 | |||
671 | /* | ||
672 | * Exception handling. Something went wrong and we can't proceed. We ought to | 713 | * Exception handling. Something went wrong and we can't proceed. We ought to |
673 | * tell the user, but since we don't have any guarantee that we're even | 714 | * tell the user, but since we don't have any guarantee that we're even |
674 | * running on the right architecture, we do virtually nothing. | 715 | * running on the right architecture, we do virtually nothing. |
@@ -715,22 +756,3 @@ __lookup_processor_type_data: | |||
715 | .quad . | 756 | .quad . |
716 | .quad cpu_table | 757 | .quad cpu_table |
717 | .size __lookup_processor_type_data, . - __lookup_processor_type_data | 758 | .size __lookup_processor_type_data, . - __lookup_processor_type_data |
718 | |||
719 | /* | ||
720 | * Determine validity of the x21 FDT pointer. | ||
721 | * The dtb must be 8-byte aligned and live in the first 512M of memory. | ||
722 | */ | ||
723 | __vet_fdt: | ||
724 | tst x21, #0x7 | ||
725 | b.ne 1f | ||
726 | cmp x21, x24 | ||
727 | b.lt 1f | ||
728 | mov x0, #(1 << 29) | ||
729 | add x0, x0, x24 | ||
730 | cmp x21, x0 | ||
731 | b.ge 1f | ||
732 | ret | ||
733 | 1: | ||
734 | mov x21, #0 | ||
735 | ret | ||
736 | ENDPROC(__vet_fdt) | ||