1#!/usr/bin/awk 2# 3# Convert cpufeatures.h to a list of compile-time masks 4# Note: this blithely assumes that each word has at least one 5# feature defined in it; if not, something else is wrong! 6# 7 8BEGIN { 9 printf "#ifndef _ASM_X86_CPUFEATUREMASKS_H\n"; 10 printf "#define _ASM_X86_CPUFEATUREMASKS_H\n\n"; 11 12 file = 0 13} 14 15FNR == 1 { 16 ++file; 17 18 # arch/x86/include/asm/cpufeatures.h 19 if (file == 1) 20 FS = "[ \t()*+]+"; 21 22 # .config 23 if (file == 2) 24 FS = "="; 25} 26 27# Create a dictionary of sorts, containing all defined feature bits 28file == 1 && $1 ~ /^#define$/ && $2 ~ /^X86_FEATURE_/ { 29 nfeat = $3 * $4 + $5; 30 feat = $2; 31 sub(/^X86_FEATURE_/, "", feat); 32 feats[nfeat] = feat; 33} 34file == 1 && $1 ~ /^#define$/ && $2 == "NCAPINTS" { 35 ncapints = int($3); 36} 37 38# Create a dictionary featstat[REQUIRED|DISABLED, FEATURE_NAME] = on | off 39file == 2 && $1 ~ /^CONFIG_X86_(REQUIRED|DISABLED)_FEATURE_/ { 40 on = ($2 == "y"); 41 if (split($1, fs, "CONFIG_X86_|_FEATURE_") == 3) 42 featstat[fs[2], fs[3]] = on; 43} 44 45END { 46 sets[1] = "REQUIRED"; 47 sets[2] = "DISABLED"; 48 49 for (ns in sets) { 50 s = sets[ns]; 51 52 printf "/*\n"; 53 printf " * %s features:\n", s; 54 printf " *\n"; 55 fstr = ""; 56 for (i = 0; i < ncapints; i++) { 57 mask = 0; 58 for (j = 0; j < 32; j++) { 59 feat = feats[i*32 + j]; 60 if (featstat[s, feat]) { 61 nfstr = fstr " " feat; 62 if (length(nfstr) > 72) { 63 printf " * %s\n", fstr; 64 nfstr = " " feat; 65 } 66 fstr = nfstr; 67 mask += (2 ^ j); 68 } 69 } 70 masks[i] = mask; 71 } 72 printf " * %s\n */\n", fstr; 73 74 for (i = 0; i < ncapints; i++) 75 printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i]; 76 77 printf "\n#define %s_MASK_BIT_SET(x)\t\t\t\\\n", s; 78 printf "\t((\t\t\t\t\t"; 79 for (i = 0; i < ncapints; i++) { 80 if (masks[i]) 81 printf "\t\\\n\t\t((x) >> 5) == %2d ? %s_MASK%d :", i, s, i; 82 } 83 printf " 0\t\\\n"; 84 printf "\t) & (1U << ((x) & 31)))\n\n"; 85 } 86 87 printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n"; 88} 89