Merge tag 'migration-20240802-pull-request' of https://gitlab.com/farosas/qemu into...
[qemu/armbru.git] / tests / tcg / hppa / stby.c
blob36bd5f723c3d560a7010b9e292d02a46a74e2e68
1 /* Test STBY */
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
9 struct S {
10 unsigned a;
11 unsigned b;
12 unsigned c;
15 static void check(const struct S *s, unsigned e,
16 const char *which, const char *insn, int ofs)
18 int err = 0;
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;
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;
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;
36 if (err) {
37 exit(1);
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)
49 static void test(const char *which)
51 struct S s = { };
53 TEST("stby,b", 0, 0x11223344);
54 TEST("stby,b", 1, 0x00223344);
55 TEST("stby,b", 2, 0x00003344);
56 TEST("stby,b", 3, 0x00000044);
58 TEST("stby,e", 0, 0x00000000);
59 TEST("stby,e", 1, 0x11000000);
60 TEST("stby,e", 2, 0x11220000);
61 TEST("stby,e", 3, 0x11223300);
64 static void *child(void *x)
66 return NULL;
69 int main()
71 int err;
72 pthread_t thr;
74 /* Run test in serial mode */
75 test("serial");
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;
84 /* Run test in parallel mode */
85 test("parallel");
86 return 0;