Skip to content

[AUTOMATED] Write the Thumb stmia base back when the base is in the list - #1901

Merged
mahaloz merged 5 commits into
Noelo-Lab:mainfrom
sjkim1127:fix/thumb-stmia-writeback
Nov 23, 2026
Merged

mahaloz merged 5 commits into
Noelo-Lab:mainfrom
sjkim1127:fix/thumb-stmia-writeback

Conversation

@sjkim1127

Copy link
Copy Markdown
Contributor

[AUTOMATED]

On Thumb, kuna treats stmia rN!,{...} as leaving rN unchanged when rN is in the register list. The instruction always adds 4 bytes per register to the base, so a function that returns the base after the store loses its result.

printf '\x03\xc0\x70\x47' > stm.bin   # stmia r0!,{r0,r1}; bx lr
kuna decompile stm.bin 0x0 --raw-image --target ARM:LE:32:v8-m:default --base 0 --isa thumb
void sub_0(void *a0,unsigned int a1)
{
  *(void **)a0 = a0;
  ((unsigned int *)a0)[1] = a1;
}
  • The 16-bit stmia gets its own body that always writes back, so the function above now ends in return (int)a0 + 8;. It disassembles as stmia r0!,{r0,r1}, which is the only form the T1 encoding has.
  • ldmia keeps the shared rule that skips the writeback when the base is loaded, which is the architecture's rule for loads.
  • The ARMv8 entry in the compiler oracle is regenerated; slacomp reproduces the old digest on the old sources.

tests/stages/kuna-thumb-stmia-writeback.xml has a function with the base in the list and one without it. 3 of its 4 assertions fail without the fix. Compared one instruction at a time against Unicorn over Cortex-M firmware, all 7 stmia forms with the base in the list differed on the base register and now match. The datatest corpus is unchanged, and decompiling that 6 MB firmware takes the same time.

🤖 Generated with Claude Code

Model: anthropic/claude-opus-5-5

The 16-bit Thumb stmia used ldmia's writeback rule, which skips the
writeback when Rn is in the register list. STM (T1) always adds
4 * BitCount to the base, so after `stmia r0!,{r0,r1}` kuna kept r0 at its
entry value and a function returning it printed as void. stmia now always
writes back and disassembles with the `!`; ldmia is unchanged.

Found by comparing kuna's lift with Unicorn instruction by instruction on
Cortex-M firmware: all seven stmia forms with the base in the list differed
on the base register and now match. The ARM8_le compiler-oracle digest is
regenerated with slacomp, which reproduces the old digest on the old sources.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sjkim1127
sjkim1127 force-pushed the fix/thumb-stmia-writeback branch from 0f4f8c8 to f0ebfb5 Compare November 23, 2026 11:23
mahaloz and others added 2 commits November 23, 2026 11:47
The architecture defines the stored base only when it is the lowest listed
register and leaves it UNKNOWN otherwise; the lift stores the entry value,
which is what QEMU stores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits on top of f0ebfb5:

  • 173abd1 merges current main (10bf37a); the only conflict was docs/baseline-stages.json, resolved to main's assertions plus this PR's four (5156).
  • 0cb5842 adds one sentence to docs/spec/02-lift-and-flow.md: for a listed Rn the lift stores its entry value. The architecture defines that word only when Rn is the lowest listed register and leaves it UNKNOWN otherwise; QEMU/Unicorn store the entry value too.

The SLEIGH change itself is unchanged.

@mahaloz
mahaloz merged commit edd75cc into Noelo-Lab:main Nov 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants