Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / arm / pcalign-a32.c
blob3c9c8cc97b13d8063d6235bf2ba555a3ae44cdbe
1 /* Test PC misalignment exception */
3 #ifdef __thumb__
4 #error "This test must be compiled for ARM"
5 #endif
7 #include <assert.h>
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <stdio.h>
12 static void *expected;
14 static void sigbus(int sig, siginfo_t *info, void *vuc)
16 assert(info->si_code == BUS_ADRALN);
17 assert(info->si_addr == expected);
18 exit(EXIT_SUCCESS);
21 int main()
23 void *tmp;
25 struct sigaction sa = {
26 .sa_sigaction = sigbus,
27 .sa_flags = SA_SIGINFO
30 if (sigaction(SIGBUS, &sa, NULL) < 0) {
31 perror("sigaction");
32 return EXIT_FAILURE;
35 asm volatile("adr %0, 1f + 2\n\t"
36 "str %0, %1\n\t"
37 "bx %0\n"
38 "1:"
39 : "=&r"(tmp), "=m"(expected));
42 * From v8, it is CONSTRAINED UNPREDICTABLE whether BXWritePC aligns
43 * the address or not. If so, we can legitimately fall through.
45 return EXIT_SUCCESS;