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