一般我们都会使用编译生成的压缩内核文件作为内核启动文件,所以分析的起点就从arch/arm/boot/compressed目录下的head.S开始。
分析前先看一些宏定义:
1、ARM()和THUMB()
#ifdef CONFIG_THUMB2_KERNEL
#if __GNUC__ < 4
#error Thumb-2 kernel requires gcc >= 4
#endif
/* The CPSR bit describing the instruction set (Thumb) */
#define PSR_ISETSTATE PSR_T_BIT
#define ARM(x...)
#define THUMB(x...) x
#ifdef __ASSEMBLY__
#define W(instr) instr.w
#define BSYM(sym) sym + 1
#else
#define WASM(instr) #instr ".w"
#endif
#else /* !CONFIG_THUMB2_KERNEL */
/* The CPSR bit describing the instruction set (ARM) */
#define PSR_ISETSTATE 0
#define ARM(x...) x
#define THUMB(x...)
#ifdef __ASSEMBLY__
#define W(instr) instr
#define BSYM(sym) sym
#else
#define WASM(instr) #instr
#endif
#endif /* CONFIG_THUMB2_KERNEL */
从以上代码可以看出来,这两个宏主要用于是否编译THUMB2指令时选择ARM指令或者THUMB指令,以上代码来自arch/arm/include/asm/unified.h。
首先找到代码的入口点,通过arch/arm/boot/compressed目录下的vmlinux.lds.in文件可知,第一个被编译的(.start)SECTION就是代码执行入口点:
/*
* linux/arch/arm/boot/compressed/vmlinux.lds.in
*
* Copyright (C) 2000 Russell King
*
* This program is free software; you can redistribute it and/or