xref: /linux/arch/x86/kernel/cpu/mkcapflags.sh (revision cd4d09ec6f6c12a2cc3db5b7d8876a325a53545b)
10c0de199SRob Landley#!/bin/sh
20c0de199SRob Landley#
3*cd4d09ecSBorislav Petkov# Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
40c0de199SRob Landley#
50c0de199SRob Landley
60c0de199SRob LandleyIN=$1
70c0de199SRob LandleyOUT=$2
80c0de199SRob Landley
9e85bd989SSylvain BERTRANDdump_array()
1080a208bdSBorislav Petkov{
1180a208bdSBorislav Petkov	ARRAY=$1
1280a208bdSBorislav Petkov	SIZE=$2
1380a208bdSBorislav Petkov	PFX=$3
1480a208bdSBorislav Petkov	POSTFIX=$4
1580a208bdSBorislav Petkov
1680a208bdSBorislav Petkov	PFX_SZ=$(echo $PFX | wc -c)
170c0de199SRob Landley	TABS="$(printf '\t\t\t\t\t')"
180c0de199SRob Landley
1980a208bdSBorislav Petkov	echo "const char * const $ARRAY[$SIZE] = {"
200c0de199SRob Landley
2180a208bdSBorislav Petkov	# Iterate through any input lines starting with #define $PFX
2280a208bdSBorislav Petkov	sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
230c0de199SRob Landley	while read i
240c0de199SRob Landley	do
250c0de199SRob Landley		# Name is everything up to the first whitespace
260c0de199SRob Landley		NAME="$(echo "$i" | sed 's/ .*//')"
270c0de199SRob Landley
280c0de199SRob Landley		# If the /* comment */ starts with a quote string, grab that.
290c0de199SRob Landley		VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
300c0de199SRob Landley		[ -z "$VALUE" ] && VALUE="\"$NAME\""
31ea174f4cSSylvain BERTRAND		[ "$VALUE" = '""' ] && continue
320c0de199SRob Landley
330c0de199SRob Landley		# Name is uppercase, VALUE is all lowercase
340c0de199SRob Landley		VALUE="$(echo "$VALUE" | tr A-Z a-z)"
350c0de199SRob Landley
3680a208bdSBorislav Petkov        if [ -n "$POSTFIX" ]; then
3780a208bdSBorislav Petkov            T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
3880a208bdSBorislav Petkov	        TABS="$(printf '\t\t\t\t\t\t')"
3980a208bdSBorislav Petkov		    TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
4080a208bdSBorislav Petkov		    printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
4180a208bdSBorislav Petkov        else
4280a208bdSBorislav Petkov		    TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
4380a208bdSBorislav Petkov            printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
4480a208bdSBorislav Petkov        fi
450c0de199SRob Landley	done
460c0de199SRob Landley	echo "};"
4780a208bdSBorislav Petkov}
4880a208bdSBorislav Petkov
4980a208bdSBorislav Petkovtrap 'rm "$OUT"' EXIT
5080a208bdSBorislav Petkov
5180a208bdSBorislav Petkov(
52*cd4d09ecSBorislav Petkov	echo "#ifndef _ASM_X86_CPUFEATURES_H"
53*cd4d09ecSBorislav Petkov	echo "#include <asm/cpufeatures.h>"
5480a208bdSBorislav Petkov	echo "#endif"
5580a208bdSBorislav Petkov	echo ""
5680a208bdSBorislav Petkov
5780a208bdSBorislav Petkov	dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" ""
5880a208bdSBorislav Petkov	echo ""
5980a208bdSBorislav Petkov
6080a208bdSBorislav Petkov	dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32"
6180a208bdSBorislav Petkov
620c0de199SRob Landley) > $OUT
630c0de199SRob Landley
640c0de199SRob Landleytrap - EXIT
65