2013-04-29 22:05:53 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2016-01-26 21:12:04 +00:00
|
|
|
# Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
|
2013-04-29 22:05:53 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
IN=$1
|
|
|
|
OUT=$2
|
|
|
|
|
2014-12-29 15:43:24 +00:00
|
|
|
dump_array()
|
2014-06-24 11:25:03 +00:00
|
|
|
{
|
|
|
|
ARRAY=$1
|
|
|
|
SIZE=$2
|
|
|
|
PFX=$3
|
|
|
|
POSTFIX=$4
|
2013-04-29 22:05:53 +00:00
|
|
|
|
2014-06-24 11:25:03 +00:00
|
|
|
PFX_SZ=$(echo $PFX | wc -c)
|
|
|
|
TABS="$(printf '\t\t\t\t\t')"
|
|
|
|
|
|
|
|
echo "const char * const $ARRAY[$SIZE] = {"
|
2013-04-29 22:05:53 +00:00
|
|
|
|
2014-06-24 11:25:03 +00:00
|
|
|
# Iterate through any input lines starting with #define $PFX
|
|
|
|
sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
|
2013-04-29 22:05:53 +00:00
|
|
|
while read i
|
|
|
|
do
|
|
|
|
# Name is everything up to the first whitespace
|
|
|
|
NAME="$(echo "$i" | sed 's/ .*//')"
|
|
|
|
|
|
|
|
# If the /* comment */ starts with a quote string, grab that.
|
|
|
|
VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
|
|
|
|
[ -z "$VALUE" ] && VALUE="\"$NAME\""
|
2014-12-23 12:39:12 +00:00
|
|
|
[ "$VALUE" = '""' ] && continue
|
2013-04-29 22:05:53 +00:00
|
|
|
|
|
|
|
# Name is uppercase, VALUE is all lowercase
|
|
|
|
VALUE="$(echo "$VALUE" | tr A-Z a-z)"
|
|
|
|
|
2014-06-24 11:25:03 +00:00
|
|
|
if [ -n "$POSTFIX" ]; then
|
|
|
|
T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
|
|
|
|
TABS="$(printf '\t\t\t\t\t\t')"
|
|
|
|
TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
|
|
|
|
printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
|
|
|
|
else
|
|
|
|
TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
|
|
|
|
printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
|
|
|
|
fi
|
2013-04-29 22:05:53 +00:00
|
|
|
done
|
|
|
|
echo "};"
|
2014-06-24 11:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trap 'rm "$OUT"' EXIT
|
|
|
|
|
|
|
|
(
|
2016-01-26 21:12:04 +00:00
|
|
|
echo "#ifndef _ASM_X86_CPUFEATURES_H"
|
|
|
|
echo "#include <asm/cpufeatures.h>"
|
2014-06-24 11:25:03 +00:00
|
|
|
echo "#endif"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" ""
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32"
|
|
|
|
|
2013-04-29 22:05:53 +00:00
|
|
|
) > $OUT
|
|
|
|
|
|
|
|
trap - EXIT
|