#!/usr/bin/python3 import re import sys import subprocess def bits(val, bottom, top): mask = (1 << (top + 1 - bottom)) - 1 mask = mask << bottom return (val & mask) >> bottom def family(sig): if bits(sig, 8, 11) == 0xf: return bits(sig, 8, 11) + bits(sig, 20, 27) return bits(sig, 8, 11) def model(sig): return bits(sig, 4, 7) | (bits(sig, 16, 19)<<4) def step(sig): return bits(sig, 0, 3) cmd = ['iucode-tool', '--list-all' ] for arg in sys.argv[1:]: cmd = cmd + [ arg ] siglist = [] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) for line in process.stdout: ##print(line) if line.find(" sig ") == -1: continue sig = re.search('sig (0x[0-9a-fA-F]+)', line).group(1) rev = re.search('rev (0x[0-9a-fA-F]+)', line).group(1) sig = int(sig, 16) rev = int(rev, 16) debug_rev = bits(rev, 31, 31) if debug_rev != 0: #print("ERROR: debug ucode file found, exiting") sys.exit(1); sigrev = {} sigrev['sig'] = sig sigrev['rev'] = rev siglist = siglist + [ sigrev ] sigdict = {} for sr in siglist: existing = sigdict.get(sr['sig']) if existing != None: # If the existing one is newer, just move on: if existing['rev'] > sr['rev']: #print("collision %s %s => %s" % (sr['sig'], sr['rev'], existing['rev'])) continue sigdict[sr['sig']] = sr for sig in sigdict: rev = sigdict[sig] print("{ .flags = X86_CPU_ID_FLAG_ENTRY_VALID, .vendor = X86_VENDOR_INTEL, .family = 0x%x, .model = 0x%02x, .steppings = 0x%04x, .driver_data = 0x%x }," % (family(sig), model(sig), 1<