openc166 0.2.7__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. {openc166-0.2.7 → openc166-0.3.0}/CMakeLists.txt +1 -1
  2. {openc166-0.2.7 → openc166-0.3.0}/PKG-INFO +24 -6
  3. {openc166-0.2.7 → openc166-0.3.0}/README.md +23 -5
  4. {openc166-0.2.7 → openc166-0.3.0}/cli/main.cpp +61 -0
  5. {openc166-0.2.7 → openc166-0.3.0}/docs/compatibility.md +59 -1
  6. {openc166-0.2.7 → openc166-0.3.0}/docs/simulator.md +3 -2
  7. {openc166-0.2.7 → openc166-0.3.0}/include/openc166/openc166.h +26 -0
  8. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/__init__.py +99 -2
  9. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/_native.py +4 -0
  10. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_openc166.py +39 -0
  11. {openc166-0.2.7 → openc166-0.3.0}/src/assembler.cpp +126 -11
  12. {openc166-0.2.7 → openc166-0.3.0}/src/assembler.hpp +28 -6
  13. {openc166-0.2.7 → openc166-0.3.0}/src/capi.cpp +34 -0
  14. {openc166-0.2.7 → openc166-0.3.0}/src/sim/cpu.cpp +14 -1
  15. {openc166-0.2.7 → openc166-0.3.0}/tests/capi/test_capi.c +32 -0
  16. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_link.cpp +73 -0
  17. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_sections.cpp +114 -0
  18. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_sim.cpp +29 -0
  19. {openc166-0.2.7 → openc166-0.3.0}/.gitattributes +0 -0
  20. {openc166-0.2.7 → openc166-0.3.0}/.github/workflows/ci.yml +0 -0
  21. {openc166-0.2.7 → openc166-0.3.0}/.github/workflows/wheels.yml +0 -0
  22. {openc166-0.2.7 → openc166-0.3.0}/.gitignore +0 -0
  23. {openc166-0.2.7 → openc166-0.3.0}/LICENSE +0 -0
  24. {openc166-0.2.7 → openc166-0.3.0}/boards/5wy19.json +0 -0
  25. {openc166-0.2.7 → openc166-0.3.0}/boards/c166.json +0 -0
  26. {openc166-0.2.7 → openc166-0.3.0}/boards/c167.json +0 -0
  27. {openc166-0.2.7 → openc166-0.3.0}/boards/c167cr.json +0 -0
  28. {openc166-0.2.7 → openc166-0.3.0}/boards/c167cs.json +0 -0
  29. {openc166-0.2.7 → openc166-0.3.0}/cli/CMakeLists.txt +0 -0
  30. {openc166-0.2.7 → openc166-0.3.0}/cmake/embed_files.cmake +0 -0
  31. {openc166-0.2.7 → openc166-0.3.0}/docs/boards.md +0 -0
  32. {openc166-0.2.7 → openc166-0.3.0}/docs/debug-info.md +0 -0
  33. {openc166-0.2.7 → openc166-0.3.0}/docs/debugger-design.md +0 -0
  34. {openc166-0.2.7 → openc166-0.3.0}/docs/ghidra.md +0 -0
  35. {openc166-0.2.7 → openc166-0.3.0}/docs/mpl.md +0 -0
  36. {openc166-0.2.7 → openc166-0.3.0}/docs/phase1-feasibility.md +0 -0
  37. {openc166-0.2.7 → openc166-0.3.0}/docs/releasing.md +0 -0
  38. {openc166-0.2.7 → openc166-0.3.0}/docs/tasking.md +0 -0
  39. {openc166-0.2.7 → openc166-0.3.0}/editors/vscode/README.md +0 -0
  40. {openc166-0.2.7 → openc166-0.3.0}/editors/vscode/extension.js +0 -0
  41. {openc166-0.2.7 → openc166-0.3.0}/editors/vscode/package.json +0 -0
  42. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/README.md +0 -0
  43. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/bsl_shim.a66 +0 -0
  44. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/driver_patch.a66 +0 -0
  45. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/kline_hello.a66 +0 -0
  46. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/loader.a66 +0 -0
  47. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/marker.a66 +0 -0
  48. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/memory_dump.a66 +0 -0
  49. {openc166-0.2.7 → openc166-0.3.0}/examples/mtos/stage2_hello.a66 +0 -0
  50. {openc166-0.2.7 → openc166-0.3.0}/examples/payload.a66 +0 -0
  51. {openc166-0.2.7 → openc166-0.3.0}/examples/sections.a66 +0 -0
  52. {openc166-0.2.7 → openc166-0.3.0}/inc/REG167.INC +0 -0
  53. {openc166-0.2.7 → openc166-0.3.0}/pyproject.toml +0 -0
  54. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/bridge.py +0 -0
  55. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/dap.py +0 -0
  56. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/ghidra.py +0 -0
  57. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/py.typed +0 -0
  58. {openc166-0.2.7 → openc166-0.3.0}/python/openc166/sim.py +0 -0
  59. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_bridge.py +0 -0
  60. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_dap.py +0 -0
  61. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_elf.py +0 -0
  62. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_ghidra.py +0 -0
  63. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_sim.py +0 -0
  64. {openc166-0.2.7 → openc166-0.3.0}/python/tests/test_stock_5wy19.py +0 -0
  65. {openc166-0.2.7 → openc166-0.3.0}/src/CMakeLists.txt +0 -0
  66. {openc166-0.2.7 → openc166-0.3.0}/src/bundled.cpp +0 -0
  67. {openc166-0.2.7 → openc166-0.3.0}/src/bundled.hpp +0 -0
  68. {openc166-0.2.7 → openc166-0.3.0}/src/capi.map +0 -0
  69. {openc166-0.2.7 → openc166-0.3.0}/src/capi_sim.cpp +0 -0
  70. {openc166-0.2.7 → openc166-0.3.0}/src/debuginfo.cpp +0 -0
  71. {openc166-0.2.7 → openc166-0.3.0}/src/diag.hpp +0 -0
  72. {openc166-0.2.7 → openc166-0.3.0}/src/disasm.cpp +0 -0
  73. {openc166-0.2.7 → openc166-0.3.0}/src/disasm.hpp +0 -0
  74. {openc166-0.2.7 → openc166-0.3.0}/src/disasm_module.cpp +0 -0
  75. {openc166-0.2.7 → openc166-0.3.0}/src/elf.cpp +0 -0
  76. {openc166-0.2.7 → openc166-0.3.0}/src/encode.cpp +0 -0
  77. {openc166-0.2.7 → openc166-0.3.0}/src/encode.hpp +0 -0
  78. {openc166-0.2.7 → openc166-0.3.0}/src/expr.cpp +0 -0
  79. {openc166-0.2.7 → openc166-0.3.0}/src/expr.hpp +0 -0
  80. {openc166-0.2.7 → openc166-0.3.0}/src/isa/c166.tbl +0 -0
  81. {openc166-0.2.7 → openc166-0.3.0}/src/isa/isa.cpp +0 -0
  82. {openc166-0.2.7 → openc166-0.3.0}/src/isa/isa.hpp +0 -0
  83. {openc166-0.2.7 → openc166-0.3.0}/src/isa/isa_types.hpp +0 -0
  84. {openc166-0.2.7 → openc166-0.3.0}/src/json.cpp +0 -0
  85. {openc166-0.2.7 → openc166-0.3.0}/src/json.hpp +0 -0
  86. {openc166-0.2.7 → openc166-0.3.0}/src/lexer.cpp +0 -0
  87. {openc166-0.2.7 → openc166-0.3.0}/src/lexer.hpp +0 -0
  88. {openc166-0.2.7 → openc166-0.3.0}/src/m166.cpp +0 -0
  89. {openc166-0.2.7 → openc166-0.3.0}/src/m166.hpp +0 -0
  90. {openc166-0.2.7 → openc166-0.3.0}/src/mpl.cpp +0 -0
  91. {openc166-0.2.7 → openc166-0.3.0}/src/mpl.hpp +0 -0
  92. {openc166-0.2.7 → openc166-0.3.0}/src/operand.cpp +0 -0
  93. {openc166-0.2.7 → openc166-0.3.0}/src/operand.hpp +0 -0
  94. {openc166-0.2.7 → openc166-0.3.0}/src/output.cpp +0 -0
  95. {openc166-0.2.7 → openc166-0.3.0}/src/predef.cpp +0 -0
  96. {openc166-0.2.7 → openc166-0.3.0}/src/predef.hpp +0 -0
  97. {openc166-0.2.7 → openc166-0.3.0}/src/sim/board_config.cpp +0 -0
  98. {openc166-0.2.7 → openc166-0.3.0}/src/sim/board_config.hpp +0 -0
  99. {openc166-0.2.7 → openc166-0.3.0}/src/sim/boards.cpp +0 -0
  100. {openc166-0.2.7 → openc166-0.3.0}/src/sim/boards.hpp +0 -0
  101. {openc166-0.2.7 → openc166-0.3.0}/src/sim/debug.cpp +0 -0
  102. {openc166-0.2.7 → openc166-0.3.0}/src/sim/debug.hpp +0 -0
  103. {openc166-0.2.7 → openc166-0.3.0}/src/sim/machine.cpp +0 -0
  104. {openc166-0.2.7 → openc166-0.3.0}/src/sim/machine.hpp +0 -0
  105. {openc166-0.2.7 → openc166-0.3.0}/src/sim/peripherals.cpp +0 -0
  106. {openc166-0.2.7 → openc166-0.3.0}/src/sim/peripherals.hpp +0 -0
  107. {openc166-0.2.7 → openc166-0.3.0}/src/value.hpp +0 -0
  108. {openc166-0.2.7 → openc166-0.3.0}/tests/CMakeLists.txt +0 -0
  109. {openc166-0.2.7 → openc166-0.3.0}/tests/acceptance/minimon.py +0 -0
  110. {openc166-0.2.7 → openc166-0.3.0}/tests/check_binary.cmake +0 -0
  111. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/alignment.a66 +0 -0
  112. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/bit_section_errors.a66 +0 -0
  113. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/bit_sections.a66 +0 -0
  114. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/bits.a66 +0 -0
  115. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/branches.a66 +0 -0
  116. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/cond.a66 +0 -0
  117. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/cond_errors.a66 +0 -0
  118. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/controls.a66 +0 -0
  119. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/defs.a66 +0 -0
  120. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/directives.a66 +0 -0
  121. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/dpp.a66 +0 -0
  122. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/expressions.a66 +0 -0
  123. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/group_errors.a66 +0 -0
  124. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/groups.a66 +0 -0
  125. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/code.inc +0 -0
  126. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/comments.inc +0 -0
  127. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/count.inc +0 -0
  128. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/crlf.inc +0 -0
  129. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/ignored.inc +0 -0
  130. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/lit.inc +0 -0
  131. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/mpl.inc +0 -0
  132. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/nested.inc +0 -0
  133. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/noeol.inc +0 -0
  134. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/regs.inc +0 -0
  135. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/sub/deep.inc +0 -0
  136. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/inc/sub/level3.inc +0 -0
  137. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/include.a66 +0 -0
  138. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/label_errors.a66 +0 -0
  139. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/labels.a66 +0 -0
  140. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/bits/1main.a66 +0 -0
  141. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/bits/2lib.a66 +0 -0
  142. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/bits/3more.a66 +0 -0
  143. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/calls/1main.a66 +0 -0
  144. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/calls/2lib.a66 +0 -0
  145. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/combine/1first.a66 +0 -0
  146. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/combine/2second.a66 +0 -0
  147. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/combine/3third.a66 +0 -0
  148. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/fixups/1use.a66 +0 -0
  149. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/fixups/2def.a66 +0 -0
  150. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/groups/1main.a66 +0 -0
  151. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/groups/2lib.a66 +0 -0
  152. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/mixed/1seg.a66 +0 -0
  153. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/mixed/2flat.a66 +0 -0
  154. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/mixed/3seg.a66 +0 -0
  155. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/regbanks/1main.a66 +0 -0
  156. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/regbanks/2lib.a66 +0 -0
  157. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/sections/1first.a66 +0 -0
  158. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/sections/2second.a66 +0 -0
  159. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/sections/3third.a66 +0 -0
  160. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/segmented/1main.a66 +0 -0
  161. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/segmented/2lib.a66 +0 -0
  162. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/unresolved/1main.a66 +0 -0
  163. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/unresolved/2one.a66 +0 -0
  164. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/unresolved/3two.a66 +0 -0
  165. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/values/1use.a66 +0 -0
  166. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/link/values/2def.a66 +0 -0
  167. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/listing.a66 +0 -0
  168. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/lit.a66 +0 -0
  169. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/lit_errors.a66 +0 -0
  170. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/locate.a66 +0 -0
  171. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/macro_args.a66 +0 -0
  172. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/macro_errors.a66 +0 -0
  173. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/macros.a66 +0 -0
  174. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl.a66 +0 -0
  175. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_exit.a66 +0 -0
  176. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_expr.a66 +0 -0
  177. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_fi.a66 +0 -0
  178. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_meta.a66 +0 -0
  179. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_paren.a66 +0 -0
  180. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_pattern.a66 +0 -0
  181. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_syntax.a66 +0 -0
  182. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/mpl_err_undefined.a66 +0 -0
  183. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/operands.a66 +0 -0
  184. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/primary.a66 +0 -0
  185. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/redefine.a66 +0 -0
  186. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/regbank_errors.a66 +0 -0
  187. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/regbanks.a66 +0 -0
  188. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/reloc.a66 +0 -0
  189. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/section_errors.a66 +0 -0
  190. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/section_length.a66 +0 -0
  191. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/segmented.a66 +0 -0
  192. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/type_operator_errors.a66 +0 -0
  193. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/cases/type_operators.a66 +0 -0
  194. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/gen_sweep.py +0 -0
  195. {openc166-0.2.7 → openc166-0.3.0}/tests/diff/keil_diff.py +0 -0
  196. {openc166-0.2.7 → openc166-0.3.0}/tests/expected/driver_patch.hex +0 -0
  197. {openc166-0.2.7 → openc166-0.3.0}/tests/expected/driver_patch.s28 +0 -0
  198. {openc166-0.2.7 → openc166-0.3.0}/tests/expected/payload.srec +0 -0
  199. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/helpers.hpp +0 -0
  200. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/main.cpp +0 -0
  201. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_assembler.cpp +0 -0
  202. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_bits.cpp +0 -0
  203. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_boards.cpp +0 -0
  204. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_branches.cpp +0 -0
  205. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_cond.cpp +0 -0
  206. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_debug.cpp +0 -0
  207. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_defs.cpp +0 -0
  208. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_dpp.cpp +0 -0
  209. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_encode.cpp +0 -0
  210. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_expr.cpp +0 -0
  211. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_groups.cpp +0 -0
  212. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_include.cpp +0 -0
  213. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_json.cpp +0 -0
  214. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_lexer.cpp +0 -0
  215. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_listing.cpp +0 -0
  216. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_lit.cpp +0 -0
  217. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_macros.cpp +0 -0
  218. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_mpl.cpp +0 -0
  219. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_output.cpp +0 -0
  220. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_peripherals.cpp +0 -0
  221. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_regbanks.cpp +0 -0
  222. {openc166-0.2.7 → openc166-0.3.0}/tests/unit/test_tasking.cpp +0 -0
  223. {openc166-0.2.7 → openc166-0.3.0}/third_party/doctest/LICENSE.txt +0 -0
  224. {openc166-0.2.7 → openc166-0.3.0}/third_party/doctest/doctest.h +0 -0
  225. {openc166-0.2.7 → openc166-0.3.0}/tools/CMakeLists.txt +0 -0
  226. {openc166-0.2.7 → openc166-0.3.0}/tools/ghidra/ExportOpenc166Symbols.py +0 -0
  227. {openc166-0.2.7 → openc166-0.3.0}/tools/isagen.cpp +0 -0
