一,前言
head.S是Linux内核的首先执行代码的文件,代码首先处理uboot传递过来的参数,通过参数判断该内核是不是支持该处理器和机器类型,接着创建页表和使能mmu,代码如下。本文是基于S3C2440开发板。
ENTRY(stext)
# 设置CPU为SVC模式
msr cpsr_c, #PSR_F_BIT | PSR_I_BIT | SVC_MODE @ ensure svc mode
@ and irqs disabled
# 处理器ID赋值到r9
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 __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
adr lr, __enable_mmu @ return (PIC) address
add pc, r10, #PROCINFO_INITFUNC
上面的代码首先设置CPU为SVC模式,然后通过读取CP15协处理器的C0寄存器的值到r9中,CP15处理器的操作方法参考ARM汇编指令3 - CP15协处理器介绍和操作方法,然后bl __lookup_processor_type查找处理器类型,本文主要分析这个函数
Linux内核启动流程解析

本文详细解析了Linux内核启动过程中的关键步骤,重点介绍了head.S文件中的处理器类型识别逻辑,包括如何读取处理器ID并查找匹配的处理器类型。
最低0.47元/天 解锁文章
1114

被折叠的 条评论
为什么被折叠?



