题
I have a library written in C mixed mixed with some assembly for ARM. It used to be compiled for armv6. Now I am trying to upgrade it to armv7. However, there is an interrupt handler which has the instruction stmdb sp!, {pc}
which is not allowed in armv7. What would be an equivalent instruction on armv7? I tried str r15, [sp, #-4]!
but that doesn't work.
解决方案
There's specific limitations regarding the use of PC
in the reg list for PUSH
and POP
instructions, depending on the operation mode, see:
ARM Instruction Set Reference, PUSH
/POP
Specifically, in Thumb[2] there is no push {pc}
operation (which is the same as saying there's no stmfd sp!, {pc}
operation - push
is mapped to stmfd sp!
).
So if you're compiling your kernel code (why else do you have/need an interrupt handler if it's not kernel code), check whether you're compiling a Thumb-2 kernel.
That said, you're saying you encountered a stmfd sp!,{pc}
instruction - you're sure that's not a typo ? stmfd sp!,{lr}
(and its sibling, ldmfd sp!, {pc}
- here PC
is present) is normal / fully legal and often required / encountered in both ARM mode and Thumb-2 mode. But that actually is the purpose of saving the program counter to the stack ? What can one do with that that wouldn't be achievable in other ways ?
其他提示
"armv7" is rather generic. What's the actual chip you're using? Are you compiling for ARMv7-M? Try PUSH {PC}
then. Though I expect that won't be the only issue you will run into. I think you should post some snippets and describe in more details what specific environment you're porting to.