blob: e2660d27889b6da2a988b34d4bf8752a7da1e35d [file] [log] [blame]
Heiko Carstensc30f6822015-02-02 07:08:44 +01001/*
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
18static 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 printf("#define %s_DWORDS %d\n", def->name, high + 1);
43 free(array);
44}
45
46static void print_facility_lists(void)
47{
48 unsigned int i;
49
50 for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
51 print_facility_list(&facility_defs[i]);
52}
53
54int main(int argc, char **argv)
55{
56 printf("#ifndef __ASM_S390_FACILITIES__\n");
57 printf("#define __ASM_S390_FACILITIES__\n");
58 printf("/*\n");
59 printf(" * DO NOT MODIFY.\n");
60 printf(" *\n");
61 printf(" * This file was generated by %s\n", __FILE__);
62 printf(" */\n\n");
63 printf("#include <linux/const.h>\n\n");
64 print_facility_lists();
65 printf("\n#endif\n");
66 return 0;
67}