Linux 4.8-rc8
[linux/fpc-iii.git] / arch / s390 / tools / gen_facilities.c
blobfe4e6c910dd727b1c2ff81e701bfa8a7c1580d03
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.
6 * Copyright IBM Corp. 2015
8 */
10 #define S390_GEN_FACILITIES_C
12 #include <strings.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <asm/facilities_src.h>
18 static void print_facility_list(struct facility_def *def)
20 unsigned int high, bit, dword, i;
21 unsigned long long *array;
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;
37 array[dword] |= 1ULL << bit;
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);
45 static void print_facility_lists(void)
47 unsigned int i;
49 for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
50 print_facility_list(&facility_defs[i]);
53 int main(int argc, char **argv)
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;