Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aligment attiribute to the Big Struct #16

Open
roowatt opened this issue Aug 15, 2024 · 0 comments
Open

Add aligment attiribute to the Big Struct #16

roowatt opened this issue Aug 15, 2024 · 0 comments

Comments

@roowatt
Copy link

roowatt commented Aug 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant