| 1 | /* Test STBY */ |
| 2 | |
| 3 | #include <pthread.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | |
| 9 | struct S { |
| 10 | unsigned a; |
| 11 | unsigned b; |
| 12 | unsigned c; |
| 13 | }; |
| 14 | |
| 15 | static void check(const struct S *s, unsigned e, |
| 16 | const char *which, const char *insn, int ofs) |
| 17 | { |
| 18 | int err = 0; |
| 19 | |
| 20 | if (s->a != 0) { |
| 21 | fprintf(stderr, "%s %s %d: garbage before word 0x%08x\n", |
| 22 | which, insn, ofs, s->a); |
| 23 | err = 1; |
| 24 | } |
| 25 | if (s->c != 0) { |
| 26 | fprintf(stderr, "%s %s %d: garbage after word 0x%08x\n", |
| 27 | which, insn, ofs, s->c); |
| 28 | err = 1; |
| 29 | } |
| 30 | if (s->b != e) { |
| 31 | fprintf(stderr, "%s %s %d: 0x%08x != 0x%08x\n", |
| 32 | which, insn, ofs, s->b, e); |
| 33 | err = 1; |
| 34 | } |
| 35 | |
| 36 | if (err) { |
| 37 | exit(1); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | #define TEST(INSN, OFS, E) \ |
| 42 | do { \ |
| 43 | s.b = 0; \ |
| 44 | asm volatile(INSN " %1, " #OFS "(%0)" \ |
| 45 | : : "r"(&s.b), "r" (0x11223344) : "memory"); \ |
| 46 | check(&s, E, which, INSN, OFS); \ |
| 47 | } while (0) |
| 48 | |
| 49 | static void test(const char *which) |
| 50 | { |
| 51 | struct S s = { }; |
| 52 | |
| 53 | TEST("stby,b", 0, 0x11223344); |
| 54 | TEST("stby,b", 1, 0x00223344); |
| 55 | TEST("stby,b", 2, 0x00003344); |
| 56 | TEST("stby,b", 3, 0x00000044); |
| 57 | |
| 58 | TEST("stby,e", 0, 0x00000000); |
| 59 | TEST("stby,e", 1, 0x11000000); |
| 60 | TEST("stby,e", 2, 0x11220000); |
| 61 | TEST("stby,e", 3, 0x11223300); |
| 62 | } |
| 63 | |
| 64 | static void *child(void *x) |
| 65 | { |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | int main() |
| 70 | { |
| 71 | int err; |
| 72 | pthread_t thr; |
| 73 | |
| 74 | /* Run test in serial mode */ |
| 75 | test("serial"); |
| 76 | |
| 77 | /* Create a dummy thread to start parallel mode. */ |
| 78 | err = pthread_create(&thr, NULL, child, NULL); |
| 79 | if (err != 0) { |
| 80 | fprintf(stderr, "pthread_create: %s\n", strerror(err)); |
| 81 | return 2; |
| 82 | } |
| 83 | |
| 84 | /* Run test in parallel mode */ |
| 85 | test("parallel"); |
| 86 | return 0; |
| 87 | } |