1#include <stdio.h>
2
3/* Number of double words needed to store all facility bits. */
4#define S390_NUM_FACILITY_DW 2
5
6
7unsigned long long stfle(unsigned long dw, unsigned bit_to_test)
8{
9  unsigned long long hoststfle[S390_NUM_FACILITY_DW], match;
10  register unsigned long long __nr asm("0") = dw - 1;
11  int cc;
12
13  asm volatile(" .insn s,0xb2b00000,%0 \n" /* stfle */
14               "ipm %2\n"
15               "srl %2,28\n"
16               : "=m" (*hoststfle), "+d" (__nr), "=d" (cc) : : "cc", "memory");
17
18  printf("the value of cc is %d and #double words is %llu\n", cc, __nr + 1);
19  if (bit_to_test < 64)
20    match = (hoststfle[0] & (1ULL << (63 - bit_to_test)));
21  else if (bit_to_test < 128)
22    match = (hoststfle[1] & (1ULL << (63 - bit_to_test)));
23  else
24    printf("code needs to be updated\n");
25
26  return match;
27}
28
29int main()
30{
31  int dw = S390_NUM_FACILITY_DW;
32
33  /* Test #1: Make sure STFLE returns sensible values. z/Arch facilities
34              must be present. */
35  if ((stfle(dw, 1)) && stfle(dw, 2))
36    printf("The z/Architecture architectural mode is installed and active\n");
37  else
38    printf("The z/Architecture architectural mode is not installed\n");
39
40  /* Test #2: Make sure the STFLE is supported. */
41  if (stfle(dw, 7))
42    printf("STFLE facility is installed\n");
43  else
44    printf("STFLE facility is not installed\n");
45
46  /* Test #3: Tell STFLE to only write 1 DW of facility bits. Expected condition
47              code should be 3 because this test is run on those machines only
48              that need 2 do double words to store facility bits. */
49  dw = 1;
50  if ((stfle(dw, 1)) && stfle(dw, 2))
51    printf("The z/Architecture architectural mode is installed and active\n");
52  else
53    printf("The z/Architecture architectural mode is not installed\n");
54
55  return 0;
56}
57