Skip to content

Instantly share code, notes, and snippets.

@ehabkost
Last active October 13, 2015 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehabkost/4271991 to your computer and use it in GitHub Desktop.
Save ehabkost/4271991 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment