gen_facilities.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #define S390_GEN_FACILITIES_C
  10. #include <strings.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <asm/facilities_src.h>
  15. static void print_facility_list(struct facility_def *def)
  16. {
  17. unsigned int high, bit, dword, i;
  18. unsigned long long *array;
  19. array = calloc(1, 8);
  20. if (!array)
  21. exit(EXIT_FAILURE);
  22. high = 0;
  23. for (i = 0; def->bits[i] != -1; i++) {
  24. bit = 63 - (def->bits[i] & 63);
  25. dword = def->bits[i] / 64;
  26. if (dword > high) {
  27. array = realloc(array, (dword + 1) * 8);
  28. if (!array)
  29. exit(EXIT_FAILURE);
  30. memset(array + high + 1, 0, (dword - high) * 8);
  31. high = dword;
  32. }
  33. array[dword] |= 1ULL << bit;
  34. }
  35. printf("#define %s ", def->name);
  36. for (i = 0; i <= high; i++)
  37. printf("_AC(0x%016llx,UL)%c", array[i], i < high ? ',' : '\n');
  38. free(array);
  39. }
  40. static void print_facility_lists(void)
  41. {
  42. unsigned int i;
  43. for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
  44. print_facility_list(&facility_defs[i]);
  45. }
  46. int main(int argc, char **argv)
  47. {
  48. printf("#ifndef __ASM_S390_FACILITIES__\n");
  49. printf("#define __ASM_S390_FACILITIES__\n");
  50. printf("/*\n");
  51. printf(" * DO NOT MODIFY.\n");
  52. printf(" *\n");
  53. printf(" * This file was generated by %s\n", __FILE__);
  54. printf(" */\n\n");
  55. printf("#include <linux/const.h>\n\n");
  56. print_facility_lists();
  57. printf("\n#endif\n");
  58. return 0;
  59. }