1 /* $OpenBSD: unalign.c,v 1.1 2005/04/26 21:37:05 miod Exp $ */ 2 /* Written by Miod Vallat, 2004 AD -- this file is in the public domain */ 3 4 /* 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. 8 * 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. 12 */ 13 14 #include <stdio.h> 15 #include <sys/types.h> 16 17 int 18 main(int argc, char *argv[]) 19 { 20 #if !defined(__LP64__) 21 long array[4] = { 0x12345678, 0x13579ace, 0xffffabcd, 0x2468fedc }; 22 long long t; 23 unsigned int i; 24 25 t = *(long long *)(array + 1); 26 #if BYTE_ORDER == BIG_ENDIAN 27 if (t != 0x13579aceffffabcdULL) 28 #else 29 if (t != 0xffffabcd13579aceULL) 30 #endif 31 return (1); 32 33 t = 0xdeadbeaffadebabeULL; 34 *(long long *)(array + 1) = t; 35 36 #if BYTE_ORDER == BIG_ENDIAN 37 if (array[1] != 0xdeadbeaf || array[2] != 0xfadebabe) 38 #else 39 if (array[1] != 0xfadebabe || array[2] != 0xdeadbeaf) 40 #endif 41 return (1); 42 43 #endif /* __LP64__ */ 44 return (0); 45 } 46