1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/boot/compressed/head.S
5 * Copyright (C) 1996-2002 Russell King
6 * Copyright (C) 2004 Hyok S. Choi (MPU support)
8 #include <linux/linkage.h>
9 #include <asm/assembler.h>
12 #include "efi-header.S"
14 AR_CLASS( .arch armv7-a )
15 M_CLASS( .arch armv7-m )
20 * Note that these macros must not contain any code which is not
21 * 100% relocatable. Any attempt to do so will result in a crash.
22 * Please select one of the following when turning on debugging.
26 #if defined(CONFIG_DEBUG_ICEDCC)
28 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
29 .macro loadsp, rb, tmp1, tmp2
32 mcr p14, 0, \ch, c0, c5, 0
34 #elif defined(CONFIG_CPU_XSCALE)
35 .macro loadsp, rb, tmp1, tmp2
38 mcr p14, 0, \ch, c8, c0, 0
41 .macro loadsp, rb, tmp1, tmp2
44 mcr p14, 0, \ch, c1, c0, 0
50 #include CONFIG_DEBUG_LL_INCLUDE
56 #if defined(CONFIG_ARCH_SA1100)
57 .macro loadsp, rb, tmp1, tmp2
58 mov \rb, #0x80000000 @ physical base address
59 #ifdef CONFIG_DEBUG_LL_SER3
60 add \rb, \rb, #0x00050000 @ Ser3
62 add \rb, \rb, #0x00010000 @ Ser1
66 .macro loadsp, rb, tmp1, tmp2
67 addruart \rb, \tmp1, \tmp2
84 .macro debug_reloc_start
87 kphex r6, 8 /* processor id */
89 kphex r7, 8 /* architecture id */
90 #ifdef CONFIG_CPU_CP15
92 mrc p15, 0, r0, c1, c0
93 kphex r0, 8 /* control reg */
96 kphex r5, 8 /* decompressed kernel start */
98 kphex r9, 8 /* decompressed kernel end */
100 kphex r4, 8 /* kernel execution address */
105 .macro debug_reloc_end
107 kphex r5, 8 /* end of kernel */
110 bl memdump /* dump 256 bytes at start of kernel */
115 * Debug kernel copy by printing the memory addresses involved
117 .macro dbgkc, begin, end, cbegin, cend
124 kphex \begin, 8 /* Start of compressed kernel */
128 kphex \end, 8 /* End of compressed kernel */
133 kphex \cbegin, 8 /* Start of kernel copy */
137 kphex \cend, 8 /* End of kernel copy */
143 .section ".start", #alloc, #execinstr
145 * sort out different calling conventions
149 * Always enter in ARM state for CPUs that support the ARM ISA.
150 * As of today (2014) that's exactly the members of the A and R
155 .type start,#function
159 #ifndef CONFIG_THUMB2_KERNEL
162 AR_CLASS( sub pc, pc, #3 ) @ A/R: switch to Thumb2 mode
163 M_CLASS( nop.w ) @ M: already in Thumb2 mode
168 .word _magic_sig @ Magic numbers to help the loader
169 .word _magic_start @ absolute load/run zImage address
170 .word _magic_end @ zImage end address
171 .word 0x04030201 @ endianness flag
172 .word 0x45454545 @ another magic number to indicate
173 .word _magic_table @ additional data table
177 ARM_BE8( setend be ) @ go BE8 if compiled for BE8
178 AR_CLASS( mrs r9, cpsr )
179 #ifdef CONFIG_ARM_VIRT_EXT
180 bl __hyp_stub_install @ get into SVC mode, reversibly
182 mov r7, r1 @ save architecture ID
183 mov r8, r2 @ save atags pointer
185 #ifndef CONFIG_CPU_V7M
187 * Booting from Angel - need to enter SVC mode and disable
188 * FIQs/IRQs (numeric definitions from angel arm.h source).
189 * We only do this if we were in user mode on entry.
191 mrs r2, cpsr @ get current mode
192 tst r2, #3 @ not user?
194 mov r0, #0x17 @ angel_SWIreason_EnterSVC
195 ARM( swi 0x123456 ) @ angel_SWI_ARM
196 THUMB( svc 0xab ) @ angel_SWI_THUMB
198 safe_svcmode_maskall r0
199 msr spsr_cxsf, r9 @ Save the CPU boot mode in
203 * Note that some cache flushing and other stuff may
204 * be needed here - is there an Angel SWI call for this?
208 * some architecture specific code can be inserted
209 * by the linker here, but it should preserve r7, r8, and r9.
214 #ifdef CONFIG_AUTO_ZRELADDR
216 * Find the start of physical memory. As we are executing
217 * without the MMU on, we are in the physical address space.
218 * We just need to get rid of any offset by aligning the
221 * This alignment is a balance between the requirements of
222 * different platforms - we have chosen 128MB to allow
223 * platforms which align the start of their physical memory
224 * to 128MB to use this feature, while allowing the zImage
225 * to be placed within the first 128MB of memory on other
226 * platforms. Increasing the alignment means we place
227 * stricter alignment requirements on the start of physical
228 * memory, but relaxing it means that we break people who
229 * are already placing their zImage in (eg) the top 64MB
233 and r4, r4, #0xf8000000
234 /* Determine final kernel image address. */
235 add r4, r4, #TEXT_OFFSET
241 * Set up a page table only if it won't overwrite ourself.
242 * That means r4 < pc || r4 - 16k page directory > &_end.
243 * Given that r4 > &_end is most unfrequent, we add a rough
244 * additional 1MB of room for a possible appended DTB.
251 orrcc r4, r4, #1 @ remember we skipped cache_on
255 ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
259 * We might be running at a different address. We need
260 * to fix up various pointers.
262 sub r0, r0, r1 @ calculate the delta offset
263 add r6, r6, r0 @ _edata
264 add r10, r10, r0 @ inflated kernel size location
267 * The kernel build system appends the size of the
268 * decompressed kernel at the end of the compressed data
269 * in little-endian form.
273 orr r9, r9, lr, lsl #8
276 orr r9, r9, lr, lsl #16
277 orr r9, r9, r10, lsl #24
279 #ifndef CONFIG_ZBOOT_ROM
280 /* malloc space is above the relocated stack (64k max) */
282 add r10, sp, #0x10000
285 * With ZBOOT_ROM the bss/stack is non relocatable,
286 * but someone could still run this code from RAM,
287 * in which case our reference is _edata.
292 mov r5, #0 @ init dtb size to 0
293 #ifdef CONFIG_ARM_APPENDED_DTB
298 * r4 = final kernel address (possibly with LSB set)
299 * r5 = appended dtb size (still unknown)
301 * r7 = architecture ID
302 * r8 = atags/device tree pointer
303 * r9 = size of decompressed image
304 * r10 = end of this image, including bss/stack/malloc space if non XIP
309 * if there are device trees (dtb) appended to zImage, advance r10 so that the
310 * dtb data will get relocated along with the kernel if necessary.
315 ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
320 bne dtb_check_done @ not found
322 #ifdef CONFIG_ARM_ATAG_DTB_COMPAT
324 * OK... Let's do some funky business here.
325 * If we do have a DTB appended to zImage, and we do have
326 * an ATAG list around, we want the later to be translated
327 * and folded into the former here. No GOT fixup has occurred
328 * yet, but none of the code we're about to call uses any
332 /* Get the initial DTB size */
335 /* convert to little endian */
336 eor r1, r5, r5, ror #16
337 bic r1, r1, #0x00ff0000
339 eor r5, r5, r1, lsr #8
341 /* 50% DTB growth should be good enough */
342 add r5, r5, r5, lsr #1
343 /* preserve 64-bit alignment */
346 /* clamp to 32KB min and 1MB max */
351 /* temporarily relocate the stack past the DTB work space */
354 stmfd sp!, {r0-r3, ip, lr}
361 * If returned value is 1, there is no ATAG at the location
362 * pointed by r8. Try the typical 0x100 offset from start
363 * of RAM and hope for the best.
366 sub r0, r4, #TEXT_OFFSET
373 ldmfd sp!, {r0-r3, ip, lr}
377 mov r8, r6 @ use the appended device tree
380 * Make sure that the DTB doesn't end up in the final
381 * kernel's .bss area. To do so, we adjust the decompressed
382 * kernel size to compensate if that .bss size is larger
383 * than the relocated code.
385 ldr r5, =_kernel_bss_size
386 adr r1, wont_overwrite
391 /* Get the current DTB size */
394 /* convert r5 (dtb size) to little endian */
395 eor r1, r5, r5, ror #16
396 bic r1, r1, #0x00ff0000
398 eor r5, r5, r1, lsr #8
401 /* preserve 64-bit alignment */
405 /* relocate some pointers past the appended dtb */
413 * Check to see if we will overwrite ourselves.
414 * r4 = final kernel address (possibly with LSB set)
415 * r9 = size of decompressed image
416 * r10 = end of this image, including bss/stack/malloc space if non XIP
418 * r4 - 16k page directory >= r10 -> OK
419 * r4 + image length <= address of wont_overwrite -> OK
420 * Note: the possible LSB in r4 is harmless here.
426 adr r9, wont_overwrite
431 * Relocate ourselves past the end of the decompressed kernel.
433 * r10 = end of the decompressed kernel
434 * Because we always copy ahead, we need to do it from the end and go
435 * backward in case the source and destination overlap.
438 * Bump to the next 256-byte boundary with the size of
439 * the relocation code added. This avoids overwriting
440 * ourself when the offset is small.
442 add r10, r10, #((reloc_code_end - restart + 256) & ~255)
445 /* Get start of code we want to copy and align it down. */
449 /* Relocate the hyp vector base if necessary */
450 #ifdef CONFIG_ARM_VIRT_EXT
452 and r0, r0, #MODE_MASK
457 * Compute the address of the hyp vectors after relocation.
458 * This requires some arithmetic since we cannot directly
459 * reference __hyp_stub_vectors in a PC-relative way.
460 * Call __hyp_set_vectors with the new address so that we
461 * can HVC again after the copy.
464 movw r1, #:lower16:__hyp_stub_vectors - 0b
465 movt r1, #:upper16:__hyp_stub_vectors - 0b
473 sub r9, r6, r5 @ size to copy
474 add r9, r9, #31 @ rounded up to a multiple
475 bic r9, r9, #31 @ ... of 32 bytes
483 * We are about to copy the kernel to a new memory area.
484 * The boundaries of the new memory area can be found in
485 * r10 and r9, whilst r5 and r6 contain the boundaries
486 * of the memory we are going to copy.
487 * Calling dbgkc will help with the printing of this
490 dbgkc r5, r6, r10, r9
493 1: ldmdb r6!, {r0 - r3, r10 - r12, lr}
495 stmdb r9!, {r0 - r3, r10 - r12, lr}
498 /* Preserve offset to relocated code. */
501 #ifndef CONFIG_ZBOOT_ROM
502 /* cache_clean_flush may use the stack, so relocate it */
514 * If delta is zero, we are running at the address we were linked at.
518 * r4 = kernel execution address (possibly with LSB set)
519 * r5 = appended dtb size (0 if not present)
520 * r7 = architecture ID
532 #ifndef CONFIG_ZBOOT_ROM
534 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
535 * we need to fix up pointers into the BSS region.
536 * Note that the stack pointer has already been fixed up.
542 * Relocate all entries in the GOT table.
543 * Bump bss entries to _edata + dtb size
545 1: ldr r1, [r11, #0] @ relocate entries in the GOT
546 add r1, r1, r0 @ This fixes up C references
547 cmp r1, r2 @ if entry >= bss_start &&
548 cmphs r3, r1 @ bss_end > entry
549 addhi r1, r1, r5 @ entry += dtb size
550 str r1, [r11], #4 @ next entry
554 /* bump our bss pointers too */
561 * Relocate entries in the GOT table. We only relocate
562 * the entries that are outside the (relocated) BSS region.
564 1: ldr r1, [r11, #0] @ relocate entries in the GOT
565 cmp r1, r2 @ entry < bss_start ||
566 cmphs r3, r1 @ _end < entry
567 addlo r1, r1, r0 @ table. This fixes up the
568 str r1, [r11], #4 @ C references.
573 not_relocated: mov r0, #0
574 1: str r0, [r2], #4 @ clear bss
582 * Did we skip the cache setup earlier?
583 * That is indicated by the LSB in r4.
591 * The C runtime environment should now be setup sufficiently.
592 * Set up some pointers, and start decompressing.
593 * r4 = kernel execution address
594 * r7 = architecture ID
598 mov r1, sp @ malloc space above stack
599 add r2, sp, #0x10000 @ 64k max
605 #ifdef CONFIG_ARM_VIRT_EXT
606 mrs r0, spsr @ Get saved CPU boot mode
607 and r0, r0, #MODE_MASK
608 cmp r0, #HYP_MODE @ if not booted in HYP mode...
609 bne __enter_kernel @ boot kernel directly
611 adr r12, .L__hyp_reentry_vectors_offset
616 __HVC(0) @ otherwise bounce to hyp mode
618 b . @ should never be reached
621 .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
629 .word __bss_start @ r2
632 .word input_data_end - 4 @ r10 (inflated size location)
633 .word _got_start @ r11
635 .word .L_user_stack_end @ sp
636 .word _end - restart + 16384 + 1024*1024
639 #ifdef CONFIG_ARCH_RPC
641 params: ldr r0, =0x10000100 @ params_phys for RPC
648 * Turn on the cache. We need to setup some page tables so that we
649 * can have both the I and D caches on.
651 * We place the page tables 16k down from the kernel execution address,
652 * and we hope that nothing else is using it. If we're using it, we
656 * r4 = kernel execution address
657 * r7 = architecture number
660 * r0, r1, r2, r3, r9, r10, r12 corrupted
661 * This routine must preserve:
665 cache_on: mov r3, #8 @ cache_on function
669 * Initialize the highest priority protection region, PR7
670 * to cover all 32bit address and cacheable and bufferable.
672 __armv4_mpu_cache_on:
673 mov r0, #0x3f @ 4G, the whole
674 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
675 mcr p15, 0, r0, c6, c7, 1
678 mcr p15, 0, r0, c2, c0, 0 @ D-cache on
679 mcr p15, 0, r0, c2, c0, 1 @ I-cache on
680 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
683 mcr p15, 0, r0, c5, c0, 1 @ I-access permission
684 mcr p15, 0, r0, c5, c0, 0 @ D-access permission
687 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
688 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
689 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
690 mrc p15, 0, r0, c1, c0, 0 @ read control reg
691 @ ...I .... ..D. WC.M
692 orr r0, r0, #0x002d @ .... .... ..1. 11.1
693 orr r0, r0, #0x1000 @ ...1 .... .... ....
695 mcr p15, 0, r0, c1, c0, 0 @ write control reg
698 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
699 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
702 __armv3_mpu_cache_on:
703 mov r0, #0x3f @ 4G, the whole
704 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
707 mcr p15, 0, r0, c2, c0, 0 @ cache on
708 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
711 mcr p15, 0, r0, c5, c0, 0 @ access permission
714 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
716 * ?? ARMv3 MMU does not allow reading the control register,
717 * does this really work on ARMv3 MPU?
719 mrc p15, 0, r0, c1, c0, 0 @ read control reg
720 @ .... .... .... WC.M
721 orr r0, r0, #0x000d @ .... .... .... 11.1
722 /* ?? this overwrites the value constructed above? */
724 mcr p15, 0, r0, c1, c0, 0 @ write control reg
726 /* ?? invalidate for the second time? */
727 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
730 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
736 __setup_mmu: sub r3, r4, #16384 @ Page directory size
737 bic r3, r3, #0xff @ Align the pointer
740 * Initialise the page tables, turning on the cacheable and bufferable
741 * bits for the RAM area only.
745 mov r9, r9, lsl #18 @ start of RAM
746 add r10, r9, #0x10000000 @ a reasonable RAM size
747 mov r1, #0x12 @ XN|U + section mapping
748 orr r1, r1, #3 << 10 @ AP=11
750 1: cmp r1, r9 @ if virt > start of RAM
751 cmphs r10, r1 @ && end of RAM > virt
752 bic r1, r1, #0x1c @ clear XN|U + C + B
753 orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
754 orrhs r1, r1, r6 @ set RAM section settings
755 str r1, [r0], #4 @ 1:1 mapping
760 * If ever we are running from Flash, then we surely want the cache
761 * to be enabled also for our execution instance... We map 2MB of it
762 * so there is no map overlap problem for up to 1 MB compressed kernel.
763 * If the execution is in RAM then we would only be duplicating the above.
765 orr r1, r6, #0x04 @ ensure B is set for this
769 orr r1, r1, r2, lsl #20
770 add r0, r3, r2, lsl #2
777 @ Enable unaligned access on v6, to allow better code generation
778 @ for the decompressor C code:
779 __armv6_mmu_cache_on:
780 mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
781 bic r0, r0, #2 @ A (no unaligned access fault)
782 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
783 mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
784 b __armv4_mmu_cache_on
786 __arm926ejs_mmu_cache_on:
787 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
788 mov r0, #4 @ put dcache in WT mode
789 mcr p15, 7, r0, c15, c0, 0
792 __armv4_mmu_cache_on:
795 mov r6, #CB_BITS | 0x12 @ U
798 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
799 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
800 mrc p15, 0, r0, c1, c0, 0 @ read control reg
801 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
803 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
804 bl __common_mmu_cache_on
806 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
810 __armv7_mmu_cache_on:
813 mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
815 movne r6, #CB_BITS | 0x02 @ !XN
818 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
820 mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
822 mrc p15, 0, r0, c1, c0, 0 @ read control reg
823 bic r0, r0, #1 << 28 @ clear SCTLR.TRE
824 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
825 orr r0, r0, #0x003c @ write buffer
826 bic r0, r0, #2 @ A (no unaligned access fault)
827 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
828 @ (needed for ARM1176)
830 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
831 mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
832 orrne r0, r0, #1 @ MMU enabled
833 movne r1, #0xfffffffd @ domain 0 = client
834 bic r6, r6, #1 << 31 @ 32-bit translation system
835 bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0
836 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
837 mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
838 mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
840 mcr p15, 0, r0, c7, c5, 4 @ ISB
841 mcr p15, 0, r0, c1, c0, 0 @ load control register
842 mrc p15, 0, r0, c1, c0, 0 @ and read it back
844 mcr p15, 0, r0, c7, c5, 4 @ ISB
849 mov r6, #CB_BITS | 0x12 @ U
852 mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
853 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
854 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
855 mrc p15, 0, r0, c1, c0, 0 @ read control reg
856 orr r0, r0, #0x1000 @ I-cache enable
857 bl __common_mmu_cache_on
859 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
862 __common_mmu_cache_on:
863 #ifndef CONFIG_THUMB2_KERNEL
865 orr r0, r0, #0x000d @ Write buffer, mmu
868 mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
869 mcr p15, 0, r1, c3, c0, 0 @ load domain access control
871 .align 5 @ cache line aligned
872 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
873 mrc p15, 0, r0, c1, c0, 0 @ and read it back to
874 sub pc, lr, r0, lsr #32 @ properly flush pipeline
877 #define PROC_ENTRY_SIZE (4*5)
880 * Here follow the relocatable cache support functions for the
881 * various processors. This is a generic hook for locating an
882 * entry and jumping to an instruction at the specified offset
883 * from the start of the block. Please note this is all position
893 call_cache_fn: adr r12, proc_types
894 #ifdef CONFIG_CPU_CP15
895 mrc p15, 0, r9, c0, c0 @ get processor ID
896 #elif defined(CONFIG_CPU_V7M)
898 * On v7-M the processor id is located in the V7M_SCB_CPUID
899 * register, but as cache handling is IMPLEMENTATION DEFINED on
900 * v7-M (if existant at all) we just return early here.
901 * If V7M_SCB_CPUID were used the cpu ID functions (i.e.
902 * __armv7_mmu_cache_{on,off,flush}) would be selected which
903 * use cp15 registers that are not implemented on v7-M.
907 ldr r9, =CONFIG_PROCESSOR_ID
909 1: ldr r1, [r12, #0] @ get value
910 ldr r2, [r12, #4] @ get mask
911 eor r1, r1, r9 @ (real ^ match)
913 ARM( addeq pc, r12, r3 ) @ call cache function
914 THUMB( addeq r12, r3 )
915 THUMB( moveq pc, r12 ) @ call cache function
916 add r12, r12, #PROC_ENTRY_SIZE
920 * Table for cache operations. This is basically:
923 * - 'cache on' method instruction
924 * - 'cache off' method instruction
925 * - 'cache flush' method instruction
927 * We match an entry using: ((real_id ^ match) & mask) == 0
929 * Writethrough caches generally only need 'on' and 'off'
930 * methods. Writeback caches _must_ have the flush method
934 .type proc_types,#object
936 .word 0x41000000 @ old ARM ID
945 .word 0x41007000 @ ARM7/710
954 .word 0x41807200 @ ARM720T (writethrough)
956 W(b) __armv4_mmu_cache_on
957 W(b) __armv4_mmu_cache_off
961 .word 0x41007400 @ ARM74x
963 W(b) __armv3_mpu_cache_on
964 W(b) __armv3_mpu_cache_off
965 W(b) __armv3_mpu_cache_flush
967 .word 0x41009400 @ ARM94x
969 W(b) __armv4_mpu_cache_on
970 W(b) __armv4_mpu_cache_off
971 W(b) __armv4_mpu_cache_flush
973 .word 0x41069260 @ ARM926EJ-S (v5TEJ)
975 W(b) __arm926ejs_mmu_cache_on
976 W(b) __armv4_mmu_cache_off
977 W(b) __armv5tej_mmu_cache_flush
979 .word 0x00007000 @ ARM7 IDs
988 @ Everything from here on will be the new ID system.
990 .word 0x4401a100 @ sa110 / sa1100
992 W(b) __armv4_mmu_cache_on
993 W(b) __armv4_mmu_cache_off
994 W(b) __armv4_mmu_cache_flush
996 .word 0x6901b110 @ sa1110
998 W(b) __armv4_mmu_cache_on
999 W(b) __armv4_mmu_cache_off
1000 W(b) __armv4_mmu_cache_flush
1003 .word 0xffffff00 @ PXA9xx
1004 W(b) __armv4_mmu_cache_on
1005 W(b) __armv4_mmu_cache_off
1006 W(b) __armv4_mmu_cache_flush
1008 .word 0x56158000 @ PXA168
1010 W(b) __armv4_mmu_cache_on
1011 W(b) __armv4_mmu_cache_off
1012 W(b) __armv5tej_mmu_cache_flush
1014 .word 0x56050000 @ Feroceon
1016 W(b) __armv4_mmu_cache_on
1017 W(b) __armv4_mmu_cache_off
1018 W(b) __armv5tej_mmu_cache_flush
1020 #ifdef CONFIG_CPU_FEROCEON_OLD_ID
1021 /* this conflicts with the standard ARMv5TE entry */
1022 .long 0x41009260 @ Old Feroceon
1024 b __armv4_mmu_cache_on
1025 b __armv4_mmu_cache_off
1026 b __armv5tej_mmu_cache_flush
1029 .word 0x66015261 @ FA526
1031 W(b) __fa526_cache_on
1032 W(b) __armv4_mmu_cache_off
1033 W(b) __fa526_cache_flush
1035 @ These match on the architecture ID
1037 .word 0x00020000 @ ARMv4T
1039 W(b) __armv4_mmu_cache_on
1040 W(b) __armv4_mmu_cache_off
1041 W(b) __armv4_mmu_cache_flush
1043 .word 0x00050000 @ ARMv5TE
1045 W(b) __armv4_mmu_cache_on
1046 W(b) __armv4_mmu_cache_off
1047 W(b) __armv4_mmu_cache_flush
1049 .word 0x00060000 @ ARMv5TEJ
1051 W(b) __armv4_mmu_cache_on
1052 W(b) __armv4_mmu_cache_off
1053 W(b) __armv5tej_mmu_cache_flush
1055 .word 0x0007b000 @ ARMv6
1057 W(b) __armv6_mmu_cache_on
1058 W(b) __armv4_mmu_cache_off
1059 W(b) __armv6_mmu_cache_flush
1061 .word 0x000f0000 @ new CPU Id
1063 W(b) __armv7_mmu_cache_on
1064 W(b) __armv7_mmu_cache_off
1065 W(b) __armv7_mmu_cache_flush
1067 .word 0 @ unrecognised type
1076 .size proc_types, . - proc_types
1079 * If you get a "non-constant expression in ".if" statement"
1080 * error from the assembler on this line, check that you have
1081 * not accidentally written a "b" instruction where you should
1082 * have written W(b).
1084 .if (. - proc_types) % PROC_ENTRY_SIZE != 0
1085 .error "The size of one or more proc_types entries is wrong."
1089 * Turn off the Cache and MMU. ARMv3 does not support
1090 * reading the control register, but ARMv4 does.
1093 * r0, r1, r2, r3, r9, r12 corrupted
1094 * This routine must preserve:
1098 cache_off: mov r3, #12 @ cache_off function
1101 __armv4_mpu_cache_off:
1102 mrc p15, 0, r0, c1, c0
1104 mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
1106 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
1107 mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
1108 mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
1111 __armv3_mpu_cache_off:
1112 mrc p15, 0, r0, c1, c0
1114 mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
1116 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
1119 __armv4_mmu_cache_off:
1121 mrc p15, 0, r0, c1, c0
1123 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1125 mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
1126 mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
1130 __armv7_mmu_cache_off:
1131 mrc p15, 0, r0, c1, c0
1137 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1139 bl __armv7_mmu_cache_flush
1142 mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
1144 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
1145 mcr p15, 0, r0, c7, c10, 4 @ DSB
1146 mcr p15, 0, r0, c7, c5, 4 @ ISB
1150 * Clean and flush the cache to maintain consistency.
1153 * r1, r2, r3, r9, r10, r11, r12 corrupted
1154 * This routine must preserve:
1162 __armv4_mpu_cache_flush:
1167 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
1168 mov r1, #7 << 5 @ 8 segments
1169 1: orr r3, r1, #63 << 26 @ 64 entries
1170 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
1171 subs r3, r3, #1 << 26
1172 bcs 2b @ entries 63 to 0
1173 subs r1, r1, #1 << 5
1174 bcs 1b @ segments 7 to 0
1177 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
1178 mcr p15, 0, ip, c7, c10, 4 @ drain WB
1181 __fa526_cache_flush:
1185 mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
1186 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1187 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1190 __armv6_mmu_cache_flush:
1193 mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
1194 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
1195 mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
1196 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1199 __armv7_mmu_cache_flush:
1202 mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
1203 tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
1206 mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
1209 mcr p15, 0, r10, c7, c10, 5 @ DMB
1210 stmfd sp!, {r0-r7, r9-r11}
1211 mrc p15, 1, r0, c0, c0, 1 @ read clidr
1212 ands r3, r0, #0x7000000 @ extract loc from clidr
1213 mov r3, r3, lsr #23 @ left align loc bit field
1214 beq finished @ if loc is 0, then no need to clean
1215 mov r10, #0 @ start clean at cache level 0
1217 add r2, r10, r10, lsr #1 @ work out 3x current cache level
1218 mov r1, r0, lsr r2 @ extract cache type bits from clidr
1219 and r1, r1, #7 @ mask of the bits for current cache only
1220 cmp r1, #2 @ see what cache we have at this level
1221 blt skip @ skip if no cache, or just i-cache
1222 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
1223 mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
1224 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
1225 and r2, r1, #7 @ extract the length of the cache lines
1226 add r2, r2, #4 @ add 4 (line length offset)
1228 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
1229 clz r5, r4 @ find bit position of way size increment
1231 ands r7, r7, r1, lsr #13 @ extract max number of the index size
1233 mov r9, r4 @ create working copy of max way size
1235 ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
1236 ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
1237 THUMB( lsl r6, r9, r5 )
1238 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
1239 THUMB( lsl r6, r7, r2 )
1240 THUMB( orr r11, r11, r6 ) @ factor index number into r11
1241 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
1242 subs r9, r9, #1 @ decrement the way
1244 subs r7, r7, #1 @ decrement the index
1247 add r10, r10, #2 @ increment cache number
1251 ldmfd sp!, {r0-r7, r9-r11}
1252 mov r10, #0 @ switch back to cache level 0
1253 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
1255 mcr p15, 0, r10, c7, c10, 4 @ DSB
1256 mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
1257 mcr p15, 0, r10, c7, c10, 4 @ DSB
1258 mcr p15, 0, r10, c7, c5, 4 @ ISB
1261 __armv5tej_mmu_cache_flush:
1264 1: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
1266 mcr p15, 0, r0, c7, c5, 0 @ flush I cache
1267 mcr p15, 0, r0, c7, c10, 4 @ drain WB
1270 __armv4_mmu_cache_flush:
1273 mov r2, #64*1024 @ default: 32K dcache size (*2)
1274 mov r11, #32 @ default: 32 byte line size
1275 mrc p15, 0, r3, c0, c0, 1 @ read cache type
1276 teq r3, r9 @ cache ID register present?
1281 mov r2, r2, lsl r1 @ base dcache size *2
1282 tst r3, #1 << 14 @ test M bit
1283 addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
1287 mov r11, r11, lsl r3 @ cache line size in bytes
1290 bic r1, r1, #63 @ align to longest cache line
1293 ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
1294 THUMB( ldr r3, [r1] ) @ s/w flush D cache
1295 THUMB( add r1, r1, r11 )
1299 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1300 mcr p15, 0, r1, c7, c6, 0 @ flush D cache
1301 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1304 __armv3_mmu_cache_flush:
1305 __armv3_mpu_cache_flush:
1309 mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
1313 * Various debugging routines for printing hex characters and
1314 * memory, which again must be relocatable.
1318 .type phexbuf,#object
1320 .size phexbuf, . - phexbuf
1322 @ phex corrupts {r0, r1, r2, r3}
1323 phex: adr r3, phexbuf
1337 @ puts corrupts {r0, r1, r2, r3}
1338 puts: loadsp r3, r2, r1
1339 1: ldrb r2, [r0], #1
1352 @ putc corrupts {r0, r1, r2, r3}
1359 @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
1360 memdump: mov r12, r0
1363 2: mov r0, r11, lsl #2
1371 ldr r0, [r12, r11, lsl #2]
1391 #ifdef CONFIG_ARM_VIRT_EXT
1393 __hyp_reentry_vectors:
1399 W(b) __enter_kernel @ hyp
1402 #endif /* CONFIG_ARM_VIRT_EXT */
1405 mov r0, #0 @ must be 0
1406 mov r1, r7 @ restore architecture number
1407 mov r2, r8 @ restore atags pointer
1408 ARM( mov pc, r4 ) @ call kernel
1409 M_CLASS( add r4, r4, #1 ) @ enter in Thumb mode for M class
1410 THUMB( bx r4 ) @ entry point is always ARM for A/R classes
1414 #ifdef CONFIG_EFI_STUB
1416 _start: .long start - .
1418 ENTRY(efi_stub_entry)
1419 @ allocate space on stack for passing current zImage address
1420 @ and for the EFI stub to return of new entry point of
1421 @ zImage, as EFI stub may copy the kernel. Pointer address
1422 @ is passed in r2. r0 and r1 are passed through from the
1423 @ EFI firmware to efi_entry
1428 mov r2, sp @ pass zImage address in r2
1431 @ Check for error return from EFI stub. r0 has FDT address
1436 @ Preserve return value of efi_entry() in r4
1439 @ our cache maintenance code relies on CP15 barrier instructions
1440 @ but since we arrived here with the MMU and caches configured
1441 @ by UEFI, we must check that the CP15BEN bit is set in SCTLR.
1442 @ Note that this bit is RAO/WI on v6 and earlier, so the ISB in
1443 @ the enable path will be executed on v7+ only.
1444 mrc p15, 0, r1, c1, c0, 0 @ read SCTLR
1445 tst r1, #(1 << 5) @ CP15BEN bit set?
1447 orr r1, r1, #(1 << 5) @ CP15 barrier instructions
1448 mcr p15, 0, r1, c1, c0, 0 @ write SCTLR
1449 ARM( .inst 0xf57ff06f @ v7+ isb )
1452 0: bl cache_clean_flush
1455 @ Set parameters for booting zImage according to boot protocol
1456 @ put FDT address in r2, it was returned by efi_entry()
1457 @ r1 is the machine type, and r0 needs to be 0
1462 @ Branch to (possibly) relocated zImage that is in [sp]
1464 ldr ip, =start_offset
1466 mov pc, lr @ no mode switch
1469 @ Return EFI_LOAD_ERROR to EFI firmware on error.
1472 ENDPROC(efi_stub_entry)
1476 .section ".stack", "aw", %nobits
1477 .L_user_stack: .space 4096