ARM 未定义指令错误 [英] ARM Undefined Instruction error

查看:37
本文介绍了ARM 未定义指令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行嵌入式系统时遇到未定义指令错误,没有协处理器,没有 MMU,Atmel 9263.嵌入式系统的内存范围为 0x20000000 - 0x23FFFFFF.到目前为止,我有两个案例:

I'm getting an Undefined Instruction error while running an embedded system, no coprocessor, no MMU, Atmel 9263. The embedded system has memory in the range 0x20000000 - 0x23FFFFFF. I've had two cases so far:

  1. SP 0x0030B840, LR 2000AE78 - LR 指向有效代码,所以我不确定是什么导致了异常,尽管 SP 是假的.我应该查看哪些其他地址、寄存器、内存位置?

  1. SP 0x0030B840, LR 2000AE78 - the LR points at valid code, so I'm not sure what causes the exception, although the SP is bogus. What other addresses, registers, memory locations should I look at?

SP 0x20D384A8, LR 0x1FFCA59C - SP 没问题,LR 是假的.有什么我可以做的事后分析来找出 LR 是如何被压垮的?看起来它从地址空间的末尾向后滚动,但我不知道如何.

SP 0x20D384A8, LR 0x1FFCA59C - SP is ok, LR is bogus. Is there some kind of post mortem that I can do to find out how the LR got crushed? Looks like it rolled backwards off the end of the address space, but I can't figure out how.

现在我只是用模拟替换大块代码并运行测试以尝试隔离问题 - 问题是有时需要 4 小时才能显示问题.

Right now I am just replacing large chunks of code with simulations and running the tests agin to try and isolate the issue - the problem is sometimes it takes 4 hours to show the problem.

如有任何提示,将不胜感激,谢谢!

Any hints out there would be appreciated, thanks!

芯片是 AT91SAM9263,我们使用的是 IAR EWARM 工具链.我很确定它是直接的 ARM,但我会检查.

The chip is the AT91SAM9263, and we are using the IAR EWARM toolchain. I'm pretty sure it is straight ARM, but I will check.

编辑

Undef Instruct 的另一个例子 - 这次 SP/LR 看起来不错.LR = 0x2000b0c4,当我在那里拆卸时:

Another example of the Undef Instruct - this time SP/LR look fine. LR = 0x2000b0c4, and when I disassemble near there:

2000b0bc e5922000 LDR R2,[R2,#+0]
2000b0c0 e12fff32 BLX R2
2000b0c4 e1b00004 MOVS R0, R4

2000b0bc e5922000 LDR R2, [R2, #+0]
2000b0c0 e12fff32 BLX R2
2000b0c4 e1b00004 MOVS R0, R4

由于 LR 是 Undef 异常之后的指令 - BLX 如何识别为未定义?注意CPSR是0x00000013,所以这都是ARM模式.但是,R2 是堆区域中的 0x226d2a08,我认为是不正确的 - 那里有 ANDEQ R0,R0,R12 的反汇编,指令是 0x0000000C,而那里的其他指令对我来说看起来像数据.所以我认为糟糕的 R2 是问题所在,我只是想了解为什么 BLX 上的 Undef?

since LR is the instruction following the Undef Exception - how is BLX identified as Undefined? Note that CPSR is 0x00000013, so this is all ARM mode. However, R2 is 0x226d2a08 which is in the heap area, and I think is incorrect - the disassmbly there is ANDEQ R0,R0,R12, the instruction is 0x0000000C, and the other instructions there look like data to me. So I think the bad R2 is the problem, I'm just trying to understand why the Undef at the BLX?

谢谢!

推荐答案

检查 CPSR 中的 T 位.如果您无意中从 ARM 模式更改为 Thumb 模式(反之亦然),则会出现未定义的指令.

Check the T bit in the CPSR. If you are inadvertently changing from ARM mode to Thumb mode (or vice versa), undefined instructions will occur.

就 SP 或 LR 损坏而言,可能是您以错误的模式执行了一些指令,从而在命中未定义指令之前损坏了它们.

As far as the SP or LR getting corrupted, it could be that you execute a few instructions in the wrong mode that corrupt them before hitting the undefined instruction.

编辑

在编辑问题时回应新的错误案例:

Responding to the new error case in the edit of the question:

LR 包含来自 BLX R2 的返回地址,因此它指向 BLX 之后的一条指令是有意义的.

LR contains the return address from the BLX R2, so it makes sense that it points to one instruction after the BLX.

如果在执行 BLX R2 时 R2 指向堆,您将跳入堆并开始执行数据,就好像它们是指令一样.这将在短时间内导致未定义的指令异常...

If R2 was pointing to the heap when the BLX R2 was executed, you'll jump into the heap and start executing the data as if they were instructions. This will cause an undefined instruction exception in short order...

如果您想查看未定义的确切指令,请查看 R14_und 寄存器(在您处于未定义指令处理程序中时定义) - 它包含未定义指令之后的下一条指令的地址.

If you want to see the exact instruction that was undefined, look at the R14_und register (defined while you're in the undefined instruction handler) - it contains the address of the next instruction after the Undefined one.

根本原因是 R2 中的错误值.假设这是 C 代码,我的猜测是一个错误的指针取消引用,但我需要查看源代码才能确定.

The root cause is the bad value in R2. Assuming this is C code, my guess is a bad pointer dereference, but I'd need to see the source to know for sure.

这篇关于ARM 未定义指令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