xref: /openbmc/qemu/tests/tcg/aarch64/dcpop.c (revision c81e4ab3)
1*c81e4ab3SZhuojia Shen /*
2*c81e4ab3SZhuojia Shen  * Test execution of DC CVAP instruction.
3*c81e4ab3SZhuojia Shen  *
4*c81e4ab3SZhuojia Shen  * Copyright (c) 2023 Zhuojia Shen <chaosdefinition@hotmail.com>
5*c81e4ab3SZhuojia Shen  * SPDX-License-Identifier: GPL-2.0-or-later
6*c81e4ab3SZhuojia Shen  */
7*c81e4ab3SZhuojia Shen 
8*c81e4ab3SZhuojia Shen #include <asm/hwcap.h>
9*c81e4ab3SZhuojia Shen #include <sys/auxv.h>
10*c81e4ab3SZhuojia Shen 
11*c81e4ab3SZhuojia Shen #include <signal.h>
12*c81e4ab3SZhuojia Shen #include <stdbool.h>
13*c81e4ab3SZhuojia Shen #include <stdio.h>
14*c81e4ab3SZhuojia Shen #include <stdlib.h>
15*c81e4ab3SZhuojia Shen 
16*c81e4ab3SZhuojia Shen #ifndef HWCAP_DCPOP
17*c81e4ab3SZhuojia Shen #define HWCAP_DCPOP (1 << 16)
18*c81e4ab3SZhuojia Shen #endif
19*c81e4ab3SZhuojia Shen 
20*c81e4ab3SZhuojia Shen bool should_fail = false;
21*c81e4ab3SZhuojia Shen 
signal_handler(int sig,siginfo_t * si,void * data)22*c81e4ab3SZhuojia Shen static void signal_handler(int sig, siginfo_t *si, void *data)
23*c81e4ab3SZhuojia Shen {
24*c81e4ab3SZhuojia Shen     ucontext_t *uc = (ucontext_t *)data;
25*c81e4ab3SZhuojia Shen 
26*c81e4ab3SZhuojia Shen     if (should_fail) {
27*c81e4ab3SZhuojia Shen         uc->uc_mcontext.pc += 4;
28*c81e4ab3SZhuojia Shen     } else {
29*c81e4ab3SZhuojia Shen         exit(EXIT_FAILURE);
30*c81e4ab3SZhuojia Shen     }
31*c81e4ab3SZhuojia Shen }
32*c81e4ab3SZhuojia Shen 
do_dc_cvap(void)33*c81e4ab3SZhuojia Shen static int do_dc_cvap(void)
34*c81e4ab3SZhuojia Shen {
35*c81e4ab3SZhuojia Shen     struct sigaction sa = {
36*c81e4ab3SZhuojia Shen         .sa_flags = SA_SIGINFO,
37*c81e4ab3SZhuojia Shen         .sa_sigaction = signal_handler,
38*c81e4ab3SZhuojia Shen     };
39*c81e4ab3SZhuojia Shen 
40*c81e4ab3SZhuojia Shen     sigemptyset(&sa.sa_mask);
41*c81e4ab3SZhuojia Shen     if (sigaction(SIGSEGV, &sa, NULL) < 0) {
42*c81e4ab3SZhuojia Shen         perror("sigaction");
43*c81e4ab3SZhuojia Shen         return EXIT_FAILURE;
44*c81e4ab3SZhuojia Shen     }
45*c81e4ab3SZhuojia Shen 
46*c81e4ab3SZhuojia Shen     asm volatile("dc cvap, %0\n\t" :: "r"(&sa));
47*c81e4ab3SZhuojia Shen 
48*c81e4ab3SZhuojia Shen     should_fail = true;
49*c81e4ab3SZhuojia Shen     asm volatile("dc cvap, %0\n\t" :: "r"(NULL));
50*c81e4ab3SZhuojia Shen     should_fail = false;
51*c81e4ab3SZhuojia Shen 
52*c81e4ab3SZhuojia Shen     return EXIT_SUCCESS;
53*c81e4ab3SZhuojia Shen }
54*c81e4ab3SZhuojia Shen 
main(void)55*c81e4ab3SZhuojia Shen int main(void)
56*c81e4ab3SZhuojia Shen {
57*c81e4ab3SZhuojia Shen     if (getauxval(AT_HWCAP) & HWCAP_DCPOP) {
58*c81e4ab3SZhuojia Shen         return do_dc_cvap();
59*c81e4ab3SZhuojia Shen     } else {
60*c81e4ab3SZhuojia Shen         printf("SKIP: no HWCAP_DCPOP on this system\n");
61*c81e4ab3SZhuojia Shen         return EXIT_SUCCESS;
62*c81e4ab3SZhuojia Shen     }
63*c81e4ab3SZhuojia Shen }
64