Skip to content

Commit f39434e

Browse files
arachsysdpgeorge
authored andcommitted
py/asmthumb: Don't corrupt base register in large offset store.
asm_thumb_store_reg_reg_offset() modifies the base register when storing with a large offset which triggers the generic path. If a variable lives in that register, this corrupts it. Fix this by saving the base register on the stack before modifying it. Signed-off-by: Chris Webb <[email protected]>
1 parent 69ead7d commit f39434e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

py/asmthumb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ void asm_thumb_store_reg_reg_offset(asm_thumb_t *as, uint reg_src, uint reg_base
492492
asm_thumb_op32(as, (OP_LDR_STR_W_HI(operation_size, reg_base) | OP_STR_W), OP_LDR_STR_W_LO(reg_src, (offset << operation_size)));
493493
} else {
494494
// Must use the generic sequence
495+
asm_thumb_op16(as, OP_PUSH_RLIST(1 << reg_base));
495496
asm_thumb_add_reg_reg_offset(as, reg_base, reg_base, offset - 31, operation_size);
496497
asm_thumb_op16(as, ((OP_LDR_STR_TABLE[operation_size] | OP_STR) << 11) | (31 << 6) | (reg_base << 3) | reg_src);
498+
asm_thumb_op16(as, OP_POP_RLIST(1 << reg_base));
497499
}
498500
}
499501

0 commit comments

Comments
 (0)