選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

76 行
2.9KB

  1. #!/usr/bin/env python3
  2. """setup.py - prepare the Power C improvement toolchain (the original disk is only read).
  3. python tools/setup.py extract the runtime library objects into lib/ and build optlib/
  4. python tools/setup.py --disk also write POWERc-opt.d81 (original + improved runtime objects)
  5. optlib/ gets drop-in replacements (same file names as on POWERc.d81):
  6. cmulti.obj faster 16x16 multiply
  7. c0047.obj faster divide / remainder (same results, fewer shift steps)
  8. c0077.obj the unsigned >= helper with its broken branch opcode ($80 -> $90) fixed
  9. """
  10. import os, sys, subprocess, shutil, hashlib
  11. HERE = os.path.dirname(os.path.abspath(__file__))
  12. ROOT = os.path.normpath(os.path.join(HERE, '..'))
  13. sys.path.insert(0, HERE)
  14. from objfmt import Obj
  15. from pcasm import assemble
  16. sys.path.insert(0, os.path.join(ROOT, 'src'))
  17. import div_patch
  18. C1541 = r'C:\Program Files\GTK3VICE-3.10-win64\bin\c1541.exe'
  19. ORIG = os.path.normpath(os.path.join(ROOT, '..', 'POWERc.d81'))
  20. def run(*a):
  21. return subprocess.run([C1541] + list(a), capture_output=True, text=True)
  22. def extract():
  23. os.makedirs(os.path.join(ROOT, 'lib'), exist_ok=True)
  24. out = run(ORIG, '-list').stdout
  25. names = []
  26. for ln in out.splitlines():
  27. if '"' in ln and ln.rstrip().endswith('seq'):
  28. nm = ln.split('"')[1]
  29. if nm.endswith(('.obj', '.o', '.l')):
  30. names.append(nm)
  31. args = []
  32. for nm in sorted(set(names)):
  33. args += ['-read', nm + ',s', os.path.join(ROOT, 'lib', nm)]
  34. run(ORIG, *args)
  35. print('extracted %d files into lib/' % len(set(names)))
  36. def build():
  37. os.makedirs(os.path.join(ROOT, 'optlib'), exist_ok=True)
  38. cm, _ = assemble(open(os.path.join(ROOT, 'src', 'cmulti.s')).read())
  39. open(os.path.join(ROOT, 'optlib', 'cmulti.obj'), 'wb').write(cm.build())
  40. o = Obj.parse(open(os.path.join(ROOT, 'lib', 'c0047.obj'), 'rb').read())
  41. open(os.path.join(ROOT, 'optlib', 'c0047.obj'), 'wb').write(div_patch.patch(o).build())
  42. o = Obj.parse(open(os.path.join(ROOT, 'lib', 'c0077.obj'), 'rb').read())
  43. assert o.code[0x1d] == 0x80, 'c0077.obj is not the expected original'
  44. o.code[0x1d] = 0x90
  45. open(os.path.join(ROOT, 'optlib', 'c0077.obj'), 'wb').write(o.build())
  46. print('built optlib/cmulti.obj c0047.obj c0077.obj')
  47. def disk():
  48. dst = os.path.join(ROOT, 'POWERc-opt.d81')
  49. shutil.copyfile(ORIG, dst)
  50. for nm in ('cmulti.obj', 'c0047.obj', 'c0077.obj'):
  51. run(dst, '-delete', nm)
  52. run(dst, '-write', os.path.join(ROOT, 'optlib', nm), nm + ',s')
  53. print('wrote', dst)
  54. if __name__ == '__main__':
  55. h = hashlib.sha256(open(ORIG, 'rb').read()).hexdigest()
  56. exp = open(os.path.join(ROOT, 'POWERc.d81.sha256')).read().split()[0]
  57. if h != exp:
  58. print('WARNING: reference/POWERc.d81 differs from the recorded original hash')
  59. extract()
  60. build()
  61. if '--disk' in sys.argv:
  62. disk()

Powered by TurnKey Linux.