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