xref: /linux/arch/arm64/tools/gen-cpucaps.awk (revision 0c6c2d3615efb7c292573f2e6c886929a2b2da6c)
1*0c6c2d36SMark Brown#!/bin/awk -f
2*0c6c2d36SMark Brown# SPDX-License-Identifier: GPL-2.0
3*0c6c2d36SMark Brown# gen-cpucaps.awk: arm64 cpucaps header generator
4*0c6c2d36SMark Brown#
5*0c6c2d36SMark Brown# Usage: awk -f gen-cpucaps.awk cpucaps.txt
6*0c6c2d36SMark Brown
7*0c6c2d36SMark Brown# Log an error and terminate
8*0c6c2d36SMark Brownfunction fatal(msg) {
9*0c6c2d36SMark Brown	print "Error at line " NR ": " msg > "/dev/stderr"
10*0c6c2d36SMark Brown	exit 1
11*0c6c2d36SMark Brown}
12*0c6c2d36SMark Brown
13*0c6c2d36SMark Brown# skip blank lines and comment lines
14*0c6c2d36SMark Brown/^$/ { next }
15*0c6c2d36SMark Brown/^#/ { next }
16*0c6c2d36SMark Brown
17*0c6c2d36SMark BrownBEGIN {
18*0c6c2d36SMark Brown	print "#ifndef __ASM_CPUCAPS_H"
19*0c6c2d36SMark Brown	print "#define __ASM_CPUCAPS_H"
20*0c6c2d36SMark Brown	print ""
21*0c6c2d36SMark Brown	print "/* Generated file - do not edit */"
22*0c6c2d36SMark Brown	cap_num = 0
23*0c6c2d36SMark Brown	print ""
24*0c6c2d36SMark Brown}
25*0c6c2d36SMark Brown
26*0c6c2d36SMark Brown/^[vA-Z0-9_]+$/ {
27*0c6c2d36SMark Brown	printf("#define ARM64_%-30s\t%d\n", $0, cap_num++)
28*0c6c2d36SMark Brown	next
29*0c6c2d36SMark Brown}
30*0c6c2d36SMark Brown
31*0c6c2d36SMark BrownEND {
32*0c6c2d36SMark Brown	printf("#define ARM64_NCAPS\t\t\t\t%d\n", cap_num)
33*0c6c2d36SMark Brown	print ""
34*0c6c2d36SMark Brown	print "#endif"
35*0c6c2d36SMark Brown}
36*0c6c2d36SMark Brown
37*0c6c2d36SMark Brown# Any lines not handled by previous rules are unexpected
38*0c6c2d36SMark Brown{
39*0c6c2d36SMark Brown	fatal("unhandled statement")
40*0c6c2d36SMark Brown}
41