走读 arch/arm64/kernel/head.S 代码时,发现一些关键点需要厘清,这里记录下来:
ARM64 flat address mapping
支持MMU功能的CPU在MMU没有开启(如上电复位时或者人为关闭)的情况下都有相关机制,ARM中采用flat address mapping。
ARM在DDI0487A_k_armv8_arm文档中对flat address mapping描述如下:
Flat address mapping
Is where the physical address for every access is equal to its virtual address.
也就是pa==va,没有基地址+偏移。
同时该文档在D4.2.8 The effects of disabling a stage of address translation谈到对AARCH64 MMU stage1/stage2 disable时特性,包括数据与地址访问。
至于MMU什么时候disable,在SCTLR_EL1.M/SCTLR_EL2.M/SCTLR_EL3.M描述时指出When this register has an architecturally-defined reset value, this field resets to 0.
这样在CPU复位上电后MMU是Disable。
Linux内核引导时地址映射要求
ARM64 Linux内核在引导时也要MMU disable,具体见head.S文件:
// arch/arm64/kernel/head.S
/*
* Kernel startup entry point.
* ---------------------------
*
* The requirements are:
* MMU = off, D-cache = off, I-cache = on or off,
* x0 = physical address to the FDT blob.
*
* This code is mostly position independent so you call this at
* __pa(PAGE_OFFSET + TEXT_OFFSET).
*
* Note that the callee-saved registers are used for storing variables
* that are useful before the MMU is enabled. The allocations are described
* in the entry routines.
*/
归纳起来,Linux在引导时MMU关闭,pa==va。这里实际上也是内核对boot loader类程序在跳入Linux内核执行时对CPU状态设置要求。
ARM64 CPU flat address mapping特性
ARM64 CPU地址空间
主要包括两部分:物理内存地址空间和虚拟地址空间