Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
0005 #
0006 
0007 set -e
0008 
0009 OUT=$1
0010 
0011 dump_array()
0012 {
0013         ARRAY=$1
0014         SIZE=$2
0015         PFX=$3
0016         POSTFIX=$4
0017         IN=$5
0018 
0019         PFX_SZ=$(echo $PFX | wc -c)
0020         TABS="$(printf '\t\t\t\t\t')"
0021 
0022         echo "const char * const $ARRAY[$SIZE] = {"
0023 
0024         # Iterate through any input lines starting with #define $PFX
0025         sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
0026         while read i
0027         do
0028                 # Name is everything up to the first whitespace
0029                 NAME="$(echo "$i" | sed 's/ .*//')"
0030 
0031                 # If the /* comment */ starts with a quote string, grab that.
0032                 VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
0033                 [ -z "$VALUE" ] && VALUE="\"$NAME\""
0034                 [ "$VALUE" = '""' ] && continue
0035 
0036                 # Name is uppercase, VALUE is all lowercase
0037                 VALUE="$(echo "$VALUE" | tr A-Z a-z)"
0038 
0039         if [ -n "$POSTFIX" ]; then
0040             T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
0041                 TABS="$(printf '\t\t\t\t\t\t')"
0042                     TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
0043                     printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
0044         else
0045                     TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
0046             printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
0047         fi
0048         done
0049         echo "};"
0050 }
0051 
0052 trap 'rm "$OUT"' EXIT
0053 
0054 (
0055         echo "#ifndef _ASM_X86_CPUFEATURES_H"
0056         echo "#include <asm/cpufeatures.h>"
0057         echo "#endif"
0058         echo ""
0059 
0060         dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" $2
0061         echo ""
0062 
0063         dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2
0064         echo ""
0065 
0066         echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES"
0067         echo "#ifndef _ASM_X86_VMXFEATURES_H"
0068         echo "#include <asm/vmxfeatures.h>"
0069         echo "#endif"
0070         dump_array "x86_vmx_flags" "NVMXINTS*32" "VMX_FEATURE_" "" $3
0071         echo "#endif /* CONFIG_X86_VMX_FEATURE_NAMES */"
0072 ) > $OUT
0073 
0074 trap - EXIT