GaloisInc / dismantle

A library of assemblers and disassemblers derived from LLVM TableGen data
24 stars 5 forks source link

Multiple "opChunk"s for a given operand causes incorrect reassembly (for a little-endian ISA) #12

Open danmatichuk opened 4 years ago

danmatichuk commented 4 years ago

Given the following little-endian mask: xxxx000F.x1F01111.xxxxxxxx.1101xxxx We specify that the F bits at position 24 and 21 belong to some operand by declaring an OperandDescriptor as such:

OperandDescriptor { opName = "F"
                  , opChunks = [(IBit 24, OBit 0, 1), (IBit 21, OBit 0, 1)]
                  , opType = OperandType "Bv2"
                  }

Once the instruction mask is reversed into big-endian format it looks like: 1101xxxx.xxxxxxxx.x1F01111.xxxx000F

Dismantle then correctly disassembles that instruction, and correctly establishes the expected value for the operand, but fails to re-assemble it in the expected way.

Original Bytes: "11011010.01001110.01001111.10110001"
Reassembled as: "11011010.01001110.01101111.10110001"

Where the value for the F operand is correctly interpreted as 01. However on re-assembly, dismantle has unexpectedly filled in 1 for both F bits, thus incorrectly setting bit number 24.