arch/arm/kernel/head.S
该文件末尾包含了语句:#include "head-common.S",__lookup_processor_type函数在arch/arm/kernel/head-common.S中定义。
关键数据结构:struct proc_info_list,在arch/arm/include/asm/procinfo.h文件中定义,Cortex对此数据结构的填充在arch/arm/mm/proc-v7.s文件中定义。
head.s中,kernel的关键入口如下:
ENTRY(stext)
ARM(
msr
cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE ) @ ensure svc mode
THUMB(
mov
r9, #PSR_F_BIT | PSR_I_BIT | SVC_MODE )
THUMB(
msr
cpsr_c, r9 )
@ ensure svc mode
@ and irqs disabled
mrc
p15, 0, r9, c0, c0
@ get processor id
bl
__lookup_processor_type
@ r5=procinfo r9=cpuid
movs
r10, r5
@ invalid processor (r5=0)?
beq
__error_p
@ yes, error 'p'
bl
__lookup_machine_type
@ r5=machinfo
movs
r8, r5
@ invalid machine (r5=0)?
beq
__error_a
@ yes, error 'a'
bl
__vet_atags
bl
__create_page_tables
/*
* The following calls CPU specific code in a position independent
* manner. See arch/arm/mm/proc-*.S for details. r10 = base of
* xxx_proc_info structure selected by __lookup_machine_type
* above. On return, the CPU will be ready for the MMU to be
* turned on, and r0 will hold the CPU control register value.
*/
ldr
r13, __switch_data
@ address to jump to after
@ mmu has been enabled
badr
lr, __enable_mmu
@ return (PIC) address
ARM(
add
pc, r10, #PROCINFO_INITFUNC
)
THUMB(
add
r12, r10, #PROCINFO_INITFUNC
)
THUMB(
mov
pc, r12
)
ENDPROC(stext)
语句“add
pc, r10, #PROCINFO_INITFUNC”通过查表调用proc-v7.s中__v7_setup函数,该函数末尾通过将lr寄存器赋给pc,导致对__enable_mmu的调用,完成使能mmu的操作,之后将r13寄存器值赋给pc,调用__switch_data数据结构中的第一个函数__mmap_switched,该函数指向最后的初始化函数,定义在head-common.s文件中,该函数最终调用init/main.c文件中的start_kernel函数。
语句“mrc
p15, 0, r9, c0, c0”将协处理器寄存器CP15读入寄存器r9,此寄存器保存CPUID;之后调用函数__lookup_processor_type查找处理器类型;