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", "ax"
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
157 * These 7 nops along with the 1 nop immediately below for
158 * !THUMB2 form 8 nops that make the compressed kernel bootable
159 * on legacy ARM systems that were assuming the kernel in a.out
160 * binary format. The boot loaders on these systems would
161 * jump 32 bytes into the image to skip the a.out header.
162 * with these 8 nops filling exactly 32 bytes, things still
163 * work as expected on these legacy systems. Thumb2 mode keeps
164 * 7 of the nops as it turns out that some boot loaders
165 * were patching the initial instructions of the kernel, i.e
166 * had started to exploit this "patch area".
171 #ifndef CONFIG_THUMB2_KERNEL
174 AR_CLASS( sub pc, pc, #3 ) @ A/R: switch to Thumb2 mode
175 M_CLASS( nop.w ) @ M: already in Thumb2 mode
180 .word _magic_sig @ Magic numbers to help the loader
181 .word _magic_start @ absolute load/run zImage address
182 .word _magic_end @ zImage end address
183 .word 0x04030201 @ endianness flag
184 .word 0x45454545 @ another magic number to indicate
185 .word _magic_table @ additional data table
189 ARM_BE8( setend be ) @ go BE8 if compiled for BE8
190 AR_CLASS( mrs r9, cpsr )
191 #ifdef CONFIG_ARM_VIRT_EXT
192 bl __hyp_stub_install @ get into SVC mode, reversibly
194 mov r7, r1 @ save architecture ID
195 mov r8, r2 @ save atags pointer
197 #ifndef CONFIG_CPU_V7M
199 * Booting from Angel - need to enter SVC mode and disable
200 * FIQs/IRQs (numeric definitions from angel arm.h source).
201 * We only do this if we were in user mode on entry.
203 mrs r2, cpsr @ get current mode
204 tst r2, #3 @ not user?
206 mov r0, #0x17 @ angel_SWIreason_EnterSVC
207 ARM( swi 0x123456 ) @ angel_SWI_ARM
208 THUMB( svc 0xab ) @ angel_SWI_THUMB
210 safe_svcmode_maskall r0
211 msr spsr_cxsf, r9 @ Save the CPU boot mode in
215 * Note that some cache flushing and other stuff may
216 * be needed here - is there an Angel SWI call for this?
220 * some architecture specific code can be inserted
221 * by the linker here, but it should preserve r7, r8, and r9.
226 #ifdef CONFIG_AUTO_ZRELADDR
228 * Find the start of physical memory. As we are executing
229 * without the MMU on, we are in the physical address space.
230 * We just need to get rid of any offset by aligning the
233 * This alignment is a balance between the requirements of
234 * different platforms - we have chosen 128MB to allow
235 * platforms which align the start of their physical memory
236 * to 128MB to use this feature, while allowing the zImage
237 * to be placed within the first 128MB of memory on other
238 * platforms. Increasing the alignment means we place
239 * stricter alignment requirements on the start of physical
240 * memory, but relaxing it means that we break people who
241 * are already placing their zImage in (eg) the top 64MB
245 and r4, r4, #0xf8000000
246 /* Determine final kernel image address. */
247 add r4, r4, #TEXT_OFFSET
253 * Set up a page table only if it won't overwrite ourself.
254 * That means r4 < pc || r4 - 16k page directory > &_end.
255 * Given that r4 > &_end is most unfrequent, we add a rough
256 * additional 1MB of room for a possible appended DTB.
263 orrcc r4, r4, #1 @ remember we skipped cache_on
267 ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
271 * We might be running at a different address. We need
272 * to fix up various pointers.
274 sub r0, r0, r1 @ calculate the delta offset
275 add r6, r6, r0 @ _edata
276 add r10, r10, r0 @ inflated kernel size location
279 * The kernel build system appends the size of the
280 * decompressed kernel at the end of the compressed data
281 * in little-endian form.
285 orr r9, r9, lr, lsl #8
288 orr r9, r9, lr, lsl #16
289 orr r9, r9, r10, lsl #24
291 #ifndef CONFIG_ZBOOT_ROM
292 /* malloc space is above the relocated stack (64k max) */
294 add r10, sp, #0x10000
297 * With ZBOOT_ROM the bss/stack is non relocatable,
298 * but someone could still run this code from RAM,
299 * in which case our reference is _edata.
304 mov r5, #0 @ init dtb size to 0
305 #ifdef CONFIG_ARM_APPENDED_DTB
310 * r4 = final kernel address (possibly with LSB set)
311 * r5 = appended dtb size (still unknown)
313 * r7 = architecture ID
314 * r8 = atags/device tree pointer
315 * r9 = size of decompressed image
316 * r10 = end of this image, including bss/stack/malloc space if non XIP
321 * if there are device trees (dtb) appended to zImage, advance r10 so that the
322 * dtb data will get relocated along with the kernel if necessary.
327 ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
332 bne dtb_check_done @ not found
334 #ifdef CONFIG_ARM_ATAG_DTB_COMPAT
336 * OK... Let's do some funky business here.
337 * If we do have a DTB appended to zImage, and we do have
338 * an ATAG list around, we want the later to be translated
339 * and folded into the former here. No GOT fixup has occurred
340 * yet, but none of the code we're about to call uses any
344 /* Get the initial DTB size */
347 /* convert to little endian */
348 eor r1, r5, r5, ror #16
349 bic r1, r1, #0x00ff0000
351 eor r5, r5, r1, lsr #8
353 /* 50% DTB growth should be good enough */
354 add r5, r5, r5, lsr #1
355 /* preserve 64-bit alignment */
358 /* clamp to 32KB min and 1MB max */
363 /* temporarily relocate the stack past the DTB work space */
366 stmfd sp!, {r0-r3, ip, lr}
373 * If returned value is 1, there is no ATAG at the location
374 * pointed by r8. Try the typical 0x100 offset from start
375 * of RAM and hope for the best.
378 sub r0, r4, #TEXT_OFFSET
385 ldmfd sp!, {r0-r3, ip, lr}
389 mov r8, r6 @ use the appended device tree
392 * Make sure that the DTB doesn't end up in the final
393 * kernel's .bss area. To do so, we adjust the decompressed
394 * kernel size to compensate if that .bss size is larger
395 * than the relocated code.
397 ldr r5, =_kernel_bss_size
398 adr r1, wont_overwrite
403 /* Get the current DTB size */
406 /* convert r5 (dtb size) to little endian */
407 eor r1, r5, r5, ror #16
408 bic r1, r1, #0x00ff0000
410 eor r5, r5, r1, lsr #8
413 /* preserve 64-bit alignment */
417 /* relocate some pointers past the appended dtb */
425 * Check to see if we will overwrite ourselves.
426 * r4 = final kernel address (possibly with LSB set)
427 * r9 = size of decompressed image
428 * r10 = end of this image, including bss/stack/malloc space if non XIP
430 * r4 - 16k page directory >= r10 -> OK
431 * r4 + image length <= address of wont_overwrite -> OK
432 * Note: the possible LSB in r4 is harmless here.
438 adr r9, wont_overwrite
443 * Relocate ourselves past the end of the decompressed kernel.
445 * r10 = end of the decompressed kernel
446 * Because we always copy ahead, we need to do it from the end and go
447 * backward in case the source and destination overlap.
450 * Bump to the next 256-byte boundary with the size of
451 * the relocation code added. This avoids overwriting
452 * ourself when the offset is small.
454 add r10, r10, #((reloc_code_end - restart + 256) & ~255)
457 /* Get start of code we want to copy and align it down. */
461 /* Relocate the hyp vector base if necessary */
462 #ifdef CONFIG_ARM_VIRT_EXT
464 and r0, r0, #MODE_MASK
469 * Compute the address of the hyp vectors after relocation.
470 * This requires some arithmetic since we cannot directly
471 * reference __hyp_stub_vectors in a PC-relative way.
472 * Call __hyp_set_vectors with the new address so that we
473 * can HVC again after the copy.
476 movw r1, #:lower16:__hyp_stub_vectors - 0b
477 movt r1, #:upper16:__hyp_stub_vectors - 0b
485 sub r9, r6, r5 @ size to copy
486 add r9, r9, #31 @ rounded up to a multiple
487 bic r9, r9, #31 @ ... of 32 bytes
495 * We are about to copy the kernel to a new memory area.
496 * The boundaries of the new memory area can be found in
497 * r10 and r9, whilst r5 and r6 contain the boundaries
498 * of the memory we are going to copy.
499 * Calling dbgkc will help with the printing of this
502 dbgkc r5, r6, r10, r9
505 1: ldmdb r6!, {r0 - r3, r10 - r12, lr}
507 stmdb r9!, {r0 - r3, r10 - r12, lr}
510 /* Preserve offset to relocated code. */
513 #ifndef CONFIG_ZBOOT_ROM
514 /* cache_clean_flush may use the stack, so relocate it */
526 * If delta is zero, we are running at the address we were linked at.
530 * r4 = kernel execution address (possibly with LSB set)
531 * r5 = appended dtb size (0 if not present)
532 * r7 = architecture ID
544 #ifndef CONFIG_ZBOOT_ROM
546 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
547 * we need to fix up pointers into the BSS region.
548 * Note that the stack pointer has already been fixed up.
554 * Relocate all entries in the GOT table.
555 * Bump bss entries to _edata + dtb size
557 1: ldr r1, [r11, #0] @ relocate entries in the GOT
558 add r1, r1, r0 @ This fixes up C references
559 cmp r1, r2 @ if entry >= bss_start &&
560 cmphs r3, r1 @ bss_end > entry
561 addhi r1, r1, r5 @ entry += dtb size
562 str r1, [r11], #4 @ next entry
566 /* bump our bss pointers too */
573 * Relocate entries in the GOT table. We only relocate
574 * the entries that are outside the (relocated) BSS region.
576 1: ldr r1, [r11, #0] @ relocate entries in the GOT
577 cmp r1, r2 @ entry < bss_start ||
578 cmphs r3, r1 @ _end < entry
579 addlo r1, r1, r0 @ table. This fixes up the
580 str r1, [r11], #4 @ C references.
585 not_relocated: mov r0, #0
586 1: str r0, [r2], #4 @ clear bss
594 * Did we skip the cache setup earlier?
595 * That is indicated by the LSB in r4.
603 * The C runtime environment should now be setup sufficiently.
604 * Set up some pointers, and start decompressing.
605 * r4 = kernel execution address
606 * r7 = architecture ID
610 mov r1, sp @ malloc space above stack
611 add r2, sp, #0x10000 @ 64k max
617 #ifdef CONFIG_ARM_VIRT_EXT
618 mrs r0, spsr @ Get saved CPU boot mode
619 and r0, r0, #MODE_MASK
620 cmp r0, #HYP_MODE @ if not booted in HYP mode...
621 bne __enter_kernel @ boot kernel directly
623 adr r12, .L__hyp_reentry_vectors_offset
628 __HVC(0) @ otherwise bounce to hyp mode
630 b . @ should never be reached
633 .L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
641 .word __bss_start @ r2
644 .word input_data_end - 4 @ r10 (inflated size location)
645 .word _got_start @ r11
647 .word .L_user_stack_end @ sp
648 .word _end - restart + 16384 + 1024*1024
651 #ifdef CONFIG_ARCH_RPC
653 params: ldr r0, =0x10000100 @ params_phys for RPC
660 * Turn on the cache. We need to setup some page tables so that we
661 * can have both the I and D caches on.
663 * We place the page tables 16k down from the kernel execution address,
664 * and we hope that nothing else is using it. If we're using it, we
668 * r4 = kernel execution address
669 * r7 = architecture number
672 * r0, r1, r2, r3, r9, r10, r12 corrupted
673 * This routine must preserve:
677 cache_on: mov r3, #8 @ cache_on function
681 * Initialize the highest priority protection region, PR7
682 * to cover all 32bit address and cacheable and bufferable.
684 __armv4_mpu_cache_on:
685 mov r0, #0x3f @ 4G, the whole
686 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
687 mcr p15, 0, r0, c6, c7, 1
690 mcr p15, 0, r0, c2, c0, 0 @ D-cache on
691 mcr p15, 0, r0, c2, c0, 1 @ I-cache on
692 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
695 mcr p15, 0, r0, c5, c0, 1 @ I-access permission
696 mcr p15, 0, r0, c5, c0, 0 @ D-access permission
699 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
700 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
701 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
702 mrc p15, 0, r0, c1, c0, 0 @ read control reg
703 @ ...I .... ..D. WC.M
704 orr r0, r0, #0x002d @ .... .... ..1. 11.1
705 orr r0, r0, #0x1000 @ ...1 .... .... ....
707 mcr p15, 0, r0, c1, c0, 0 @ write control reg
710 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
711 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
714 __armv3_mpu_cache_on:
715 mov r0, #0x3f @ 4G, the whole
716 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
719 mcr p15, 0, r0, c2, c0, 0 @ cache on
720 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
723 mcr p15, 0, r0, c5, c0, 0 @ access permission
726 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
728 * ?? ARMv3 MMU does not allow reading the control register,
729 * does this really work on ARMv3 MPU?
731 mrc p15, 0, r0, c1, c0, 0 @ read control reg
732 @ .... .... .... WC.M
733 orr r0, r0, #0x000d @ .... .... .... 11.1
734 /* ?? this overwrites the value constructed above? */
736 mcr p15, 0, r0, c1, c0, 0 @ write control reg
738 /* ?? invalidate for the second time? */
739 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
742 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
748 __setup_mmu: sub r3, r4, #16384 @ Page directory size
749 bic r3, r3, #0xff @ Align the pointer
752 * Initialise the page tables, turning on the cacheable and bufferable
753 * bits for the RAM area only.
757 mov r9, r9, lsl #18 @ start of RAM
758 add r10, r9, #0x10000000 @ a reasonable RAM size
759 mov r1, #0x12 @ XN|U + section mapping
760 orr r1, r1, #3 << 10 @ AP=11
762 1: cmp r1, r9 @ if virt > start of RAM
763 cmphs r10, r1 @ && end of RAM > virt
764 bic r1, r1, #0x1c @ clear XN|U + C + B
765 orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
766 orrhs r1, r1, r6 @ set RAM section settings
767 str r1, [r0], #4 @ 1:1 mapping
772 * If ever we are running from Flash, then we surely want the cache
773 * to be enabled also for our execution instance... We map 2MB of it
774 * so there is no map overlap problem for up to 1 MB compressed kernel.
775 * If the execution is in RAM then we would only be duplicating the above.
777 orr r1, r6, #0x04 @ ensure B is set for this
781 orr r1, r1, r2, lsl #20
782 add r0, r3, r2, lsl #2
789 @ Enable unaligned access on v6, to allow better code generation
790 @ for the decompressor C code:
791 __armv6_mmu_cache_on:
792 mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
793 bic r0, r0, #2 @ A (no unaligned access fault)
794 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
795 mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
796 b __armv4_mmu_cache_on
798 __arm926ejs_mmu_cache_on:
799 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
800 mov r0, #4 @ put dcache in WT mode
801 mcr p15, 7, r0, c15, c0, 0
804 __armv4_mmu_cache_on:
807 mov r6, #CB_BITS | 0x12 @ U
810 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
811 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
812 mrc p15, 0, r0, c1, c0, 0 @ read control reg
813 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
815 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
816 bl __common_mmu_cache_on
818 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
822 __armv7_mmu_cache_on:
825 mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
827 movne r6, #CB_BITS | 0x02 @ !XN
830 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
832 mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
834 mrc p15, 0, r0, c1, c0, 0 @ read control reg
835 bic r0, r0, #1 << 28 @ clear SCTLR.TRE
836 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
837 orr r0, r0, #0x003c @ write buffer
838 bic r0, r0, #2 @ A (no unaligned access fault)
839 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
840 @ (needed for ARM1176)
842 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
843 mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
844 orrne r0, r0, #1 @ MMU enabled
845 movne r1, #0xfffffffd @ domain 0 = client
846 bic r6, r6, #1 << 31 @ 32-bit translation system
847 bic r6, r6, #(7 << 0) | (1 << 4) @ use only ttbr0
848 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
849 mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
850 mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
852 mcr p15, 0, r0, c7, c5, 4 @ ISB
853 mcr p15, 0, r0, c1, c0, 0 @ load control register
854 mrc p15, 0, r0, c1, c0, 0 @ and read it back
856 mcr p15, 0, r0, c7, c5, 4 @ ISB
861 mov r6, #CB_BITS | 0x12 @ U
864 mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
865 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
866 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
867 mrc p15, 0, r0, c1, c0, 0 @ read control reg
868 orr r0, r0, #0x1000 @ I-cache enable
869 bl __common_mmu_cache_on
871 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
874 __common_mmu_cache_on:
875 #ifndef CONFIG_THUMB2_KERNEL
877 orr r0, r0, #0x000d @ Write buffer, mmu
880 mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
881 mcr p15, 0, r1, c3, c0, 0 @ load domain access control
883 .align 5 @ cache line aligned
884 1: mcr p15, 0, r0, c1, c0, 0 @ load control register
885 mrc p15, 0, r0, c1, c0, 0 @ and read it back to
886 sub pc, lr, r0, lsr #32 @ properly flush pipeline
889 #define PROC_ENTRY_SIZE (4*5)
892 * Here follow the relocatable cache support functions for the
893 * various processors. This is a generic hook for locating an
894 * entry and jumping to an instruction at the specified offset
895 * from the start of the block. Please note this is all position
905 call_cache_fn: adr r12, proc_types
906 #ifdef CONFIG_CPU_CP15
907 mrc p15, 0, r9, c0, c0 @ get processor ID
908 #elif defined(CONFIG_CPU_V7M)
910 * On v7-M the processor id is located in the V7M_SCB_CPUID
911 * register, but as cache handling is IMPLEMENTATION DEFINED on
912 * v7-M (if existant at all) we just return early here.
913 * If V7M_SCB_CPUID were used the cpu ID functions (i.e.
914 * __armv7_mmu_cache_{on,off,flush}) would be selected which
915 * use cp15 registers that are not implemented on v7-M.
919 ldr r9, =CONFIG_PROCESSOR_ID
921 1: ldr r1, [r12, #0] @ get value
922 ldr r2, [r12, #4] @ get mask
923 eor r1, r1, r9 @ (real ^ match)
925 ARM( addeq pc, r12, r3 ) @ call cache function
926 THUMB( addeq r12, r3 )
927 THUMB( moveq pc, r12 ) @ call cache function
928 add r12, r12, #PROC_ENTRY_SIZE
932 * Table for cache operations. This is basically:
935 * - 'cache on' method instruction
936 * - 'cache off' method instruction
937 * - 'cache flush' method instruction
939 * We match an entry using: ((real_id ^ match) & mask) == 0
941 * Writethrough caches generally only need 'on' and 'off'
942 * methods. Writeback caches _must_ have the flush method
946 .type proc_types,#object
948 .word 0x41000000 @ old ARM ID
957 .word 0x41007000 @ ARM7/710
966 .word 0x41807200 @ ARM720T (writethrough)
968 W(b) __armv4_mmu_cache_on
969 W(b) __armv4_mmu_cache_off
973 .word 0x41007400 @ ARM74x
975 W(b) __armv3_mpu_cache_on
976 W(b) __armv3_mpu_cache_off
977 W(b) __armv3_mpu_cache_flush
979 .word 0x41009400 @ ARM94x
981 W(b) __armv4_mpu_cache_on
982 W(b) __armv4_mpu_cache_off
983 W(b) __armv4_mpu_cache_flush
985 .word 0x41069260 @ ARM926EJ-S (v5TEJ)
987 W(b) __arm926ejs_mmu_cache_on
988 W(b) __armv4_mmu_cache_off
989 W(b) __armv5tej_mmu_cache_flush
991 .word 0x00007000 @ ARM7 IDs
1000 @ Everything from here on will be the new ID system.
1002 .word 0x4401a100 @ sa110 / sa1100
1004 W(b) __armv4_mmu_cache_on
1005 W(b) __armv4_mmu_cache_off
1006 W(b) __armv4_mmu_cache_flush
1008 .word 0x6901b110 @ sa1110
1010 W(b) __armv4_mmu_cache_on
1011 W(b) __armv4_mmu_cache_off
1012 W(b) __armv4_mmu_cache_flush
1015 .word 0xffffff00 @ PXA9xx
1016 W(b) __armv4_mmu_cache_on
1017 W(b) __armv4_mmu_cache_off
1018 W(b) __armv4_mmu_cache_flush
1020 .word 0x56158000 @ PXA168
1022 W(b) __armv4_mmu_cache_on
1023 W(b) __armv4_mmu_cache_off
1024 W(b) __armv5tej_mmu_cache_flush
1026 .word 0x56050000 @ Feroceon
1028 W(b) __armv4_mmu_cache_on
1029 W(b) __armv4_mmu_cache_off
1030 W(b) __armv5tej_mmu_cache_flush
1032 #ifdef CONFIG_CPU_FEROCEON_OLD_ID
1033 /* this conflicts with the standard ARMv5TE entry */
1034 .long 0x41009260 @ Old Feroceon
1036 b __armv4_mmu_cache_on
1037 b __armv4_mmu_cache_off
1038 b __armv5tej_mmu_cache_flush
1041 .word 0x66015261 @ FA526
1043 W(b) __fa526_cache_on
1044 W(b) __armv4_mmu_cache_off
1045 W(b) __fa526_cache_flush
1047 @ These match on the architecture ID
1049 .word 0x00020000 @ ARMv4T
1051 W(b) __armv4_mmu_cache_on
1052 W(b) __armv4_mmu_cache_off
1053 W(b) __armv4_mmu_cache_flush
1055 .word 0x00050000 @ ARMv5TE
1057 W(b) __armv4_mmu_cache_on
1058 W(b) __armv4_mmu_cache_off
1059 W(b) __armv4_mmu_cache_flush
1061 .word 0x00060000 @ ARMv5TEJ
1063 W(b) __armv4_mmu_cache_on
1064 W(b) __armv4_mmu_cache_off
1065 W(b) __armv5tej_mmu_cache_flush
1067 .word 0x0007b000 @ ARMv6
1069 W(b) __armv6_mmu_cache_on
1070 W(b) __armv4_mmu_cache_off
1071 W(b) __armv6_mmu_cache_flush
1073 .word 0x000f0000 @ new CPU Id
1075 W(b) __armv7_mmu_cache_on
1076 W(b) __armv7_mmu_cache_off
1077 W(b) __armv7_mmu_cache_flush
1079 .word 0 @ unrecognised type
1088 .size proc_types, . - proc_types
1091 * If you get a "non-constant expression in ".if" statement"
1092 * error from the assembler on this line, check that you have
1093 * not accidentally written a "b" instruction where you should
1094 * have written W(b).
1096 .if (. - proc_types) % PROC_ENTRY_SIZE != 0
1097 .error "The size of one or more proc_types entries is wrong."
1101 * Turn off the Cache and MMU. ARMv3 does not support
1102 * reading the control register, but ARMv4 does.
1105 * r0, r1, r2, r3, r9, r12 corrupted
1106 * This routine must preserve:
1110 cache_off: mov r3, #12 @ cache_off function
1113 __armv4_mpu_cache_off:
1114 mrc p15, 0, r0, c1, c0
1116 mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
1118 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
1119 mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
1120 mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
1123 __armv3_mpu_cache_off:
1124 mrc p15, 0, r0, c1, c0
1126 mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
1128 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
1131 __armv4_mmu_cache_off:
1133 mrc p15, 0, r0, c1, c0
1135 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1137 mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
1138 mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
1142 __armv7_mmu_cache_off:
1143 mrc p15, 0, r0, c1, c0
1149 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1151 bl __armv7_mmu_cache_flush
1154 mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
1156 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
1157 mcr p15, 0, r0, c7, c10, 4 @ DSB
1158 mcr p15, 0, r0, c7, c5, 4 @ ISB
1162 * Clean and flush the cache to maintain consistency.
1165 * r1, r2, r3, r9, r10, r11, r12 corrupted
1166 * This routine must preserve:
1174 __armv4_mpu_cache_flush:
1179 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
1180 mov r1, #7 << 5 @ 8 segments
1181 1: orr r3, r1, #63 << 26 @ 64 entries
1182 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
1183 subs r3, r3, #1 << 26
1184 bcs 2b @ entries 63 to 0
1185 subs r1, r1, #1 << 5
1186 bcs 1b @ segments 7 to 0
1189 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
1190 mcr p15, 0, ip, c7, c10, 4 @ drain WB
1193 __fa526_cache_flush:
1197 mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
1198 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1199 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1202 __armv6_mmu_cache_flush:
1205 mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
1206 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
1207 mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
1208 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1211 __armv7_mmu_cache_flush:
1214 mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
1215 tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
1218 mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
1221 mcr p15, 0, r10, c7, c10, 5 @ DMB
1222 stmfd sp!, {r0-r7, r9-r11}
1223 mrc p15, 1, r0, c0, c0, 1 @ read clidr
1224 ands r3, r0, #0x7000000 @ extract loc from clidr
1225 mov r3, r3, lsr #23 @ left align loc bit field
1226 beq finished @ if loc is 0, then no need to clean
1227 mov r10, #0 @ start clean at cache level 0
1229 add r2, r10, r10, lsr #1 @ work out 3x current cache level
1230 mov r1, r0, lsr r2 @ extract cache type bits from clidr
1231 and r1, r1, #7 @ mask of the bits for current cache only
1232 cmp r1, #2 @ see what cache we have at this level
1233 blt skip @ skip if no cache, or just i-cache
1234 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
1235 mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
1236 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
1237 and r2, r1, #7 @ extract the length of the cache lines
1238 add r2, r2, #4 @ add 4 (line length offset)
1240 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
1241 clz r5, r4 @ find bit position of way size increment
1243 ands r7, r7, r1, lsr #13 @ extract max number of the index size
1245 mov r9, r4 @ create working copy of max way size
1247 ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
1248 ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
1249 THUMB( lsl r6, r9, r5 )
1250 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
1251 THUMB( lsl r6, r7, r2 )
1252 THUMB( orr r11, r11, r6 ) @ factor index number into r11
1253 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
1254 subs r9, r9, #1 @ decrement the way
1256 subs r7, r7, #1 @ decrement the index
1259 add r10, r10, #2 @ increment cache number
1263 ldmfd sp!, {r0-r7, r9-r11}
1264 mov r10, #0 @ switch back to cache level 0
1265 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
1267 mcr p15, 0, r10, c7, c10, 4 @ DSB
1268 mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
1269 mcr p15, 0, r10, c7, c10, 4 @ DSB
1270 mcr p15, 0, r10, c7, c5, 4 @ ISB
1273 __armv5tej_mmu_cache_flush:
1276 1: mrc p15, 0, APSR_nzcv, c7, c14, 3 @ test,clean,invalidate D cache
1278 mcr p15, 0, r0, c7, c5, 0 @ flush I cache
1279 mcr p15, 0, r0, c7, c10, 4 @ drain WB
1282 __armv4_mmu_cache_flush:
1285 mov r2, #64*1024 @ default: 32K dcache size (*2)
1286 mov r11, #32 @ default: 32 byte line size
1287 mrc p15, 0, r3, c0, c0, 1 @ read cache type
1288 teq r3, r9 @ cache ID register present?
1293 mov r2, r2, lsl r1 @ base dcache size *2
1294 tst r3, #1 << 14 @ test M bit
1295 addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
1299 mov r11, r11, lsl r3 @ cache line size in bytes
1302 bic r1, r1, #63 @ align to longest cache line
1305 ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
1306 THUMB( ldr r3, [r1] ) @ s/w flush D cache
1307 THUMB( add r1, r1, r11 )
1311 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1312 mcr p15, 0, r1, c7, c6, 0 @ flush D cache
1313 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1316 __armv3_mmu_cache_flush:
1317 __armv3_mpu_cache_flush:
1321 mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
1325 * Various debugging routines for printing hex characters and
1326 * memory, which again must be relocatable.
1330 .type phexbuf,#object
1332 .size phexbuf, . - phexbuf
1334 @ phex corrupts {r0, r1, r2, r3}
1335 phex: adr r3, phexbuf
1349 @ puts corrupts {r0, r1, r2, r3}
1350 puts: loadsp r3, r2, r1
1351 1: ldrb r2, [r0], #1
1364 @ putc corrupts {r0, r1, r2, r3}
1371 @ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
1372 memdump: mov r12, r0
1375 2: mov r0, r11, lsl #2
1383 ldr r0, [r12, r11, lsl #2]
1403 #ifdef CONFIG_ARM_VIRT_EXT
1405 __hyp_reentry_vectors:
1411 W(b) __enter_kernel @ hyp
1414 #endif /* CONFIG_ARM_VIRT_EXT */
1417 mov r0, #0 @ must be 0
1418 mov r1, r7 @ restore architecture number
1419 mov r2, r8 @ restore atags pointer
1420 ARM( mov pc, r4 ) @ call kernel
1421 M_CLASS( add r4, r4, #1 ) @ enter in Thumb mode for M class
1422 THUMB( bx r4 ) @ entry point is always ARM for A/R classes
1426 #ifdef CONFIG_EFI_STUB
1428 _start: .long start - .
1430 ENTRY(efi_stub_entry)
1431 @ allocate space on stack for passing current zImage address
1432 @ and for the EFI stub to return of new entry point of
1433 @ zImage, as EFI stub may copy the kernel. Pointer address
1434 @ is passed in r2. r0 and r1 are passed through from the
1435 @ EFI firmware to efi_entry
1440 mov r2, sp @ pass zImage address in r2
1443 @ Check for error return from EFI stub. r0 has FDT address
1448 @ Preserve return value of efi_entry() in r4
1451 @ our cache maintenance code relies on CP15 barrier instructions
1452 @ but since we arrived here with the MMU and caches configured
1453 @ by UEFI, we must check that the CP15BEN bit is set in SCTLR.
1454 @ Note that this bit is RAO/WI on v6 and earlier, so the ISB in
1455 @ the enable path will be executed on v7+ only.
1456 mrc p15, 0, r1, c1, c0, 0 @ read SCTLR
1457 tst r1, #(1 << 5) @ CP15BEN bit set?
1459 orr r1, r1, #(1 << 5) @ CP15 barrier instructions
1460 mcr p15, 0, r1, c1, c0, 0 @ write SCTLR
1461 ARM( .inst 0xf57ff06f @ v7+ isb )
1464 0: bl cache_clean_flush
1467 @ Set parameters for booting zImage according to boot protocol
1468 @ put FDT address in r2, it was returned by efi_entry()
1469 @ r1 is the machine type, and r0 needs to be 0
1474 @ Branch to (possibly) relocated zImage that is in [sp]
1476 ldr ip, =start_offset
1478 mov pc, lr @ no mode switch
1481 @ Return EFI_LOAD_ERROR to EFI firmware on error.
1484 ENDPROC(efi_stub_entry)
1488 .section ".stack", "aw", %nobits
1489 .L_user_stack: .space 4096