Hello,
A colleague of mine, while processing some binary data, transfered a RAM memory address to a function. That address was not even (ARM7 architecture) so the LDR instruction behaved exactly as the assembly manual specifies it should in case of a misaligned address - round in the address + some more shift magic, which created a memory access off by 1 byte. My question is: Is there a way to deal with this runtime error in advance?
Christoph,
Thanks for your reply. Hmm, that was not what I was hoping to hear. But still it makes perfect sense - the compiler cannot know in advance whether a pointer will contain an unaligned address or not. I guess that you just have to be prepared for it. What is rather worrying (maybe it is a question of taste or style...) is that some ARM cores (non Cortex) do not complain at all if an unaligned access is done. So one can write/import broken code, without ever knowing _why_ it does not work as expected. The C166 resets when an unaligned access is executed, as far as I recall.
is that some ARM cores (non Cortex) do not complain at all if an unaligned access is done.
It's not the fault of the core, really. If I remember correctly, the ARM7 core was originally designed to be used in ASICs, and hence does not come with any fancy peripherals (no memory controller). It's up to the chip designer to include (or omit, if minimal gate count/power consumption is required) these.
Then again, producing a misaligned access in C requires playing fast and loose with pointers.