1#!/usr/bin/env python 2 3from __future__ import print_function 4 5import argparse 6import sys 7import re 8 9 10parser = argparse.ArgumentParser(description='x86 CPUID dump parser') 11parser.add_argument("input", metavar="INPUT", nargs=1, 12 help="Path to CPUID dump log") 13 14 15def main(args): 16 options = parser.parse_args(args) 17 18 cpuid_dump = list() 19 for line in open(options.input[0]).read().splitlines(): 20 match = re.match(r"CPUID ([\dA-F]{8}): ([\dA-F]{8})-([\dA-F]{8})-([\dA-F]{8})-([\dA-F]{8})", line) 21 if match is not None: 22 input_eax, eax, ebx, ecx, edx = tuple(int(match.group(i), 16) for i in [1, 2, 3, 4, 5]) 23 line = line[match.end(0):].strip() 24 input_ecx = None 25 match = re.match(r"\[SL (\d{2})\]", line) 26 if match is not None: 27 input_ecx = int(match.group(1), 16) 28 cpuid_dump.append((input_eax, input_ecx, eax, ebx, ecx, edx)) 29 30 31 print("struct cpuinfo_mock_cpuid cpuid_dump[] = {") 32 for input_eax, input_ecx, eax, ebx, ecx, edx in cpuid_dump: 33 print("\t{") 34 print("\t\t.input_eax = 0x%08X," % input_eax) 35 if input_ecx is not None: 36 print("\t\t.input_ecx = 0x%08X," % input_ecx) 37 print("\t\t.eax = 0x%08X," % eax) 38 print("\t\t.ebx = 0x%08X," % ebx) 39 print("\t\t.ecx = 0x%08X," % ecx) 40 print("\t\t.edx = 0x%08X," % edx) 41 print("\t},") 42 print("};") 43 print() 44 45 46if __name__ == "__main__": 47 main(sys.argv[1:]) 48