Skip to content

Add aligment attiribute to the Big Struct #16

@roowatt

Description

@roowatt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions