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

Undesired reserved space #18

Open
0xfede7c8 opened this issue Nov 5, 2024 · 1 comment
Open

Undesired reserved space #18

0xfede7c8 opened this issue Nov 5, 2024 · 1 comment

Comments

@0xfede7c8
Copy link

0xfede7c8 commented Nov 5, 2024

Hi, first of all, thank you very much for the work. It is very useful and professional.

Now, the "issue" I had is the following. Maybe I'm doing something wrong but, I don't know why I have this padding created on the .h file.

The RDL is a simple file:

regfile regfile1 {
  default regwidth = 32;

  reg {field {} field1reg1;} reg1;

  reg {field {} field1reg2;} reg2;
};

addrmap test2_regmap {
    default regwidth = 32;
    
    reg {field {} field1reg3;} reg3;

    regfile1 regf;
};

And I run peakrdl with:

peakrdl c-header test2_regmap.rdl -o out.h

I'm getting the .h:

....
// Addrmap - test2_regmap
typedef struct __attribute__ ((__packed__)) {
    uint32_t reg3;
    uint8_t RESERVED_4_7[0x4];
    regfile1_t regf;
} test2_regmap_t;
...

I don't know why there is a reserved array of chars. I think it is aligned to 32bits.

Do you know what may be happening? Any recommendations appreciated.

@0xfede7c8
Copy link
Author

0xfede7c8 commented Nov 6, 2024

Update:

I checked the code where this padding is added:

https://github.com/SystemRDL/PeakRDL-cheader/blob/main/src/peakrdl_cheader/header_generator.py#L275

#...
padding = child.raw_address_offset - current_offset
if padding:
    self.write_byte_padding(current_offset, padding)
    current_offset += padding
#...

Basically this is saying that if the child's (current node) max offset (the size of the child basically) is bigger than the current offset (the current position in the addrmap) a padding will be added to match the maximum of the child.

It's fun because if I include a bunch of registers as a regfile, the child.raw_address_offset is bigger than if I add the registers to the regmap "manually" (this means not using a regfile). In that last case each register will be processed manually, where the child.raw_address_offset is always smaller than the current_offset so no padding is needed.

Example:

regfile regfile1 {
  default regwidth = 32;

  reg {field {} field1reg1;} reg1;

  reg {field {} field1reg2;} reg2;
};

addrmap test2_regmap {
    default regwidth = 32;
    
    reg {field {} field1reg3;} reg3;

    regfile1 regf;
};

This creates padding.

addrmap test2_regmap {
    default regwidth = 32;
    
    reg {field {} field1reg3;} reg3;
    
   reg {field {} field1reg1;} reg1;
   reg {field {} field1reg2;} reg2;
};

This doesn't.

Am I missing something here?

I would understand this logic a bit more if we were creating a C union but we are talking about structs here.
Every hing would be appreciated.

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