gen_facilities.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Simple program to generate defines out of facility lists that use the bit
  3. * numbering scheme from the Princples of Operations: most significant bit
  4. * has bit number 0.
  5. *
  6. * Copyright IBM Corp. 2015
  7. *
  8. */
  9. #include <strings.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. struct facility_def {
  14. char *name;
  15. int *bits;
  16. };
  17. static struct facility_def facility_defs[] = {
  18. {
  19. /*
  20. * FACILITIES_ALS contains the list of facilities that are
  21. * required to run a kernel that is compiled e.g. with
  22. * -march=<machine>.
  23. */
  24. .name = "FACILITIES_ALS",
  25. .bits = (int[]){
  26. #ifdef CONFIG_HAVE_MARCH_Z900_FEATURES
  27. 0, /* N3 instructions */
  28. 1, /* z/Arch mode installed */
  29. #endif
  30. #ifdef CONFIG_HAVE_MARCH_Z990_FEATURES
  31. 18, /* long displacement facility */
  32. #endif
  33. #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
  34. 7, /* stfle */
  35. 17, /* message security assist */
  36. 21, /* extended-immediate facility */
  37. 25, /* store clock fast */
  38. #endif
  39. #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
  40. 27, /* mvcos */
  41. 32, /* compare and swap and store */
  42. 33, /* compare and swap and store 2 */
  43. 34, /* general extension facility */
  44. 35, /* execute extensions */
  45. #endif
  46. #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
  47. 45, /* fast-BCR, etc. */
  48. #endif
  49. #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
  50. 49, /* misc-instruction-extensions */
  51. 52, /* interlocked facility 2 */
  52. #endif
  53. #ifdef CONFIG_HAVE_MARCH_Z13_FEATURES
  54. 53, /* load-and-zero-rightmost-byte, etc. */
  55. #endif
  56. -1 /* END */
  57. }
  58. },
  59. {
  60. .name = "FACILITIES_KVM",
  61. .bits = (int[]){
  62. 0, /* N3 instructions */
  63. 1, /* z/Arch mode installed */
  64. 2, /* z/Arch mode active */
  65. 3, /* DAT-enhancement */
  66. 4, /* idte segment table */
  67. 5, /* idte region table */
  68. 6, /* ASN-and-LX reuse */
  69. 7, /* stfle */
  70. 8, /* enhanced-DAT 1 */
  71. 9, /* sense-running-status */
  72. 10, /* conditional sske */
  73. 13, /* ipte-range */
  74. 14, /* nonquiescing key-setting */
  75. 73, /* transactional execution */
  76. 75, /* access-exception-fetch/store indication */
  77. 76, /* msa extension 3 */
  78. 77, /* msa extension 4 */
  79. 78, /* enhanced-DAT 2 */
  80. -1 /* END */
  81. }
  82. },
  83. };
  84. static void print_facility_list(struct facility_def *def)
  85. {
  86. unsigned int high, bit, dword, i;
  87. unsigned long long *array;
  88. array = calloc(1, 8);
  89. if (!array)
  90. exit(EXIT_FAILURE);
  91. high = 0;
  92. for (i = 0; def->bits[i] != -1; i++) {
  93. bit = 63 - (def->bits[i] & 63);
  94. dword = def->bits[i] / 64;
  95. if (dword > high) {
  96. array = realloc(array, (dword + 1) * 8);
  97. if (!array)
  98. exit(EXIT_FAILURE);
  99. memset(array + high + 1, 0, (dword - high) * 8);
  100. high = dword;
  101. }
  102. array[dword] |= 1ULL << bit;
  103. }
  104. printf("#define %s ", def->name);
  105. for (i = 0; i <= high; i++)
  106. printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
  107. free(array);
  108. }
  109. static void print_facility_lists(void)
  110. {
  111. unsigned int i;
  112. for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
  113. print_facility_list(&facility_defs[i]);
  114. }
  115. int main(int argc, char **argv)
  116. {
  117. printf("#ifndef __ASM_S390_FACILITIES__\n");
  118. printf("#define __ASM_S390_FACILITIES__\n");
  119. printf("/*\n");
  120. printf(" * DO NOT MODIFY.\n");
  121. printf(" *\n");
  122. printf(" * This file was generated by %s\n", __FILE__);
  123. printf(" */\n\n");
  124. printf("#include <linux/const.h>\n\n");
  125. print_facility_lists();
  126. printf("\n#endif\n");
  127. return 0;
  128. }