mkcapflags.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. IN=$1
  7. OUT=$2
  8. dump_array()
  9. {
  10. ARRAY=$1
  11. SIZE=$2
  12. PFX=$3
  13. POSTFIX=$4
  14. PFX_SZ=$(echo $PFX | wc -c)
  15. TABS="$(printf '\t\t\t\t\t')"
  16. echo "const char * const $ARRAY[$SIZE] = {"
  17. # Iterate through any input lines starting with #define $PFX
  18. sed -n -e 's/\t/ /g' -e "s/^ *# *define *$PFX//p" $IN |
  19. while read i
  20. do
  21. # Name is everything up to the first whitespace
  22. NAME="$(echo "$i" | sed 's/ .*//')"
  23. # If the /* comment */ starts with a quote string, grab that.
  24. VALUE="$(echo "$i" | sed -n 's@.*/\* *\("[^"]*"\).*\*/@\1@p')"
  25. [ -z "$VALUE" ] && VALUE="\"$NAME\""
  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_" ""
  48. echo ""
  49. dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32"
  50. ) > $OUT
  51. trap - EXIT