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?
Marcus,
I thought it was clear that the address in question was the address of the data to process, not the instruction to execute...
What difference two letters can make. I was reading this as "[...]transfered a RAM memory address of a function. That address was not even [and caused grief, etc]". Sorry about this.
Back to the question -- it is still not clear what the situation is. Are you using assembler or C? Why use an LDR in the first place if the address may be unaligned? Or were you just observing the compiler generate an LDR? If C, why not just use memcpy() and properly declared pointers?
I would not use a run-time check for this. If the pointer has been properly declared, as e.g. (char *) or (__packed int *) (as others have pointed out), memcpy() is likely your best option.
> 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.
In fact none of them complains by default. Some return rotated data, some others force the two LSB to 0. Some allow to trap unaligned access, others don't.
> So one can write/import broken code
As usual with low level languages.
Best regards Marcus http://www.doulos.com/arm/
If C, why not just use memcpy() and properly declared pointers?
because we didn't feel like using __packed due to its toll... I think the question has been answered to my satisfaction. thank you all.