summaryrefslogtreecommitdiff
path: root/regress/sys/kern/unalign/unalign.c
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2008-07-26 10:25:05 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2008-07-26 10:25:05 +0000
commit99b10a8cd0788883785e8f6fd607b2a6d4ceaa98 (patch)
tree5f823003158b8500afeb112dd71ac5422728d626 /regress/sys/kern/unalign/unalign.c
parente7a7a934620a960e5a1f61baf25f66e73d977b17 (diff)
Make sure the test array is 64 bit aligned, this now makes sparc fail this
test.
Diffstat (limited to 'regress/sys/kern/unalign/unalign.c')
-rw-r--r--regress/sys/kern/unalign/unalign.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/regress/sys/kern/unalign/unalign.c b/regress/sys/kern/unalign/unalign.c
index 7721d01b54f..aeacad5266a 100644
--- a/regress/sys/kern/unalign/unalign.c
+++ b/regress/sys/kern/unalign/unalign.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unalign.c,v 1.1 2005/04/26 21:37:05 miod Exp $ */
+/* $OpenBSD: unalign.c,v 1.2 2008/07/26 10:25:04 miod Exp $ */
/* Written by Miod Vallat, 2004 AD -- this file is in the public domain */
/*
@@ -14,15 +14,14 @@
#include <stdio.h>
#include <sys/types.h>
+uint32_t array[5];
+
int
-main(int argc, char *argv[])
+unalign_read(uint64_t *addr)
{
-#if !defined(__LP64__)
- long array[4] = { 0x12345678, 0x13579ace, 0xffffabcd, 0x2468fedc };
- long long t;
- unsigned int i;
+ uint64_t t;
- t = *(long long *)(array + 1);
+ t = *addr;
#if BYTE_ORDER == BIG_ENDIAN
if (t != 0x13579aceffffabcdULL)
#else
@@ -30,16 +29,45 @@ main(int argc, char *argv[])
#endif
return (1);
+ return (0);
+}
+
+void
+unalign_write(uint64_t *addr)
+{
+ uint64_t t;
+
t = 0xdeadbeaffadebabeULL;
- *(long long *)(array + 1) = t;
+ *addr = t;
+}
+
+int
+main(int argc, char *argv[])
+{
+#if !defined(__LP64__)
+ uint32_t *addr = array;
+
+ /* align on a 64 bit boundary */
+ if (((uint32_t)addr & 7) != 0)
+ addr++;
+
+ addr[0] = 0x12345678;
+ addr[1] = 0x13579ace;
+ addr[2] = 0xffffabcd;
+ addr[3] = 0x2468fedc;
+
+ if (unalign_read((uint64_t *)(addr + 1)))
+ return (1);
+
+ unalign_write((uint64_t *)(addr + 1));
#if BYTE_ORDER == BIG_ENDIAN
- if (array[1] != 0xdeadbeaf || array[2] != 0xfadebabe)
+ if (addr[1] != 0xdeadbeaf || addr[2] != 0xfadebabe)
#else
- if (array[1] != 0xfadebabe || array[2] != 0xdeadbeaf)
+ if (addr[1] != 0xfadebabe || addr[2] != 0xdeadbeaf)
#endif
return (1);
-
#endif /* __LP64__ */
+
return (0);
}