mkcapflags.sh 1.5 KB

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