Add bug 494246 to NEWS
[valgrind.git] / none / tests / ppc64 / scv_test.c
blob5c8df226f489fc2ef49bee52568e4c0e3db42669
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stdlib.h>
5 #ifdef HAS_ISA_3_00
6 #include <asm/unistd.h>
7 #include <sys/auxv.h>
9 #define ASM_INPUT_0 "0" (r0)
11 #define INTERNAL_SYSCALL_SCV(name, nr) \
12 ({ \
13 register long int r0 __asm__ ("r0"); \
14 register long int r3 __asm__ ("r3"); \
15 register long int r4 __asm__ ("r4"); \
16 register long int r5 __asm__ ("r5"); \
17 register long int r6 __asm__ ("r6"); \
18 register long int r7 __asm__ ("r7"); \
19 register long int r8 __asm__ ("r8"); \
20 r0=name; \
21 __asm__ __volatile__ \
22 (".machine power9\n" \
23 "scv 0\n\t" \
24 "0:" \
25 : "=&r" (r0), \
26 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
27 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
28 : ASM_INPUT_##nr \
29 : "r9", "r10", "r11", "r12", \
30 "cr0", "cr1", "cr5", "cr6", "cr7", "xer", \
31 "lr", "ctr", "memory"); \
32 r3; \
35 #define INTERNAL_SYSCALL_SC(name, nr) \
36 ({ \
37 register long int r0 __asm__ ("r0"); \
38 register long int r3 __asm__ ("r3"); \
39 register long int r4 __asm__ ("r4"); \
40 register long int r5 __asm__ ("r5"); \
41 register long int r6 __asm__ ("r6"); \
42 register long int r7 __asm__ ("r7"); \
43 register long int r8 __asm__ ("r8"); \
44 r0=name; \
45 __asm__ __volatile__ \
46 ("sc\n\t" \
47 "mfcr %0\n\t" \
48 "0:" \
49 : "=&r" (r0), \
50 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
51 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
52 : ASM_INPUT_##nr \
53 : "r9", "r10", "r11", "r12", \
54 "xer", "cr0", "ctr", "memory"); \
55 r0 & (1 << 28) ? -r3 : r3; \
58 #define PPC_FEATURE2_SCV 0x00100000 /* scv syscall enabled */
60 #endif
62 int
63 main(void)
66 #ifdef HAS_ISA_3_00
67 int result;
68 unsigned long hwcaps2_val;
70 result = INTERNAL_SYSCALL_SC(__NR_gettid, 0);
72 if (result < 0) {
73 printf("The sc instruction test unexpectedly failed\n");
74 exit (-1);
77 hwcaps2_val = getauxval(AT_HWCAP2);
79 if ((hwcaps2_val & PPC_FEATURE2_SCV) == PPC_FEATURE2_SCV) {
80 /* system supports the scv instruction */
81 result = INTERNAL_SYSCALL_SCV(__NR_gettid, 0);
83 if (result < 0) {
84 printf("The scv instruction test unexpectedly failed\n");
85 exit (-1);
89 printf("Success\n");
90 #else
91 printf("HAS_ISA_3_00 not detected.\n");
92 #endif
93 return 0;