public
Last active

  • Download Gist
cpu-feature-array.sed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# usage: sed -i -f cpu-feature-array.sed $(git grep -E -l -- '->cpuid_|CPUX86State')
 
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*ext_features\([^\[]\|$\)/\1features[FEAT_1_ECX]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*ext2_features\([^\[]\|$\)/\1features[FEAT_8000_0001_EDX]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*ext3_features\([^\[]\|$\)/\1features[FEAT_8000_0001_ECX]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*ext4_features\([^\[]\|$\)/\1features[FEAT_C000_0001_EDX]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*kvm_features\([^\[]\|$\)/\1features[FEAT_KVM]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*svm_features\([^\[]\|$\)/\1features[FEAT_SVM]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*7_0_ebx_features\([^\[]\|$\)/\1features[FEAT_7_0_EBX]\3/g
s/\(env->\|env\.\|cpu->\|def->\|def\.\|^ *\.\)\(cpuid_\)*features\([^\[]\|$\)/\1features[FEAT_1_EDX]\3/g
 
 
# changes to the structs:
 
# cpu.c struct:
 
/^ uint32_t cpuid_features;$/{
i \
FeatureWordArray features;
d
}
 
 
# cpu.h struct:
/^ uint32_t features, ext_features, ext2_features, ext3_features;$/{
i \
FeatureWordArray features;
d
}
 
# lines that are being replaced:
/^ uint32_t cpuid.*features;$/d
/^ \/\* Flags from CPUID\[EAX=7,ECX=0\].EBX \*\/$/d
/^ uint32_t kvm_features, svm_features;$/d
/^ \/\* Store the results of Centaur's CPUID instructions \*\/$/d
/^ uint32_t ext4_features;$/d
/^ \/\* The feature bits on CPUID\[EAX=7,ECX=0\].EBX \*\/$/d
/^ uint32_t cpuid_7_0_ebx_features;$/d

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.