/* * See what happens when we try to load Maverick doublewords from * a boundary not aligned to 8 bytes (or not to 4 bytes) * * Usage: alignment n * where n is the offset in bytes to use from an 8-byte-aligned address * * non-4-aligned maverick double loads with /proc/cpu/alignment = * 5 (signal+warn) cause bus errors and increment field "User" * 3 (fixup+warn) cause illegal instruction and increment User and Skipped * 1 (warn) hangs giving 100 User faults a second until something else runs, * then returns the value at the pointer & ~3. * 0 (ignore) immediately returns the value at pointer & ~3. */ #include char __attribute__((aligned(8))) buf[16]; main(int argc, char **argv) { register volatile double df asm("mvd4"); register double *dp asm("r3"); int offset; if (argc != 2 || (offset = atoi(argv[1])) < 0 || offset > 8) { fputs("Usage: aligment n (0-8)\n", stderr); exit(1); } buf[7] = 1; dp = (double *)(buf + offset); asm volatile("cfldrd mvd4, [r3]" : "=v" (df) : "m" (*dp)); /* df = *dp; /* Boom! :) */ printf("Got %g\n", df); exit(0); }