mkcapflags.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
  5. #
  6. set -e
  7. OUT=$1
  8. dump_array()
  9. {
  10. ARRAY=$1
  11. SIZE=$2
  12. PFX=$3
  13. POSTFIX=$4
  14. IN=$5
  15. PFX_SZ=$(echo $PFX | wc -c)
  16. TABS="$(printf '\t\t\t\t\t')"
  17. echo "const char * const $ARRAY[$SIZE] = {"
  18. # Iterate through any input lines starting with #define $PFX
  19. sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
  20. while read i
  21. do
  22. # Name is everything up to the first whitespace
  23. NAME="$(echo "$i" | sed 's/ .*//')"
  24. # If the /* comment */ starts with a quote string, grab that.
  25. VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
  26. [ -z "$VALUE" ] && VALUE="\"$NAME\""
  27. [ "$VALUE" = '""' ] && continue
  28. # Name is uppercase, VALUE is all lowercase
  29. VALUE="$(echo "$VALUE" | tr A-Z a-z)"
  30. if [ -n "$POSTFIX" ]; then
  31. T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
  32. TABS="$(printf '\t\t\t\t\t\t')"
  33. TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
  34. printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
  35. else
  36. TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
  37. printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
  38. fi
  39. done
  40. echo "};"
  41. }
  42. trap 'rm "$OUT"' EXIT
  43. (
  44. echo "#ifndef _ASM_X86_CPUFEATURES_H"
  45. echo "#include <asm/cpufeatures.h>"
  46. echo "#endif"
  47. echo ""
  48. dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" $2
  49. echo ""
  50. dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2
  51. echo ""
  52. echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES"
  53. echo "#ifndef _ASM_X86_VMXFEATURES_H"
  54. echo "#include <asm/vmxfeatures.h>"
  55. echo "#endif"
  56. dump_array "x86_vmx_flags" "NVMXINTS*32" "VMX_FEATURE_" "" $3
  57. echo "#endif /* CONFIG_X86_VMX_FEATURE_NAMES */"
  58. ) > $OUT
  59. trap - EXIT