本文介绍了当前的执行模式/异常级别等是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 ARMv8 架构的新手.我有以下几个基本问题:
I am new to ARMv8 architecture. I have following basic questions on my mind:
我如何知道当前的执行模式是 AArch32 还是 AArch64?我应该阅读 CPSR 还是 SPSR 来确定这一点?
How do I know what is the current execution mode AArch32 or AArch64? Should I read CPSR or SPSR to ascertain this?
当前的异常级别是什么,EL0/1/2/3?
What is the current Exception level, EL0/1/2/3?
一旦出现异常,我是否可以读取任何寄存器来确定我是否在 Serror/Synchronous/IRQ/FIQ 异常处理程序中.
Once an exception comes, can i read any register to determine whether I am in Serror/Synchronous/IRQ/FIQ exception handler.
TIA.
推荐答案
- 32 位和 64 位的汇编指令及其二进制编码完全不同.因此,您当前处于哪种模式的信息是您/编译器在编译期间已经需要知道的信息.在运行时检查它们没有意义.对于 C,C++ 检查可以在编译时 (
#ifdef
) 通过编译器提供的宏完成,例如armclang
提供的宏:__aarch64__
for 64位,__arm__
为 32 位 - 取决于执行模式:
- aarch32:
MRS , CPSR
将当前状态读入寄存器编号 n.然后提取包含当前模式的位 3:0. - aarch64:
MRS , CurrentEL
将当前 EL 读入寄存器编号 n
- aarch32:
- The assembly instructions and their binary encoding are entirely different for 32 and 64 bit. So the information what mode you are currently in is something that you/ the compiler already needs to know during compilation. checking for them at runtime doesn't make sense. For C, C++ checking can be done at compile time (
#ifdef
) through compiler provided macros like the ones provided byarmclang
:__aarch64__
for 64 bit,__arm__
for 32 bit - depends on the execution mode:
- aarch32:
MRS <Rn>, CPSR
read the current state into register number n. Then extract bits 3:0 that contain the current mode. - aarch64:
MRS <Xn>, CurrentEL
read the current EL into register number n
- aarch32:
这篇关于当前的执行模式/异常级别等是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!