8 typedef enum exit_codes_
{
10 #if defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le)
11 /* If the insn that got queried for: exists */
12 POWER_INSN_AVAILABLE
= 0,
13 /* If the insn that got queried for: does not exist on this platform */
14 POWER_INSN_UNAVAILABLE
= 1,
15 /* If the insn that got queried for: does not exist in the vocabulary of this program */
16 POWER_INSN_UNRECOGNIZED
= 2,
18 /* Note: Please keep USAGE_ERROR last. */
21 /* When not on a POWER system: */
27 #if defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le)
28 /* Signal Handling support for unsupported instructions. */
29 static jmp_buf unsup_insn_env
;
30 static void unsup_insn_handler(int signal_number
)
32 if (signal_number
== SIGILL
)
33 longjmp(unsup_insn_env
, 1);
36 static struct sigaction unsup_insn_action
= (struct sigaction
) {
37 .sa_handler
= &unsup_insn_handler
,
40 /* Instruction existence tests. */
41 static bool dcbzl_available(void)
43 #define MAX_DCBZL_SZB (128) /* largest known effect of dcbzl */
44 char *test_block
= NULL
;
45 register char *rb
asm ("r14");
47 bool dcbzl_exists
= false;
49 err
= posix_memalign ((void **)&test_block
, MAX_DCBZL_SZB
, 4 * MAX_DCBZL_SZB
);
51 fprintf(stderr
, "posix_memalign() failed (err = %d [%s])\n", err
, strerror(err
));
57 if (setjmp(unsup_insn_env
) != 0)
60 sigaction(SIGILL
, &unsup_insn_action
, NULL
);
61 asm volatile ("dcbzl 0, %[RB]" : : [RB
] "r" (rb
));
71 int main(int argc
, char **argv
)
75 #if defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le)
78 fprintf(stderr
, "usage: power_insn_available <insn>\n" );
83 if (strcmp (insn
, "dcbzl") == 0)
84 status
= ((dcbzl_available ()) ? POWER_INSN_AVAILABLE
: POWER_INSN_UNAVAILABLE
);
86 /* power_insn_available has not been taught anything about this insn yet. */
87 status
= POWER_INSN_UNRECOGNIZED
;
89 status
= NOT_POWER_ARCH
;