1 /* $OpenBSD: unalign.c,v 1.2 2008/07/26 10:25:04 miod Exp $ */
2 /* Written by Miod Vallat, 2004 AD -- this file is in the public domain */
5 * This test checks for the ability, for 32 bit systems, to correctly
6 * access a long long (64 bit) value aligned on a 32 bit boundary, but not
7 * on a 64 bit boundary.
9 * All architectures should pass this test; on m88k this requires assistance
10 * from the kernel to recover from the misaligned operand exception: see
11 * double_reg_fixup() in arch/m88k/m88k/trap.c for details.
15 #include <sys/types.h>
20 unalign_read(uint64_t *addr)
25 #if BYTE_ORDER == BIG_ENDIAN
26 if (t != 0x13579aceffffabcdULL)
28 if (t != 0xffffabcd13579aceULL)
36 unalign_write(uint64_t *addr)
40 t = 0xdeadbeaffadebabeULL;
45 main(int argc, char *argv[])
47 #if !defined(__LP64__)
48 uint32_t *addr = array;
50 /* align on a 64 bit boundary */
51 if (((uint32_t)addr & 7) != 0)
59 if (unalign_read((uint64_t *)(addr + 1)))
62 unalign_write((uint64_t *)(addr + 1));
64 #if BYTE_ORDER == BIG_ENDIAN
65 if (addr[1] != 0xdeadbeaf || addr[2] != 0xfadebabe)
67 if (addr[1] != 0xfadebabe || addr[2] != 0xdeadbeaf)