/*1* linux/arch/arm/kernel/head-common.S2*3* Copyright (C) 1994-2002 Russell King4* Copyright (c) 2003 ARM Limited5* All Rights Reserved6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*11*/1213#define ATAG_CORE 0x5441000114#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)15#define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)1617#ifdef CONFIG_CPU_BIG_ENDIAN18#define OF_DT_MAGIC 0xd00dfeed19#else20#define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */21#endif2223/*24* Exception handling. Something went wrong and we can't proceed. We25* ought to tell the user, but since we don't have any guarantee that26* we're even running on the right architecture, we do virtually nothing.27*28* If CONFIG_DEBUG_LL is set we try to print out something about the error29* and hope for the best (useful if bootloader fails to pass a proper30* machine ID for example).31*/32__HEAD3334/* Determine validity of the r2 atags pointer. The heuristic requires35* that the pointer be aligned, in the first 16k of physical RAM and36* that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE37* is selected, then it will also accept a dtb pointer. Future revisions38* of this function may be more lenient with the physical address and39* may also be able to move the ATAGS block if necessary.40*41* Returns:42* r2 either valid atags pointer, valid dtb pointer, or zero43* r5, r6 corrupted44*/45__vet_atags:46tst r2, #0x3 @ aligned?47bne 1f4849ldr r5, [r2, #0]50#ifdef CONFIG_OF_FLATTREE51ldr r6, =OF_DT_MAGIC @ is it a DTB?52cmp r5, r653beq 2f54#endif55cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?56cmpne r5, #ATAG_CORE_SIZE_EMPTY57bne 1f58ldr r5, [r2, #4]59ldr r6, =ATAG_CORE60cmp r5, r661bne 1f62632: mov pc, lr @ atag/dtb pointer is ok64651: mov r2, #066mov pc, lr67ENDPROC(__vet_atags)6869/*70* The following fragment of code is executed with the MMU on in MMU mode,71* and uses absolute addresses; this is not position independent.72*73* r0 = cp#15 control register74* r1 = machine ID75* r2 = atags/dtb pointer76* r9 = processor ID77*/78__INIT79__mmap_switched:80adr r3, __mmap_switched_data8182ldmia r3!, {r4, r5, r6, r7}83cmp r4, r5 @ Copy data segment if needed841: cmpne r5, r685ldrne fp, [r4], #486strne fp, [r5], #487bne 1b8889mov fp, #0 @ Clear BSS (and zero fp)901: cmp r6, r791strcc fp, [r6],#492bcc 1b9394ARM( ldmia r3, {r4, r5, r6, r7, sp})95THUMB( ldmia r3, {r4, r5, r6, r7} )96THUMB( ldr sp, [r3, #16] )97str r9, [r4] @ Save processor ID98str r1, [r5] @ Save machine type99str r2, [r6] @ Save atags pointer100bic r4, r0, #CR_A @ Clear 'A' bit101stmia r7, {r0, r4} @ Save control register values102b start_kernel103ENDPROC(__mmap_switched)104105.align 2106.type __mmap_switched_data, %object107__mmap_switched_data:108.long __data_loc @ r4109.long _sdata @ r5110.long __bss_start @ r6111.long _end @ r7112.long processor_id @ r4113.long __machine_arch_type @ r5114.long __atags_pointer @ r6115.long cr_alignment @ r7116.long init_thread_union + THREAD_START_SP @ sp117.size __mmap_switched_data, . - __mmap_switched_data118119/*120* This provides a C-API version of __lookup_processor_type121*/122ENTRY(lookup_processor_type)123stmfd sp!, {r4 - r6, r9, lr}124mov r9, r0125bl __lookup_processor_type126mov r0, r5127ldmfd sp!, {r4 - r6, r9, pc}128ENDPROC(lookup_processor_type)129130/*131* Read processor ID register (CP#15, CR0), and look up in the linker-built132* supported processor list. Note that we can't use the absolute addresses133* for the __proc_info lists since we aren't running with the MMU on134* (and therefore, we are not in the correct address space). We have to135* calculate the offset.136*137* r9 = cpuid138* Returns:139* r3, r4, r6 corrupted140* r5 = proc_info pointer in physical address space141* r9 = cpuid (preserved)142*/143__CPUINIT144__lookup_processor_type:145adr r3, __lookup_processor_type_data146ldmia r3, {r4 - r6}147sub r3, r3, r4 @ get offset between virt&phys148add r5, r5, r3 @ convert virt addresses to149add r6, r6, r3 @ physical address space1501: ldmia r5, {r3, r4} @ value, mask151and r4, r4, r9 @ mask wanted bits152teq r3, r4153beq 2f154add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)155cmp r5, r6156blo 1b157mov r5, #0 @ unknown processor1582: mov pc, lr159ENDPROC(__lookup_processor_type)160161/*162* Look in <asm/procinfo.h> for information about the __proc_info structure.163*/164.align 2165.type __lookup_processor_type_data, %object166__lookup_processor_type_data:167.long .168.long __proc_info_begin169.long __proc_info_end170.size __lookup_processor_type_data, . - __lookup_processor_type_data171172__error_p:173#ifdef CONFIG_DEBUG_LL174adr r0, str_p1175bl printascii176mov r0, r9177bl printhex8178adr r0, str_p2179bl printascii180b __error181str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"182str_p2: .asciz ").\n"183.align184#endif185ENDPROC(__error_p)186187__error:188#ifdef CONFIG_ARCH_RPC189/*190* Turn the screen red on a error - RiscPC only.191*/192mov r0, #0x02000000193mov r3, #0x11194orr r3, r3, r3, lsl #8195orr r3, r3, r3, lsl #16196str r3, [r0], #4197str r3, [r0], #4198str r3, [r0], #4199str r3, [r0], #4200#endif2011: mov r0, r0202b 1b203ENDPROC(__error)204205206