@@ -1,6 +1,6 @@
1
1
  cmake_minimum_required(VERSION 3.20)
2
2
  project(openc166
3
- VERSION 0.2.7
3
+ VERSION 0.3.0
4
4
  DESCRIPTION "Keil A166-compatible assembler for the Infineon C166/C167 family"
5
5
  LANGUAGES CXX)
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openc166
3
- Version: 0.2.7
3
+ Version: 0.3.0
4
4
  Summary: Keil A166-compatible assembler for the Infineon C166/C167 microcontrollers
5
5
  Keywords: c166,c167,st10,assembler,keil,a166,infineon,ecu
6
6
  License-Expression: MIT
@@ -93,7 +93,9 @@ Early development (version 0.x). What works today:
93
93
  - Several source files linked into one program, as L166 does: `EXTERN`,
94
94
  `PUBLIC` and `GLOBAL` symbols, and sections of the same name combined
95
95
  across files. Each file is assembled separately (a "module"), so a name
96
- that is not `PUBLIC` stays private to its file.
96
+ that is not `PUBLIC` stays private to its file. Library modules
97
+ (`--lib`) are linked only when the program needs a name they define, as
98
+ L166 takes modules from a library.
97
99
  - Register banks (`REGBANK`/`REGDEF`), placed in `0FC00H..0FDFFH` as L166
