当前的执行模式/异常级别等是什么? [英] what is the current execution mode/exception level, etc?
本文介绍了当前的执行模式/异常级别等是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是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语言,可以在编译时(
#ifdef
)通过编译器提供的宏(例如armclang
:__ aarch64 __
(用于64位),__ arm __
(用于32位) - 取决于执行模式:
- aarch32:
MRS< Rn> ;, CPSR
将当前状态读入寄存器数然后提取包含当前模式的3:0位。 - aarch64:
MRS< Xn>,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:
这篇关于当前的执行模式/异常级别等是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文