linux aarch64 head.S set_cpu_boot_mode_flag
阿新 • • 發佈:2022-03-06
set_cpu_boot_mode_flag
使用 el2_setup 的返回值,填充 __boot_cpu_mode 這個全域性陣列 ,
1、__boot_cpu_mode 也在 head.S 裡面定義的。初始值如下:
/* * We need to find out the CPU boot mode long after boot, so we need to * store it in a writable variable. * * This is not in .bss, because we set it sufficiently early that the boot-time * zeroing of .bss would clobber it. */ SYM_DATA_START(__boot_cpu_mode) .long BOOT_CPU_MODE_EL2 .long BOOT_CPU_MODE_EL1 SYM_DATA_END(__boot_cpu_mode)
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, #41: 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)
3、set_cpu_boot_mode_flag 程式碼邏輯
1 running_mode = el2_setup(); 2 3 set_cpu_boot_mode_flag(running_mode){4 5 if(running_mode == #BOOT_CPU_MODE_EL2){ 6 __boot_cpu_mode.field2 = #BOOT_CPU_MODE_EL2 7 }else{ 8 __boot_cpu_mode.field1 = #BOOT_CPU_MODE_EL1 9 } 10 }
如果running_mode 為EL2, 則__boot_cpu_mode 的兩個field 都為 #BOOT_CPU_MODE_EL2
如果 running_mode 為EL1, 則__boot_cpu_mode 的兩個field 都為 #BOOT_CPU_MODE_EL1