2 * Copyright (c) 2007-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <arm/proc_reg.h>
29 #include <arm64/asm.h>
30 #include <arm64/proc_reg.h>
31 #include <pexpert/arm64/board_config.h>
32 #include <mach_assert.h>
33 #include <machine/asm.h>
35 #include <arm64/tunables/tunables.s>
36 #include <arm64/exception_asm.h>
38 #if __ARM_KERNEL_PROTECT__
40 #endif /* __ARM_KERNEL_PROTECT__ */
44 .macro MSR_VBAR_EL1_X0
45 #if defined(KERNEL_INTEGRITY_KTRR)
47 bl EXT(pinst_set_vbar)
55 #if defined(KERNEL_INTEGRITY_KTRR)
65 .macro MSR_TTBR1_EL1_X0
66 #if defined(KERNEL_INTEGRITY_KTRR)
68 bl EXT(pinst_set_ttbr1)
75 .macro MSR_SCTLR_EL1_X0
76 #if defined(KERNEL_INTEGRITY_KTRR)
79 // This may abort, do so on SP1
82 bl EXT(pinst_set_sctlr)
83 msr SPSel, #0 // Back to SP0
87 #endif /* defined(KERNEL_INTEGRITY_KTRR) */
91 * Checks the reset handler for global and CPU-specific reset-assist functions,
92 * then jumps to the reset handler with boot args and cpu data. This is copied
93 * to the first physical page during CPU bootstrap (see cpu.c).
96 * x19 - Reset handler data pointer
97 * x20 - Boot args pointer
98 * x21 - CPU data pointer
102 .globl EXT(LowResetVectorBase)
103 LEXT(LowResetVectorBase)
105 * On reset, both RVBAR_EL1 and VBAR_EL1 point here. SPSel.SP is 1,
106 * so on reset the CPU will jump to offset 0x0 and on exceptions
107 * the CPU will jump to offset 0x200, 0x280, 0x300, or 0x380.
108 * In order for both the reset vector and exception vectors to
109 * coexist in the same space, the reset code is moved to the end
110 * of the exception vector area.
114 /* EL1 SP1: These vectors trap errors during early startup on non-boot CPUs. */
125 .globl EXT(reset_vector)
127 // Preserve x0 for start_first_cpu, if called
128 // Unlock the core for debugging
130 msr DAIFSet, #(DAIFSC_ALL) // Disable all interrupts
132 #if !(defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR))
133 // Set low reset vector before attempting any loads
134 adrp x0, EXT(LowExceptionVectorBase)@page
135 add x0, x0, EXT(LowExceptionVectorBase)@pageoff
141 // Process reset handlers
142 adrp x19, EXT(ResetHandlerData)@page // Get address of the reset handler data
143 add x19, x19, EXT(ResetHandlerData)@pageoff
144 mrs x15, MPIDR_EL1 // Load MPIDR to get CPU number
146 and x0, x15, #0xFFFF // CPU number in Affinity0, cluster ID in Affinity1
148 and x0, x15, #0xFF // CPU number is in MPIDR Affinity Level 0
150 ldr x1, [x19, CPU_DATA_ENTRIES] // Load start of data entries
151 add x3, x1, MAX_CPUS * 16 // end addr of data entries = start + (16 * MAX_CPUS)
152 Lcheck_cpu_data_entry:
153 ldr x21, [x1, CPU_DATA_PADDR] // Load physical CPU data address
154 cbz x21, Lnext_cpu_data_entry
155 ldr w2, [x21, CPU_PHYS_ID] // Load ccc cpu phys id
156 cmp x0, x2 // Compare cpu data phys cpu and MPIDR_EL1 phys cpu
157 b.eq Lfound_cpu_data_entry // Branch if match
158 Lnext_cpu_data_entry:
159 add x1, x1, #16 // Increment to the next cpu data entry
161 b.eq Lskip_cpu_reset_handler // Not found
162 b Lcheck_cpu_data_entry // loop
163 Lfound_cpu_data_entry:
164 adrp x20, EXT(const_boot_args)@page
165 add x20, x20, EXT(const_boot_args)@pageoff
166 ldr x0, [x21, CPU_RESET_HANDLER] // Call CPU reset handler
167 cbz x0, Lskip_cpu_reset_handler
169 // Validate that our handler is one of the two expected handlers
170 adrp x2, EXT(resume_idle_cpu)@page
171 add x2, x2, EXT(resume_idle_cpu)@pageoff
174 adrp x2, EXT(start_cpu)@page
175 add x2, x2, EXT(start_cpu)@pageoff
177 bne Lskip_cpu_reset_handler
184 #if __ARM_KERNEL_PROTECT__ && defined(KERNEL_INTEGRITY_KTRR)
186 * Populate TPIDR_EL1 (in case the CPU takes an exception while
187 * turning on the MMU).
189 ldr x13, [x21, CPU_ACTIVE_THREAD]
191 #endif /* __ARM_KERNEL_PROTECT__ */
194 Lskip_cpu_reset_handler:
195 b . // Hang if the handler is NULL or returns
198 .global EXT(LowResetVectorEnd)
199 LEXT(LowResetVectorEnd)
200 .global EXT(SleepToken)
203 .space (stSize_NUM),0
206 .section __DATA_CONST,__const
208 .globl EXT(ResetHandlerData)
209 LEXT(ResetHandlerData)
210 .space (rhdSize_NUM),0 // (filled with 0s)
215 * __start trampoline is located at a position relative to LowResetVectorBase
216 * so that iBoot can compute the reset vector position to set IORVBAR using
217 * only the kernel entry point. Reset vector = (__start & ~0xfff)
222 b EXT(start_first_cpu)
226 * Provides an early-boot exception vector so that the processor will spin
227 * and preserve exception information (e.g., ELR_EL1) when early CPU bootstrap
228 * code triggers an exception. This is copied to the second physical page
229 * during CPU bootstrap (see cpu.c).
232 .global EXT(LowExceptionVectorBase)
233 LEXT(LowExceptionVectorBase)
271 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
273 * Provide a global symbol so that we can narrow the V=P mapping to cover
274 * this page during arm_vm_init.
277 .globl EXT(bootstrap_instructions)
278 LEXT(bootstrap_instructions)
280 #endif /* defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR) */
282 .globl EXT(resume_idle_cpu)
283 LEXT(resume_idle_cpu)
284 adrp lr, EXT(arm_init_idle_cpu)@page
285 add lr, lr, EXT(arm_init_idle_cpu)@pageoff
289 .globl EXT(start_cpu)
291 adrp lr, EXT(arm_init_cpu)@page
292 add lr, lr, EXT(arm_init_cpu)@pageoff
297 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
298 // This is done right away in reset vector for pre-KTRR devices
299 // Set low reset vector now that we are in the KTRR-free zone
300 adrp x0, EXT(LowExceptionVectorBase)@page
301 add x0, x0, EXT(LowExceptionVectorBase)@pageoff
303 #endif /* defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR) */
305 // x20 set to BootArgs phys address
306 // x21 set to cpu data phys address
308 // Get the kernel memory parameters from the boot args
309 ldr x22, [x20, BA_VIRT_BASE] // Get the kernel virt base
310 ldr x23, [x20, BA_PHYS_BASE] // Get the kernel phys base
311 ldr x24, [x20, BA_MEM_SIZE] // Get the physical memory size
312 adrp x25, EXT(bootstrap_pagetables)@page // Get the start of the page tables
313 ldr x26, [x20, BA_BOOT_FLAGS] // Get the kernel boot flags
316 // Set TPIDRRO_EL0 with the CPU number
317 ldr x0, [x21, CPU_NUMBER_GS]
320 // Set the exception stack pointer
321 ldr x0, [x21, CPU_EXCEPSTACK_TOP]
324 // Set SP_EL1 to exception stack
325 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
327 bl EXT(pinst_spsel_1)
334 // Set the interrupt stack pointer
335 ldr x0, [x21, CPU_INTSTACK_TOP]
346 * create_l1_table_entry
348 * Given a virtual address, creates a table entry in an L1 translation table
349 * to point to an L2 translation table.
350 * arg0 - Virtual address
351 * arg1 - L1 table address
352 * arg2 - L2 table address
353 * arg3 - Scratch register
354 * arg4 - Scratch register
355 * arg5 - Scratch register
357 .macro create_l1_table_entry
358 and $3, $0, #(ARM_TT_L1_INDEX_MASK)
359 lsr $3, $3, #(ARM_TT_L1_SHIFT) // Get index in L1 table for L2 table
360 lsl $3, $3, #(TTE_SHIFT) // Convert index into pointer offset
361 add $3, $1, $3 // Get L1 entry pointer
362 mov $4, #(ARM_TTE_BOOT_TABLE) // Get L1 table entry template
363 and $5, $2, #(ARM_TTE_TABLE_MASK) // Get address bits of L2 table
364 orr $5, $4, $5 // Create table entry for L2 table
365 str $5, [$3] // Write entry to L1 table
369 * create_l2_block_entries
371 * Given base virtual and physical addresses, creates consecutive block entries
372 * in an L2 translation table.
373 * arg0 - Virtual address
374 * arg1 - Physical address
375 * arg2 - L2 table address
376 * arg3 - Number of entries
377 * arg4 - Scratch register
378 * arg5 - Scratch register
379 * arg6 - Scratch register
380 * arg7 - Scratch register
382 .macro create_l2_block_entries
383 and $4, $0, #(ARM_TT_L2_INDEX_MASK)
384 lsr $4, $4, #(ARM_TTE_BLOCK_L2_SHIFT) // Get index in L2 table for block entry
385 lsl $4, $4, #(TTE_SHIFT) // Convert index into pointer offset
386 add $4, $2, $4 // Get L2 entry pointer
387 mov $5, #(ARM_TTE_BOOT_BLOCK) // Get L2 block entry template
388 and $6, $1, #(ARM_TTE_BLOCK_L2_MASK) // Get address bits of block mapping
391 mov $7, #(ARM_TT_L2_SIZE)
393 str $6, [$4], #(1 << TTE_SHIFT) // Write entry to L2 table and advance
394 add $6, $6, $7 // Increment the output address
395 subs $5, $5, #1 // Decrement the number of entries
400 * arg0 - virtual start address
401 * arg1 - physical start address
402 * arg2 - number of entries to map
403 * arg3 - L1 table address
404 * arg4 - free space pointer
405 * arg5 - scratch (entries mapped per loop)
411 .macro create_bootstrap_mapping
412 /* calculate entries left in this page */
413 and $5, $0, #(ARM_TT_L2_INDEX_MASK)
414 lsr $5, $5, #(ARM_TT_L2_SHIFT)
415 mov $6, #(TTE_PGENTRIES)
418 /* allocate an L2 table */
419 3: add $4, $4, PGBYTES
421 /* create_l1_table_entry(virt_base, L1 table, L2 table, scratch1, scratch2, scratch3) */
422 create_l1_table_entry $0, $3, $4, $6, $7, $8
424 /* determine how many entries to map this loop - the smaller of entries
425 * remaining in page and total entries left */
429 /* create_l2_block_entries(virt_base, phys_base, L2 table, num_ents, scratch1, scratch2, scratch3) */
430 create_l2_block_entries $0, $1, $4, $5, $6, $7, $8, $9
432 /* subtract entries just mapped and bail out if we're done */
436 /* entries left to map - advance base pointers */
437 add $0, $0, $5, lsl #(ARM_TT_L2_SHIFT)
438 add $1, $1, $5, lsl #(ARM_TT_L2_SHIFT)
440 mov $5, #(TTE_PGENTRIES) /* subsequent loops map (up to) a whole L2 page */
447 * Cold boot init routine. Called from __start
451 .globl EXT(start_first_cpu)
452 LEXT(start_first_cpu)
454 // Unlock the core for debugging
456 msr DAIFSet, #(DAIFSC_ALL) // Disable all interrupts
461 // Set low reset vector before attempting any loads
462 adrp x0, EXT(LowExceptionVectorBase)@page
463 add x0, x0, EXT(LowExceptionVectorBase)@pageoff
467 // Get the kernel memory parameters from the boot args
468 ldr x22, [x20, BA_VIRT_BASE] // Get the kernel virt base
469 ldr x23, [x20, BA_PHYS_BASE] // Get the kernel phys base
470 ldr x24, [x20, BA_MEM_SIZE] // Get the physical memory size
471 adrp x25, EXT(bootstrap_pagetables)@page // Get the start of the page tables
472 ldr x26, [x20, BA_BOOT_FLAGS] // Get the kernel boot flags
474 // Clear the register that will be used to store the userspace thread pointer and CPU number.
475 // We may not actually be booting from ordinal CPU 0, so this register will be updated
476 // in ml_parse_cpu_topology(), which happens later in bootstrap.
479 // Set up exception stack pointer
480 adrp x0, EXT(excepstack_top)@page // Load top of exception stack
481 add x0, x0, EXT(excepstack_top)@pageoff
482 add x0, x0, x22 // Convert to KVA
485 // Set SP_EL1 to exception stack
486 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
487 bl EXT(pinst_spsel_1)
494 // Set up interrupt stack pointer
495 adrp x0, EXT(intstack_top)@page // Load top of irq stack
496 add x0, x0, EXT(intstack_top)@pageoff
497 add x0, x0, x22 // Convert to KVA
499 msr SPSel, #0 // Set SP_EL0 to interrupt stack
502 // Load address to the C init routine into link register
503 adrp lr, EXT(arm_init)@page
504 add lr, lr, EXT(arm_init)@pageoff
505 add lr, lr, x22 // Convert to KVA
509 * Set up the bootstrap page tables with a single block entry for the V=P
510 * mapping, a single block entry for the trampolined kernel address (KVA),
511 * and all else invalid. This requires four pages:
512 * Page 1 - V=P L1 table
513 * Page 2 - V=P L2 table
514 * Page 3 - KVA L1 table
515 * Page 4 - KVA L2 table
518 // Invalidate all entries in the bootstrap page tables
519 mov x0, #(ARM_TTE_EMPTY) // Load invalid entry template
520 mov x1, x25 // Start at V=P pagetable root
521 mov x2, #(TTE_PGENTRIES) // Load number of entries per page
522 lsl x2, x2, #2 // Shift by 2 for num entries on 4 pages
524 Linvalidate_bootstrap: // do {
525 str x0, [x1], #(1 << TTE_SHIFT) // Invalidate and advance
526 subs x2, x2, #1 // entries--
527 b.ne Linvalidate_bootstrap // } while (entries != 0)
530 * In order to reclaim memory on targets where TZ0 (or some other entity)
531 * must be located at the base of memory, iBoot may set the virtual and
532 * physical base addresses to immediately follow whatever lies at the
533 * base of physical memory.
535 * If the base address belongs to TZ0, it may be dangerous for xnu to map
536 * it (as it may be prefetched, despite being technically inaccessible).
537 * In order to avoid this issue while keeping the mapping code simple, we
538 * may continue to use block mappings, but we will only map the kernelcache
539 * mach header to the end of memory.
541 * Given that iBoot guarantees that the unslid kernelcache base address
542 * will begin on an L2 boundary, this should prevent us from accidentally
545 adrp x0, EXT(_mh_execute_header)@page // address of kernel mach header
546 add x0, x0, EXT(_mh_execute_header)@pageoff
547 ldr w1, [x0, #0x18] // load mach_header->flags
548 tbz w1, #0x1f, Lkernelcache_base_found // if MH_DYLIB_IN_CACHE unset, base is kernel mach header
549 ldr w1, [x0, #0x20] // load first segment cmd (offset sizeof(kernel_mach_header_t))
550 cmp w1, #0x19 // must be LC_SEGMENT_64
552 ldr x1, [x0, #0x38] // load first segment vmaddr
553 sub x1, x0, x1 // compute slide
554 MOV64 x0, VM_KERNEL_LINK_ADDRESS
555 add x0, x0, x1 // base is kernel link address + slide
557 Lkernelcache_base_found:
559 * Adjust physical and virtual base addresses to account for physical
560 * memory preceeding xnu Mach-O header
561 * x22 - Kernel virtual base
562 * x23 - Kernel physical base
563 * x24 - Physical memory size
571 * x0 - V=P virtual cursor
572 * x4 - V=P physical cursor
573 * x14 - KVA virtual cursor
574 * x15 - KVA physical cursor
584 * x2 - free mem pointer from which we allocate a variable number of L2
585 * pages. The maximum number of bootstrap page table pages is limited to
586 * BOOTSTRAP_TABLE_SIZE. For a 2G 4k page device, assuming the worst-case
587 * slide, we need 1xL1 and up to 3xL2 pages (1GB mapped per L1 entry), so
588 * 8 total pages for V=P and KVA.
595 * Setup the V=P bootstrap mapping
596 * x5 - total number of L2 entries to allocate
598 lsr x5, x24, #(ARM_TT_L2_SHIFT)
599 /* create_bootstrap_mapping(vbase, pbase, num_ents, L1 table, freeptr) */
600 create_bootstrap_mapping x0, x4, x5, x1, x2, x6, x10, x11, x12, x13
602 /* Setup the KVA bootstrap mapping */
603 lsr x5, x24, #(ARM_TT_L2_SHIFT)
604 create_bootstrap_mapping x14, x15, x5, x3, x2, x9, x10, x11, x12, x13
606 /* Ensure TTEs are visible */
613 * Begin common CPU initialization
616 * x20 - PA of boot args
617 * x21 - zero on cold boot, PA of cpu data on warm reset
618 * x22 - Kernel virtual base
619 * x23 - Kernel physical base
620 * x25 - PA of the V=P pagetable root
621 * lr - KVA of C init routine
622 * sp - SP_EL0 selected
624 * SP_EL0 - KVA of CPU's interrupt stack
625 * SP_EL1 - KVA of CPU's exception stack
626 * TPIDRRO_EL0 - CPU number
636 // Set the translation control register.
637 adrp x0, EXT(sysreg_restore)@page // Load TCR value from the system register restore structure
638 add x0, x0, EXT(sysreg_restore)@pageoff
639 ldr x1, [x0, SR_RESTORE_TCR_EL1]
642 /* Set up translation table base registers.
643 * TTBR0 - V=P table @ top of kernel
644 * TTBR1 - KVA table @ top of kernel + 1 page
646 #if defined(KERNEL_INTEGRITY_KTRR) || defined(KERNEL_INTEGRITY_CTRR)
647 /* Note that for KTRR configurations, the V=P map will be modified by
651 and x0, x25, #(TTBR_BADDR_MASK)
656 and x0, x0, #(TTBR_BADDR_MASK)
659 // Set up MAIR attr0 for normal memory, attr1 for device memory
661 mov x1, #(MAIR_WRITEBACK << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_WRITEBACK))
663 mov x1, #(MAIR_INNERWRITEBACK << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_INNERWRITEBACK))
665 mov x1, #(MAIR_DISABLE << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_DISABLE))
667 mov x1, #(MAIR_WRITETHRU << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_WRITETHRU))
669 mov x1, #(MAIR_WRITECOMB << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_WRITECOMB))
671 mov x1, #(MAIR_POSTED << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_POSTED))
673 mov x1, #(MAIR_POSTED_REORDERED << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_POSTED_REORDERED))
675 mov x1, #(MAIR_POSTED_COMBINED_REORDERED << MAIR_ATTR_SHIFT(CACHE_ATTRINDX_POSTED_COMBINED_REORDERED))
682 #if defined(APPLEHURRICANE)
683 // <rdar://problem/26726624> Increase Snoop reservation in EDB to reduce starvation risk
684 // Needs to be done before MMU is enabled
685 HID_INSERT_BITS HID5, ARM64_REG_HID5_CrdEdbSnpRsvd_mask, ARM64_REG_HID5_CrdEdbSnpRsvd_VALUE, x12
689 // Setup timer interrupt routing; must be done before MMU is enabled
690 mrs x15, MPIDR_EL1 // Load MPIDR to get CPU number
691 and x15, x15, #0xFF // CPU number is in MPIDR Affinity Level 0
694 add x0, x0, #0x0040 // x0: 0x4000004X Core Timers interrupt control
695 add x0, x0, x15, lsl #2
696 mov w1, #0xF0 // x1: 0xF0 Route to Core FIQs
701 #ifndef __ARM_IC_NOALIAS_ICACHE__
702 /* Invalidate the TLB and icache on systems that do not guarantee that the
703 * caches are invalidated on reset.
709 /* If x21 is not 0, then this is either the start_cpu path or
710 * the resume_idle_cpu path. cpu_ttep should already be
711 * populated, so just switch to the kernel_pmap now.
715 adrp x0, EXT(cpu_ttep)@page
716 add x0, x0, EXT(cpu_ttep)@pageoff
721 // Set up the exception vectors
722 #if __ARM_KERNEL_PROTECT__
723 /* If this is not the first reset of the boot CPU, the alternate mapping
724 * for the exception vectors will be set up, so use it. Otherwise, we
725 * should use the mapping located in the kernelcache mapping.
727 MOV64 x0, ARM_KERNEL_PROTECT_EXCEPTION_START
730 #endif /* __ARM_KERNEL_PROTECT__ */
731 adrp x0, EXT(ExceptionVectorsBase)@page // Load exception vectors base address
732 add x0, x0, EXT(ExceptionVectorsBase)@pageoff
733 add x0, x0, x22 // Convert exception vector address to KVA
741 // Enable caches, MMU, ROP and JOP
742 MOV64 x0, SCTLR_EL1_DEFAULT
743 orr x0, x0, #(SCTLR_PACIB_ENABLED) /* IB is ROP */
745 MOV64 x1, SCTLR_JOP_KEYS_ENABLED
747 #else /* HAS_APPLE_PAC */
749 // Enable caches and MMU
750 MOV64 x0, SCTLR_EL1_DEFAULT
751 #endif /* HAS_APPLE_PAC */
755 MOV64 x1, SCTLR_EL1_DEFAULT
757 orr x1, x1, #(SCTLR_PACIB_ENABLED)
758 MOV64 x2, SCTLR_JOP_KEYS_ENABLED
760 #endif /* HAS_APPLE_PAC */
764 #if (!CONFIG_KERNEL_INTEGRITY || (CONFIG_KERNEL_INTEGRITY && !defined(KERNEL_INTEGRITY_WT)))
767 * If we have a Watchtower monitor it will setup CPACR_EL1 for us, touching
768 * it here would trap to EL3.
772 mov x0, #(CPACR_FPEN_ENABLE)
776 // Clear thread pointer
777 msr TPIDR_EL1, xzr // Set thread register
780 #if defined(APPLE_ARM64_ARCH_FAMILY)
781 // Initialization common to all non-virtual Apple targets
783 ARM64_READ_EP_SPR x15, x12, S3_0_C15_C4_1, S3_0_C15_C4_0
784 orr x12, x12, ARM64_REG_HID4_DisDcMVAOps
785 orr x12, x12, ARM64_REG_HID4_DisDcSWL2Ops
786 ARM64_WRITE_EP_SPR x15, x12, S3_0_C15_C4_1, S3_0_C15_C4_0
787 #endif // APPLE_ARM64_ARCH_FAMILY
789 // Read MIDR before start of per-SoC tunables
792 APPLY_TUNABLES x12, x13
797 // Unmask external IRQs if we're restarting from non-retention WFI
799 and x9, x9, #(~(ARM64_REG_CYC_OVRD_irq_mask | ARM64_REG_CYC_OVRD_fiq_mask))
803 // If x21 != 0, we're doing a warm reset, so we need to trampoline to the kernel pmap.
804 cbnz x21, Ltrampoline
806 // Set KVA of boot args as first arg
815 // x1: KVA page table phys base
817 bl EXT(kasan_bootstrap)
823 // Return to arm_init()
827 // Load VA of the trampoline
828 adrp x0, arm_init_tramp@page
829 add x0, x0, arm_init_tramp@pageoff
833 // Branch to the trampoline
837 * V=P to KVA trampoline.
838 * x0 - KVA of cpu data pointer
843 /* On a warm boot, the full kernel translation table is initialized in
844 * addition to the bootstrap tables. The layout is as follows:
846 * +--Top of Memory--+
852 * +--Top + 5 pages--+
856 * +--Top + 4 pages--+
860 * +--Top + 2 pages--+
864 * +--Top of Kernel--+
869 * +---Kernel Base---+
874 #if defined(HAS_VMSA_LOCK)
877 // Convert CPU data PA to VA and set as first argument
883 /* Return to arm_init() */
886 //#include "globals_asm.h"