kernel启动流程-head.S的执行__5.set_cpu_boot_mode_flag

本专题基于《arm64_linux head.S的执行流程》系列文章,针对内核5.10,分析head.S的执行过程。重点记录了head.S的set_cpu_boot_mode_flag执行过程,包括__boot_cpu_mode的定义,以及根据CPU启动模式将其保存到相应位置。

1.前言

kernel版本:5.10
平台:arm64

本专题主要基于《arm64_linux head.S的执行流程》系列文章,前者是基于3.18,本专题针对的是内核5.10。主要分析head.S的执行过程。本文主要记录head.S的set_cpu_boot_mode_flag执行过程。

2.set_cpu_boot_mode_flag

/*
 * Sets the __boot_cpu_mode flag depending on the CPU boot mode passed
 * in w0. See arch/arm64/include/asm/virt.h for more info.
 */
SYM_FUNC_START_LOCAL(set_cpu_boot_mode_flag)
        adr_l   x1, __boot_cpu_mode
        cmp     w0, #BOOT_CPU_MODE_EL2
        b.ne    1f
        add     x1, x1, #4
1:      str     w0, [x1]                        // This CPU has booted in EL1
        dmb     sy
        dc      ivac, x1                        // Invalidate potentially stale cache line
        ret
SYM_FUNC_END(set_cpu_boot_mode_flag)

__boot_cpu_mode保存了启动时的特权级别,定义如下:

/*
 * __boot_cpu_mode records what mode CPUs were booted in.
 * A correctly-implemented bootloader must start all CPUs in the same mode:                                                                      
 * In this case, both 32bit halves of __boot_cpu_mode will contain the
 * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).                                                                   
 *
 * Should the bootloader fail to do this, the two values will be different.
 * This allows the kernel to flag an error when the secondaries have come up.                                                                    
 */
extern u32 __boot_cpu_mode[2]; 

CPU的启动模式在el2_setup时保存到了w0中,此处将启动模式保存到__boot_cpu_mode中,如果启动模式为EL1则保存到__boot_cpu_mode[0],如果启动模式为EL2,则保存到__boot_cpu_mode[1]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值