#20070 - gladius - Sat May 01, 2004 4:22 am
I know that halfword reads on unaligned addresses are a no-no (undefined by the ARM spec.), but I was wondering what the actual behaviour is.
I seem to recall it would load 8 bits of the halfword from the unaligned access into the register, but my memory is sketchy, and I don't have access to hardware at this moment.
Thanks.
#20075 - poslundc - Sat May 01, 2004 1:09 pm
IIRC, the last bit of the address is ignored, so if you read a halfword from an odd address then it is rounded down to an even address.
In other words:
*(u16 *)(0x03000000)
and
*(u16 *)(0x03000001)
... should produce the same result.
Dan.
#25504 - ecurtz - Tue Aug 24, 2004 4:36 am
According to this FAQ at ARM an unaligned read on the 7TDMI has the (very desirable in my case) behavior of reading the entire word, but shifting the addressed byte into the low byte of the result. This seems to imply that I can just use word loads with shifts instead of half word loads, which require extra work. I tried this on hardware a second ago and it works, are there any gotchas I need to know about or is this kosher?
(Actually as I typed this up I realized the behavior may differ between cartridge and EWRAM. I'll go make another test case...)
<edit> I just tried it from cart and it seemed fine. Is this a common trick? Is there some gotcha about the "A flag in bit 1 of CP15 register" that means I'll get an exception at some point? </edit>
#25732 - torne - Fri Aug 27, 2004 7:30 pm
Yes, it will work that way. CP15 is the system control coprocessor and is not present on the GBA, so the alignment error bit in it will unsuprisingly not be set ;)
I've never needed to use this, but it's legit on a system such as the GBA where you can depend on the memory controller's behaviour.
#25769 - ecurtz - Sat Aug 28, 2004 5:11 am
Thanks for the confirmation torne.
It seems like there would be a number of cases where this would be useful. I ran into it looking up entries in a color table.