2

一个问题是未定义指令何时发生......我们需要从 R14_SVC 或 R14_UNDEF 获取当前正在执行的指令吗?. 目前我正在解决一个发生未定义指令的问题。在检查 R14_SVC 时,我发现指令如下:

0x46BFD73C cmp r0, #0x0
0x46BFD740 beq 0x46BFD75C
0x46BFD744 ldr r0,0x46BFE358

所以在我的假设中,未定义的指令会在执行指令时发生beq 0x46BFD75C

让我感到困惑的一件事是我检查了它r14_undef并且指令是不同的。

0x46bfd4b8  bx r14
0x46bfd4bC  mov r0, 0x01
0x46bfd4c0  bx r14

哪一个导致了未定义的指令异常?

4

1 回答 1

3

All of your answers are in the ARM ARM, ARM Architectural Reference Manual. go to infocenter.arm.com under reference manuals find the architecture family you are interested in. The non-cortex-m series all handle these exceptions the same way

When an Undefined Instruction exception occurs, the following actions are performed:
R14_und = address of next instruction after the Undefined instruction
SPSR_und = CPSR
CPSR[4:0] = 0b11011 /* Enter Undefined Instruction mode */
CPSR[5] = 0 /* Execute in ARM state */
            /* CPSR[6] is unchanged */
CPSR[7] = 1 /* Disable normal interrupts */
            /* CPSR[8] is unchanged */
CPSR[9] = CP15_reg1_EEbit
/* Endianness on exception entry */
if high vectors configured then
    PC = 0xFFFF0004
else
    PC = 0x00000004

R14_und points at the next instruction AFTER the undefined instruction. you have to examine SPSR_und to determine what mode the processor was in (arm or thumb) to know if you need to subtract 2 or 4 from R14_und and if you need to fetch 2 or 4 bytes. Unfortunately if on a newer architecture that supports thumb2 you may have to fetch 4 bytes even in thumb mode and try to figure out what happened. being variable word length it is very possible to be in a situation where it is impossible to determine what happened. If you are not using thumb2 instructions then it is deterministic.

于 2012-07-12T13:58:22.147 回答