/* SPDX-License-Identifier: GPL-2.0-only */1/*2* linux/arch/arm/kernel/head-common.S3*4* Copyright (C) 1994-2002 Russell King5* Copyright (c) 2003 ARM Limited6* All Rights Reserved7*/8#include <asm/assembler.h>910#define ATAG_CORE 0x5441000111#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)12#define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)1314#ifdef CONFIG_CPU_BIG_ENDIAN15#define OF_DT_MAGIC 0xd00dfeed16#else17#define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */18#endif1920/*21* Exception handling. Something went wrong and we can't proceed. We22* ought to tell the user, but since we don't have any guarantee that23* we're even running on the right architecture, we do virtually nothing.24*25* If CONFIG_DEBUG_LL is set we try to print out something about the error26* and hope for the best (useful if bootloader fails to pass a proper27* machine ID for example).28*/29__HEAD3031/* Determine validity of the r2 atags pointer. The heuristic requires32* that the pointer be aligned, in the first 16k of physical RAM and33* that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE34* is selected, then it will also accept a dtb pointer. Future revisions35* of this function may be more lenient with the physical address and36* may also be able to move the ATAGS block if necessary.37*38* Returns:39* r2 either valid atags pointer, valid dtb pointer, or zero40* r5, r6 corrupted41*/42__vet_atags:43tst r2, #0x3 @ aligned?44bne 1f4546ldr r5, [r2, #0]47#ifdef CONFIG_OF_FLATTREE48ldr r6, =OF_DT_MAGIC @ is it a DTB?49cmp r5, r650beq 2f51#endif52cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?53cmpne r5, #ATAG_CORE_SIZE_EMPTY54bne 1f55ldr r5, [r2, #4]56ldr r6, =ATAG_CORE57cmp r5, r658bne 1f59602: ret lr @ atag/dtb pointer is ok61621: mov r2, #063ret lr64ENDPROC(__vet_atags)6566/*67* The following fragment of code is executed with the MMU on in MMU mode,68* and uses absolute addresses; this is not position independent.69*70* r0 = cp#15 control register (exc_ret for M-class)71* r1 = machine ID72* r2 = atags/dtb pointer73* r9 = processor ID74*/75__INIT76__mmap_switched:7778mov r7, r179mov r8, r280mov r10, r08182adr r4, __mmap_switched_data83mov fp, #08485#if defined(CONFIG_XIP_DEFLATED_DATA)86ARM( ldr sp, [r4], #4 )87THUMB( ldr sp, [r4] )88THUMB( add r4, #4 )89bl __inflate_kernel_data @ decompress .data to RAM90teq r0, #091bne __error92#elif defined(CONFIG_XIP_KERNEL)93ARM( ldmia r4!, {r0, r1, r2, sp} )94THUMB( ldmia r4!, {r0, r1, r2, r3} )95THUMB( mov sp, r3 )96sub r2, r2, r197bl __memcpy @ copy .data to RAM98#endif99100ARM( ldmia r4!, {r0, r1, sp} )101THUMB( ldmia r4!, {r0, r1, r3} )102THUMB( mov sp, r3 )103sub r2, r1, r0104mov r1, #0105bl __memset @ clear .bss106107adr_l r0, init_task @ get swapper task_struct108set_current r0, r1109110ldmia r4, {r0, r1, r2, r3}111str r9, [r0] @ Save processor ID112str r7, [r1] @ Save machine type113str r8, [r2] @ Save atags pointer114cmp r3, #0115strne r10, [r3] @ Save control register values116#ifdef CONFIG_KASAN117bl kasan_early_init118#endif119mov lr, #0120b start_kernel121ENDPROC(__mmap_switched)122123.align 2124.type __mmap_switched_data, %object125__mmap_switched_data:126#ifdef CONFIG_XIP_KERNEL127#ifndef CONFIG_XIP_DEFLATED_DATA128.long _sdata @ r0129.long __data_loc @ r1130.long _edata_loc @ r2131#endif132.long __bss_stop @ sp (temporary stack in .bss)133#endif134135.long __bss_start @ r0136.long __bss_stop @ r1137.long init_thread_union + THREAD_START_SP @ sp138139.long processor_id @ r0140.long __machine_arch_type @ r1141.long __atags_pointer @ r2142#ifdef CONFIG_CPU_CP15143.long cr_alignment @ r3144#else145M_CLASS(.long exc_ret) @ r3146AR_CLASS(.long 0) @ r3147#endif148.size __mmap_switched_data, . - __mmap_switched_data149150__FINIT151.text152153/*154* This provides a C-API version of __lookup_processor_type155*/156ENTRY(lookup_processor_type)157stmfd sp!, {r4 - r6, r9, lr}158mov r9, r0159bl __lookup_processor_type160mov r0, r5161ldmfd sp!, {r4 - r6, r9, pc}162ENDPROC(lookup_processor_type)163164/*165* Read processor ID register (CP#15, CR0), and look up in the linker-built166* supported processor list. Note that we can't use the absolute addresses167* for the __proc_info lists since we aren't running with the MMU on168* (and therefore, we are not in the correct address space). We have to169* calculate the offset.170*171* r9 = cpuid172* Returns:173* r3, r4, r6 corrupted174* r5 = proc_info pointer in physical address space175* r9 = cpuid (preserved)176*/177__lookup_processor_type:178/*179* Look in <asm/procinfo.h> for information about the __proc_info180* structure.181*/182adr_l r5, __proc_info_begin183adr_l r6, __proc_info_end1841: ldmia r5, {r3, r4} @ value, mask185and r4, r4, r9 @ mask wanted bits186teq r3, r4187beq 2f188add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)189cmp r5, r6190blo 1b191mov r5, #0 @ unknown processor1922: ret lr193ENDPROC(__lookup_processor_type)194195__error_lpae:196#ifdef CONFIG_DEBUG_LL197adr r0, str_lpae198bl printascii199b __error200str_lpae: .asciz "\nError: Kernel with LPAE support, but CPU does not support LPAE.\n"201#else202b __error203#endif204.align205ENDPROC(__error_lpae)206207__error_p:208#ifdef CONFIG_DEBUG_LL209adr r0, str_p1210bl printascii211mov r0, r9212bl printhex8213adr r0, str_p2214bl printascii215b __error216str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"217str_p2: .asciz ").\n"218.align219#endif220ENDPROC(__error_p)221222__error:223#ifdef CONFIG_ARCH_RPC224/*225* Turn the screen red on a error - RiscPC only.226*/227mov r0, #0x02000000228mov r3, #0x11229orr r3, r3, r3, lsl #8230orr r3, r3, r3, lsl #16231str r3, [r0], #4232str r3, [r0], #4233str r3, [r0], #4234str r3, [r0], #4235#endif2361: mov r0, r0237b 1b238ENDPROC(__error)239240241