我们如何检测未定义指令异常的原因是由于Arm V7 ISA中的浮点指令



在ARMv7 ISA中,如何确定由于浮点异常之一而发生的未定义指令异常?另外,我读到默认情况下VFP单元是禁用的,当VFP指令第一次被应用程序使用时,内核将使用异常处理来启用VFP单元并让应用程序继续。我想这个异常应该是未定义指令异常。我理解未定义的指示也可能是由于其他情况。我在文档ARM DUI 0471C第128页的undef handler上读了一些,上面写着

Examine the undefined instruction to see if it has to be emulated. This is similar to the way in which an SVC handler extracts the number of an SVC, but rather than extracting the bottom 24 bits, the emulator must extract bits [27:24]

If bits [27:24] = b1110 or b110x, the instruction is a coprocessor instruction

位域似乎没有给我准确的指示,指令是一个浮点指令,例如位[27:24] of VADD =0010。所以这个方法似乎不是最好的方法。

从我在ARM中读到的,我可以使用FPEXC.DEX位来确定这是一个浮点指令异常。但这是在我们启用VFP单元之后。我需要在undef处理程序中首先做这个检查。什么是最合适的方法来检测异常从浮点指令?

fpexc.en位可用于此目的。这个想法很简单

  • 如果VFP被禁用,假设VFP指令是导致此错误的原因->启用VFP并尝试再次执行该指令。
  • 如果VFP是启用的,那么确实有一些非常糟糕的事情。

处理程序看起来像这样:

ctrl    .req    r0
push    {...}
vmrs    ctrl,   fpexc             // Check vfp status
tst     ctrl,   #(1 << 30)        // fpexc.en
bne     .L.undefinedHandler.die   // if vfp enabled -> there is another reason for this exception
// enable VFP and try again
ldr     ctrl,   =fpexc.en.mask              // enable vfp
vmsr    fpexc,  ctrl
// Reloading vfp state & d0-d31 regs
// some code is skipped here
pop     {...}
subs    pc,     lr,     #4  // return & try faulty instructions again
.L.undefinedHandler.die:
// F... really unknown instruction

简单地说,指令在VFP禁用和VFP启用的情况下执行两次。有效的VFP指令只会产生一次异常。未知指令将产生两次异常。优点:指令解析是多余的。

PS:有点晚了,但可能对某人有用:)

最新更新