Replace keystone-engine with a minimal in-house Thumb-2 assembler#385
Open
BrianPugh wants to merge 1 commit into
Open
Replace keystone-engine with a minimal in-house Thumb-2 assembler#385BrianPugh wants to merge 1 commit into
BrianPugh wants to merge 1 commit into
Conversation
keystone-engine is unmaintained and painful to build (no macOS-arm64 wheel), and the patcher only ever assembles a small, fixed set of Thumb-2 instructions. Replace it with a purpose-built, dependency-free assembler. - Add gnw_patch/thumb_asm.py: encodes movw (T3), mov.w/add.w/sub.w (T2/T3 modified immediate, incl. conditional forms), mov (T1), sub sp (T2), ldr.w [pc, #imm] (T2 literal), narrow/wide b (T2/T4), and IT blocks. Includes the ARM ThumbExpandImm encoder. Rejects operands keystone rejects. - Wire it into FirmwarePatchMixin.asm(); drop CachedKeystone, the lazy keystone import, the keystone_cache.json hack, compact_json_encoder.py, and the dead InvalidAsmError. - Move keystone-engine from the optional [patch] group to dev (Linux/Windows only via a platform marker) where it serves purely as the test oracle. - Add tests/test_thumb_asm.py: compares assemble() against keystone-engine exhaustively (every movw immediate, every modified immediate, branch sweeps, IT blocks, register guards) plus the exact instruction strings the Mario/Zelda patches emit. Skips gracefully where keystone is unavailable. Also covers the assembly forms introduced by PR #381 (ldr.w pc-literal with signed offsets and conditional add.w), verified byte-for-byte against keystone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
keystone-engine is unmaintained and painful to build (no macOS-arm64 wheel), and the patcher only ever assembles a small, fixed set of Thumb-2 instructions. Replace it with a purpose-built, dependency-free assembler.
Also covers the assembly forms introduced by PR #381 (ldr.w pc-literal with signed offsets and conditional add.w), verified byte-for-byte against keystone.