I'm working on an ARMv7 platform, and encountered a register-access problem. The registers in the device module has a strong WORD requirement for access:
typedef unsigned char u8;
struct reg {
u8 byte0; u8 byte1; u8 byte2; u8 byte3;
};
when try c code like this: reg.byte0 = 0x3, normally gcc generate assembly code similar LDRB r1, [r0], and this byte operation will lead undefined behavior of my platform.
It there an option so that gcc will produce code "read reg, mask byte0" and then a dword "LDR r1, [r0]" rather than "LDRB" op code?
update: the destination i wanna access is a device register on SOC. It has 4 fields and we use a struct representing this register. Accessing byte0 field like reg.byte0 = 3 normally generate byte access assembly code. I want to know whether this kind of c code reg.byte0=3 could be assembled to word access (32 bit, LDR) code.
really sorry for my poor English!
UPDATE: The example is just a simplification for real world. and volatile and memory barrier are also used in linux driver. just forgot to add in examples. It's ARM11 on which i'm working on.
1) seems memcpy not good for me, because different register has various fields, i cannot write all of access-inline-function
2) using union seems effective and i'll update result when completing test.
UPDATE2: just test union and it still cannot work on my platform.
i think the better way is to use explicit word access and do not confuse compiler.
UPDATE3: seems someone else post the exact same question, and it has been resolved. Force GCC to access structs with words
thanks your guys!