xref: /qemu/tests/tcg/aarch64/pcalign-a64.c (revision b83a80e8)
1 /* Test PC misalignment exception */
2 
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 
8 static void *expected;
9 
10 static void sigbus(int sig, siginfo_t *info, void *vuc)
11 {
12     assert(info->si_code == BUS_ADRALN);
13     assert(info->si_addr == expected);
14     exit(EXIT_SUCCESS);
15 }
16 
17 int main()
18 {
19     void *tmp;
20 
21     struct sigaction sa = {
22         .sa_sigaction = sigbus,
23         .sa_flags = SA_SIGINFO
24     };
25 
26     if (sigaction(SIGBUS, &sa, NULL) < 0) {
27         perror("sigaction");
28         return EXIT_FAILURE;
29     }
30 
31     asm volatile("adr %0, 1f + 1\n\t"
32                  "str %0, %1\n\t"
33                  "br  %0\n"
34                  "1:"
35                  : "=&r"(tmp), "=m"(expected));
36     abort();
37 }
38