-
Notifications
You must be signed in to change notification settings - Fork 19
Description
I had cause to refactor some test code and was no longr using a #define to access the register bank, which lead to some errors.
After some initial head scratching, it was obvious as to what was happening. Due to the refactored code, the compiler could no longer be certain of the alignment of the "big struct" which resulted in all register accesses be decomposed into byte accesses. The fix is simple, it is to add an aligned attribute in addition to the packed attribute.
SystemRDL/PeakRDL has rules regarding alignment, so I guess it is possible to add the appropriate alignment attribute.
typedef struct __attribute__ ((__packed__)) {
misc_regs_t_t misc_regs;
} my_regbank_t;becomes (32bit alignment)
typedef struct __attribute__ ((__packed__,aligned(4))) {
misc_regs_t_t misc_regs;
} my_regbank_t;I have been meaning to raise an issue, but wanted to take the time to put together a test case etc. but... I just got bitten by this issue again today after forgetting to add the attribute after regenerating a resgister block for the first time for a little while.
This showed up as a subtle bug where a wide (buffered write) register updated very strangely due to the buffered section hiding the non-atomic update of the lower 4 bytes but then the upper bytes updating one at a time.
If a better explanantion is required, or a test case let me know. But hopefully the proposed change in straightforward enough and non-controversial they aren't required.