2
0

gen_sysreg_offsets.py 880 B

12345678910111213141516171819202122
  1. with open("sysreg_offsets.txt", "r") as infile:
  2. indata = [[int(part, 16) for part in line.split(" ")]
  3. for line in infile.read().strip().split("\n")]
  4. hvheader = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Hypervisor.framework/Headers/hv_vcpu_types.h"
  5. with open(hvheader, "r") as infile:
  6. headerlines = [
  7. line.strip().split("=") for line in infile.read().split("\n")
  8. if "HV_SYS_REG_" in line
  9. ]
  10. headermap = dict([(int(a[1].rstrip(","), 16), a[0].strip())
  11. for a in headerlines])
  12. template = """case {}:
  13. o = {};
  14. f = {};
  15. break;
  16. """
  17. outstr = ""
  18. for entry in indata:
  19. regname = headermap[entry[0]]
  20. outstr += template.format(regname, hex(entry[1]), hex(entry[2]))
  21. with open("../sysreg_offsets.h", "w") as outfile:
  22. outfile.write(outstr)