98
100
  places them, and the `NAME`, `SSKDEF`, `PECDEF` and `TYPEDEC` directives.
99
101
  - **TASKING sources** (`--dialect tasking`): the common part of TASKING's
@@ -107,7 +109,8 @@ Early development (version 0.x). What works today:
107
109
 
108
110
  Not done yet:
109
111
 
110
- - OMF-166 object files and libraries
112
+ - OMF-166 object files and libraries (library modules are sources; see
113
+ `--lib`)
111
114
  - TASKING's m166 macros with parameters (`@DEFINE`), loops and string
112
115
  functions
113
116
 
@@ -149,6 +152,11 @@ linker joins the object files of A166:
149
152
  each symbol comes from.
150
153
  - Code outside sections starts at `--origin` in every file, so normally
151
154
  each file puts its code in sections.
155
+ - `--lib FILE` adds a library module, which is linked only if it defines a
156
+ name that the program needs (`EXTERN`) and no other module defines; it
157
+ may then pull in other library modules. `--lib DIR` adds each `.a66`
158
+ file of a directory. A runtime library can be a directory with one
159
+ routine per file.
152
160
 
153
161
  `$INCLUDE` looks in each file's own directory.
154
162
  [docs/compatibility.md](https://github.com/Dante383/openc166/blob/main/docs/compatibility.md#linking-several-files)
@@ -169,6 +177,9 @@ carry the address of every record, so they hold only the bytes used.
169
177
  | `-f, --format FMT` | `bin`, `hex` or `srec` (default: from the output extension) |
170
178
  | `--origin ADDR` | address of code outside sections, and the lowest address for sections without `AT` (default 0) |
171
179
  | `--section NAME=ADDR` | put section `NAME`, which has no `AT`, at `ADDR` (may be repeated) |
180
+ | `--class NAME=FIRST-LAST[,...]` | put the sections of class `NAME` in these address ranges, like L166's `CLASSES` (may be repeated) |
181
+ | `--lib PATH` | library module, or a directory of them: linked only when needed (may be repeated) |
182
+ | `--reserve FIRST-LAST[,...]` | keep these addresses free of placed sections, like L166's `RESERVE` (may be repeated) |
172
183
  | `--base ADDR` | binary: address of the first byte of the file |
173
184
  | `--fill BYTE` | binary: value of gaps between pieces of code (default `0FFh`) |
174
185
  | `--record-size N` | HEX and S-records: data bytes per record (default 16) |
@@ -180,7 +191,9 @@ carry the address of every record, so they hold only the bytes used.
180
191
  Sections without `AT` go in order of first appearance to the first free,
181
192
  suitably aligned place from the origin on, as L166 places them by default.
182
193
  `--section` overrides that for chosen sections, like L166's `SECTIONS`
183
- control. The listing ends with a table of where each section went.
194
+ control, and `--class` and `--reserve` give a memory map, like its
195
+ `CLASSES` and `RESERVE` controls: code in flash, variables in RAM.
196
+ The listing ends with a table of where each section went.
184
197
  [examples/sections.a66](https://github.com/Dante383/openc166/blob/main/examples/sections.a66) shows both.
185
198
 
186
199
  Intel HEX files use extended linear address records (type 04) for addresses
@@ -223,9 +236,14 @@ image.base # 0xE000, the address of image.data[0]
223
236
  image.data # b'\xe6\xf4\xef\xbe\xcb\x00'
224
237
  ```
225
238
 
226
- - `openc166.assemble(source, *, file_name=None, cpu=None, origin=0, include_dirs=(), sections=None, dialect="keil", controls=())`
239
+ - `openc166.assemble(source, *, file_name=None, cpu=None, origin=0, include_dirs=(), sections=None, classes=None, reserve=(), dialect="keil", controls=())`
227
240
  assembles a `str` or `bytes`. `sections` gives addresses for sections
228
- without `AT`, e.g. `{"VARS": 0xF600}`. `dialect="tasking"` reads TASKING
241
+ without `AT`, e.g. `{"VARS": 0xF600}`; `classes` gives address ranges
242
+ for the sections of a class, e.g. `{"NDATA": [(0xC000, 0xDFFF)]}`, and
243
+ `reserve` ranges that no placed section may use; `libraries` gives
244
+ library modules (paths of files or directories, `(name, text)` pairs or
245
+ a dict), linked only when needed, and `result.library_modules` says how
246
+ many of `result.modules` were. `dialect="tasking"` reads TASKING
229
247
  source; `controls` is a list of controls read before the source, as with
230
248
  `-c`. `openc166.assemble_file(path, ...)`
231
249
  reads a file; `$INCLUDE` then also searches the file's directory.
@@ -70,7 +70,9 @@ Early development (version 0.x). What works today:
70
70
  - Several source files linked into one program, as L166 does: `EXTERN`,
71
71
  `PUBLIC` and `GLOBAL` symbols, and sections of the same name combined
72
72
  across files. Each file is assembled separately (a "module"), so a name
73
- that is not `PUBLIC` stays private to its file.
73
+ that is not `PUBLIC` stays private to its file. Library modules
74
+ (`--lib`) are linked only when the program needs a name they define, as
75
+ L166 takes modules from a library.
74
76
  - Register banks (`REGBANK`/`REGDEF`), placed in `0FC00H..0FDFFH` as L166
75
77
  places them, and the `NAME`, `SSKDEF`, `PECDEF` and `TYPEDEC` directives.
76
78
  - **TASKING sources** (`--dialect tasking`): the common part of TASKING's
@@ -84,7 +86,8 @@ Early development (version 0.x). What works today:
84
86
 
85
87
  Not done yet:
86
88
 
87
- - OMF-166 object files and libraries
89
+ - OMF-166 object files and libraries (library modules are sources; see
90
+ `--lib`)
88
91
  - TASKING's m166 macros with parameters (`@DEFINE`), loops and string
89
92
  functions
90
93
 
@@ -126,6 +129,11 @@ linker joins the object files of A166:
126
129
  each symbol comes from.
127
130
  - Code outside sections starts at `--origin` in every file, so normally
128
131
  each file puts its code in sections.
132
+ - `--lib FILE` adds a library module, which is linked only if it defines a
133
+ name that the program needs (`EXTERN`) and no other module defines; it
134
+ may then pull in other library modules. `--lib DIR` adds each `.a66`
135
+ file of a directory. A runtime library can be a directory with one
136
+ routine per file.
129
137
 
130
138
  `$INCLUDE` looks in each file's own directory.
131
139
  [docs/compatibility.md](https://github.com/Dante383/openc166/blob/main/docs/compatibility.md#linking-several-files)
@@ -146,6 +154,9 @@ carry the address of every record, so they hold only the bytes used.
146
154
  | `-f, --format FMT` | `bin`, `hex` or `srec` (default: from the output extension) |
147
155
  | `--origin ADDR` | address of code outside sections, and the lowest address for sections without `AT` (default 0) |
148
156
  | `--section NAME=ADDR` | put section `NAME`, which has no `AT`, at `ADDR` (may be repeated) |
157
+ | `--class NAME=FIRST-LAST[,...]` | put the sections of class `NAME` in these address ranges, like L166's `CLASSES` (may be repeated) |
158
+ | `--lib PATH` | library module, or a directory of them: linked only when needed (may be repeated) |
159
+ | `--reserve FIRST-LAST[,...]` | keep these addresses free of placed sections, like L166's `RESERVE` (may be repeated) |
149
160
  | `--base ADDR` | binary: address of the first byte of the file |
150
161
  | `--fill BYTE` | binary: value of gaps between pieces of code (default `0FFh`) |
151
162
  | `--record-size N` | HEX and S-records: data bytes per record (default 16) |
@@ -157,7 +168,9 @@ carry the address of every record, so they hold only the bytes used.
157
168
  Sections without `AT` go in order of first appearance to the first free,
158
169
  suitably aligned place from the origin on, as L166 places them by default.
159
170
  `--section` overrides that for chosen sections, like L166's `SECTIONS`
160
- control. The listing ends with a table of where each section went.
171
+ control, and `--class` and `--reserve` give a memory map, like its
172
+ `CLASSES` and `RESERVE` controls: code in flash, variables in RAM.
173
+ The listing ends with a table of where each section went.
161
174
  [examples/sections.a66](https://github.com/Dante383/openc166/blob/main/examples/sections.a66) shows both.
162
175
 
163
176
  Intel HEX files use extended linear address records (type 04) for addresses
@@ -200,9 +213,14 @@ image.base # 0xE000, the address of image.data[0]
200
213
  image.data # b'\xe6\xf4\xef\xbe\xcb\x00'
201
214
  ```
202
215
 
203
- - `openc166.assemble(source, *, file_name=None, cpu=None, origin=0, include_dirs=(), sections=None, dialect="keil", controls=())`
216
+ - `openc166.assemble(source, *, file_name=None, cpu=None, origin=0, include_dirs=(), sections=None, classes=None, reserve=(), dialect="keil", controls=())`
204
217
  assembles a `str` or `bytes`. `sections` gives addresses for sections
205
- without `AT`, e.g. `{"VARS": 0xF600}`. `dialect="tasking"` reads TASKING
218
+ without `AT`, e.g. `{"VARS": 0xF600}`; `classes` gives address ranges
219
+ for the sections of a class, e.g. `{"NDATA": [(0xC000, 0xDFFF)]}`, and
220
+ `reserve` ranges that no placed section may use; `libraries` gives
221
+ library modules (paths of files or directories, `(name, text)` pairs or
222
+ a dict), linked only when needed, and `result.library_modules` says how
223
+ many of `result.modules` were. `dialect="tasking"` reads TASKING
206
224
  source; `controls` is a list of controls read before the source, as with
207
225
  `-c`. `openc166.assemble_file(path, ...)`
208
226
  reads a file; `$INCLUDE` then also searches the file's directory.
@@ -2,9 +2,11 @@
2
2
  // openc166 command-line tool.
3
3
  #include "assembler.hpp"
4
4
 
5
+ #include <algorithm>
5
6
  #include <cctype>
6
7
  #include <cstdio>
7
8
  #include <cstdlib>
9
+ #include <filesystem>
8
10
  #include <fstream>
9
11
  #include <iostream>
10
12
  #include <iterator>
@@ -43,6 +45,18 @@ options:
43
45
  --section NAME=ADDR
44
46
  put section NAME, which has no AT, at ADDR (may be repeated);
45
47
  the other sections without AT go to the first free place
48
+ --class NAME=RANGE[,RANGE...]
49
+ put the sections of class NAME, which have no AT, in these
50
+ address ranges, trying them in order, like L166's CLASSES;
51
+ a RANGE is FIRST-LAST, e.g. --class NDATA=0C000h-0DFFFh
52
+ (may be repeated)
53
+ --reserve RANGE[,RANGE...]
54
+ keep these addresses free of the sections openc166 places,
55
+ like L166's RESERVE (may be repeated)
56
+ --lib PATH library module: linked only if it defines a name that the
57
+ program needs and nothing else defines, like a member of an
58
+ L166 library; a directory gives each of its .a66 files, in
59
+ order of name (may be repeated)
46
60
  --base ADDR bin: address of the first byte of the file (default: lowest address used)
47
61
  --fill BYTE bin: value of unused bytes inside the file (default 0FFh)
48
62
  --record-size N hex, srec: data bytes per record (default 16)
@@ -81,6 +95,26 @@ std::int64_t parse_number(std::string_view s, const char* what) {
81
95
  return v;
82
96
  }
83
97
 
98
+ // FIRST-LAST[,FIRST-LAST...], both ends inclusive.
99
+ std::vector<oc166::AssembleOptions::Range> parse_ranges(std::string_view s, const char* option) {
100
+ std::vector<oc166::AssembleOptions::Range> out;
101
+ for (std::size_t pos = 0; pos <= s.size();) {
102
+ std::size_t comma = s.find(',', pos);
103
+ if (comma == std::string_view::npos) comma = s.size();
104
+ std::string_view item = s.substr(pos, comma - pos);
105
+ std::size_t dash = item.find('-');
106
+ if (dash == std::string_view::npos)
107
+ throw UsageError(std::string(option) + " needs ranges FIRST-LAST, not '" + std::string(item) + "'");
108
+ std::int64_t first = parse_number(item.substr(0, dash), "range start");
109
+ std::int64_t last = parse_number(item.substr(dash + 1), "range end");
110
+ if (last > 0xFFFFFF) throw UsageError("range '" + std::string(item) + "' must end below 1000000h");
111
+ if (first > last) throw UsageError("range '" + std::string(item) + "' is empty");
112
+ out.push_back({first, last});
113
+ pos = comma + 1;
114
+ }
115
+ return out;
116
+ }
117
+
84
118
  std::string read_file(const std::string& path) {
85
119
  std::ifstream in(path, std::ios::binary);
86
120
  if (!in) throw std::runtime_error("cannot open '" + path + "'");
@@ -118,6 +152,7 @@ std::string replace_extension(const std::string& path, const std::string& ext) {
118
152
  int run(int argc, char** argv) {
119
153
  oc166::AssembleOptions opt;
120
154
  std::vector<std::string> inputs;
155
+ std::vector<std::string> libraries;
121
156
  std::string output, listing, debug_info;
122
157
  std::optional<std::int64_t> base;
123
158
  std::uint8_t fill = 0xFF;
@@ -190,6 +225,17 @@ int run(int argc, char** argv) {
190
225
  std::int64_t address = parse_number(v.substr(eq + 1), "section address");
191
226
  if (address > 0xFFFFFF) throw UsageError("section address must be below 1000000h");
192
227
  opt.section_addresses.emplace_back(std::string(v.substr(0, eq)), address);
228
+ } else if (is("", "--class")) {
229
+ std::string_view v = value();
230
+ std::size_t eq = v.find('=');
231
+ if (eq == std::string_view::npos || eq == 0)
232
+ throw UsageError("--class needs NAME=FIRST-LAST, not '" + std::string(v) + "'");
233
+ for (const auto& r : parse_ranges(v.substr(eq + 1), "--class"))
234
+ opt.class_ranges.emplace_back(std::string(v.substr(0, eq)), r);
235
+ } else if (is("", "--reserve")) {
236
+ for (const auto& r : parse_ranges(value(), "--reserve")) opt.reserved.push_back(r);
237
+ } else if (is("", "--lib")) {
238
+ libraries.emplace_back(value());
193
239
  } else if (is("", "--base")) {
194
240
  base = parse_number(value(), "base address");
195
241
  } else if (is("-I", "--incdir")) {
@@ -233,6 +279,21 @@ int run(int argc, char** argv) {
233
279
 
234
280
  std::vector<oc166::Source> sources;
235
281
  for (const auto& input : inputs) sources.push_back({input, read_file(input)});
282
+ for (const auto& lib : libraries) {
283
+ namespace fs = std::filesystem;
284
+ std::error_code ec;
285
+ if (!fs::is_directory(lib, ec)) {
286
+ opt.libraries.push_back({lib, read_file(lib)});
287
+ continue;
288
+ }
289
+ std::vector<std::string> files;
290
+ for (const auto& entry : fs::directory_iterator(lib, ec))
291
+ if (entry.is_regular_file(ec) && lower(entry.path().extension().string()) == ".a66")
292
+ files.push_back(entry.path().string());
293
+ if (ec) throw std::runtime_error("cannot read directory '" + lib + "'");
294
+ std::sort(files.begin(), files.end());
295
+ for (const auto& f : files) opt.libraries.push_back({f, read_file(f)});
296
+ }
236
297
  opt.file_name = inputs.front();
237
298
  oc166::AssemblyResult result = oc166::assemble(sources, opt);
238
299
 
@@ -566,6 +566,7 @@ Messages that Keil does not have use codes starting with `OC`:
566
566
  | OC32 | warning | TASKING: a `STDNAMES` file that cannot be found; openc166's built-in `REG167.INC` is used instead |
567
567
  | OC33 | error | an MPL macro or `%WHILE` that never stops: calls nested more than 256 deep, or more than 20 million calls and loop rounds; the assembly stops (see [mpl.md](mpl.md)) |
568
568
  | OC34 | warning | MPL `%IN` or `%OUT`, which use the console in Keil |
569
+ | OC35 | warning | `--class` ranges for a class that no section has |
569
570
 
570
571
  ## Sections
571
572
 
@@ -615,7 +616,8 @@ default:
615
616
  - [register banks](#register-banks-and-linker-directives) first, in
616
617
  `0FC00H..0FDFFH`; then `BITADDRESSABLE` sections in `0FD00H..0FDFFH`,
617
618
  and then `BIT` sections (see [BIT sections](#bit-sections));
618
- - the sections of [groups](#groups) first, then the others;
619
+ - the sections of [groups](#groups) first, then those whose class has
620
+ address ranges (see below), then the others;
619
621
  - `DATA` and `CONST` sections inside one 16 KB data page, and `CODE`,
620
622
  `HDATA` and `HCONST` sections inside one 64 KB segment, unless they are
621
623
  bigger than that;
@@ -628,6 +630,32 @@ without `AT` can be placed this way (OC14). An address that does not suit
628
630
  the align type, or a name that matches no section, gives warning OC13. A
629
631
  section that fits nowhere gives OC12.
630
632
 
633
+ **Memory map.** Like L166's `CLASSES` and `RESERVE` controls:
634
+
635
+ - `--class NAME=FIRST-LAST[,FIRST-LAST...]` (Python:
636
+ `classes={"NDATA": [(0xC000, 0xDFFF)]}`) gives address ranges, both ends
637
+ inclusive, for the sections of class `NAME`. Each such section goes in
638
+ the first of the ranges where it fits, tried in the order given, instead
639
+ of anywhere from `--origin` on. Class names ignore case. Repeating
640
+ `--class` with the same name adds ranges. Sections of a class without
641
+ ranges, and sections without a class, are placed as before.
642
+ - `--reserve FIRST-LAST[,FIRST-LAST...]` (Python: `reserve=[(0, 0x1FF)]`)
643
+ keeps addresses free of every section that openc166 places. Sections
644
+ with `AT` or `--section` may still use them, as in L166.
645
+
646
+ ```sh
647
+ openc166 main.a66 lib.a66 --reserve 0-1FFh \
648
+ --class NCODE=0200h-7FFFh --class NCONST=8000h-0BFFFh \
649
+ --class NDATA=0C000h-0DFFFh,0F600h-0FDFFh -o prog.hex
650
+ ```
651
+
652
+ A section with a class that has ranges is placed before the sections
653
+ without, so that those do not take its room. A section of a group still
654
+ stays in the group's page or segment, inside its class's ranges. Ranges
655
+ from `10000H` on are only usable with `$SEGMENTED`. A section that fits
656
+ in none of its ranges gives OC12, and ranges for a class that no section
657
+ has give warning OC35.
658
+
631
659
  The listing ends with a table of every section: type, align type, address,
632
660
  size, whether the address came from `AT`, from `--section`, or from
633
661
  openc166, and its class and group if it has them.
@@ -904,6 +932,36 @@ differs, L15 in L166).
904
932
  overlaps (OC1) if more than one module has some. Keil does not allow
905
933
  such code at all (A44).
906
934
 
935
+ ### Library modules
936
+
937
+ L166 takes from a library only the modules that the program needs.
938
+ openc166 does the same with library modules, which are sources rather
939
+ than object files: `--lib FILE` on the command line (a directory gives each
940
+ of its `.a66` files, in order of name), `libraries=` in Python, and
941
+ `oc166_options_add_library()` in C.
942
+
943
+ ```sh
944
+ openc166 main.a66 --lib runtime/ -o prog.hex
945
+ ```
946
+
947
+ - A library module is linked only if it makes `PUBLIC` or `GLOBAL` a name
948
+ that a linked module declares `EXTERN` and that no linked module defines.
949
+ Its own `EXTERN`s may then pull in other library modules, from any
950
+ library, in any order.
951
+ - When several library modules define a needed name, the first one given
952
+ is used. A name that the program's own modules define never pulls in a
953
+ library module, so a module can replace a library routine.
954
+ - Linked library modules follow the other modules, in the order given, and
955
+ are then exactly like them: their sections join, their names are
956
+ checked, and their errors count. An `EXTERN` that is declared but never
957
+ used still pulls in its module, as in L166.
958
+ - Library modules that are not linked do not appear in the result, and
959
+ their errors are not reported.
960
+
961
+ To decide, openc166 runs a first pass over each module on its own. A
962
+ `PUBLIC` or `EXTERN` that depends on conditional assembly counts as that
963
+ first pass sees it.
964
+
907
965
  ## Data alignment
908
966
 
909
967
  Keil moves word data to an even address and double-word data to a multiple
@@ -182,8 +182,9 @@ they are not part of snapshots, so reverse execution does not replay them.
182
182
  ## What the core models, and how closely
183
183
 
184
184
  - The whole instruction set, decoded from `src/isa/c166.tbl`. Flags follow
185
- the instruction set manual; they are checked by unit tests, not yet
186
- against a real C167 (design §6: the MiniMon oracle is the next step).
185
+ the instruction set manual; an instruction that writes PSW itself
186
+ (`POP PSW`, `BCLR PSW.3`) keeps the value written, not its flag
187
+ update. They are checked by unit tests, not yet against a real C167 (design §6: the MiniMon oracle is the next step).
187
188
  - Register banks in IRAM through CP; DPP paging; EXTR, EXTP(R), EXTS(R)
188
189
  and ATOMIC, which also block interrupts. The debugger steps a sequence as
189
190
  one unit.
@@ -102,6 +102,29 @@ OC166_API int oc166_options_add_include_dir(oc166_options *opts, const char *dir
102
102
  * -1 for an empty name or an address outside 0..0FFFFFFH. */
103
103
  OC166_API int oc166_options_set_section_address(oc166_options *opts, const char *name, int64_t address);
104
104
 
105
+ /* Adds the address range first..last (both inclusive) to the class
106
+ * 'class_name' (any case), like the CLASSES control of Keil's L166: a
107
+ * section of that class without an address of its own goes in the first of
108
+ * its class's ranges where it fits, in the order they were added, instead
109
+ * of anywhere from the origin on. Returns 0, or -1 for an empty name or a
110
+ * range that is empty or outside 0..0FFFFFFH. */
111
+ OC166_API int oc166_options_add_class_range(oc166_options *opts, const char *class_name, int64_t first, int64_t last);
112
+
113
+ /* Keeps the addresses first..last (both inclusive) free of every section
114
+ * that openc166 places, like the RESERVE control of Keil's L166. Sections
115
+ * with AT or an address of their own may still use them. Returns 0, or -1
116
+ * for a range that is empty or outside 0..0FFFFFFH. */
117
+ OC166_API int oc166_options_add_reserved(oc166_options *opts, int64_t first, int64_t last);
118
+
119
+ /* Adds a library module: 'length' bytes of source, and the name of its file
120
+ * (may be NULL: "libraryN.a66"), for diagnostics and $INCLUDE. Like a member
121
+ * of an L166 library, it is linked only if it makes PUBLIC or GLOBAL a name
122
+ * that a linked module declares EXTERN and no linked module defines; it may
123
+ * then pull in other library modules. When several define a name, the first
124
+ * one added is used. The text is copied. Returns 0, or -1 on failure. */
125
+ OC166_API int oc166_options_add_library(oc166_options *opts, const char *source, size_t length,
126
+ const char *file_name);
127
+
105
128
  /* ---- Assembling -------------------------------------------------------- */
106
129
 
107
130
  typedef struct oc166_result oc166_result;
@@ -135,6 +158,9 @@ OC166_API oc166_result *oc166_assemble_many(const oc166_options *opts, size_t co
135
158
  * module 'index', or NULL if 'index' is out of range. */
136
159
  OC166_API size_t oc166_result_module_count(const oc166_result *r);
137
160
  OC166_API const char *oc166_result_module(const oc166_result *r, size_t index);
161
+ /* How many of the last modules are library modules that were linked
162
+ * (oc166_options_add_library). */
163
+ OC166_API size_t oc166_result_library_module_count(const oc166_result *r);
138
164
 
139
165
  OC166_API size_t oc166_result_error_count(const oc166_result *r);
140
166
  OC166_API size_t oc166_result_warning_count(const oc166_result *r);
@@ -57,6 +57,10 @@ __version__: str = _lib.oc166_version().decode("ascii")
57
57
 
58
58
  PathLike = Union[str, "os.PathLike[str]"]
59
59
  SourceText = Union[str, bytes]
60
+ Ranges = Union[Tuple[int, int], Iterable[Tuple[int, int]]]
61
+ # Library modules: paths of files or directories of .a66 files, (file name,
62
+ # source text) pairs, or a dict of file name to source text.
63
+ Libraries = Union[PathLike, Mapping[PathLike, SourceText], Iterable[Union[PathLike, Tuple[PathLike, SourceText]]]]
60
64
 
61
65
 
62
66
  def _text(b: Optional[bytes]) -> str:
@@ -235,7 +239,11 @@ class Result:
235
239
  _text(_lib.oc166_result_module(handle, i))
236
240
  for i in range(_lib.oc166_result_module_count(handle))
237
241
  ]
238
- """File name of each module: one per source."""
242
+ """File name of each module: one per source, then the library
243
+ modules that were linked."""
244
+
245
+ self.library_modules: int = _lib.oc166_result_library_module_count(handle)
246
+ """How many of the last modules are linked library modules."""
239
247
 
240
248
  self.all_symbols: List[Symbol] = []
241
249
  """The names defined in every module, sorted by name, then module."""
@@ -426,6 +434,9 @@ def assemble(
426
434
  origin: int = 0,
427
435
  include_dirs: Iterable[PathLike] = (),
428
436
  sections: Optional[Mapping[str, int]] = None,
437
+ classes: Optional[Mapping[str, Ranges]] = None,
438
+ reserve: Ranges = (),
439
+ libraries: Libraries = (),
429
440
  dialect: str = "keil",
430
441
  controls: Iterable[str] = (),
431
442
  ) -> Result:
@@ -444,6 +455,20 @@ def assemble(
444
455
  like the SECTIONS control of Keil's L166:
445
456
  {"MYDATA": 0xF600}. The other sections go in order of
446
457
  appearance to the first free place from the origin on.
458
+ classes address ranges for the sections of a class, by class
459
+ name (any case), like the CLASSES control of L166:
460
+ {"NDATA": [(0xC000, 0xDFFF)], "NCODE": (0x0, 0x7FFF)}.
461
+ Both ends are inclusive. A section of that class without
462
+ AT or an address in 'sections' goes in the first of the
463
+ ranges where it fits.
464
+ reserve address ranges (first, last), inclusive, that no section
465
+ placed by openc166 may use, like L166's RESERVE.
466
+ libraries library modules, like the members of an L166 library:
467
+ paths of .a66 files or of directories (each .a66 file in
468
+ them, by name), (file name, source) pairs, or a dict of
469
+ file name to source. A library module is linked only if it
470
+ makes PUBLIC or GLOBAL a name that a linked module needs
471
+ (EXTERN) and none defines; it may pull in others in turn.
447
472
  dialect "keil" (the default) for Keil A166 sources, or "tasking"
448
473
  for TASKING a166 sources, which first pass through
449
474
  openc166's m166 preprocessor (@SET, @IF, ...). TASKING
@@ -459,6 +484,9 @@ def assemble(
459
484
  origin,
460
485
  include_dirs,
461
486
  sections,
487
+ classes,
488
+ reserve,
489
+ libraries,
462
490
  dialect,
463
491
  controls,
464
492
  )
@@ -472,7 +500,49 @@ def _source_bytes(source: SourceText) -> bytes:
472
500
  return bytes(source)
473
501
 
474
502
 
475
- def _run(call, cpu, origin, include_dirs, sections, dialect, controls) -> Result:
503
+ def _ranges(ranges, what):
504
+ """A (first, last) pair or a list of them, checked."""
505
+ if len(ranges) == 2 and all(isinstance(v, int) for v in ranges):
506
+ ranges = [ranges]
507
+ out = []
508
+ for r in ranges:
509
+ try:
510
+ first, last = r
511
+ except (TypeError, ValueError):
512
+ raise ValueError("bad range {!r} for {} (use (first, last))".format(r, what)) from None
513
+ if not (isinstance(first, int) and isinstance(last, int) and 0 <= first <= last <= 0xFFFFFF):
514
+ raise ValueError("bad range {!r} for {} (use 0 <= first <= last <= 0FFFFFFH)".format(r, what))
515
+ out.append((first, last))
516
+ return out
517
+
518
+
519
+ def _library_sources(libraries):
520
+ """(file name, source bytes) of each library module."""
521
+ if isinstance(libraries, (str, bytes)) or hasattr(libraries, "__fspath__"):
522
+ libraries = [libraries]
523
+ items = list(libraries.items()) if isinstance(libraries, Mapping) else list(libraries)
524
+ out = []
525
+ for item in items:
526
+ if isinstance(item, tuple):
527
+ lib_name, text = item
528
+ out.append((os.fsencode(os.fspath(lib_name)), _source_bytes(text)))
529
+ continue
530
+ path = os.fspath(item)
531
+ if os.path.isdir(path):
532
+ files = sorted(
533
+ os.path.join(path, f)
534
+ for f in os.listdir(path)
535
+ if f.lower().endswith(".a66") and os.path.isfile(os.path.join(path, f))
536
+ )
537
+ else:
538
+ files = [path]
539
+ for f in files:
540
+ with open(f, "rb") as fh:
541
+ out.append((os.fsencode(f), fh.read()))
542
+ return out
543
+
544
+
545
+ def _run(call, cpu, origin, include_dirs, sections, classes, reserve, libraries, dialect, controls) -> Result:
476
546
  """Makes the options, calls call(options) and wraps the result."""
477
547
  opts = _lib.oc166_options_new()
478
548
  if not opts:
@@ -498,6 +568,15 @@ def _run(call, cpu, origin, include_dirs, sections, dialect, controls) -> Result
498
568
  )
499
569
  if _lib.oc166_options_set_section_address(opts, str(sec_name).encode("utf-8"), address) != 0:
500
570
  raise ValueError("bad section name {!r}".format(sec_name))
571
+ for class_name, ranges in (classes or {}).items():
572
+ for first, last in _ranges(ranges, "class {!r}".format(class_name)):
573
+ if _lib.oc166_options_add_class_range(opts, str(class_name).encode("utf-8"), first, last) != 0:
574
+ raise ValueError("bad class name {!r}".format(class_name))
575
+ for first, last in _ranges(reserve, "reserve"):
576
+ _lib.oc166_options_add_reserved(opts, first, last)
577
+ for lib_name, text in _library_sources(libraries):
578
+ if _lib.oc166_options_add_library(opts, text, len(text), lib_name) != 0:
579
+ raise MemoryError("cannot add library module")
501
580
  handle = call(opts)
502
581
  finally:
503
582
  _lib.oc166_options_free(opts)
@@ -513,6 +592,9 @@ def assemble_file(
513
592
  origin: int = 0,
514
593
  include_dirs: Iterable[PathLike] = (),
515
594
  sections: Optional[Mapping[str, int]] = None,
595
+ classes: Optional[Mapping[str, Ranges]] = None,
596
+ reserve: Ranges = (),
597
+ libraries: Libraries = (),
516
598
  dialect: str = "keil",
517
599
  controls: Iterable[str] = (),
518
600
  ) -> Result:
@@ -526,6 +608,9 @@ def assemble_file(
526
608
  origin=origin,
527
609
  include_dirs=include_dirs,
528
610
  sections=sections,
611
+ classes=classes,
612
+ reserve=reserve,
613
+ libraries=libraries,
529
614
  dialect=dialect,
530
615
  controls=controls,
531
616
  )
@@ -538,6 +623,9 @@ def assemble_many(
538
623
  origin: int = 0,
539
624
  include_dirs: Iterable[PathLike] = (),
540
625
  sections: Optional[Mapping[str, int]] = None,
626
+ classes: Optional[Mapping[str, Ranges]] = None,
627
+ reserve: Ranges = (),
628
+ libraries: Libraries = (),
541
629
  dialect: str = "keil",
542
630
  controls: Iterable[str] = (),
543
631
  ) -> Result:
@@ -576,6 +664,9 @@ def assemble_many(
576
664
  origin,
577
665
  include_dirs,
578
666
  sections,
667
+ classes,
668
+ reserve,
669
+ libraries,
579
670
  dialect,
580
671
  controls,
581
672
  )
@@ -588,6 +679,9 @@ def assemble_files(
588
679
  origin: int = 0,
589
680
  include_dirs: Iterable[PathLike] = (),
590
681
  sections: Optional[Mapping[str, int]] = None,
682
+ classes: Optional[Mapping[str, Ranges]] = None,
683
+ reserve: Ranges = (),
684
+ libraries: Libraries = (),
591
685
  dialect: str = "keil",
592
686
  controls: Iterable[str] = (),
593
687
  ) -> Result:
@@ -605,6 +699,9 @@ def assemble_files(
605
699
  origin=origin,
606
700
  include_dirs=include_dirs,
607
701
  sections=sections,
702
+ classes=classes,
703
+ reserve=reserve,
704
+ libraries=libraries,
608
705
  dialect=dialect,
609
706
  controls=controls,
610
707
  )
@@ -148,6 +148,9 @@ _declare("oc166_options_add_control", _int, _p, _str)
148
148
  _declare("oc166_options_set_origin", _int, _p, ctypes.c_int64)
149
149
  _declare("oc166_options_add_include_dir", _int, _p, _str)
150
150
  _declare("oc166_options_set_section_address", _int, _p, _str, ctypes.c_int64)
151
+ _declare("oc166_options_add_class_range", _int, _p, _str, ctypes.c_int64, ctypes.c_int64)
152
+ _declare("oc166_options_add_reserved", _int, _p, ctypes.c_int64, ctypes.c_int64)
153
+ _declare("oc166_options_add_library", _int, _p, ctypes.c_char_p, _size, _str)
151
154
  _declare("oc166_assemble", _p, _p, _str, _size, _str)
152
155
  _declare("oc166_result_free", None, _p)
153
156
  _declare("oc166_result_error_count", _size, _p)
@@ -171,6 +174,7 @@ _declare("oc166_result_section", _int, _p, _size, ctypes.POINTER(Section))
171
174
  _declare("oc166_assemble_many", _p, _p, _size, ctypes.POINTER(_str), ctypes.POINTER(_size), ctypes.POINTER(_str))
172
175
  _declare("oc166_result_module_count", _size, _p)
173
176
  _declare("oc166_result_module", _str, _p, _size)
177
+ _declare("oc166_result_library_module_count", _size, _p)
174
178
  _declare("oc166_result_symbol_module", _int, _p, _size)
175
179
  _declare("oc166_result_symbol_exported", _int, _p, _size)
176
180
  _declare("oc166_result_section_class", _str, _p, _size)
@@ -374,6 +374,24 @@ class SectionTest(unittest.TestCase):
374
374
  self.assertEqual((prog.bit, prog.bit_size), (0, 16))
375
375
  self.assertEqual(result.chunks[0].data.hex(), "3f01")
376
376
 
377
+ def test_classes_and_reserve(self):
378
+ source = self.SOURCE.replace("Vars SECTION DATA", "Vars SECTION DATA 'NDATA'")
379
+ result = openc166.assemble(source, origin=0x8000, classes={"ndata": [(0xC000, 0xDFFF)]})
380
+ self.assertTrue(result.ok, result.diagnostics)
381
+ self.assertEqual(result.sections["Vars"].address, 0xC000)
382
+ result = openc166.assemble(
383
+ source, origin=0x8000, classes={"NDATA": (0xC000, 0xDFFF)}, reserve=[(0xC000, 0xC0FF)]
384
+ )
385
+ self.assertTrue(result.ok, result.diagnostics)
386
+ self.assertEqual(result.sections["Vars"].address, 0xC100)
387
+ result = openc166.assemble(source, classes={"NONE": (0, 1)})
388
+ self.assertEqual([d.code for d in result.warnings], ["OC35"])
389
+ for bad in ((2, 1), (-1, 5), (0, 0x1000000), "x", [(1, 2, 3)]):
390
+ with self.assertRaises(ValueError):
391
+ openc166.assemble(source, classes={"NDATA": bad})
392
+ with self.assertRaises(ValueError):
393
+ openc166.assemble(source, reserve=bad)
394
+
377
395
  def test_given_problems(self):
378
396
  result = openc166.assemble(self.SOURCE, sections={"FIXED": 0x100, "NONE": 0x200})
379
397
  self.assertEqual([d.code for d in result.errors], ["OC14"])
@@ -407,6 +425,27 @@ class LinkTest(unittest.TestCase):
407
425
  " END\n"
408
426
  )
409
427
 
428
+ def test_libraries(self):
429
+ unused = ("unused.a66", "PUBLIC OTHER\nOTHER EQU 1\n garbage\n END\n")
430
+ for libraries in ([unused, ("data.a66", self.DATA)], {"unused.a66": unused[1], "data.a66": self.DATA}):
431
+ result = openc166.assemble(self.MAIN, file_name="main.a66", origin=0x8000, libraries=libraries)
432
+ self.assertTrue(result.ok, result.diagnostics)
433
+ self.assertEqual(result.modules, ["main.a66", "data.a66"])
434
+ self.assertEqual(result.library_modules, 1)
435
+ self.assertEqual(result.chunks[0].data.hex(), "f2f400c0e6f53412cb00")
436
+ with tempfile.TemporaryDirectory() as d:
437
+ for name, text in (unused, ("data.a66", self.DATA)):
438
+ with open(os.path.join(d, name), "w") as f:
439
+ f.write(text)
440
+ main = os.path.join(d, "main.src")
441
+ with open(main, "w") as f:
442
+ f.write(self.MAIN)
443
+ for libraries in (d, [os.path.join(d, "data.a66")]):
444
+ result = openc166.assemble_files([main], origin=0x8000, libraries=libraries)
445
+ self.assertTrue(result.ok, result.diagnostics)
446
+ self.assertEqual(result.library_modules, 1)
447
+ self.assertEqual(os.path.basename(result.modules[1]), "data.a66")
448
+
410
449
  def test_assemble_many(self):
411
450
  for sources in ({"main.a66": self.MAIN, "data.a66": self.DATA.encode()},
412
451
  [("main.a66", self.MAIN), ("data.a66", self.DATA)]):