net: use UNALIGNED_PUT() to access IP address
This commit allows the net_ipv6_addr_create_iid() argument addr to
have relaxed alignment.
This commit makes the following tests pass on qemu_leon3:
- net.6lo
Details:
sparc-zephyr-elf-gcc 9.2.0 compiles the beginning of
net_ipv6_addr_create_iid(),
addr->s6_addr[0] = 0xfe;
addr->s6_addr[1] = 0x8e;
UNALIGNED_PUT(0, &addr->s6_addr16[1]);
UNALIGNED_PUT(0, &addr->s6_addr32[1]);
into
400089d4 <net_ipv6_addr_create_iid>:
400089d4: 9d e3 bf a0 save %sp, -96, %sp
400089d8: 03 3f a0 00 sethi %hi(0xfe800000), %g1
400089dc: c0 2e 20 04 clrb [ %i0 + 4 ]
400089e0: c2 26 00 00 st %g1, [ %i0 ]
400089e4: c0 2e 20 05 clrb [ %i0 + 5 ]
400089e8: c0 2e 20 06 clrb [ %i0 + 6 ]
400089ec: c0 2e 20 07 clrb [ %i0 + 7 ]
%i0 is the function argument "addr". %g1 is prepared with the value
0xfe800000. The "clrb" instruction sets a single byte in memory to
0 and has no alignment restriction.
We get an unaligned exception on PC 400089e0 when %i0 ("addr") is
not a multiple of 4. The instruction "st" stores the full 32-bit
register %g1 to memory address in %i0. The effective address (%i0)
of the 32-bit register store is required to be naturally aligned by
the architecture.
The compiler assumes that "addr" is aligned according to its type
and has knowledge about the data representation.
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
1 file changed