summaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/mkcapflags.pl
blob: c7b3fe2d72e0f71b94577fde23622a8797eca941 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w
#
# Generate the x86_cap_flags[] array from include/asm-x86/cpufeature.h
#

($in, $out) = @ARGV;

open(IN, "< $in\0")   or die "$0: cannot open: $in: $!\n";
open(OUT, "> $out\0") or die "$0: cannot create: $out: $!\n";

print OUT "#include <asm/cpufeature.h>\n\n";
print OUT "const char * const x86_cap_flags[NCAPINTS*32] = {\n";

%features = ();
$err = 0;

while (defined($line = <IN>)) {
	if ($line =~ /^\s*\#\s*define\s+(X86_FEATURE_(\S+))\s+(.*)$/) {
		$macro = $1;
		$feature = "\L$2";
		$tail = $3;
		if ($tail =~ /\/\*\s*\"([^"]*)\".*\*\//) {
			$feature = "\L$1";
		}

		next if ($feature eq '');

		if ($features{$feature}++) {
			print STDERR "$in: duplicate feature name: $feature\n";
			$err++;
		}
		printf OUT "\t%-32s = \"%s\",\n", "[$macro]", $feature;
	}
}
print OUT "};\n";

close(IN);
close(OUT);

if ($err) {
	unlink($out);
	exit(1);
}

exit(0);