xref: /openbmc/qemu/tests/tcg/aarch64/test-826.c (revision 5242ef88)
1 #include <sys/mman.h>
2 #include <unistd.h>
3 #include <signal.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <assert.h>
7 
8 static void *expected;
9 
10 void sigsegv(int sig, siginfo_t *info, void *vuc)
11 {
12     ucontext_t *uc = vuc;
13 
14     assert(info->si_addr == expected);
15     uc->uc_mcontext.pc += 4;
16 }
17 
18 int main()
19 {
20     struct sigaction sa = {
21         .sa_sigaction = sigsegv,
22         .sa_flags = SA_SIGINFO
23     };
24 
25     void *page;
26     long ofs;
27 
28     if (sigaction(SIGSEGV, &sa, NULL) < 0) {
29         perror("sigaction");
30         return EXIT_FAILURE;
31     }
32 
33     page = mmap(0, getpagesize(), PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
34     if (page == MAP_FAILED) {
35         perror("mmap");
36         return EXIT_FAILURE;
37     }
38 
39     ofs = 0x124;
40     expected = page + ofs;
41 
42     asm("ptrue p0.d, vl1\n\t"
43         "dup z0.d, %0\n\t"
44         "ldnt1h {z1.d}, p0/z, [z0.d, %1]\n\t"
45         "dup z1.d, %1\n\t"
46         "ldnt1h {z0.d}, p0/z, [z1.d, %0]"
47         : : "r"(page), "r"(ofs) : "v0", "v1");
48 
49     return EXIT_SUCCESS;
50 }
51