import json
import xmltodict
-def checkFeature(cpuid, feature):
+def checkCPUIDFeature(cpuData, feature):
eax_in = feature["eax_in"]
ecx_in = feature["ecx_in"]
eax = feature["eax"]
ecx = feature["ecx"]
edx = feature["edx"]
+ if "cpuid" not in cpuData:
+ return False
+
+ cpuid = cpuData["cpuid"]
if eax_in not in cpuid or ecx_in not in cpuid[eax_in]:
return False
(edx > 0 and leaf["edx"] & edx == edx))
-def addFeature(cpuid, feature):
+def checkFeature(cpuData, feature):
+ if feature["type"] == "cpuid":
+ return checkCPUIDFeature(cpuData, feature)
+
+ return False
+
+
+def addCPUIDFeature(cpuData, feature):
+ if "cpuid" not in cpuData:
+ cpuData["cpuid"] = {}
+ cpuid = cpuData["cpuid"]
+
if feature["eax_in"] not in cpuid:
cpuid[feature["eax_in"]] = {}
leaf = cpuid[feature["eax_in"]]
leaf[reg] |= feature[reg]
+def addFeature(cpuData, feature):
+ if feature["type"] == "cpuid":
+ addCPUIDFeature(cpuData, feature)
+
+
def parseQemu(path, features):
cpuData = {}
with open(path, "r") as f:
data = xmltodict.parse(f)
for leaf in data["cpudata"]["cpuid"]:
- feature = {}
+ feature = {"type": "cpuid"}
feature["eax_in"] = int(leaf["@eax_in"], 0)
feature["ecx_in"] = int(leaf["@ecx_in"], 0)
for reg in ["eax", "ebx", "ecx", "edx"]:
def parseMapFeature(data):
- cpuid = {}
+ cpuid = {"type": "cpuid"}
for reg in ["eax_in", "ecx_in", "eax", "ebx", "ecx", "edx"]:
attr = "@%s" % reg
return cpuMap
-def formatCPUData(cpuid, path, comment):
+def formatCPUData(cpuData, path, comment):
print(path)
with open(path, "w") as f:
f.write("<!-- " + comment + " -->\n")
f.write("<cpudata arch='x86'>\n")
+
+ cpuid = cpuData["cpuid"]
for eax_in in sorted(cpuid.keys()):
for ecx_in in sorted(cpuid[eax_in].keys()):
leaf = cpuid[eax_in][ecx_in]
cpuData = parseCPUData(cpuDataFile)
qemu = parseQemu(jsonFile, cpuMap)
- enabled = {}
- disabled = {}
+ enabled = {"cpuid": {}}
+ disabled = {"cpuid": {}}
for feature in cpuMap.values():
if checkFeature(qemu, feature):
addFeature(enabled, feature)