Repository navigation
arm: set the carry flag of logical instructions with a rotated immediate - #1582
Open
bacescuandrei wants to merge 1 commit into
Open
bacescuandrei wants to merge 1 commit into
bacescuandrei wants to merge 1 commit into
Conversation
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.
Flag-setting logical instructions with a modified immediate (
ANDS,EORS,ORRS,BICS,MOVS,MVNS,TST,TEQ) never updated the carry flag. In ARMExpandImm_C and ThumbExpandImm_C, an immediate encoded with a rotation sets C to bit 31 of the expanded value. SoANDS R0, R1, 0xFF000000should set C, andANDS R0, R1, 0x00FF0000should clear it.sem.pyhad aTODO: set cf if ROT imm in argumentfor this, andMOVS/MVNShadTODO handle cf.The operand already holds the expanded value, so the new
imm_carry()reads the rotation from the encoding (instr.b):imm12[11:8].i:imm3[2].When the immediate is rotated, C is the value's MSB; otherwise C is left unchanged. The flag-setting logical instructions call it for an immediate operand.
test_rotated_imm_carryintest/arch/arm/sem.pycovers each instruction, plus an unrotated immediate that keeps C. It fails without the change and passes with it. The rest oftest/arch/arm/sem.pyandtest/arch/arm/arch.pypass.I also compared these instructions against Unicorn (Cortex-A15) on all their immediate forms and edge values, running miasm's IR through the symbolic execution engine:
The T32 forms that still differ are decoder issues I'll report separately:
lsr #32/asr #32withimm5 = 0are decoded as a shift of 0.orr{s}.w rd, rn, #immis decoded withRdandRnswapped.