Skip to content

alpha: sign-extend memory-format displacement - #3036

Open
Samin061 wants to merge 1 commit into
capstone-engine:nextfrom
Samin061:alpha-mem-disp-signext
Open

alpha: sign-extend memory-format displacement#3036
Samin061 wants to merge 1 commit into
capstone-engine:nextfrom
Samin061:alpha-mem-disp-signext

Conversation

@Samin061

Copy link
Copy Markdown
Contributor

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

The Alpha memory-format instructions (lda, the integer loads/stores, the store-conditional forms, and the lds/ldt/sts/stt float loads and stores) carry a 16-bit displacement that the ISA treats as signed, but the decoder read it out of the instruction word as a plain unsigned field and never sign-extended it, so any displacement with bit 15 set decoded to a large positive value. cstool -d alpha 0xb0,0xb0,0x42,0x20 shows it: the offset prints as 0xb0b0 and operands[1].imm is 0xb0b0, where it should be -20304. The displacement is read in the shared decode macro at the four memory-format cases (indices 1, 22, 23, 24), each storing fieldFromInstruction_4(insn, 0, 16) straight into the operand. Casting that field through int16_t at those four sites stores the signed offset, so the same word now decodes to lda $2,-0x4f50($2). Positive displacements are unaffected.

Test plan

cstool -d alpha 0xb0,0xb0,0x42,0x20 now prints lda $2,-0x4f50($2) with operands[1].imm = 0xffffffffffffb0b0. I added negative-displacement cases to tests/MC/Alpha/insn-alpha.s.yaml covering the integer, store-conditional and float-memory forms, and updated the two detail cases in tests/details/alpha.yaml and tests/details/cs_common_details.yaml that had captured the old unsigned value.

Closing issues

closes #3021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

alpha: Signed memory-format offset interpreted as unsigned

1 participant