Reputation: 53
I am writing a simple arm emulator. arm has different formats/Class of instruction as given on this link After reading instruction in binary format How can I determine to which class/format instruction belongs.
Upvotes: 3
Views: 194
Reputation: 76723
I've recently written a ARM emulator myself.
Here's the strategy I've used:
Use a mask and a value to test against after the mask has been applied.
Here's a snippet from the GNU disassembler for ARM:
(* V7 instructions. *)
(arch:ARM_EXT_V7; value:$f910f000; mask:$ff70f000; i:_und; assembly:'pli'#9'%a'),
(arch:ARM_EXT_V7; value:$f3af80f0; mask:$fffffff0; i:_und; assembly:'dbg'#9'#%0-3d'),
(arch:ARM_EXT_V7; value:$f3bf8f50; mask:$fffffff0; i:_und; assembly:'dmb'#9'%U'),
(arch:ARM_EXT_V7; value:$f3bf8f40; mask:$fffffff0; i:_und; assembly:'dsb'#9'%U'),
(arch:ARM_EXT_V7; value:$f3bf8f60; mask:$fffffff0; i:_und; assembly:'isb'#9'%U'),
And here's how you apply it:
if (InstructionBytes and Mask) = value
then we have a matchYou need to make sure you apply the masks in the correct order.
Instructions introduced in a newer revision should always be checked first.
There is no need to worry whether you're in ARM or Thumb mode.
Just disassemble for both and store both disassemblies side by side. If a mode change occurs switch the table you're reading your disassembled instructions from.
Upvotes: 1