Kernel启动流程源码解析 2 head.S

本文深入解析了Linux内核在ARM64架构下从head.S开始的启动流程,重点关注了__cpu_setup、__enable_mmu以及__mmap_switched等关键步骤,详细阐述了如何从裸机代码逐步过渡到启用MMU的过程。
摘要由CSDN通过智能技术生成

  1. __cpu_setup。定义kernel\arch\arm64\mm\proc.S中。
#define MAIR(attr, mt)    ((attr) << ((mt) * 8))

/*
 *    __cpu_setup
 *
 *    Initialise the processor for turning the MMU on.  Return in x0 the
 *    value of the SCTLR_EL1 register.
 */
ENTRY(__cpu_setup)
    ic    iallu                // I+BTB cache invalidate // 使instruction和BTB cache中的所有的cache line是无效,直到PoU // BTB(Branch Target Buffer)
    tlbi    vmalle1is            // invalidate I + D TLBs // 使TLB内容无效vm-all-e1-is,vmall表示invalidate all TLB entry,e1表示EL1,is表示inner sharebility
    dsb    ish // dsb 数据同步屏蔽指令,确保前面的指令执行完成,ish表示inner shareable

    mov    x0, #3 << 20
    msr    cpacr_el1, x0            // Enable FP/ASIMD // 使能SIMD and floating-point
    msr    mdscr_el1, xzr            // Reset mdscr_el1 // Monitor Debug System Control Register
    /*
     * Memory region attributes for LPAE:
     *
     *   n = AttrIndx[2:0] // 最重要的memory attributes指向MAIR_ELx中具体的memory attribute
     *            n    MAIR
     *   DEVICE_nGnRnE    000    00000000 // G:Gathering 表示对多个memory的访问是否可以合并
     *   DEVICE_nGnRE    001    00000100 // R: Re-ordering 表示是否允许处理器对内存访问指令进行重排
     *   DEVICE_GRE        010    00001100 // E: Early Write Acknowledgement
     *   NORMAL_NC        011    01000100 // 前面加n表示不允许
     *   NORMAL        100    11111111 // C: 表示是否cacheable
     */
    ldr    x5, =MAIR(0x00, MT_DEVICE_nGnRnE) | \
             MAIR(0x04, MT_DEVICE_nGnRE) | \
             MAIR(0x0c, MT_DEVICE_GRE) | \
             MAIR(0x44, MT_NORMAL_NC) | \</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值