linux启动流程分析(基于ARM架构)

本文从arch/arm/boot/compressed目录下的head.S开始分析Linux在ARM架构下的启动流程。通过vmlinux.lds.in文件确定代码入口点为.start SECTION,并在head.s中找到相应的汇编代码。讲解了Solaris汇编语法兼容的.section指令及其标志,如#alloc、#write、#execinstr和#tls等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一般我们都会使用编译生成的压缩内核文件作为内核启动文件,所以分析的起点就从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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值