mkcapflags.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. IN=$1
  8. OUT=$2
  9. dump_array()
  10. {
  11. ARRAY=$1
  12. SIZE=$2
  13. PFX=$3
  14. POSTFIX=$4
  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_" ""
  49. echo ""
  50. dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32"
  51. ) > $OUT
  52. trap - EXIT