I'm trying to cast an address (provided as a u64 value) to a pointer to a packed struct that represents a firmware table. I've defined my struct like this:
pub const Rsdp2Descriptor = packed struct {
signature: u64, // originally [8]u8
checksum: u8,
oem_id: u48, // originally [6]u8
revision: u8,
rsdt_address: u32,
length: u32,
xsdt_address: u64,
extended_checksum: u8,
reserved: u24, // originally [3]u8
};
I chose to use integer types instead of byte arrays because using [8]u8, [6]u8, etc. in a packed struct is apparently not allowed in Zig.
However, this approach causes my struct to have a u64 alignment. When I cast an address (e.g., 0x777e014, appropriately converted to a virtual address) to a pointer to this struct, I get an alignment safety check error.
I can't use the align attribute on individual fields of a packed struct either. How can I work around this alignment safety issue while still being able to interpret the incoming data correctly?