mkcapflags.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. [ ! "$VALUE" ] && continue
  27. # Name is uppercase, VALUE is all lowercase
  28. VALUE="$(echo "$VALUE" | tr A-Z a-z)"
  29. if [ -n "$POSTFIX" ]; then
  30. T=$(( $PFX_SZ + $(echo $POSTFIX | wc -c) + 2 ))
  31. TABS="$(printf '\t\t\t\t\t\t')"
  32. TABCOUNT=$(( ( 6*8 - ($T + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
  33. printf "\t[%s - %s]%.*s = %s,\n" "$PFX$NAME" "$POSTFIX" "$TABCOUNT" "$TABS" "$VALUE"
  34. else
  35. TABCOUNT=$(( ( 5*8 - ($PFX_SZ + 1) - $(echo "$NAME" | wc -c) ) / 8 ))
  36. printf "\t[%s]%.*s = %s,\n" "$PFX$NAME" "$TABCOUNT" "$TABS" "$VALUE"
  37. fi
  38. done
  39. echo "};"
  40. }
  41. trap 'rm "$OUT"' EXIT
  42. (
  43. echo "#ifndef _ASM_X86_CPUFEATURES_H"
  44. echo "#include <asm/cpufeatures.h>"
  45. echo "#endif"
  46. echo ""
  47. dump_array "x86_cap_flags" "NCAPINTS*32" "X86_FEATURE_" "" $2
  48. echo ""
  49. dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2
  50. echo ""
  51. echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES"
  52. echo "#ifndef _ASM_X86_VMXFEATURES_H"
  53. echo "#include <asm/vmxfeatures.h>"
  54. echo "#endif"
  55. dump_array "x86_vmx_flags" "NVMXINTS*32" "VMX_FEATURE_" "" $3
  56. echo "#endif /* CONFIG_X86_VMX_FEATURE_NAMES */"
  57. ) > $OUT
  58. trap - EXIT