aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/arm/pcalign-a32.c
blob: 3c9c8cc97b13d8063d6235bf2ba555a3ae44cdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Test PC misalignment exception */

#ifdef __thumb__
#error "This test must be compiled for ARM"
#endif

#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>

static void *expected;

static void sigbus(int sig, siginfo_t *info, void *vuc)
{
    assert(info->si_code == BUS_ADRALN);
    assert(info->si_addr == expected);
    exit(EXIT_SUCCESS);
}

int main()
{
    void *tmp;

    struct sigaction sa = {
        .sa_sigaction = sigbus,
        .sa_flags = SA_SIGINFO
    };

    if (sigaction(SIGBUS, &sa, NULL) < 0) {
        perror("sigaction");
        return EXIT_FAILURE;
    }

    asm volatile("adr %0, 1f + 2\n\t"
                 "str %0, %1\n\t"
                 "bx  %0\n"
                 "1:"
                 : "=&r"(tmp), "=m"(expected));

    /*
     * From v8, it is CONSTRAINED UNPREDICTABLE whether BXWritePC aligns
     * the address or not.  If so, we can legitimately fall through.
     */
    return EXIT_SUCCESS;
}