#undef NDEBUG
#include <stdio.h>
#include <stdint.h>
#include <assert.h>

struct test_data {
	uint32_t word0;
	uint32_t word1;
};

static uint32_t test_area[8];

static void init_data(void)
{
	int i;
	char *ptr = (char *)&test_area[0];

	for (i = 0; i < (8*4); i++) {
		ptr[i] = i;
	}
}

int
do_unalign_test(char *ptr)
{
	struct test_data *test = (struct test_data *)ptr;
	uint32_t *test2 = (uint32_t *)(ptr + 8);
	uint32_t val, a, b, c;

	printf("QNX unaligned access test\n");

#if !defined(__ARM__)
	a = test->word0;
	b = test->word1;
	c = *test2;
#else
	__asm__ __volatile__ (
		"	ldm %3, {r0, r1}	\n"
		"	ldr %2, [%3, #8]	\n"
                "       mov %0, r0              \n"
                "       mov %1, r1              \n"
		: "=&r" (a), "=&r" (b), "=&r" (c)
		: "r" (test)
                : "r0", "r1"
	);
#endif

	printf("a, b, c = %08x, %08x, %08x\n", a, b, c);
	assert(a == 0x04030201);
	assert(b == 0x08070605);
	assert(c == 0x0c0b0a09);

	return 0;
}

int
main (int argc, char *argv[])
{
	char *ptr = (char *)&test_area[0];

	ptr ++;

        init_data();

	return do_unalign_test(ptr);
}
