diff --git a/repos/os/src/drivers/nic/spec/zynq/cadence_gem.h b/repos/os/src/drivers/nic/spec/zynq/cadence_gem.h index 525df294fb..ead14683e8 100644 --- a/repos/os/src/drivers/nic/spec/zynq/cadence_gem.h +++ b/repos/os/src/drivers/nic/spec/zynq/cadence_gem.h @@ -343,6 +343,20 @@ namespace Genode struct Counter : Bitfield<0, 16> { }; }; + /** + * These two structs help avoiding the following compile errors in + * places where the driver has to convert MAC addresses pointers + * to integer pointers: + * + * error: taking address of packed member of ‘Net::Mac_address’ + * may result in an unaligned pointer value + * + * As the MAC address type is packed and therefore has alignment 1, + * we have to ensure that the pointer type we convert it to also + * has alignment 1, i.e., that it is also packed. + */ + struct Packed_uint16 { uint16_t value; } __attribute__((packed)); + struct Packed_uint32 { uint32_t value; } __attribute__((packed)); class Phy_timeout_for_idle : public Genode::Exception {}; class Unkown_ethernet_speed : public Genode::Exception {}; @@ -437,11 +451,11 @@ namespace Genode Nic::Mac_address read_mac_address() { Nic::Mac_address mac; - uint32_t* const low_addr_pointer = reinterpret_cast(&mac.addr[0]); - uint16_t* const high_addr_pointer = reinterpret_cast(&mac.addr[4]); + Packed_uint32 * const low_addr_pointer = reinterpret_cast(&mac.addr[0]); + Packed_uint16 * const high_addr_pointer = reinterpret_cast(&mac.addr[4]); - *low_addr_pointer = read(); - *high_addr_pointer = read(); + low_addr_pointer->value = read(); + high_addr_pointer->value = read(); return mac; } @@ -676,11 +690,11 @@ namespace Genode void write_mac_address(const Nic::Mac_address &mac) { - const uint32_t* const low_addr_pointer = reinterpret_cast(&mac.addr[0]); - const uint16_t* const high_addr_pointer = reinterpret_cast(&mac.addr[4]); + Packed_uint32 const * const low_addr_pointer = reinterpret_cast(&mac.addr[0]); + Packed_uint16 const * const high_addr_pointer = reinterpret_cast(&mac.addr[4]); - write(*low_addr_pointer); - write(*high_addr_pointer); + write(low_addr_pointer->value); + write(high_addr_pointer->value); } void rx_buffer_reset_pkt(Nic::Packet_descriptor pkt)