--------------------------------------------------------------------------
-- |
-- Module      :  Text.Disassembler.X86Disassembler
-- Copyright   :  (c) Martin Grabmueller and Dirk Kleeblatt
-- License     :  BSD3
-- 
-- Maintainer  :  martin@grabmueller.de,klee@cs.tu-berlin.de
-- Stability   :  provisional
-- Portability :  portable
--
-- Disassembler for x86 machine code.
--
-- This is a disassembler for object code for the x86 architecture.
-- It provides functions for disassembling byte arrays, byte lists and
-- memory blocks containing raw binary code.
-- 
-- Features:
--
-- - Disassembles memory blocks, lists or arrays of bytes into lists of
--   instructions.
--
-- - Abstract instructions provide as much information as possible about
--   opcodes, addressing modes or operand sizes, allowing for detailed
--   output.
--
-- - Provides functions for displaying instructions in Intel or AT&T
--   style (like the GNU tools)
--
-- Differences to GNU tools, like gdb or objdump:
--
-- - Displacements are shown in decimal, with sign if negative.
--
-- Missing: 
--
-- - LOCK and repeat prefixes are recognized, but not contained in the
--   opcodes of instructions.
--
-- - Support for 16-bit addressing modes.  Could be added when needed.
--
-- - Complete disassembly of all 64-bit instructions.  I have tried to
--   disassemble them properly but have been limited to the information
--   in the docs, because I have no 64-bit machine to test on.  This will
--   probably change when I get GNU as to produce 64-bit object files.
--
-- - Not all MMX and SSE/SSE2/SSE3 instructions are decoded yet.  This is
--   just a matter of missing time.
--
-- - segment override prefixes are decoded, but not appended to memory
--   references
--
-- On the implementation:
--
-- This disassembler uses the Parsec parser combinators, working on byte
-- lists.  This proved to be very convenient, as the combinators keep
-- track of the current position, etc.
--------------------------------------------------------------------------

module Text.Disassembler.X86Disassembler(
  -- * Types
  Opcode,
  Operand(..),
  InstrOperandSize(..),
  Instruction(..),
  ShowStyle(..),
  Config(..),
  -- * Functions
  disassembleBlock,
  disassembleList,
  disassembleArray,
  disassembleFile,
  disassembleBlockWithConfig,
  disassembleListWithConfig,
  disassembleArrayWithConfig,
  disassembleFileWithConfig,
  showIntel,
  showAtt,
  defaultConfig
  ) where

import Text.ParserCombinators.Parsec
import Control.Monad.State
import System.IO
import Data.List
import Data.Char
import Data.Array.IArray
import Numeric
import Foreign

-- | All opcodes are represented by this enumeration type.

data Opcode = InvalidOpcode
	    | AAA
	    | AAD
	    | AAM
	    | AAS
	    | ADC
	    | ADD
	    | ADDPD
	    | ADDPS
	    | ADDSD
	    | ADDSS
	    | ADDSUBPD
	    | ADDUBPS
	    | AND
	    | ANDNPD
	    | ANDNPS
	    | ANDPD
	    | ANDPS
	    | ARPL
	    | BOUND
	    | BSF
	    | BSR
	    | BT
	    | BTC
	    | BTR
	    | BTS
	    | CALL
	    | CALLF
	    | CBW
	    | CDQ
	    | CDQE
	    | CLC
	    | CLD
	    | CLFLUSH
	    | CLI
	    | CLTS
	    | CMC
	    | CMOVA
	    | CMOVB
	    | CMOVBE
	    | CMOVE
	    | CMOVG
	    | CMOVGE
	    | CMOVL
	    | CMOVLE
	    | CMOVNB
	    | CMOVNE
	    | CMOVNO
	    | CMOVNP
	    | CMOVNS
	    | CMOVO
	    | CMOVP
	    | CMOVS
	    | CMP
	    | CMPS
	    | CMPXCHG
	    | CMPXCHG16B
	    | CMPXCHG8B
	    | COMISD
	    | COMISS
	    | CPUID
	    | CWD
	    | CWDE
	    | DAA
	    | DAS
	    | DEC
	    | DIV
	    | DIVPD
	    | DIVPS
	    | DIVSD
	    | DIVSS
	    | EMMS
	    | ENTER
	    | FABS
	    | FADD
	    | FADDP
	    | FBLD
	    | FBSTP
	    | FCHS
	    | FCLEX
	    | FCMOVB
	    | FCMOVBE
	    | FCMOVE
	    | FCMOVNB
	    | FCMOVNBE
	    | FCMOVNE
	    | FCMOVNU
	    | FCMOVU
	    | FCOM
	    | FCOMI
	    | FCOMIP
	    | FCOMP
	    | FCOMPP
	    | FDIV
	    | FDIVP
	    | FDIVR
	    | FDIVRP
	    | FFREE
	    | FIADD
	    | FICOM
	    | FICOMP
	    | FIDIV
	    | FIDIVR
	    | FILD
	    | FIMUL
	    | FINIT
	    | FIST
	    | FISTP
	    | FISTPP
	    | FISTTP
	    | FISUB
	    | FISUBR
	    | FLD
	    | FLD1
	    | FLDCW
	    | FLDENV
	    | FLDL2E
	    | FLDL2T
	    | FLDLG2
	    | FLDLN2
	    | FLDPI
	    | FLDZ
	    | FMUL
	    | FMULP
	    | FNOP
	    | FRSTOR
	    | FSAVE
	    | FST
	    | FSTCW
	    | FSTENV
	    | FSTP
	    | FSTSW
	    | FSUB
	    | FSUBP
	    | FSUBR
	    | FSUBRP
	    | FTST
	    | FUCOM
	    | FUCOMI
	    | FUCOMIP
	    | FUCOMP
	    | FUCOMPP
	    | FXAM
	    | FXCH
	    | FXRSTOR
	    | FXSAVE
	    | HADDPD
	    | HADDPS
	    | HLT
	    | HSUBPD
	    | HSUBPS
	    | IDIV
	    | IMUL
	    | BSWAP
	    | IN
	    | INC
	    | INS
	    | INT
	    | INT3
	    | INTO
	    | INVD
	    | INVLPG
	    | IRET
	    | JA
	    | JB
	    | JBE
	    | JCXZ
	    | JE
	    | JG
	    | JGE
	    | JL
	    | JLE
	    | JMP
	    | JMPF
	    | JMPN
	    | JNB
	    | JNE
	    | JNO
	    | JNP
	    | JNS
	    | JO
	    | JP
	    | JS
	    | LAHF
	    | LAR
	    | LDDQU
	    | LDMXCSR
	    | LDS
	    | LEA
	    | LEAVE
	    | LES
	    | LFENCE
	    | LFS
	    | LGDT
	    | LGS
	    | LIDT
	    | LLDT
	    | LMSW
	    | LODS
	    | LOOP
	    | LOOPE
	    | LOOPNE
	    | LSL
	    | LSS
	    | LTR
	    | MASKMOVQ
	    | MAXPD
	    | MAXPS
	    | MAXSD
	    | MAXSS
	    | MFENCE
	    | MINPD
	    | MINPS
	    | MINSD
	    | MINSS
	    | MONITOR
	    | MOV 
	    | MOVAPD
	    | MOVAPS
	    | MOVDDUP
	    | MOVHPD
	    | MOVHPS
	    | MOVLHPS
	    | MOVLPD
	    | MOVLPS
	    | MOVLSDUP
	    | MOVMSKPD
	    | MOVMSKPS
	    | MOVNTDQ
	    | MOVNTPD
	    | MOVNTPS
	    | MOVNTQ
	    | MOVQ
	    | MOVS
	    | MOVSD
	    | MOVSLDUP
	    | MOVSS
	    | MOVSXB
	    | MOVSXD
	    | MOVSXW
	    | MOVUPD
	    | MOVUPS
	    | MOVZXB
	    | MOVZXW
	    | MUL
	    | MULPD
	    | MULPS
	    | MULSD
	    | MULSS
	    | MWAIT
	    | NEG
	    | NOP
	    | NOT
	    | OR
	    | ORPD
	    | ORPS
	    | OUT
	    | OUTS
	    | PADDB
	    | PADDD
	    | PADDQ
	    | PADDSB
	    | PADDSW
	    | PADDUSB
	    | PADDUSW
	    | PADDW
	    | PAND
	    | PANDN
	    | PAUSE
	    | PAVGB
	    | PAVGW
	    | PMADDWD
	    | PMAXSW
	    | PMAXUB
	    | PMINSW
	    | PMINUB
	    | PMOVMSKB
	    | PMULHUW
	    | PMULHW
	    | PMULLW
	    | PMULUDQ
	    | POP
	    | POPA
	    | POPAD
	    | POPF
	    | POPFD
	    | POPFQ
	    | POR
	    | PREFETCHNTA
	    | PREFETCHT0
	    | PREFETCHT1
	    | PREFETCHT2
	    | PSADBW
	    | PSLLD
	    | PSLLDQ
	    | PSLLQ
	    | PSLLW
	    | PSRAD
	    | PSRAW
	    | PSRLD
	    | PSRLDQ
	    | PSRLQ
	    | PSRLW
	    | PSUBB
	    | PSUBD
	    | PSUBQ
	    | PSUBSB
	    | PSUBSQ
	    | PSUBUSB
	    | PSUBUSW
	    | PSUBW
	    | PUSH
	    | PUSHA
	    | PUSHAD
	    | PUSHF
	    | PUSHFD
	    | PUSHFQ
	    | PXOR
	    | RCL
	    | RCPPS
	    | RCPSS
	    | RCR
	    | RDMSR
	    | RDPMC
	    | RDTSC
	    | RET
	    | RETF
	    | ROL
	    | ROR
	    | RSM
	    | RSQRTPS
	    | RSQRTSS
	    | SAHF
	    | SAR
	    | SBB
	    | SCAS
	    | SETA
	    | SETB
	    | SETBE
	    | SETE
	    | SETG
	    | SETGE
	    | SETL
	    | SETLE
	    | SETNB
	    | SETNE
	    | SETNO
	    | SETNP
	    | SETNS
	    | SETO
	    | SETP
	    | SETS
	    | SFENCE
	    | SGDT
	    | SHL
	    | SHLD
	    | SHR
	    | SHRD
	    | SIDT
	    | SLDT
	    | SMSW
	    | SQRTPD
	    | SQRTPS
	    | SQRTSD
	    | SQRTSS
	    | STC
	    | STD
	    | STI
	    | STMXCSR
	    | STOS
	    | STR
	    | SUB
	    | SUBPD
	    | SUBPS
	    | SUBSD
	    | SUBSS
	    | SWAPGS
	    | SYSCALL
	    | SYSENTER
	    | SYSEXIT
	    | TEST
	    | UCOMISD
	    | UCOMISS
	    | UD2
	    | UNPCKHPD
	    | UNPCKHPS
	    | UNPCKLPD
	    | UNPCKLPS
	    | VERR
	    | VERW
	    | VMCALL
	    | VMCLEAR
	    | VMLAUNCH
	    | VMPTRLD
	    | VMPTRST
	    | VMREAD
	    | VMRESUME
	    | VMWRITE
	    | VMXOFF
	    | VMXON
	    | WAIT
	    | WBINVD
	    | WRMSR
	    | XADD
	    | XCHG
	    | XLAT
	    | XOR
	    | XORPD
	    | XORPS
  deriving (Int -> Opcode -> ShowS
[Opcode] -> ShowS
Opcode -> String
(Int -> Opcode -> ShowS)
-> (Opcode -> String) -> ([Opcode] -> ShowS) -> Show Opcode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Opcode] -> ShowS
$cshowList :: [Opcode] -> ShowS
show :: Opcode -> String
$cshow :: Opcode -> String
showsPrec :: Int -> Opcode -> ShowS
$cshowsPrec :: Int -> Opcode -> ShowS
Show, Opcode -> Opcode -> Bool
(Opcode -> Opcode -> Bool)
-> (Opcode -> Opcode -> Bool) -> Eq Opcode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Opcode -> Opcode -> Bool
$c/= :: Opcode -> Opcode -> Bool
== :: Opcode -> Opcode -> Bool
$c== :: Opcode -> Opcode -> Bool
Eq)

-- Display an opcode in lower case.

showOp :: Opcode -> String
showOp :: Opcode -> String
showOp = ((Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower) ShowS -> (Opcode -> String) -> Opcode -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Opcode -> String
forall a. Show a => a -> String
show

-- | All operands are in one of the following locations:
--
-- - Constants in the instruction stream
--
-- - Memory locations
--
-- - Registers
--
-- Memory locations are referred to by on of several addressing modes:
--
-- - Absolute (address in instruction stream)
--
-- - Register-indirect (address in register)
--
-- - Register-indirect with displacement
--
-- - Base-Index with scale
--
-- - Base-Index with scale and displacement 
--
-- Displacements can be encoded as 8 or 32-bit immediates in the
-- instruction stream, but are encoded as Int in instructions for
-- simplicity.
--
data Operand = OpImm Word32		-- ^ Immediate value
              | OpAddr Word32 InstrOperandSize -- ^ Absolute address
              | OpReg String Int	-- ^ Register
              | OpFPReg Int		-- ^ Floating-point register
              | OpInd String InstrOperandSize -- ^Register-indirect
              | OpIndDisp String Int InstrOperandSize
	        -- ^ Register-indirect with displacement
              | OpBaseIndex String String Int InstrOperandSize
        				-- ^ Base plus scaled index
              | OpIndexDisp String Int Int InstrOperandSize
       		 -- ^ Scaled index with displacement
              | OpBaseIndexDisp String String Int Int InstrOperandSize
       		 -- ^ Base plus scaled index with displacement
  deriving (Operand -> Operand -> Bool
(Operand -> Operand -> Bool)
-> (Operand -> Operand -> Bool) -> Eq Operand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Operand -> Operand -> Bool
$c/= :: Operand -> Operand -> Bool
== :: Operand -> Operand -> Bool
$c== :: Operand -> Operand -> Bool
Eq)

-- Show an operand in AT&T style.

showAttOps :: Operand -> String
showAttOps (OpImm Word32
w) = Word32 -> String
showImm Word32
w
showAttOps (OpAddr Word32
w InstrOperandSize
_) = Word32 -> String
forall a. Integral a => a -> String
showAddr Word32
w
showAttOps (OpReg String
s Int
num) = String
"%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
showAttOps (OpFPReg Int
0) = String
"%st"
showAttOps (OpFPReg Int
i) = String
"%st(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAttOps (OpInd String
s InstrOperandSize
_) = String
"(%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAttOps (OpIndDisp String
s Int
disp InstrOperandSize
_) = Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"(%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAttOps (OpBaseIndex String
b String
i Int
s InstrOperandSize
_) = String
"(%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
",%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"," String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAttOps (OpIndexDisp String
i Int
s Int
disp InstrOperandSize
_) = Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"(%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"," String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
  Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAttOps (OpBaseIndexDisp String
b String
i Int
s Int
disp InstrOperandSize
_) = Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"(%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
",%" String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
  String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"," String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"

-- Show an operand in Intel style.

showIntelOps :: p -> Operand -> String
showIntelOps p
opsize (OpImm Word32
w) = Word32 -> String
showIntelImm Word32
w
showIntelOps p
opsize (OpAddr Word32
w InstrOperandSize
sz) = InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word32 -> String
forall a. Integral a => a -> String
showIntelAddr Word32
w String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
showIntelOps p
opsize (OpReg String
s Int
num) = String
s
showIntelOps p
opsize (OpFPReg Int
0) = String
"st"
showIntelOps p
opsize (OpFPReg Int
i) = String
"st(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showIntelOps p
opsize (OpInd String
s InstrOperandSize
sz) = InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
showIntelOps p
opsize (OpIndDisp String
s Int
disp InstrOperandSize
sz) = 
    InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
       (if Int
disp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 then String
"" else String
"+") String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
showIntelOps p
opsize (OpBaseIndex String
b String
i Int
s InstrOperandSize
sz) = 
    InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"+" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"*" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
showIntelOps p
opsize (OpIndexDisp String
i Int
s Int
disp InstrOperandSize
sz) = 
    InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"*" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
       (if Int
disp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 then String
"" else String
"+") String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
showIntelOps p
opsize (OpBaseIndexDisp String
b String
i Int
s Int
disp InstrOperandSize
sz) = 
    InstrOperandSize -> String
opInd InstrOperandSize
sz String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"[" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"+" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"*" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
       (if Int
disp Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 then String
"" else String
"+") String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
      Int -> String
forall a. Show a => a -> String
show Int
disp String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"]"
opInd :: InstrOperandSize -> String
opInd InstrOperandSize
OPNONE = String
""
opInd InstrOperandSize
OP8 = String
"byte ptr "
opInd InstrOperandSize
OP16 = String
"word ptr "
opInd InstrOperandSize
OP32 = String
"dword ptr "
opInd InstrOperandSize
OPF32 = String
"dword ptr "
opInd InstrOperandSize
OP64 = String
"qword ptr "
opInd InstrOperandSize
OPF64 = String
"qword ptr "
opInd InstrOperandSize
OPF80 = String
"tbyte ptr "
opInd InstrOperandSize
OP128 = String
"dqword ptr "

-- | Encodes the default and currently active operand or address size.  Can
-- be changed with the operand- or address-size prefixes 0x66 and 0x67.

data OperandSize = BIT16 | BIT32

-- | Some opcodes can operate on data of several widths.  This information
-- is encoded in instructions using the following enumeration type..

data InstrOperandSize = OPNONE -- ^ No operand size specified
       	        | OP8 	       -- ^ 8-bit integer operand
       	        | OP16 	       -- ^ 16-bit integer operand
       	        | OP32	       -- ^ 32-bit integer operand
       	        | OP64	       -- ^ 64-bit integer operand
       	        | OP128	       -- ^ 128-bit integer operand
       	        | OPF32	       -- ^ 32-bit floating point operand
       	        | OPF64	       -- ^ 64-bit floating point operand
       	        | OPF80	       -- ^ 80-bit floating point operand
  deriving (Int -> InstrOperandSize -> ShowS
[InstrOperandSize] -> ShowS
InstrOperandSize -> String
(Int -> InstrOperandSize -> ShowS)
-> (InstrOperandSize -> String)
-> ([InstrOperandSize] -> ShowS)
-> Show InstrOperandSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstrOperandSize] -> ShowS
$cshowList :: [InstrOperandSize] -> ShowS
show :: InstrOperandSize -> String
$cshow :: InstrOperandSize -> String
showsPrec :: Int -> InstrOperandSize -> ShowS
$cshowsPrec :: Int -> InstrOperandSize -> ShowS
Show, InstrOperandSize -> InstrOperandSize -> Bool
(InstrOperandSize -> InstrOperandSize -> Bool)
-> (InstrOperandSize -> InstrOperandSize -> Bool)
-> Eq InstrOperandSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstrOperandSize -> InstrOperandSize -> Bool
$c/= :: InstrOperandSize -> InstrOperandSize -> Bool
== :: InstrOperandSize -> InstrOperandSize -> Bool
$c== :: InstrOperandSize -> InstrOperandSize -> Bool
Eq)


-- | The disassembly routines return lists of the following datatype.  It
-- encodes both invalid byte sequences (with a useful error message, if
-- possible), or a valid instruction.  Both variants contain the list of
-- opcode bytes from which the instruction was decoded and the address of
-- the instruction.

data Instruction = 
    BadInstruction Word8 String Int [Word8]   -- ^ Invalid instruction
  | PseudoInstruction Int String                  -- ^ Pseudo instruction, e.g. label
  | Instruction { Instruction -> Opcode
opcode :: Opcode, 	      -- ^ Opcode of the instruction
       		  Instruction -> InstrOperandSize
opsize :: InstrOperandSize, -- ^ Operand size, if any
       		  Instruction -> [Operand]
operands :: [Operand],      -- ^ Instruction operands
                  Instruction -> Int
address :: Int,             -- ^ Start address of instruction
       		  Instruction -> [Word8]
bytes ::[Word8]	      -- ^ Instruction bytes
                 }			      -- ^ Valid instruction
  deriving (Instruction -> Instruction -> Bool
(Instruction -> Instruction -> Bool)
-> (Instruction -> Instruction -> Bool) -> Eq Instruction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Instruction -> Instruction -> Bool
$c/= :: Instruction -> Instruction -> Bool
== :: Instruction -> Instruction -> Bool
$c== :: Instruction -> Instruction -> Bool
Eq)

instance Show Instruction where
    show :: Instruction -> String
show = Instruction -> String
showIntel

data Instr = Bad Word8 String
            | Instr Opcode InstrOperandSize [Operand]

-- Show an integer as an 8-digit hexadecimal number with leading zeroes.

hex32 :: Int -> String
hex32 :: Int -> String
hex32 Int
i =
    let w :: Word32
        w :: Word32
w = Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i
        s :: String
s = Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
w String
""
    in Int -> ShowS
forall a. Int -> [a] -> [a]
take (Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) (Char -> String
forall a. a -> [a]
repeat Char
'0') String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s

-- Show a byte as an 2-digit hexadecimal number with leading zeroes.

hex8 :: Word8 -> String
hex8 :: Word8 -> String
hex8 Word8
i =
    let s :: String
s = Word8 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word8
i String
""
    in Int -> ShowS
forall a. Int -> [a] -> [a]
take (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) [Char
'0',Char
'0'] String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s


-- | Instructions can be displayed either in Intel or AT&T style (like in
-- GNU tools).
--
-- Intel style:
--
-- - Destination operand comes first, source second.
--
-- - No register or immediate prefixes.
--
-- - Memory operands are annotated with operand size.
--
-- - Hexadecimal numbers are suffixed with @H@ and prefixed with @0@ if
--   necessary.
--
-- AT&T style:
--
-- - Source operand comes first, destination second.
--
-- - Register names are prefixes with @%@.
--
-- - Immediates are prefixed with @$@.
--
-- - Hexadecimal numbers are prefixes with @0x@
--
-- - Opcodes are suffixed with operand size, when ambiguous otherwise.
data ShowStyle = IntelStyle		-- ^ Show in Intel style
                | AttStyle		-- ^ Show in AT&T style

-- | Show an instruction in Intel style.

showIntel :: Instruction -> [Char]
showIntel :: Instruction -> String
showIntel (BadInstruction Word8
b String
desc Int
pos [Word8]
bytes) =
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
    String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
desc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", byte=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showIntel (PseudoInstruction Int
pos String
s) =
    Int -> String
hex32 Int
pos String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"                          " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
showIntel (Instruction Opcode
op InstrOperandSize
opsize [] Int
pos [Word8]
bytes) = 
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
       Opcode -> String
showOp Opcode
op
showIntel (Instruction Opcode
op InstrOperandSize
opsize [Operand]
ops Int
pos [Word8]
bytes) = 
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
        String -> Int -> String
enlarge (Opcode -> String
showOp Opcode
op) Int
6 String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
       [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
"," ((Operand -> String) -> [Operand] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (InstrOperandSize -> Operand -> String
forall p. p -> Operand -> String
showIntelOps InstrOperandSize
opsize) [Operand]
ops))

-- | Show an instruction in AT&T style.

showAtt :: Instruction -> [Char]
showAtt :: Instruction -> String
showAtt (BadInstruction Word8
b String
desc Int
pos [Word8]
bytes) = 
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
       String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
desc String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", byte=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")"
showAtt (PseudoInstruction Int
pos String
s) =
    Int -> String
hex32 Int
pos String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"                          " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s
showAtt (Instruction Opcode
op InstrOperandSize
opsize [] Int
pos [Word8]
bytes) = 
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
       Opcode -> String
showOp Opcode
op String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Operand] -> InstrOperandSize -> String
showInstrSuffix [] InstrOperandSize
opsize
showAtt (Instruction Opcode
op InstrOperandSize
opsize [Operand]
ops Int
pos [Word8]
bytes) = 
    Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes String -> ShowS
forall a. [a] -> [a] -> [a]
++
       String -> Int -> String
enlarge (Opcode -> String
showOp Opcode
op String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
ops InstrOperandSize
opsize) Int
6 String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
       [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
"," ((Operand -> String) -> [Operand] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Operand -> String
showAttOps ([Operand] -> [Operand]
forall a. [a] -> [a]
reverse [Operand]
ops)))

showPosBytes :: Int -> [Word8] -> String
showPosBytes Int
pos [Word8]
bytes =
    Int -> String
hex32 Int
pos String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ 
      String -> Int -> String
enlarge ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
" " ((Word8 -> String) -> [Word8] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Word8 -> String
hex8 [Word8]
bytes))) Int
30

enlarge :: String -> Int -> String
enlarge String
s Int
i = String
s String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> ShowS
forall a. Int -> [a] -> [a]
take (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) (Char -> String
forall a. a -> [a]
repeat Char
' ')

opSizeSuffix :: InstrOperandSize -> String
opSizeSuffix InstrOperandSize
OPNONE = String
""
opSizeSuffix InstrOperandSize
OP8 = String
"b"
opSizeSuffix InstrOperandSize
OP16 = String
"w"
opSizeSuffix InstrOperandSize
OP32 = String
"l"
opSizeSuffix InstrOperandSize
OP64 = String
"q"
opSizeSuffix InstrOperandSize
OP128 = String
"dq"
opSizeSuffix InstrOperandSize
OPF32 = String
"s"
opSizeSuffix InstrOperandSize
OPF64 = String
"l"
opSizeSuffix InstrOperandSize
OPF80 = String
"t"

showInstrSuffix :: [Operand] -> InstrOperandSize -> String
showInstrSuffix [] InstrOperandSize
sz = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpImm Word32
_) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
--showInstrSuffix ((OpReg _ _) : []) s = ""
showInstrSuffix ((OpReg String
_ Int
_) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
OPNONE
showInstrSuffix ((OpFPReg Int
_) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpAddr Word32
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpAddr Word32
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpInd String
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpInd String
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpIndDisp String
_ Int
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpIndDisp String
_ Int
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpBaseIndex String
_ String
_ Int
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpBaseIndex String
_ String
_ Int
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpIndexDisp String
_ Int
_ Int
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpIndexDisp String
_ Int
_ Int
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz
showInstrSuffix ((OpBaseIndexDisp String
_ String
_ Int
_ Int
_ InstrOperandSize
OPNONE) : [Operand]
os) InstrOperandSize
s = [Operand] -> InstrOperandSize -> String
showInstrSuffix [Operand]
os InstrOperandSize
s
showInstrSuffix ((OpBaseIndexDisp String
_ String
_ Int
_ Int
_ InstrOperandSize
sz) : [Operand]
os) InstrOperandSize
s = InstrOperandSize -> String
opSizeSuffix InstrOperandSize
sz

-- showInstrOperandSize ops OPNONE | noRegop ops = ""
-- showInstrOperandSize ops OP8 | noRegop ops = "b"
-- showInstrOperandSize ops OP16 | noRegop ops = "w"
-- showInstrOperandSize ops OP32 | noRegop ops = "l"
-- showInstrOperandSize ops OPF32 | noRegop ops = "s"
-- showInstrOperandSize ops OP64 | noRegop ops = "q"
-- showInstrOperandSize ops OPF64 | noRegop ops = "l"
-- showInstrOperandSize ops OPF80 | noRegop ops = "e"
-- showInstrOperandSize ops OP128 | noRegop ops = ""
-- showInstrOperandSize _ _ = ""

-- noRegop ops = null (filter isRegop ops)
-- isRegop (OpReg _ _) = True
-- isRegop _ = False

-- Show an immediate value in hexadecimal.

showImm :: Word32 -> String
showImm :: Word32 -> String
showImm Word32
i =
  String
"$0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
i String
""

showIntelImm :: Word32 -> String
showIntelImm :: Word32 -> String
showIntelImm Word32
i =
  let h :: String
h = Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
i String
"H"
      (Char
f:String
_) = String
h
  in (if Char -> Bool
isDigit Char
f then String
"" else String
"0") String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
h

-- Show an address in hexadecimal.

showAddr :: a -> String
showAddr a
i =  
  let w :: Word32
      w :: Word32
w = a -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i
  in String
"0x" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
w String
""
showIntelAddr :: a -> String
showIntelAddr a
i = 
  let w :: Word32
      w :: Word32
w = a -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
i
      h :: String
h = Word32 -> ShowS
forall a. (Integral a, Show a) => a -> ShowS
showHex Word32
w String
"H"
      (Char
f:String
_) = String
h
  in (if Char -> Bool
isDigit Char
f then String
"" else String
"0") String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
h

-- | Disassemble a block of memory.  Starting at the location
-- pointed to by the given pointer, the given number of bytes are
-- disassembled.

disassembleBlock :: Ptr Word8 -> Int -> IO (Either ParseError [Instruction])
disassembleBlock :: Ptr Word8 -> Int -> IO (Either ParseError [Instruction])
disassembleBlock Ptr Word8
ptr Int
len = 
    Config -> Ptr Word8 -> Int -> IO (Either ParseError [Instruction])
disassembleBlockWithConfig Config
defaultConfig{confStartAddr :: Word32
confStartAddr = Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Ptr Word8 -> Ptr Any -> Int
forall a b. Ptr a -> Ptr b -> Int
minusPtr Ptr Word8
ptr Ptr Any
forall a. Ptr a
nullPtr)} 
                               Ptr Word8
ptr Int
len

disassembleBlockWithConfig :: Config -> Ptr Word8 -> Int -> IO (Either ParseError [Instruction])
disassembleBlockWithConfig :: Config -> Ptr Word8 -> Int -> IO (Either ParseError [Instruction])
disassembleBlockWithConfig Config
config Ptr Word8
ptr Int
len = do
  [Word8]
l <- Ptr Word8 -> Int -> Int -> [Word8] -> IO [Word8]
toList Ptr Word8
ptr Int
len Int
0 []
  PState -> [Word8] -> IO (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions (Config -> PState
configToState Config
config) ([Word8] -> [Word8]
forall a. [a] -> [a]
reverse [Word8]
l)
  where 
  toList :: (Ptr Word8) -> Int -> Int -> [Word8] -> IO [Word8]
  toList :: Ptr Word8 -> Int -> Int -> [Word8] -> IO [Word8]
toList Ptr Word8
ptr Int
len Int
idx [Word8]
acc | Int
idx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len =
       	   do Word8
p <- Ptr Word8 -> Int -> IO Word8
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr Word8
ptr Int
idx
       	      Ptr Word8 -> Int -> Int -> [Word8] -> IO [Word8]
toList Ptr Word8
ptr Int
len (Int
idx Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word8
p Word8 -> [Word8] -> [Word8]
forall a. a -> [a] -> [a]
: [Word8]
acc)
--       	      return (p : r)
  toList Ptr Word8
ptr Int
len Int
idx [Word8]
acc | Int
idx Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len = [Word8] -> IO [Word8]
forall (m :: * -> *) a. Monad m => a -> m a
return [Word8]
acc

-- | Disassemble the contents of the given array.

disassembleArray :: (Monad m, IArray a Word8, Ix i) =>
                    a i Word8 -> m (Either ParseError [Instruction])
disassembleArray :: a i Word8 -> m (Either ParseError [Instruction])
disassembleArray a i Word8
arr = Config -> a i Word8 -> m (Either ParseError [Instruction])
forall (m :: * -> *) (a :: * -> * -> *) i.
(Monad m, IArray a Word8, Ix i) =>
Config -> a i Word8 -> m (Either ParseError [Instruction])
disassembleArrayWithConfig Config
defaultConfig a i Word8
arr

disassembleArrayWithConfig :: (Monad m, IArray a Word8, Ix i) => Config ->
                             a i Word8 -> m (Either ParseError [Instruction])
disassembleArrayWithConfig :: Config -> a i Word8 -> m (Either ParseError [Instruction])
disassembleArrayWithConfig Config
config a i Word8
arr =
  let l :: [Word8]
l = a i Word8 -> [Word8]
forall (a :: * -> * -> *) e i. (IArray a e, Ix i) => a i e -> [e]
elems a i Word8
arr
  in PState -> [Word8] -> m (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions (Config -> PState
configToState Config
config) [Word8]
l

-- | Disassemble the contents of the given list.

disassembleList :: (Monad m) =>
                   [Word8] -> m (Either ParseError [Instruction])
disassembleList :: [Word8] -> m (Either ParseError [Instruction])
disassembleList [Word8]
ls = Config -> [Word8] -> m (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
Config -> [Word8] -> m (Either ParseError [Instruction])
disassembleListWithConfig Config
defaultConfig [Word8]
ls

disassembleListWithConfig :: (Monad m) => Config ->
                   [Word8] -> m (Either ParseError [Instruction])
disassembleListWithConfig :: Config -> [Word8] -> m (Either ParseError [Instruction])
disassembleListWithConfig Config
config [Word8]
ls =
    PState -> [Word8] -> m (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions (Config -> PState
configToState Config
config) [Word8]
ls

disassembleFile :: String -> IO (Either ParseError [Instruction])
disassembleFile String
filename = Config -> String -> IO (Either ParseError [Instruction])
disassembleFileWithConfig Config
defaultConfig String
filename

disassembleFileWithConfig :: Config -> String -> IO (Either ParseError [Instruction])
disassembleFileWithConfig Config
config String
filename = do
  String
l <- String -> IO String
readFile String
filename
  PState -> [Word8] -> IO (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions (Config -> PState
configToState Config
config) ((Char -> Word8) -> String -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) String
l)

instrToString :: [Instruction] -> ShowStyle -> [String]
instrToString [Instruction]
insts ShowStyle
style =
  (Instruction -> String) -> [Instruction] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Instruction -> String
showInstr [Instruction]
insts
 where
 showInstr :: Instruction -> String
showInstr = case ShowStyle
style of
       	  ShowStyle
IntelStyle -> Instruction -> String
showIntel
       	  ShowStyle
AttStyle -> Instruction -> String
showAtt

-- | Test function for disassembling the contents of a binary file and
-- displaying it in the provided style ("IntelStyle" or "AttStyle").

testFile :: FilePath -> ShowStyle -> IO ()
testFile :: String -> ShowStyle -> IO ()
testFile String
fname ShowStyle
style = do
  String
l <- String -> IO String
readFile String
fname
  Either ParseError [Instruction]
i <- PState -> [Word8] -> IO (Either ParseError [Instruction])
forall (m :: * -> *).
Monad m =>
PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions PState
defaultState ((Char -> Word8) -> String -> [Word8]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) String
l)
  case Either ParseError [Instruction]
i of
    Left ParseError
err -> String -> IO ()
putStrLn (ParseError -> String
forall a. Show a => a -> String
show ParseError
err)
    Right [Instruction]
i' -> (Instruction -> IO ()) -> [Instruction] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (String -> IO ()
putStrLn (String -> IO ())
-> (Instruction -> String) -> Instruction -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Instruction -> String
showInstr) [Instruction]
i'
 where
 showInstr :: Instruction -> String
showInstr = case ShowStyle
style of
       	  ShowStyle
IntelStyle -> Instruction -> String
showIntel
       	  ShowStyle
AttStyle -> Instruction -> String
showAtt

-- This is the state maintained by the disassembler.

data PState = PState { PState -> OperandSize
defaultBitMode :: OperandSize,
       	               PState -> OperandSize
operandBitMode :: OperandSize,
       	               PState -> OperandSize
addressBitMode :: OperandSize,
       	               PState -> Bool
in64BitMode :: Bool,
                       PState -> [Word8]
prefixes :: [Word8],
       	               PState -> Word32
startAddr :: Word32
                      }

data Config = Config {Config -> OperandSize
confDefaultBitMode :: OperandSize,
                      Config -> OperandSize
confOperandBitMode :: OperandSize,
                      Config -> OperandSize
confAddressBitMode :: OperandSize,
                      Config -> Bool
confIn64BitMode        :: Bool,
                      Config -> Word32
confStartAddr          :: Word32}

defaultConfig :: Config
defaultConfig = Config :: OperandSize
-> OperandSize -> OperandSize -> Bool -> Word32 -> Config
Config{ confDefaultBitMode :: OperandSize
confDefaultBitMode = OperandSize
BIT32,
       	                confOperandBitMode :: OperandSize
confOperandBitMode = OperandSize
BIT32, 
       	                confAddressBitMode :: OperandSize
confAddressBitMode = OperandSize
BIT32, 
       	                confIn64BitMode :: Bool
confIn64BitMode = Bool
False,
       	                confStartAddr :: Word32
confStartAddr = Word32
0}

configToState :: Config -> PState
configToState (Config OperandSize
defBitMode OperandSize
opMode OperandSize
addrMode Bool
in64 Word32
confStartAddr) =
    PState
defaultState{defaultBitMode :: OperandSize
defaultBitMode = OperandSize
defBitMode,
                 operandBitMode :: OperandSize
operandBitMode = OperandSize
opMode,
                 addressBitMode :: OperandSize
addressBitMode = OperandSize
addrMode,
                 in64BitMode :: Bool
in64BitMode = Bool
in64,
                 startAddr :: Word32
startAddr = Word32
confStartAddr}
           
-- Default state to be used if no other is given to the disassembly
-- routines.

defaultState :: PState
defaultState = PState :: OperandSize
-> OperandSize
-> OperandSize
-> Bool
-> [Word8]
-> Word32
-> PState
PState { defaultBitMode :: OperandSize
defaultBitMode = OperandSize
BIT32,
       	          operandBitMode :: OperandSize
operandBitMode = OperandSize
BIT32, 
       	          addressBitMode :: OperandSize
addressBitMode = OperandSize
BIT32, 
       	          in64BitMode :: Bool
in64BitMode = Bool
False,
       	          prefixes :: [Word8]
prefixes = [],
       	          startAddr :: Word32
startAddr = Word32
0}

type Word8Parser a = GenParser Word8 PState a

parseInstructions :: PState -> [Word8] -> m (Either ParseError [Instruction])
parseInstructions PState
st [Word8]
l =
    Either ParseError [Instruction]
-> m (Either ParseError [Instruction])
forall (m :: * -> *) a. Monad m => a -> m a
return (GenParser Word8 PState [Instruction]
-> PState -> String -> [Word8] -> Either ParseError [Instruction]
forall tok st a.
GenParser tok st a -> st -> String -> [tok] -> Either ParseError a
runParser GenParser Word8 PState [Instruction]
instructionSequence PState
st String
"memory block" [Word8]
l)

-- Parse a possibly empty sequence of instructions.

instructionSequence :: GenParser Word8 PState [Instruction]
instructionSequence = ParsecT [Word8] PState Identity Instruction
-> GenParser Word8 PState [Instruction]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [Word8] PState Identity Instruction
instruction

-- Parse a single instruction.  The result is either a valid instruction
-- or an indicator that there starts no valid instruction at the current
-- position.

instruction :: ParsecT [Word8] PState Identity Instruction
instruction = do
    SourcePos
startPos' <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
    let startPos :: Int
startPos = SourcePos -> Int
sourceColumn SourcePos
startPos' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
    [Word8]
input <- ParsecT [Word8] PState Identity [Word8]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    PState -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState PState
st{operandBitMode :: OperandSize
operandBitMode = PState -> OperandSize
defaultBitMode PState
st,
                 addressBitMode :: OperandSize
addressBitMode = PState -> OperandSize
defaultBitMode PState
st,
               prefixes :: [Word8]
prefixes = []}
    ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [Word8] PState Identity ()
parsePrefix
    Word8
b <- Word8Parser Word8
anyWord8
    case Word8
-> [(Word8, Word8 -> Word8Parser Instr)]
-> Maybe (Word8 -> Word8Parser Instr)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Word8
b [(Word8, Word8 -> Word8Parser Instr)]
oneByteOpCodeMap of
      Just Word8 -> Word8Parser Instr
p -> do Instr
i <- Word8 -> Word8Parser Instr
p Word8
b
       		   SourcePos
endPos' <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
       		   let endPos :: Int
endPos = SourcePos -> Int
sourceColumn SourcePos
endPos' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
		   case Instr
i of
       		     Instr Opcode
oc InstrOperandSize
opsize [Operand]
ops -> do
       	               Instruction -> ParsecT [Word8] PState Identity Instruction
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction -> ParsecT [Word8] PState Identity Instruction)
-> Instruction -> ParsecT [Word8] PState Identity Instruction
forall a b. (a -> b) -> a -> b
$ Opcode
-> InstrOperandSize -> [Operand] -> Int -> [Word8] -> Instruction
Instruction Opcode
oc InstrOperandSize
opsize [Operand]
ops
       		            (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (PState -> Word32
startAddr PState
st) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
startPos)
       		            (Int -> [Word8] -> [Word8]
forall a. Int -> [a] -> [a]
take (Int
endPos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
startPos) [Word8]
input)
       	             Bad Word8
b String
desc ->
       	               Instruction -> ParsecT [Word8] PState Identity Instruction
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction -> ParsecT [Word8] PState Identity Instruction)
-> Instruction -> ParsecT [Word8] PState Identity Instruction
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Int -> [Word8] -> Instruction
BadInstruction Word8
b String
desc 
       		            (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (PState -> Word32
startAddr PState
st) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
startPos)
       		            (Int -> [Word8] -> [Word8]
forall a. Int -> [a] -> [a]
take (Int
endPos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
startPos) [Word8]
input)
      Maybe (Word8 -> Word8Parser Instr)
Nothing -> do Bad Word8
b String
desc <- Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
		    SourcePos
endPos' <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
       		    let endPos :: Int
endPos = SourcePos -> Int
sourceColumn SourcePos
endPos' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
       		    Instruction -> ParsecT [Word8] PState Identity Instruction
forall (m :: * -> *) a. Monad m => a -> m a
return (Instruction -> ParsecT [Word8] PState Identity Instruction)
-> Instruction -> ParsecT [Word8] PState Identity Instruction
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Int -> [Word8] -> Instruction
BadInstruction Word8
b String
desc 
       	                (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (PState -> Word32
startAddr PState
st) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
startPos)
       		        (Int -> [Word8] -> [Word8]
forall a. Int -> [a] -> [a]
take (Int
endPos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
startPos) [Word8]
input)

toggleBitMode :: OperandSize -> OperandSize
toggleBitMode OperandSize
BIT16 = OperandSize
BIT32
toggleBitMode OperandSize
BIT32 = OperandSize
BIT16

rex_B :: Integer
rex_B = Integer
0x1
rex_X :: Integer
rex_X = Integer
0x2
rex_R :: Word8
rex_R = Word8
0x4
rex_W :: Word8
rex_W = Word8
0x8

-- Return True if the given REX prefix bit appears in the list of current
-- instruction prefixes, False otherwise.

hasREX :: Word8 -> PState -> Bool
hasREX Word8
rex PState
st =
    let rexs :: [Word8]
rexs = (Word8 -> Bool) -> [Word8] -> [Word8]
forall a. (a -> Bool) -> [a] -> [a]
filter (\ Word8
b -> Word8
b Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0x40 Bool -> Bool -> Bool
&& Word8
b Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0x4f) (PState -> [Word8]
prefixes PState
st) in
       case [Word8]
rexs of
         (Word8
r : [Word8]
_) -> if Word8
r Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
rex Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
rex then Bool
True else Bool
False
         [Word8]
_ -> Bool
False

-- Return True if the given prefix appears in the list of current
-- instruction prefixes, False otherwise.

hasPrefix :: Word8 -> PState -> Bool
hasPrefix Word8
b PState
st = Word8
b Word8 -> [Word8] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` PState -> [Word8]
prefixes PState
st

addPrefix :: Word8 -> ParsecT s PState m ()
addPrefix Word8
b = do
    PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    PState -> ParsecT s PState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState PState
st{prefixes :: [Word8]
prefixes = Word8
b Word8 -> [Word8] -> [Word8]
forall a. a -> [a] -> [a]
: PState -> [Word8]
prefixes PState
st}

-- Parse a single prefix byte and remember it in the parser state.  If in
-- 64-bit mode, accept REX prefixes.

parsePrefix :: ParsecT [Word8] PState Identity ()
parsePrefix = do
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0xf0 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- LOCK
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0xf2 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- REPNE/REPNZ
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0xf3 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- REP or REPE/REPZ
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x2e Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- CS segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x36 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- SS segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x3e Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- DS segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x26 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- ES segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x64 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- FS segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x65 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- GS segment override
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x2e Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- branch not taken
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x3e Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix) -- branch taken
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    do Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x66 -- operand-size override
       PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       PState -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState PState
st{operandBitMode :: OperandSize
operandBitMode = OperandSize -> OperandSize
toggleBitMode (PState -> OperandSize
operandBitMode PState
st)}
       Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix Word8
0x66
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
    do Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x67 -- address-size override
       PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       PState -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState PState
st{addressBitMode :: OperandSize
addressBitMode = OperandSize -> OperandSize
toggleBitMode (PState -> OperandSize
addressBitMode PState
st)}
       Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix Word8
0x66
  ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>  do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
          if PState -> Bool
in64BitMode PState
st 
            then    (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x40 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x41 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x42 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x43 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x44 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x45 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x46 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x47 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x48 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x49 Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4a Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4b Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4c Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4d Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4e Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
                     ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
-> ParsecT [Word8] PState Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
                     (Word8 -> Word8Parser Word8
forall p (m :: * -> *) a u.
(Stream p m a, Show a, Eq a) =>
a -> ParsecT p u m a
word8 Word8
0x4f Word8Parser Word8
-> (Word8 -> ParsecT [Word8] PState Identity ())
-> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word8 -> ParsecT [Word8] PState Identity ()
forall (m :: * -> *) s. Monad m => Word8 -> ParsecT s PState m ()
addPrefix)
             else ParsecT [Word8] PState Identity ()
forall tok st a. GenParser tok st a
pzero

-- Accept the single unsigned byte B.

word8 :: a -> ParsecT p u m a
word8 a
b = do
    (a -> String)
-> (SourcePos -> a -> p -> SourcePos)
-> (a -> Maybe a)
-> ParsecT p u m a
forall s (m :: * -> *) t a u.
Stream s m t =>
(t -> String)
-> (SourcePos -> t -> s -> SourcePos)
-> (t -> Maybe a)
-> ParsecT s u m a
tokenPrim a -> String
forall a. Show a => a -> String
showByte SourcePos -> a -> p -> SourcePos
forall p p. SourcePos -> p -> p -> SourcePos
nextPos a -> Maybe a
testByte
  where
  showByte :: a -> String
showByte a
by = a -> String
forall a. Show a => a -> String
show a
by
  nextPos :: SourcePos -> p -> p -> SourcePos
nextPos SourcePos
pos p
x p
xs = SourcePos -> Int -> SourcePos
incSourceColumn SourcePos
pos Int
1
  testByte :: a -> Maybe a
testByte a
by = if a
b a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
by then a -> Maybe a
forall a. a -> Maybe a
Just a
by else Maybe a
forall a. Maybe a
Nothing

-- Accept and return a single unsigned byte.

anyWord8 :: Word8Parser Word8
anyWord8 :: Word8Parser Word8
anyWord8 = do
    (Word8 -> String)
-> (SourcePos -> Word8 -> [Word8] -> SourcePos)
-> (Word8 -> Maybe Word8)
-> Word8Parser Word8
forall s (m :: * -> *) t a u.
Stream s m t =>
(t -> String)
-> (SourcePos -> t -> s -> SourcePos)
-> (t -> Maybe a)
-> ParsecT s u m a
tokenPrim Word8 -> String
forall a. Show a => a -> String
showByte SourcePos -> Word8 -> [Word8] -> SourcePos
forall p p. SourcePos -> p -> p -> SourcePos
nextPos Word8 -> Maybe Word8
forall a. a -> Maybe a
testByte
  where
  showByte :: a -> String
showByte a
by = a -> String
forall a. Show a => a -> String
show a
by
  nextPos :: SourcePos -> p -> p -> SourcePos
nextPos SourcePos
pos p
x p
xs = SourcePos -> Int -> SourcePos
incSourceColumn SourcePos
pos Int
1
  testByte :: a -> Maybe a
testByte a
by =  a -> Maybe a
forall a. a -> Maybe a
Just a
by

-- Accept any 8-bit signed byte.

anyInt8 :: Word8Parser Int8
anyInt8 :: Word8Parser Int8
anyInt8 = do
   Word8
b <- Word8Parser Word8
anyWord8
   let i :: Int8
       i :: Int8
i = Word8 -> Int8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b
   Int8 -> Word8Parser Int8
forall (m :: * -> *) a. Monad m => a -> m a
return Int8
i

-- Accept any 16-bit unsigned word.

anyWord16 :: ParsecT [Word8] PState Identity Word16
anyWord16 = do
     Word8
b0 <- Word8Parser Word8
anyWord8
     Word8
b1 <- Word8Parser Word8
anyWord8
     let w0, w1 :: Word16
         w0 :: Word16
w0 = Word8 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b0
         w1 :: Word16
w1 = Word8 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b1
     Word16 -> ParsecT [Word8] PState Identity Word16
forall (m :: * -> *) a. Monad m => a -> m a
return (Word16 -> ParsecT [Word8] PState Identity Word16)
-> Word16 -> ParsecT [Word8] PState Identity Word16
forall a b. (a -> b) -> a -> b
$ Word16
w0 Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.|. (Word16
w1 Word16 -> Int -> Word16
forall a. Bits a => a -> Int -> a
`shiftL` Int
8)

-- Accept any 16-bit signed integer.

anyInt16 :: ParsecT [Word8] PState Identity Int16
anyInt16 = do
     Word16
b0 <- ParsecT [Word8] PState Identity Word16
anyWord16
     let w0 :: Int16
         w0 :: Int16
w0 = Word16 -> Int16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
b0
     Int16 -> ParsecT [Word8] PState Identity Int16
forall (m :: * -> *) a. Monad m => a -> m a
return (Int16 -> ParsecT [Word8] PState Identity Int16)
-> Int16 -> ParsecT [Word8] PState Identity Int16
forall a b. (a -> b) -> a -> b
$ Int16
w0

-- Accept a 32-bit unsigned word.

anyWord32 :: ParsecT [Word8] PState Identity Word32
anyWord32 = do
     Word16
b0 <- ParsecT [Word8] PState Identity Word16
anyWord16
     Word16
b1 <- ParsecT [Word8] PState Identity Word16
anyWord16
     let w0, w1 :: Word32
         w0 :: Word32
w0 = Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
b0
         w1 :: Word32
w1 = Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
b1
     Word32 -> ParsecT [Word8] PState Identity Word32
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> ParsecT [Word8] PState Identity Word32)
-> Word32 -> ParsecT [Word8] PState Identity Word32
forall a b. (a -> b) -> a -> b
$ Word32
w0 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|. (Word32
w1 Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
`shiftL` Int
16)

-- Accept a 32-bit signed integer.

anyInt32 :: Word8Parser Int32
anyInt32 :: Word8Parser Int32
anyInt32 = do
     Word32
b0 <- ParsecT [Word8] PState Identity Word32
anyWord32
     let w0 :: Int32
         w0 :: Int32
w0 = Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
b0
     Int32 -> Word8Parser Int32
forall (m :: * -> *) a. Monad m => a -> m a
return (Int32 -> Word8Parser Int32) -> Int32 -> Word8Parser Int32
forall a b. (a -> b) -> a -> b
$ Int32
w0

-- Accept a 64-bit unsigned word.

anyWord64 :: Word8Parser Word64
anyWord64 :: Word8Parser Word64
anyWord64 = do
     Word32
b0 <- ParsecT [Word8] PState Identity Word32
anyWord32
     Word32
b1 <- ParsecT [Word8] PState Identity Word32
anyWord32
     let w0, w1 :: Word64
         w0 :: Word64
w0 = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
b0
         w1 :: Word64
w1 = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
b1
     Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64 -> Word8Parser Word64) -> Word64 -> Word8Parser Word64
forall a b. (a -> b) -> a -> b
$ Word64
w0 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
w1 Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32)

-- Accept a 64-bit signed integer.

anyInt64 :: Word8Parser Int64
anyInt64 :: Word8Parser Int64
anyInt64 = do
     Word64
b0 <- Word8Parser Word64
anyWord64
     let w0 :: Int64
         w0 :: Int64
w0 = Word64 -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
b0
     Int64 -> Word8Parser Int64
forall (m :: * -> *) a. Monad m => a -> m a
return (Int64 -> Word8Parser Int64) -> Int64 -> Word8Parser Int64
forall a b. (a -> b) -> a -> b
$ Int64
w0

-- Accept a 16-bit word for 16-bit operand-size, a 32-bit word for
-- 32-bit operand-size, or a 64-bit word in 64-bit mode.

anyWordV :: Word8Parser Word64
anyWordV :: Word8Parser Word64
anyWordV = do
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    if PState -> Bool
in64BitMode PState
st
       then do Word64
w <- Word8Parser Word64
anyWord64
               Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
w
        else case PState -> OperandSize
operandBitMode PState
st of
              OperandSize
BIT16 -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
       	                  let w' :: Word64
       	                      w' :: Word64
w' = Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w
       	                  Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
w'
              OperandSize
BIT32 -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
       	                  let w' :: Word64
       	                      w' :: Word64
w' = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w
       	                  Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
w'

-- Accept a 16-bit word for 16-bit operand-size or a 32-bit word for
-- 32-bit operand-size or 64-bit mode.

anyWordZ :: Word8Parser Word32
anyWordZ :: ParsecT [Word8] PState Identity Word32
anyWordZ = do
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    case PState -> OperandSize
operandBitMode PState
st of
      OperandSize
BIT16 -> do 
        Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
       	let w' :: Word32
       	    w' :: Word32
w' = Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w
       	Word32 -> ParsecT [Word8] PState Identity Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
w'
      OperandSize
BIT32 -> ParsecT [Word8] PState Identity Word32
anyWord32

-- Accept a 16-bit integer for 16-bit operand-size or a 32-bit word for
-- 32-bit operand-size or 64-bit mode.

anyIntZ :: Word8Parser Int32
anyIntZ :: Word8Parser Int32
anyIntZ = do
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    case PState -> OperandSize
operandBitMode PState
st of
      OperandSize
BIT16 -> do 
        Int16
w <- ParsecT [Word8] PState Identity Int16
anyInt16
       	let w' :: Int32
       	    w' :: Int32
w' = Int16 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int16
w
       	Int32 -> Word8Parser Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
w'
      OperandSize
BIT32 -> Word8Parser Int32
anyInt32

-- Accept a 32-bit far address for 16-bit operand-size or a 48-bit far
-- address for 32-bit operand-size.

anyWordP :: Word8Parser Word64
anyWordP :: Word8Parser Word64
anyWordP = do
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    case PState -> OperandSize
operandBitMode PState
st of
      OperandSize
BIT16 -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
       	          let w' :: Word64
       	              w' :: Word64
w' = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w
		  Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
w'
      OperandSize
_ -> do Word32
w1 <- ParsecT [Word8] PState Identity Word32
anyWord32
       	      Word16
w2 <- ParsecT [Word8] PState Identity Word16
anyWord16
              let w1', w2' :: Word64
       	          w1' :: Word64
w1' = Word32 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w1
                  w2' :: Word64
w2' = Word16 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w2
       	      Word64 -> Word8Parser Word64
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64
w1' Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
w2' Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
`shiftL` Int
32))

oneByteOpCodeMap :: [(Word8, Word8 -> Word8Parser Instr)]
oneByteOpCodeMap =
    [(Word8
0x00, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x01, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x02, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x03, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x04, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x05, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADD),
     (Word8
0x06, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"es")),
     (Word8
0x07, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePOPSeg String
"es")),
     (Word8
0x08, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x09, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x0a, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x0b, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x0c, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x0d, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
OR),
     (Word8
0x0e, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"cs")),
     (Word8
0x0f, Word8 -> Word8Parser Instr
twoByteEscape),

     (Word8
0x10, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x11, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x12, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x13, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x14, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x15, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
ADC),
     (Word8
0x16, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"ss")),
     (Word8
0x17, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePOPSeg String
"ss")),
     (Word8
0x18, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x19, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x1a, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x1b, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x1c, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x1d, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SBB),
     (Word8
0x1e, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"ds")),
     (Word8
0x1f, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (String -> Word8 -> Word8Parser Instr
parsePOPSeg String
"ds")),

     (Word8
0x20, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x21, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x22, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x23, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x24, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x25, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
AND),
     (Word8
0x26, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- ES segment override prefix
     (Word8
0x27, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
DAA InstrOperandSize
OPNONE)),
     (Word8
0x28, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x29, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x2a, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x2b, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x2c, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x2d, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
SUB),
     (Word8
0x2e, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- CS segment override prefix
     (Word8
0x2f, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
DAS InstrOperandSize
OPNONE)),

     (Word8
0x30, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x31, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x32, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x33, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x34, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x35, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
XOR),
     (Word8
0x36, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- SS segment override prefix
     (Word8
0x37, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
AAA InstrOperandSize
OPNONE)),
     (Word8
0x38, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x39, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x3a, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x3b, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x3c, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x3d, Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
CMP),
     (Word8
0x3e, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- DS segment override prefix
     (Word8
0x3f, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
AAS InstrOperandSize
OPNONE)),

     (Word8
0x40, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC), -- REX Prefix in 64-bit mode
     (Word8
0x41, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC), -- ...
     (Word8
0x42, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x43, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x44, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x45, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x46, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x47, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseINC),
     (Word8
0x48, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x49, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4a, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4b, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4c, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4d, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4e, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),
     (Word8
0x4f, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseDEC),

     (Word8
0x50, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x51, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x52, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x53, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x54, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x55, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x56, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x57, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePUSH),
     (Word8
0x58, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x59, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5a, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5b, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5c, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5d, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5e, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),
     (Word8
0x5f, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Show a, Bits a) =>
a -> ParsecT s PState Identity Instr
parsePOP),

     (Word8
0x60, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall t s. t -> ParsecT s PState Identity Instr
parsePUSHA),
     (Word8
0x61, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall t s. t -> ParsecT s PState Identity Instr
parsePOPA),
     (Word8
0x62, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseBOUND),
     (Word8
0x63, (Word8 -> Word8Parser Instr)
-> (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
choose64BitMode Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseARPL Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMOVSXD), -- MOVSXD in 64-bit mode
     (Word8
0x64, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- FS segment override prefix
     (Word8
0x65, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- GS segment override prefix
     (Word8
0x66, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- operand-size prefix
     (Word8
0x67, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- address-size prefix
     (Word8
0x68, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parsePUSHImm),
     (Word8
0x69, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseIMUL),
     (Word8
0x6a, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parsePUSHImm),
     (Word8
0x6b, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseIMUL),
     (Word8
0x6c, Word8 -> Word8Parser Instr
forall t (m :: * -> *) s.
(Eq t, Num t, Monad m) =>
t -> ParsecT s PState m Instr
parseINS),
     (Word8
0x6d, Word8 -> Word8Parser Instr
forall t (m :: * -> *) s.
(Eq t, Num t, Monad m) =>
t -> ParsecT s PState m Instr
parseINS),
     (Word8
0x6e, Word8 -> Word8Parser Instr
forall t (m :: * -> *) s.
(Eq t, Num t, Monad m) =>
t -> ParsecT s PState m Instr
parseOUTS),
     (Word8
0x6f, Word8 -> Word8Parser Instr
forall t (m :: * -> *) s.
(Eq t, Num t, Monad m) =>
t -> ParsecT s PState m Instr
parseOUTS),

     (Word8
0x70, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x71, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x72, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x73, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x74, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x75, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x76, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x77, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x78, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x79, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7a, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7b, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7c, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7d, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7e, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),
     (Word8
0x7f, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccShort),

     (Word8
0x80, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp1),
     (Word8
0x81, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp1),
     (Word8
0x82, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp1),
     (Word8
0x83, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp1),
     (Word8
0x84, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseTEST),
     (Word8
0x85, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseTEST),
     (Word8
0x86, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseXCHG),
     (Word8
0x87, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseXCHG),
     (Word8
0x88, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x89, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x8a, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x8b, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x8c, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x8d, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseLEA),
     (Word8
0x8e, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOV),
     (Word8
0x8f, Word8 -> Word8Parser Instr
parseGrp1A),

     (Word8
0x90, Word8 -> Word8Parser Instr
parse0x90), -- NOP, PAUSE(F3), XCHG r8,rAX
     (Word8
0x91, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x92, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x93, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x94, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x95, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x96, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x97, Word8 -> Word8Parser Instr
parseXCHGReg),
     (Word8
0x98, Word8 -> Word8Parser Instr
forall (m :: * -> *) t s. Monad m => t -> ParsecT s PState m Instr
parseCBW_CWDE_CDQE),
     (Word8
0x99, Word8 -> Word8Parser Instr
forall (m :: * -> *) t s. Monad m => t -> ParsecT s PState m Instr
parseCWD_CDQ_CQO),
     (Word8
0x9a, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseCALLF),
     (Word8
0x9b, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
WAIT InstrOperandSize
OPNONE),
     (Word8
0x9c, Word8 -> Word8Parser Instr
forall (m :: * -> *) t s. Monad m => t -> ParsecT s PState m Instr
parsePUSHF),
     (Word8
0x9d, Word8 -> Word8Parser Instr
forall (m :: * -> *) t s. Monad m => t -> ParsecT s PState m Instr
parsePOPF),
     (Word8
0x9e, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
SAHF InstrOperandSize
OPNONE),
     (Word8
0x9f, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
LAHF InstrOperandSize
OPNONE),

     (Word8
0xa0, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVImm),
     (Word8
0xa1, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVImm),
     (Word8
0xa2, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVImm),
     (Word8
0xa3, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVImm),
     (Word8
0xa4, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseMOVS),
     (Word8
0xa5, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseMOVS),
     (Word8
0xa6, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseCMPS),
     (Word8
0xa7, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseCMPS),
     (Word8
0xa8, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseTESTImm),
     (Word8
0xa9, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseTESTImm),
     (Word8
0xaa, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseSTOS),
     (Word8
0xab, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseSTOS),
     (Word8
0xac, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseLODS),
     (Word8
0xad, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseLODS),
     (Word8
0xae, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseSCAS),
     (Word8
0xaf, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseSCAS),

     (Word8
0xb0, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb1, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb2, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb3, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb4, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb5, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb6, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb7, Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg),
     (Word8
0xb8, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xb9, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xba, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xbb, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xbc, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xbd, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xbe, Word8 -> Word8Parser Instr
parseMOVImmToReg),
     (Word8
0xbf, Word8 -> Word8Parser Instr
parseMOVImmToReg),

     (Word8
0xc0, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xc1, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xc2, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseRETN),
     (Word8
0xc3, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseRETN),
     (Word8
0xc4, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
LES)),
     (Word8
0xc5, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode (Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
LDS)),
     (Word8
0xc6, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp11),
     (Word8
0xc7, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp11),
     (Word8
0xc8, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseENTER),
     (Word8
0xc9, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
LEAVE InstrOperandSize
OPNONE),
     (Word8
0xca, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericIw Opcode
RETF),
     (Word8
0xcb, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
RETF InstrOperandSize
OPNONE),
     (Word8
0xcc, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
INT3 InstrOperandSize
OPNONE),
     (Word8
0xcd, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericIb Opcode
INT),
     (Word8
0xce, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
INTO InstrOperandSize
OPNONE),
     (Word8
0xcf, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
IRET InstrOperandSize
OPNONE),

     (Word8
0xd0, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xd1, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xd2, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xd3, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp2),
     (Word8
0xd4, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericIb Opcode
AAM),
     (Word8
0xd5, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericIb Opcode
AAD),
     (Word8
0xd6, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved), -- reserved
     (Word8
0xd7, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
XLAT InstrOperandSize
OPNONE),
     (Word8
0xd8, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xd9, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xda, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xdb, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xdc, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xdd, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xde, Word8 -> Word8Parser Instr
parseESC),
     (Word8
0xdf, Word8 -> Word8Parser Instr
parseESC),

     (Word8
0xe0, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
LOOPNE),
     (Word8
0xe1, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
LOOPE),
     (Word8
0xe2, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
LOOP),
     (Word8
0xe3, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
JCXZ), -- depends on bit mode
     (Word8
0xe4, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseINImm),
     (Word8
0xe5, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseINImm),
     (Word8
0xe6, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseOUTImm),
     (Word8
0xe7, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseOUTImm),
     (Word8
0xe8, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJz Opcode
CALL),
     (Word8
0xe9, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJz Opcode
JMP),
     (Word8
0xea, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseJMPF),
     (Word8
0xeb, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
JMP),
     (Word8
0xec, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseIN),
     (Word8
0xed, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseIN),
     (Word8
0xee, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseOUT),
     (Word8
0xef, Word8 -> Word8Parser Instr
forall a s. (Eq a, Num a) => a -> ParsecT s PState Identity Instr
parseOUT),

     (Word8
0xf0, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- LOCK prefix
     (Word8
0xf1, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved), -- reserved
     (Word8
0xf2, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- REPNE prefix
     (Word8
0xf3, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidPrefix), -- REP/REPQ prefix
     (Word8
0xf4, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
HLT InstrOperandSize
OPNONE),
     (Word8
0xf5, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CMC InstrOperandSize
OPNONE),
     (Word8
0xf6, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp3),
     (Word8
0xf7, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseGrp3),
     (Word8
0xf8, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CLC InstrOperandSize
OPNONE),
     (Word8
0xf9, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
STC InstrOperandSize
OPNONE),
     (Word8
0xfa, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CLI InstrOperandSize
OPNONE),
     (Word8
0xfb, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
STI InstrOperandSize
OPNONE),
     (Word8
0xfc, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CLD InstrOperandSize
OPNONE),
     (Word8
0xfd, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
STD InstrOperandSize
OPNONE),
     (Word8
0xfe, Word8 -> Word8Parser Instr
parseGrp4),
     (Word8
0xff, Word8 -> Word8Parser Instr
parseGrp5)

     ]

parseInvalidPrefix :: Word8 -> m Instr
parseInvalidPrefix Word8
b = do
  Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> m Instr) -> Instr -> m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"invalid prefix"

parseInvalidOpcode :: Word8 -> m Instr
parseInvalidOpcode Word8
b = do
  Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> m Instr) -> Instr -> m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"invalid opcode"

parseReserved :: Word8 -> m Instr
parseReserved Word8
b = do
  Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> m Instr) -> Instr -> m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"reserved opcode"

parseUndefined :: a -> Word8 -> m Instr
parseUndefined a
name Word8
b = do
  Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> m Instr) -> Instr -> m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b (String
"undefined opcode: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
name)

parseUnimplemented :: Word8 -> m Instr
parseUnimplemented Word8
b = do
  Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> m Instr) -> Instr -> m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"not implemented yet"

invalidIn64BitMode :: (Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
invalidIn64BitMode Word8 -> ParsecT s PState m Instr
p Word8
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"invalid in 64-bit mode"
     else Word8 -> ParsecT s PState m Instr
p Word8
b

onlyIn64BitMode :: (Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
onlyIn64BitMode Word8 -> ParsecT s PState m Instr
p Word8
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then Word8 -> ParsecT s PState m Instr
p Word8
b
     else Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"only in 64-bit mode"

choose64BitMode :: (t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
choose64BitMode t -> ParsecT s PState m b
p32 t -> ParsecT s PState m b
p64 t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then t -> ParsecT s PState m b
p64 t
b
     else t -> ParsecT s PState m b
p32 t
b

chooseOperandSize :: (t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize t -> ParsecT s PState m b
p16 t -> ParsecT s PState m b
p32 t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case PState -> OperandSize
operandBitMode PState
st of
    OperandSize
BIT16 -> t -> ParsecT s PState m b
p16 t
b
    OperandSize
BIT32 -> t -> ParsecT s PState m b
p32 t
b

chooseAddressSize :: (t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseAddressSize t -> ParsecT s PState m b
p16 t -> ParsecT s PState m b
p32 t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case PState -> OperandSize
addressBitMode PState
st of
    OperandSize
BIT16 -> t -> ParsecT s PState m b
p16 t
b
    OperandSize
BIT32 -> t -> ParsecT s PState m b
p32 t
b

parseModRM :: ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM = do
  Word8
b <- Word8Parser Word8
anyWord8
  Word8 -> ParsecT [Word8] PState Identity (Word8, Word8, Word8)
forall (m :: * -> *) c.
(Monad m, Bits c, Num c) =>
c -> m (c, c, c)
parseModRM' Word8
b
parseModRM' :: c -> m (c, c, c)
parseModRM' c
b = do
  (c, c, c) -> m (c, c, c)
forall (m :: * -> *) a. Monad m => a -> m a
return (c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftR` Int
6, (c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftR` Int
3) c -> c -> c
forall a. Bits a => a -> a -> a
.&. c
7, (c
b c -> c -> c
forall a. Bits a => a -> a -> a
.&. c
7))

parseSIB :: ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseSIB = do
  Word8
b <- Word8Parser Word8
anyWord8
  Word8 -> ParsecT [Word8] PState Identity (Word8, Word8, Word8)
forall (m :: * -> *) c.
(Monad m, Bits c, Num c) =>
c -> m (c, c, c)
parseSIB' Word8
b
parseSIB' :: c -> m (c, c, c)
parseSIB' c
b = do
  (c, c, c) -> m (c, c, c)
forall (m :: * -> *) a. Monad m => a -> m a
return (c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftR` Int
6, (c
b c -> Int -> c
forall a. Bits a => a -> Int -> a
`shiftR` Int
3) c -> c -> c
forall a. Bits a => a -> a -> a
.&. c
7, (c
b c -> c -> c
forall a. Bits a => a -> a -> a
.&. c
7))

scaleToFactor :: a -> p
scaleToFactor a
0 = p
1
scaleToFactor a
1 = p
2
scaleToFactor a
2 = p
4
scaleToFactor a
3 = p
8


parseAddress32 :: InstrOperandSize ->
		  Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 :: InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
s = do
  Word8
b <- Word8Parser Word8
anyWord8
  InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
s Word8
b

parseAddress32' :: InstrOperandSize -> 
    Word8 ->
    Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' :: InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
opsize Word8
modrm = do
  (Word8
mod, Word8
reg_opc, Word8
rm) <- Word8 -> ParsecT [Word8] PState Identity (Word8, Word8, Word8)
forall (m :: * -> *) c.
(Monad m, Bits c, Num c) =>
c -> m (c, c, c)
parseModRM' Word8
modrm
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let opregnames :: [String]
opregnames = if PState -> Bool
in64BitMode PState
st Bool -> Bool -> Bool
&& Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
                     then [String]
regnames64
       	      else case PState -> OperandSize
operandBitMode PState
st of 
			OperandSize
BIT16 -> [String]
regnames16
       			OperandSize
BIT32 -> [String]
regnames32
  let addregnames :: [String]
addregnames = if PState -> Bool
in64BitMode PState
st Bool -> Bool -> Bool
&& Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
                      then [String]
regnames64
       	       else case PState -> OperandSize
addressBitMode PState
st of 
			OperandSize
BIT16 -> [String]
regnames16
       			OperandSize
BIT32 -> [String]
regnames32
  case Word8
mod of
    Word8
0 -> case Word8
rm of
            Word8
4 -> do 
	     (Word8
s, Word8
i, Word8
b) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseSIB
       	     case (Word8
i, Word8
b) of
               (Word8
4, Word8
5) -> do
                           Word32
disp <- ParsecT [Word8] PState Identity Word32
anyWord32
                           (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> InstrOperandSize -> Operand
OpAddr (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
disp) InstrOperandSize
opsize,
                                          String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
                                                (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
                                          Word8
mod, Word8
reg_opc, Word8
rm)
               (Word8
_, Word8
5) -> do
                           Word32
disp <- ParsecT [Word8] PState Identity Word32
anyWord32
                           (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> Int -> InstrOperandSize -> Operand
OpIndexDisp ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
                                               (Word8 -> Int
forall a p. (Eq a, Num a, Num p) => a -> p
scaleToFactor Word8
s)
                                               (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
disp)
                                               InstrOperandSize
opsize,
                                   String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
                                         (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
                                   Word8
mod, Word8
reg_opc, Word8
rm)
       	       (Word8
4, Word8
_) -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> InstrOperandSize -> Operand
OpInd ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b) InstrOperandSize
opsize,
       	                   String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			     (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       		           Word8
mod, Word8
reg_opc, Word8
rm)
       	       (Word8
_ ,Word8
_) -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> String -> Int -> InstrOperandSize -> Operand
OpBaseIndex 
       		              ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)
       	                      ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
       		              (Integer -> Int
forall a p. (Eq a, Num a, Num p) => a -> p
scaleToFactor (Word8 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
s))
			      InstrOperandSize
opsize,
       		            String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	                    Word8
mod, Word8
reg_opc, Word8
rm)
            Word8
5 -> do 
	     Word32
disp <- ParsecT [Word8] PState Identity Word32
anyWord32
       	     (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> InstrOperandSize -> Operand
OpAddr Word32
disp InstrOperandSize
opsize, 
       	             String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
		       (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	             Word8
mod, Word8
reg_opc, Word8
rm)
            Word8
_ -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> InstrOperandSize -> Operand
OpInd ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm) InstrOperandSize
opsize, 
       	          String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			(Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	          Word8
mod, Word8
reg_opc, Word8
rm)
    Word8
1 -> case Word8
rm of
            Word8
4 -> do 
	     (Word8
s, Word8
i, Word8
b) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseSIB
	     Int8
disp <- Word8Parser Int8
anyInt8
       	     case Word8
i of
       	       Word8
4 -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> InstrOperandSize -> Operand
OpIndDisp
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b) 
       		            (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
disp) InstrOperandSize
opsize,
       	                    String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       		            Word8
mod, Word8
reg_opc, Word8
rm)
       	       Word8
_ -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> String -> Int -> Int -> InstrOperandSize -> Operand
OpBaseIndexDisp
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
       		            (Integer -> Int
forall a p. (Eq a, Num a, Num p) => a -> p
scaleToFactor (Word8 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
s))
       		            (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
disp)
			    InstrOperandSize
opsize,
       		            String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	                    Word8
mod, Word8
reg_opc, Word8
rm)
            Word8
_ -> do Int8
disp <- Word8Parser Int8
anyInt8
                    (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> InstrOperandSize -> Operand
OpIndDisp
       			    ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm) 
       			    (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
disp)
			    InstrOperandSize
opsize,
       			    String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
                            Word8
mod, Word8
reg_opc, Word8
rm)
    Word8
2 -> case Word8
rm of
            Word8
4 -> do 
	     (Word8
s, Word8
i, Word8
b) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseSIB
	     Int32
disp <- Word8Parser Int32
anyInt32
             case Word8
i of
       	       Word8
4 -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> InstrOperandSize -> Operand
OpIndDisp
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)
       		            (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
disp)
			    InstrOperandSize
opsize,
       		            String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       		            Word8
mod, Word8
reg_opc, Word8
rm)
       	       Word8
_ -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> String -> Int -> Int -> InstrOperandSize -> Operand
OpBaseIndexDisp
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)
       		            ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
i)
       		            (Integer -> Int
forall a p. (Eq a, Num a, Num p) => a -> p
scaleToFactor (Word8 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
s))
       		            (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
disp)
			    InstrOperandSize
opsize,
       		            String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	                    Word8
mod, Word8
reg_opc, Word8
rm)
            Word8
_ -> do 
	     Int32
disp <- Word8Parser Int32
anyInt32
       	     (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> InstrOperandSize -> Operand
OpIndDisp
       	             ([String]
addregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
       	             (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
disp)
		     InstrOperandSize
opsize,
       	             String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
		       (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
       	             Word8
mod, Word8
reg_opc, Word8
rm)
    Word8
3 -> (Operand, Operand, Word8, Word8, Word8)
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
		   (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm),
                  String -> Int -> Operand
OpReg ([String]
opregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc)
		    (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg_opc),
                 Word8
mod, Word8
reg_opc, Word8
rm)

parseALU :: Opcode -> Word8 -> Word8Parser Instr
parseALU :: Opcode -> Word8 -> Word8Parser Instr
parseALU Opcode
op Word8
b = do
    InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
    case Word8
b Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x07 of
      Word8
0 -> do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
OP8 [Operand
op1,
       	           (String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
      Word8
1 -> do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
opsize [Operand
op1, Operand
op2]
      Word8
2 -> do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
OP8 
       	           [(String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
		       (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg), Operand
op1]
      Word8
3 -> do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
opsize [Operand
op2, Operand
op1]
      Word8
4 -> do Word8
b <- Word8Parser Word8
anyWord8
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
OP8 [(String -> Int -> Operand
OpReg String
"al" Int
0), (Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b))]
      Word8
5 -> do Word32
b <- ParsecT [Word8] PState Identity Word32
anyWordZ
              String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
              Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
op InstrOperandSize
opsize [(String -> Int -> Operand
OpReg String
rn Int
0), (Word32 -> Operand
OpImm Word32
b)]
      Word8
_ -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"no ALU opcode (internal error)"
    

parsePUSHSeg :: String -> Word8 -> Word8Parser Instr
parsePUSHSeg :: String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
r Word8
_ = do
     Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
OP16 [(String -> Int -> Operand
OpReg String
r Int
0)] -- FIXME: register number

parsePOPSeg :: String -> Word8 -> Word8Parser Instr
parsePOPSeg :: String -> Word8 -> Word8Parser Instr
parsePOPSeg String
r Word8
_ = do
     Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POP InstrOperandSize
OP16 [(String -> Int -> Operand
OpReg String
r Int
0)] -- FIXME: register number

parseGenericGvEw :: Opcode -> p -> Word8Parser Instr
parseGenericGvEw Opcode
name p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP16
  case Operand
op1 of
    OpReg String
_ Int
num -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP16 [Operand
op2, 
					       String -> Int -> Operand
OpReg ([String]
regnames16 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num]
    Operand
_ -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP8 [Operand
op2, Operand
op1]

parseGenericGvEb :: Opcode -> p -> Word8Parser Instr
parseGenericGvEb Opcode
name p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  case Operand
op1 of
    OpReg String
_ Int
num -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP8 [Operand
op2, 
					       String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num]
    Operand
_ -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP8 [Operand
op2, Operand
op1]

parseGenericGvEv :: Opcode -> p -> Word8Parser Instr
parseGenericGvEv Opcode
name p
b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
opsize [Operand
op2, Operand
op1]

parseGenericEvGv :: Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
name p
b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
opsize [Operand
op1, Operand
op2]

parseGenericEbGb :: Opcode -> p -> Word8Parser Instr
parseGenericEbGb Opcode
name p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP8 [Operand
op1, (String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
				(Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))]

parseGenericEv :: Opcode -> p -> Word8Parser Instr
parseGenericEv Opcode
name p
b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
_, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
opsize [Operand
op1]

twoByteOpCodeMap :: [(Word8, Word8 -> Word8Parser Instr)]
twoByteOpCodeMap = 
    [(Word8
0x00, Word8 -> Word8Parser Instr
parseGrp6),
     (Word8
0x01, Word8 -> Word8Parser Instr
parseGrp7),
     (Word8
0x02, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEw Opcode
LAR),
     (Word8
0x03, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEw Opcode
LSL),
     (Word8
0x04, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x05, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
onlyIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
SYSCALL InstrOperandSize
OPNONE)),
     (Word8
0x06, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CLTS InstrOperandSize
OPNONE),
     (Word8
0x07, (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
onlyIn64BitMode (Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
SYSCALL InstrOperandSize
OPNONE)),
     (Word8
0x08, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
INVD InstrOperandSize
OPNONE),
     (Word8
0x09, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
WBINVD InstrOperandSize
OPNONE),
     (Word8
0x0a, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x0b, Opcode -> Word8 -> Word8Parser Instr
forall (m :: * -> *) a. (Monad m, Show a) => a -> Word8 -> m Instr
parseUndefined Opcode
UD2),
     (Word8
0x0c, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x0d, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEv Opcode
NOP),
     (Word8
0x0e, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x0f, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),

     (Word8
0x10, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVUPS),
     (Word8
0x11, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVUPS),
     (Word8
0x12, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVLPS),
     (Word8
0x13, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVLPS),
     (Word8
0x14, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseUNPCKLPS),
     (Word8
0x15, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseUNPCKHPS),
     (Word8
0x16, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVHPS),
     (Word8
0x17, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVHPS),
     (Word8
0x18, Word8 -> Word8Parser Instr
parseGrp16),
     (Word8
0x19, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1a, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1b, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1c, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1d, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1e, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x1f, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEv Opcode
NOP),

     (Word8
0x20, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVCtrlDebug),
     (Word8
0x21, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVCtrlDebug),
     (Word8
0x22, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVCtrlDebug),
     (Word8
0x23, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVCtrlDebug),
     (Word8
0x24, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x25, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x26, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x27, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x28, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVAPS),
     (Word8
0x29, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseMOVAPS),
     (Word8
0x2a, Word8 -> Word8Parser Instr
parseCVTI2PS),
     (Word8
0x2b, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMOVNTPS),
     (Word8
0x2c, Word8 -> Word8Parser Instr
parseCVTTPS2PI),
     (Word8
0x2d, Word8 -> Word8Parser Instr
parseCVTPS2PI),
     (Word8
0x2e, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseUCOMISS),
     (Word8
0x2f, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseCOMISS),

     (Word8
0x30, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
WRMSR InstrOperandSize
OPNONE),
     (Word8
0x31, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
RDTSC InstrOperandSize
OPNONE),
     (Word8
0x32, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
RDMSR InstrOperandSize
OPNONE),
     (Word8
0x33, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
RDPMC InstrOperandSize
OPNONE),
     (Word8
0x34, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
SYSENTER InstrOperandSize
OPNONE),
     (Word8
0x35, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
SYSEXIT InstrOperandSize
OPNONE),
     (Word8
0x36, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x37, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x38, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x39, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3a, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3b, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3c, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3d, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3e, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x3f, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),

     (Word8
0x40, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x41, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x42, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x43, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x44, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x45, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x46, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x47, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x48, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x49, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4a, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4b, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4c, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4d, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4e, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),
     (Word8
0x4f, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseCMOVcc),

     (Word8
0x50, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMOVSKPS),
     (Word8
0x51, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseSQRTPS),
     (Word8
0x52, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseRSQRTPS),
     (Word8
0x53, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseRCPPS),
     (Word8
0x54, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseANDPS),
     (Word8
0x55, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseANDNPS),
     (Word8
0x56, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseORPS),
     (Word8
0x57, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseXORPS),
     (Word8
0x58, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseADDPS),
     (Word8
0x59, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMULPS),
     (Word8
0x5a, Word8 -> Word8Parser Instr
parseCVTPS2PD),
     (Word8
0x5b, Word8 -> Word8Parser Instr
parseCVTDQ2PS),
     (Word8
0x5c, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseSUBPS),
     (Word8
0x5d, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMINPS),
     (Word8
0x5e, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseDIVPS),
     (Word8
0x5f, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMAXPS),

     (Word8
0x60, Word8 -> Word8Parser Instr
parsePUNPCKLBW),
     (Word8
0x61, Word8 -> Word8Parser Instr
parsePUNPCKLWD),
     (Word8
0x62, Word8 -> Word8Parser Instr
parsePUNPCKLDQ),
     (Word8
0x63, Word8 -> Word8Parser Instr
parsePACKSSWB),
     (Word8
0x64, Word8 -> Word8Parser Instr
parsePCMPGTB),
     (Word8
0x65, Word8 -> Word8Parser Instr
parsePCMPGTW),
     (Word8
0x66, Word8 -> Word8Parser Instr
parsePCMPGTD),
     (Word8
0x67, Word8 -> Word8Parser Instr
parsePACKUSWB),
     (Word8
0x68, Word8 -> Word8Parser Instr
parsePUNPCKHBW),
     (Word8
0x69, Word8 -> Word8Parser Instr
parsePUNPCKHWD),
     (Word8
0x6a, Word8 -> Word8Parser Instr
parsePUNPCKHDQ),
     (Word8
0x6b, Word8 -> Word8Parser Instr
parsePACKSSDW),
     (Word8
0x6c, Word8 -> Word8Parser Instr
parsePUNPCKLQDQ),
     (Word8
0x6d, Word8 -> Word8Parser Instr
parsePUNPCKHQDQ),
     (Word8
0x6e, Word8 -> Word8Parser Instr
parseMOVD_Q),
     (Word8
0x6f, Word8 -> Word8Parser Instr
parseMOVQ),

     (Word8
0x70, Word8 -> Word8Parser Instr
parsePSHUFW),
     (Word8
0x71, Word8 -> Word8Parser Instr
parseGrp12),
     (Word8
0x72, Word8 -> Word8Parser Instr
parseGrp13),
     (Word8
0x73, Word8 -> Word8Parser Instr
parseGrp14),
     (Word8
0x74, Word8 -> Word8Parser Instr
parsePCMPEQB),
     (Word8
0x75, Word8 -> Word8Parser Instr
parsePCMPEQW),
     (Word8
0x76, Word8 -> Word8Parser Instr
parsePCMPEQD),
     (Word8
0x77, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
EMMS InstrOperandSize
OPNONE),
     (Word8
0x78, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseVMREAD),
     (Word8
0x79, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseVMWRITE),
     (Word8
0x7a, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x7b, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0x7c, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseHADDPS),
     (Word8
0x7d, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseHSUBPS),
     (Word8
0x7e, Word8 -> Word8Parser Instr
parseMOVD_Q),
     (Word8
0x7f, Word8 -> Word8Parser Instr
parseMOVQ),

     (Word8
0x80, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x81, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x82, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x83, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x84, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x85, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x86, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x87, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x88, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x89, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8a, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8b, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8c, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8d, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8e, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),
     (Word8
0x8f, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseJccLong),

     (Word8
0x90, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x91, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x92, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x93, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x94, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x95, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x96, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x97, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x98, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x99, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9a, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9b, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9c, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9d, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9e, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),
     (Word8
0x9f, Word8 -> Word8Parser Instr
forall a. (Num a, Bits a) => a -> Word8Parser Instr
parseSETcc),

     (Word8
0xa0, String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"fs"),
     (Word8
0xa1, String -> Word8 -> Word8Parser Instr
parsePOPSeg String
"fs"),
     (Word8
0xa2, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
CPUID InstrOperandSize
OPNONE),
     (Word8
0xa3, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
BT),
     (Word8
0xa4, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseSHLD),
     (Word8
0xa5, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseSHLD),
     (Word8
0xa6, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0xa7, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0xa8, String -> Word8 -> Word8Parser Instr
parsePUSHSeg String
"gs"),
     (Word8
0xa9, String -> Word8 -> Word8Parser Instr
parsePOPSeg String
"gs"),
     (Word8
0xaa, Opcode -> InstrOperandSize -> Word8 -> Word8Parser Instr
forall (m :: * -> *) p.
Monad m =>
Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
RSM InstrOperandSize
OPNONE),
     (Word8
0xab, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
BTS),
     (Word8
0xac, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseSHRD),
     (Word8
0xad, Word8 -> Word8Parser Instr
forall a. (Eq a, Num a) => a -> Word8Parser Instr
parseSHRD),
     (Word8
0xae, Word8 -> Word8Parser Instr
parseGrp15),
     (Word8
0xaf, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEv Opcode
IMUL),

     (Word8
0xb0, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEbGb Opcode
CMPXCHG),
     (Word8
0xb1, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
CMPXCHG),
     (Word8
0xb2, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
LSS),
     (Word8
0xb3, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
BTR),
     (Word8
0xb4, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
LFS),
     (Word8
0xb5, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
LGS),
     (Word8
0xb6, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEb Opcode
MOVZXB),
     (Word8
0xb7, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEw Opcode
MOVZXW),
     (Word8
0xb8, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved),
     (Word8
0xb9, Word8 -> Word8Parser Instr
parseGrp10),
     (Word8
0xba, Word8 -> Word8Parser Instr
parseGrp8),
     (Word8
0xbb, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
BTC),
     (Word8
0xbc, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEv Opcode
BSF),
     (Word8
0xbd, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEv Opcode
BSR),
     (Word8
0xbe, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEb Opcode
MOVSXB),
     (Word8
0xbf, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericGvEw Opcode
MOVSXW),

     (Word8
0xc0, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEbGb Opcode
XADD),
     (Word8
0xc1, Opcode -> Word8 -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseGenericEvGv Opcode
XADD),
     (Word8
0xc2, Word8 -> Word8Parser Instr
parseCMPPS),
     (Word8
0xc3, Word8 -> Word8Parser Instr
parseMOVNTI),
     (Word8
0xc4, Word8 -> Word8Parser Instr
parsePINSRW),
     (Word8
0xc5, Word8 -> Word8Parser Instr
parsePEXTRW),
     (Word8
0xc6, Word8 -> Word8Parser Instr
parseSHUFPS),
     (Word8
0xc7, Word8 -> Word8Parser Instr
parseGrp9),
     (Word8
0xc8, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xc9, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xca, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xcb, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xcc, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xcd, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xce, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),
     (Word8
0xcf, Word8 -> Word8Parser Instr
forall a s.
(Integral a, Bits a) =>
a -> ParsecT s PState Identity Instr
parseBSWAP),

     (Word8
0xd0, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseADDSUBPS),
     (Word8
0xd1, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSRLW),
     (Word8
0xd2, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSRLD),
     (Word8
0xd3, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSRLQ),
     (Word8
0xd4, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDQ),
     (Word8
0xd5, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMULLW),
     (Word8
0xd6, Word8 -> Word8Parser Instr
parseMOVQ),
     (Word8
0xd7, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMOVMSKB),
     (Word8
0xd8, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBUSB),
     (Word8
0xd9, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBUSW),
     (Word8
0xda, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMINUB),
     (Word8
0xdb, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePAND),
     (Word8
0xdc, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDUSB),
     (Word8
0xdd, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDUSW),
     (Word8
0xde, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMAXUB),
     (Word8
0xdf, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePANDN),

     (Word8
0xe0, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePAVGB),
     (Word8
0xe1, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSRAW),
     (Word8
0xe2, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSRAD),
     (Word8
0xe3, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePAVGW),
     (Word8
0xe4, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMULHUW),
     (Word8
0xe5, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMULHW),
     (Word8
0xe6, Word8 -> Word8Parser Instr
parseCVTPD2DQ),
     (Word8
0xe7, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMOVNTQ),
     (Word8
0xe8, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBSB),
     (Word8
0xe9, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBSQ),
     (Word8
0xea, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMINSW),
     (Word8
0xeb, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePOR),
     (Word8
0xec, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDSB),
     (Word8
0xed, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDSW),
     (Word8
0xee, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMAXSW),
     (Word8
0xef, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePXOR),

     (Word8
0xf0, Word8 -> Word8Parser Instr
parseLDDQU),
     (Word8
0xf1, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSLLW),
     (Word8
0xf2, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSLLD),
     (Word8
0xf3, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSLLQ),
     (Word8
0xf4, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMULUDQ),
     (Word8
0xf5, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePMADDWD),
     (Word8
0xf6, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSADBW),
     (Word8
0xf7, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parseMASKMOVQ),
     (Word8
0xf8, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBB),
     (Word8
0xf9, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBW),
     (Word8
0xfa, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBD),
     (Word8
0xfb, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePSUBQ),
     (Word8
0xfc, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDB),
     (Word8
0xfd, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDW),
     (Word8
0xfe, Word8 -> Word8Parser Instr
forall p. p -> Word8Parser Instr
parsePADDD),
     (Word8
0xff, Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseReserved)
     ]

twoByteEscape :: Word8 -> Word8Parser Instr
twoByteEscape :: Word8 -> Word8Parser Instr
twoByteEscape Word8
b1 = do
  Word8
b <- Word8Parser Word8
anyWord8
  case Word8
-> [(Word8, Word8 -> Word8Parser Instr)]
-> Maybe (Word8 -> Word8Parser Instr)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Word8
b [(Word8, Word8 -> Word8Parser Instr)]
twoByteOpCodeMap of
    Just Word8 -> Word8Parser Instr
p -> Word8 -> Word8Parser Instr
p Word8
b
    Maybe (Word8 -> Word8Parser Instr)
Nothing -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Word8 -> String -> Instr
Bad Word8
b String
"invalid two-byte opcode"

parseGeneric :: Opcode -> InstrOperandSize -> p -> m Instr
parseGeneric Opcode
name InstrOperandSize
opsize p
_ = do
    Instr -> m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
opsize [])
parseGenericIb :: Opcode -> p -> Word8Parser Instr
parseGenericIb Opcode
name p
b = do
    Word8
b <-  Word8Parser Word8
anyWord8
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP8 [Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]
parseGenericIw :: Opcode -> p -> Word8Parser Instr
parseGenericIw Opcode
name p
_ = do
    Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
    SourcePos
pos <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP16 [Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)]
parseGenericJb :: Opcode -> p -> Word8Parser Instr
parseGenericJb Opcode
name p
_ = do
    Int8
b <- Word8Parser Int8
anyInt8
    SourcePos
pos <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OPNONE 
        [Word32 -> InstrOperandSize -> Operand
OpAddr (Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
b Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+
       		(PState -> Word32
startAddr PState
st)) InstrOperandSize
OPNONE]
parseGenericJz :: Opcode -> p -> Word8Parser Instr
parseGenericJz Opcode
name p
_ = do
    Int32
b <- Word8Parser Int32
anyIntZ
    SourcePos
pos <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
    PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OPNONE 
        [Word32 -> InstrOperandSize -> Operand
OpAddr (Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
b Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+
       	       (PState -> Word32
startAddr PState
st)) InstrOperandSize
OPNONE]

parseINC :: a -> ParsecT s PState Identity Instr
parseINC a
b = do
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  let reg :: a
reg = a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0x0f
  String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)
  Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INC InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]

parseDEC :: a -> ParsecT s PState Identity Instr
parseDEC a
b = do
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  let reg :: a
reg = (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0x0f) a -> a -> a
forall a. Num a => a -> a -> a
- a
8
  String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)
  Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
DEC InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]

parsePUSH :: a -> ParsecT s PState Identity Instr
parsePUSH a
b = 
    let reg :: a
reg = a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0x0f in do
      PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
      String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)
      InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
      if Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
         then Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
opsize [String -> Int -> Operand
OpReg (String
"r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show (a
reg a -> a -> a
forall a. Num a => a -> a -> a
+ a
8))
					   (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]
          else Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn
					    (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]

parsePOP :: a -> ParsecT s PState Identity Instr
parsePOP a
b = 
    let reg :: a
reg = (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0x0f) a -> a -> a
forall a. Num a => a -> a -> a
- a
8 in do
      PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
      String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)
      InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
      if Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
         then Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POP InstrOperandSize
opsize [String -> Int -> Operand
OpReg (String
"r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show (a
reg a -> a -> a
forall a. Num a => a -> a -> a
+ a
8))
					 (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]
          else Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POP InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]

parsePUSHA :: t -> ParsecT s PState Identity Instr
parsePUSHA = do
  (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHA InstrOperandSize
OPNONE [])
    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHAD InstrOperandSize
OPNONE [])
parsePOPA :: t -> ParsecT s PState Identity Instr
parsePOPA = do
  (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPA InstrOperandSize
OPNONE [])
    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPAD InstrOperandSize
OPNONE [])

parseBOUND :: p -> Word8Parser Instr
parseBOUND p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BOUND InstrOperandSize
OPNONE [Operand
op2, Operand
op1]
  
parseARPL :: p -> Word8Parser Instr
parseARPL p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP16
  let rn :: String
rn = [String]
regnames16 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
ARPL InstrOperandSize
OPNONE [Operand
op1, (String -> Int -> Operand
OpReg String
rn (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))]
     
parseMOVSXD :: p -> Word8Parser Instr
parseMOVSXD p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVSXD InstrOperandSize
OPNONE [Operand
op2, Operand
op1]

parsePUSHImm :: a -> Word8Parser Instr
parsePUSHImm a
0x68 = do
  Word32
w <- ParsecT [Word8] PState Identity Word32
anyWordZ
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
opsize [Word32 -> Operand
OpImm Word32
w]
parsePUSHImm a
0x6a = do
  Word8
w <- Word8Parser Word8
anyWord8
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
opsize [Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
w)]

parseIMUL :: a -> Word8Parser Instr
parseIMUL a
0x69 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word32
imm <- ParsecT [Word8] PState Identity Word32
anyWordZ
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IMUL InstrOperandSize
opsize [Operand
op2, Operand
op1, Word32 -> Operand
OpImm Word32
imm]
parseIMUL a
0x6b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word8
imm <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IMUL InstrOperandSize
opsize [Operand
op2, Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]

parseINS :: t -> ParsecT s PState m Instr
parseINS t
0x6c = Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INS InstrOperandSize
OP8 []
parseINS b :: t
b@t
0x6d = (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
                   (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INS InstrOperandSize
OP16 [])
                  (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INS InstrOperandSize
OP32 []) t
b

parseOUTS :: t -> ParsecT s PState m Instr
parseOUTS t
0x6e = Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUTS InstrOperandSize
OP8 []
parseOUTS b :: t
b@t
0x6f = (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
                     (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUTS InstrOperandSize
OP16 [])
                     (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUTS InstrOperandSize
OP32 []) t
b

parseJccShort :: a -> Word8Parser Instr
parseJccShort a
b = do
  Int8
disp <- Word8Parser Int8
anyInt8
  SourcePos
pos <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr (a -> Opcode
forall a. (Eq a, Num a) => a -> Opcode
jccname (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf)) InstrOperandSize
OPNONE
        [Word32 -> InstrOperandSize -> Operand
OpAddr (Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int8
disp Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+
                (PState -> Word32
startAddr PState
st)) InstrOperandSize
OPNONE]

parseTEST :: a -> Word8Parser Instr
parseTEST a
0x84 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
OP8 [Operand
op1, String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseTEST a
0x85 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
opsize [Operand
op1, Operand
op2]

parseXCHG :: a -> Word8Parser Instr
parseXCHG a
0x86 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
XCHG InstrOperandSize
OP8 [Operand
op1, String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			   (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseXCHG a
0x87 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
XCHG InstrOperandSize
opsize[Operand
op1, Operand
op2]

parseMOV :: a -> Word8Parser Instr
parseMOV a
0x88  = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [Operand
op1, String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseMOV a
0x89  = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [Operand
op1, Operand
op2]
parseMOV a
0x8a  = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg), Operand
op1]
parseMOV a
0x8b  = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [Operand
op2, Operand
op1]
parseMOV a
0x8c  = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP16
  let rn :: String
rn = [String]
segregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP16 [Operand
op1, String -> Int -> Operand
OpReg String
rn (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseMOV a
0x8e  = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP16
  let rn :: String
rn = [String]
segregnames [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP16 [String -> Int -> Operand
OpReg String
rn (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg), Operand
op1]

parseLEA :: p -> Word8Parser Instr
parseLEA p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LEA InstrOperandSize
OPNONE [Operand
op2, Operand
op1]


parse0x90 :: Word8 -> Word8Parser Instr
parse0x90 Word8
b = do
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
     then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PAUSE InstrOperandSize
OPNONE []
     else do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
             if PState -> Bool
in64BitMode PState
st
                then Word8 -> Word8Parser Instr
parseXCHGReg Word8
b
       		else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
NOP InstrOperandSize
OPNONE []

-- FIXME: Register name handling not quite right

parseXCHGReg :: Word8 -> Word8Parser Instr
parseXCHGReg :: Word8 -> Word8Parser Instr
parseXCHGReg Word8
b = 
    let reg :: Word8
reg = Word8
b Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f in do
      PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
      if Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
         then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
XCHG InstrOperandSize
OP64 [String -> Int -> Operand
OpReg String
"rax" Int
0, 
       					String -> Int -> Operand
OpReg (String
"r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show (Word8
reg Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
8))
					(Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
         else do String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
       		 Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
XCHG InstrOperandSize
OP64 [String -> Int -> Operand
OpReg String
"rax" Int
0,
					   String -> Int -> Operand
OpReg String
rn (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]

parseCBW_CWDE_CDQE :: t -> ParsecT s PState m Instr
parseCBW_CWDE_CDQE t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
             then Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CDQE InstrOperandSize
OPNONE []
              else Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CWDE InstrOperandSize
OPNONE []
     else (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
            (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CBW InstrOperandSize
OPNONE [])
            (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CWDE InstrOperandSize
OPNONE []) t
b

parseCWD_CDQ_CQO :: t -> ParsecT s PState m Instr
parseCWD_CDQ_CQO t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
             then Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CDQE InstrOperandSize
OPNONE []
              else Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CDQ InstrOperandSize
OPNONE []
     else (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
            (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CWD InstrOperandSize
OPNONE [])
            (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CDQ InstrOperandSize
OPNONE []) t
b

parseCALLF :: p -> Word8Parser Instr
parseCALLF p
b = do
    Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
    Word16
s <- ParsecT [Word8] PState Identity Word16
anyWord16
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CALLF InstrOperandSize
OPNONE [Word32 -> Operand
OpImm (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w),
       		           Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
s)]

-- FIXME: Check default/operand sizes.

parsePUSHF :: t -> ParsecT s PState m Instr
parsePUSHF t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHF InstrOperandSize
OPNONE [])
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHFQ InstrOperandSize
OPNONE []) t
b
     else (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHF InstrOperandSize
OPNONE [])
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSHFD InstrOperandSize
OPNONE []) t
b

parsePOPF :: t -> ParsecT s PState m Instr
parsePOPF t
b = do
  PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if PState -> Bool
in64BitMode PState
st
     then (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPF InstrOperandSize
OPNONE [])
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPFQ InstrOperandSize
OPNONE []) t
b
     else (t -> ParsecT s PState m Instr)
-> (t -> ParsecT s PState m Instr) -> t -> ParsecT s PState m Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPF InstrOperandSize
OPNONE [])
             (\ t
_ -> Instr -> ParsecT s PState m Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState m Instr)
-> Instr -> ParsecT s PState m Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POPFD InstrOperandSize
OPNONE []) t
b

parseJMPF :: p -> Word8Parser Instr
parseJMPF p
b = do
    Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
JMPF InstrOperandSize
OPNONE [Word32 -> Operand
OpImm Word32
w]

parseMOVImm :: t -> Word8Parser Instr
parseMOVImm b :: t
b@t
0xa0 = do
  (t -> Word8Parser Instr)
-> (t -> Word8Parser Instr) -> t -> Word8Parser Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseAddressSize
    (\ t
_ -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
               Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)])
    (\ t
_ -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
               Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Word32 -> Operand
OpImm Word32
w]) t
b
parseMOVImm b :: t
b@t
0xa1 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  String
reg <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
  (t -> Word8Parser Instr)
-> (t -> Word8Parser Instr) -> t -> Word8Parser Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseAddressSize
    (\ t
_ -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
               Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
reg Int
0, Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)])
    (\ t
_ -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
       	       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
reg Int
0, Word32 -> Operand
OpImm Word32
w]) t
b
parseMOVImm b :: t
b@t
0xa2 = do
  (t -> Word8Parser Instr)
-> (t -> Word8Parser Instr) -> t -> Word8Parser Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseAddressSize
    (\ t
_ -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
       	       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w), String -> Int -> Operand
OpReg String
"al" Int
0])
    (\ t
_ -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
       	       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [Word32 -> Operand
OpImm Word32
w, String -> Int -> Operand
OpReg String
"al" Int
0]) t
b
parseMOVImm b :: t
b@t
0xa3 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  String
reg <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
  (t -> Word8Parser Instr)
-> (t -> Word8Parser Instr) -> t -> Word8Parser Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseAddressSize
    (\ t
_ -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
       	       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w), String -> Int -> Operand
OpReg String
reg Int
0])
    (\ t
_ -> do Word32
w <- ParsecT [Word8] PState Identity Word32
anyWord32
               Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [Word32 -> Operand
OpImm Word32
w, String -> Int -> Operand
OpReg String
reg Int
0]) t
b

parseMOVS :: a -> ParsecT s PState Identity Instr
parseMOVS a
0xa4 = Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVS InstrOperandSize
OP8 []
parseMOVS b :: a
b@a
0xa5 = do
  PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVS InstrOperandSize
opsize []

parseCMPS :: a -> ParsecT s PState Identity Instr
parseCMPS a
0xa6 = Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CMPS InstrOperandSize
OP8 []
parseCMPS a
0xa7 = do
  PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CMPS InstrOperandSize
opsize []

parseTESTImm :: a -> Word8Parser Instr
parseTESTImm a
0xa8 = do
  Word8
imm <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
parseTESTImm a
0xa9 = do
  Word32
imm <- ParsecT [Word8] PState Identity Word32
anyWordZ
  String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Word32 -> Operand
OpImm Word32
imm]
  

parseSTOS :: t -> ParsecT s PState Identity Instr
parseSTOS t
0xaa = Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
OP8 []
parseSTOS b :: t
b@t
0xab = do
  PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  if PState -> Bool
in64BitMode PState
st
     then if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
             then Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
opsize []
              else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
opsize [])
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
opsize []) t
b
     else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
opsize [])
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STOS InstrOperandSize
opsize []) t
b

parseLODS :: t -> ParsecT s PState Identity Instr
parseLODS t
0xac = Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
OP8 []
parseLODS b :: t
b@t
0xad = do
  PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  if PState -> Bool
in64BitMode PState
st
     then if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
             then Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
opsize []
              else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
opsize [])
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
opsize []) t
b
     else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
opsize [])
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LODS InstrOperandSize
opsize []) t
b

parseSCAS :: t -> ParsecT s PState Identity Instr
parseSCAS t
0xae = Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
OP8 []
parseSCAS b :: t
b@t
0xaf = do
  PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  if PState -> Bool
in64BitMode PState
st
     then if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
             then Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
opsize []
              else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
opsize [])
                    (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
opsize []) t
b
     else (t -> ParsecT s PState Identity Instr)
-> (t -> ParsecT s PState Identity Instr)
-> t
-> ParsecT s PState Identity Instr
forall (m :: * -> *) t s b.
Monad m =>
(t -> ParsecT s PState m b)
-> (t -> ParsecT s PState m b) -> t -> ParsecT s PState m b
chooseOperandSize
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
opsize [])
            (\ t
_ -> Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SCAS InstrOperandSize
opsize []) t
b

parseMOVImmByteToByteReg :: Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg :: Word8 -> Word8Parser Instr
parseMOVImmByteToByteReg Word8
b = do
  let reg :: Word8
reg = Word8
b Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Word8
imm <- Word8Parser Word8
anyWord8
  if Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
     then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg (String
"r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
reg String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"l")
				   (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
       				  Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
     else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
				    (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg), 
       				  Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]

parseMOVImmToReg :: Word8 -> Word8Parser Instr
parseMOVImmToReg :: Word8 -> Word8Parser Instr
parseMOVImmToReg Word8
b = do
  let reg :: Word8
reg = (Word8
b Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8)
  Word64
imm <- Word8Parser Word64
anyWordV
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg), 
			     Word32 -> Operand
OpImm (Word64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
imm)]

parseRETN :: a -> Word8Parser Instr
parseRETN a
0xc2 = do
    Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
RET InstrOperandSize
OPNONE [Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)]
parseRETN a
0xc3 = Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
RET InstrOperandSize
OPNONE []

parseLoadSegmentRegister :: Opcode -> p -> Word8Parser Instr
parseLoadSegmentRegister Opcode
opcode p
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode InstrOperandSize
OPNONE [Operand
op2, Operand
op1]

parseENTER :: p -> Word8Parser Instr
parseENTER p
b = do
    Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
    Word8
b <- Word8Parser Word8
anyWord8
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
ENTER InstrOperandSize
OPNONE [Word32 -> Operand
OpImm (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w), 
       		           Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]

-- Floating-point operations.  These can probably shortened by doing some
-- arithmetic/logical tricks on the opcodes, but since the instruction
-- set is still quite irregular (even though much better than the integer
-- ops), I haven't bothered yet.

parseESC :: Word8 -> Word8Parser Instr
parseESC Word8
0xd8 = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPF32 Word8
modrm
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OPF32 [Operand
op1]
     else if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f))]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8))]
 where ops :: [Opcode]
ops = [Opcode
FADD, Opcode
FMUL, Opcode
FCOM, Opcode
FCOMP, 
               Opcode
FSUB, Opcode
FSUBR, Opcode
FDIV, Opcode
FDIVR]
             
parseESC b :: Word8
b@Word8
0xd9 = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1', Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
	     let op1 :: Operand
op1 = case Operand
op1' of 
		         OpAddr Word32
a InstrOperandSize
_ -> Word32 -> InstrOperandSize -> Operand
OpAddr Word32
a  ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			 Operand
op -> Operand
op
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
lowOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) 
       	              ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) [Operand
op1]
     else if (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0xd0)
             then if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
8
                    then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	          ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                         [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f))]
                    else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	          ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                         [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f)
       			      Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
8)]
              else case Word8
modrm of
       		     Word8
0xd0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FNOP InstrOperandSize
OPNONE []
                     Word8
0xe0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FCHS InstrOperandSize
OPNONE []
                     Word8
0xe1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FABS InstrOperandSize
OPNONE []
                     Word8
0xe4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FTST InstrOperandSize
OPNONE []
                     Word8
0xe5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FXAM InstrOperandSize
OPNONE []
                     Word8
0xe8 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLD1 InstrOperandSize
OPNONE []
                     Word8
0xe9 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDL2T InstrOperandSize
OPNONE []
                     Word8
0xea -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDL2E InstrOperandSize
OPNONE []
                     Word8
0xeb -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDPI InstrOperandSize
OPNONE []
                     Word8
0xec -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDLG2 InstrOperandSize
OPNONE []
                     Word8
0xed -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDLN2 InstrOperandSize
OPNONE []
                     Word8
0xee -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FLDZ InstrOperandSize
OPNONE []
                     Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
 where lowOps :: [Opcode]
lowOps = [Opcode
FLD, Opcode
InvalidOpcode, Opcode
FST, Opcode
FSTP, 
                  Opcode
FLDENV, Opcode
FLDCW, Opcode
FSTENV, Opcode
FSTCW]
       opsizes :: [InstrOperandSize]
opsizes = [InstrOperandSize
OPF32, InstrOperandSize
OPNONE, InstrOperandSize
OPF32, InstrOperandSize
OPF32,
                   InstrOperandSize
OPNONE, InstrOperandSize
OPNONE, InstrOperandSize
OPNONE, InstrOperandSize
OPNONE]
       ops :: [Opcode]
ops = [Opcode
FLD, Opcode
FXCH]

parseESC Word8
0xda = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OPNONE [Operand
op1]
     else if (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0xe0)
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f))]
              else case Word8
modrm of
                     Word8
0xe1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FUCOMPP InstrOperandSize
OPNONE []
                     Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xda
 where ops :: [Opcode]
ops = [Opcode
FIADD, Opcode
FIMUL, Opcode
FICOM, Opcode
FICOMP, 
               Opcode
FISUB, Opcode
FISUBR, Opcode
FIDIV, Opcode
FIDIVR]
       ops' :: [Opcode]
ops' = [Opcode
FCMOVB, Opcode
FCMOVE, Opcode
FCMOVBE, Opcode
FCMOVU]

parseESC Word8
0xdb = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1', Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
	     let op1 :: Operand
op1 = case Operand
op1' of 
		         OpAddr Word32
a InstrOperandSize
_ -> Word32 -> InstrOperandSize -> Operand
OpAddr Word32
a  ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			 Operand
op -> Operand
op
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) 
       	              ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) [Operand
op1]
     else 
      case Word8
modrm of
         Word8
0xe2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FCLEX InstrOperandSize
OPNONE []
         Word8
0xe3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FINIT InstrOperandSize
OPNONE []
         Word8
_ ->
           if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f))]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg Int
0, Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8))]
 where ops :: [Opcode]
ops = [Opcode
FILD, Opcode
FISTP, Opcode
FIST, Opcode
FISTP, 
               Opcode
InvalidOpcode, Opcode
FLD, Opcode
InvalidOpcode, Opcode
FSTP]
       opsizes :: [InstrOperandSize]
opsizes = [InstrOperandSize
OP32, InstrOperandSize
OP32, InstrOperandSize
OP32, InstrOperandSize
OP32,
                   InstrOperandSize
OPNONE, InstrOperandSize
OPF80, InstrOperandSize
OPNONE, InstrOperandSize
OPF80]
       ops' :: [Opcode]
ops' = [Opcode
FCMOVNB, Opcode
FCMOVNE, Opcode
FCMOVNBE, Opcode
FCMOVNU,
                Opcode
InvalidOpcode, Opcode
FUCOMI, Opcode
FCOMI, Opcode
InvalidOpcode]

parseESC Word8
0xdc = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OPNONE [Operand
op1]
     else
       if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xd0 Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0xe0
        then Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xdc
        else if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f)), Int -> Operand
OpFPReg Int
0]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8)), Int -> Operand
OpFPReg Int
0]
 where ops :: [Opcode]
ops = [Opcode
FADD, Opcode
FMUL, Opcode
FCOM, Opcode
FCOMP, 
               Opcode
FSUB, Opcode
FSUBR, Opcode
FDIV, Opcode
FDIVR]
             
parseESC Word8
0xdd = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1', Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
	     let op1 :: Operand
op1 = case Operand
op1' of 
		         OpAddr Word32
a InstrOperandSize
_ -> Word32 -> InstrOperandSize -> Operand
OpAddr Word32
a  ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
			 Operand
op -> Operand
op
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) 
       	              ([InstrOperandSize]
opsizes [InstrOperandSize] -> Int -> InstrOperandSize
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) [Operand
op1]
     else
       if (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xc8) Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xd0 Bool -> Bool -> Bool
|| (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xf0 Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0xff)
        then Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xdc
        else if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f)), Int -> Operand
OpFPReg Int
0]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8)), Int -> Operand
OpFPReg Int
0]
 where ops :: [Opcode]
ops = [Opcode
FLD, Opcode
FISTTP, Opcode
FST, Opcode
FSTP, 
               Opcode
FRSTOR, Opcode
InvalidOpcode, Opcode
FSAVE, Opcode
FSTSW]
       opsizes :: [InstrOperandSize]
opsizes = [InstrOperandSize
OPF64, InstrOperandSize
OP64, InstrOperandSize
OPF64, InstrOperandSize
OPF64,
                   InstrOperandSize
OPNONE, InstrOperandSize
OPNONE, InstrOperandSize
OPNONE, InstrOperandSize
OP16]
       ops' :: [Opcode]
ops' = [Opcode
FFREE, Opcode
InvalidOpcode, Opcode
FST, Opcode
FSTP, 
                Opcode
FUCOM, Opcode
FUCOMP]
             
parseESC Word8
0xde = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OPNONE [Operand
op1]
     else
       if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xd0 Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xe0
        then case Word8
modrm of
       	 Word8
0xd9 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FCOMPP InstrOperandSize
OPNONE []
       	 Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xde
        else if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f)), Int -> Operand
OpFPReg Int
0]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8)), Int -> Operand
OpFPReg Int
0]
 where ops :: [Opcode]
ops = [Opcode
FIADD, Opcode
FIMUL, Opcode
FICOM, Opcode
FICOMP, 
               Opcode
FISUB, Opcode
FISUBR, Opcode
FIDIV, Opcode
FIDIVR]
       ops' :: [Opcode]
ops' = [Opcode
FADDP, Opcode
FMULP, Opcode
InvalidOpcode, Opcode
InvalidOpcode,
                Opcode
FSUBRP, Opcode
FSUBP, Opcode
FDIVRP, Opcode
FDIVP]
             
             
parseESC Word8
0xdf = do
  Word8
modrm <- Word8Parser Word8
anyWord8
  let modrm' :: Word8
      modrm' :: Word8
modrm' = Word8
modrm Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
0xc0
  if Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xbf
     then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8 -> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32' InstrOperandSize
OPNONE Word8
modrm
             Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
ops [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OPNONE [Operand
op1]
     else
       case Word8
modrm of
           Word8
0xe0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FSTSW InstrOperandSize
OPNONE [String -> Int -> Operand
OpReg String
"ax" Int
0]
           Word8
_ -> 
             if (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xe8 Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xef) Bool -> Bool -> Bool
||
                (Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word8
0xf0 Bool -> Bool -> Bool
&& Word8
modrm Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word8
0xf7)
             then
             if (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Bool
forall a. Ord a => a -> a -> Bool
< Word8
0x8
             then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f)), Int -> Operand
OpFPReg Int
0]
              else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr 
       	     ([Opcode]
ops' [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm' Word8 -> Int -> Word8
forall a. Bits a => a -> Int -> a
`shiftR` Int
3))) InstrOperandSize
OPNONE
                    [Int -> Operand
OpFPReg (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ((Word8
modrm Word8 -> Word8 -> Word8
forall a. Bits a => a -> a -> a
.&. Word8
0x0f) Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
- Word8
8)), Int -> Operand
OpFPReg Int
0]
             else Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xdf
 where ops :: [Opcode]
ops = [Opcode
FILD, Opcode
FISTPP, Opcode
FIST, Opcode
FISTP, 
               Opcode
FBLD, Opcode
FILD, Opcode
FBSTP, Opcode
FISTP]
       ops' :: [Opcode]
ops' = [Opcode
InvalidOpcode, Opcode
InvalidOpcode, Opcode
InvalidOpcode, Opcode
InvalidOpcode,
                Opcode
InvalidOpcode, Opcode
FUCOMIP, Opcode
FCOMIP, Opcode
InvalidOpcode]

parseINImm :: a -> Word8Parser Instr
parseINImm a
0xe4 = do
    Word8
b <- Word8Parser Word8
anyWord8
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IN InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]
parseINImm a
0xe5 = do
    Word8
b <- Word8Parser Word8
anyWord8
    String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
    InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IN InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]
parseOUTImm :: a -> Word8Parser Instr
parseOUTImm a
0xe6 = do
    Word8
b <- Word8Parser Word8
anyWord8
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUT InstrOperandSize
OP8 [Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b), String -> Int -> Operand
OpReg String
"al" Int
0]
parseOUTImm a
0xe7 = do
    Word8
b <- Word8Parser Word8
anyWord8
    String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
    InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
    Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUT InstrOperandSize
opsize [Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b), String -> Int -> Operand
OpReg String
rn Int
0]

parseIN :: a -> ParsecT s PState Identity Instr
parseIN a
0xec = do
    Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IN InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, String -> Int -> Operand
OpReg String
"dx" Int
2]
parseIN a
0xed = do
    String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
    InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
    Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IN InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, String -> Int -> Operand
OpReg String
"dx" Int
2]
parseOUT :: a -> ParsecT s PState Identity Instr
parseOUT a
0xee = do
    Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUT InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"dx" Int
2, String -> Int -> Operand
OpReg String
"al" Int
0]
parseOUT a
0xef = do
    String
rn <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
    InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
    Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
OUT InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
"dx" Int
2, String -> Int -> Operand
OpReg String
rn Int
0]

-- Return the name of the register encoded with R.  Take 64-bit mode and
-- possible REX and operand-size prefixes into account.

registerName :: Int -> ParsecT s PState m String
registerName Int
r = do
    PState
st <- ParsecT s PState m PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    if PState -> Bool
in64BitMode PState
st Bool -> Bool -> Bool
&& Word8 -> PState -> Bool
hasREX Word8
rex_R PState
st
       then String -> ParsecT s PState m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ParsecT s PState m String)
-> String -> ParsecT s PState m String
forall a b. (a -> b) -> a -> b
$ String
"r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8)
       else case PState -> OperandSize
operandBitMode PState
st of
              OperandSize
BIT16 -> String -> ParsecT s PState m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ParsecT s PState m String)
-> String -> ParsecT s PState m String
forall a b. (a -> b) -> a -> b
$ [String]
regnames16 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
r
              OperandSize
BIT32 -> String -> ParsecT s PState m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ParsecT s PState m String)
-> String -> ParsecT s PState m String
forall a b. (a -> b) -> a -> b
$ [String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
r

instrOperandSize :: ParsecT s PState Identity InstrOperandSize
instrOperandSize = do
    PState
st <- ParsecT s PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    if PState -> Bool
in64BitMode PState
st Bool -> Bool -> Bool
&& Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
       then InstrOperandSize -> ParsecT s PState Identity InstrOperandSize
forall (m :: * -> *) a. Monad m => a -> m a
return (InstrOperandSize -> ParsecT s PState Identity InstrOperandSize)
-> InstrOperandSize -> ParsecT s PState Identity InstrOperandSize
forall a b. (a -> b) -> a -> b
$ InstrOperandSize
OP64
       else case PState -> OperandSize
operandBitMode PState
st of
              OperandSize
BIT16 -> InstrOperandSize -> ParsecT s PState Identity InstrOperandSize
forall (m :: * -> *) a. Monad m => a -> m a
return InstrOperandSize
OP16
              OperandSize
BIT32 -> InstrOperandSize -> ParsecT s PState Identity InstrOperandSize
forall (m :: * -> *) a. Monad m => a -> m a
return InstrOperandSize
OP32

regnames8 :: [String]
regnames8 = [String
"al", String
"cl", String
"dl", String
"bl", String
"ah", String
"ch", String
"dh", String
"bh"]
regnames16 :: [String]
regnames16 = [String
"ax", String
"cx", String
"dx", String
"bx", String
"sp", String
"bp", String
"si", String
"di"]
regnames32 :: [String]
regnames32 = [String
"eax", String
"ecx", String
"edx", String
"ebx", String
"esp", String
"ebp", String
"esi", String
"edi"]
regnames64 :: [String]
regnames64 = [String
"rax", String
"rcx", String
"rdx", String
"rbx", String
"rsp", String
"rbp", String
"rsi", String
"rdi"]
segregnames :: [String]
segregnames = [String
"es", String
"cs", String
"ss", String
"ds", String
"fs", String
"gs", String
"<invalid>", String
"<invalid>"]
mmxregs :: [String]
mmxregs = [String
"mm0", String
"mm1", String
"mm2", String
"mm3", String
"mm4", String
"mm5", String
"mm6", String
"mm7"]
xmmregs :: [String]
xmmregs = [String
"xmm0", String
"xmm1", String
"xmm2", String
"xmm3", String
"xmm4", String
"xmm5", String
"xmm6", String
"xmm7"]

jccname :: a -> Opcode
jccname a
0 = Opcode
JO
jccname a
1 = Opcode
JNO
jccname a
2 = Opcode
JB
jccname a
3 = Opcode
JNB
jccname a
4 = Opcode
JE
jccname a
5 = Opcode
JNE
jccname a
6 = Opcode
JBE
jccname a
7 = Opcode
JA
jccname a
8 = Opcode
JS
jccname a
9 = Opcode
JNS
jccname a
10 = Opcode
JP
jccname a
11 = Opcode
JNP
jccname a
12 = Opcode
JL
jccname a
13 = Opcode
JGE
jccname a
14 = Opcode
JLE
jccname a
15 = Opcode
JG

setccname :: a -> Opcode
setccname a
0 = Opcode
SETO
setccname a
1 = Opcode
SETNO
setccname a
2 = Opcode
SETB
setccname a
3 = Opcode
SETNB
setccname a
4 = Opcode
SETE
setccname a
5 = Opcode
SETNE
setccname a
6 = Opcode
SETBE
setccname a
7 = Opcode
SETA
setccname a
8 = Opcode
SETS
setccname a
9 = Opcode
SETNS
setccname a
10 = Opcode
SETP
setccname a
11 = Opcode
SETNP
setccname a
12 = Opcode
SETL
setccname a
13 = Opcode
SETGE
setccname a
14 = Opcode
SETLE
setccname a
15 = Opcode
SETG

cmovccname :: a -> Opcode
cmovccname a
0 = Opcode
CMOVO
cmovccname a
1 = Opcode
CMOVNO
cmovccname a
2 = Opcode
CMOVB
cmovccname a
3 = Opcode
CMOVNB
cmovccname a
4 = Opcode
CMOVE
cmovccname a
5 = Opcode
CMOVNE
cmovccname a
6 = Opcode
CMOVBE
cmovccname a
7 = Opcode
CMOVA
cmovccname a
8 = Opcode
CMOVS
cmovccname a
9 = Opcode
CMOVNS
cmovccname a
10 = Opcode
CMOVP
cmovccname a
11 = Opcode
CMOVNP
cmovccname a
12 = Opcode
CMOVL
cmovccname a
13 = Opcode
CMOVGE
cmovccname a
14 = Opcode
CMOVLE
cmovccname a
15 = Opcode
CMOVG

parseGrp1 :: a -> Word8Parser Instr
parseGrp1 a
0x80 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Word8
immb <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
aluOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OP8 
    [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
immb)]
parseGrp1 a
0x81 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word32
immb <- ParsecT [Word8] PState Identity Word32
anyWordZ
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
aluOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
opsize 
    [Operand
op1, Word32 -> Operand
OpImm (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
immb)]
parseGrp1 a
0x82 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Word8
immb <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
aluOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OP8 
    [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
immb)]
parseGrp1 a
0x83 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word8
immb <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
aluOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
opsize
    [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
immb)]
aluOps :: [Opcode]
aluOps = [Opcode
ADD, Opcode
OR, Opcode
ADC, Opcode
SBB, Opcode
AND, Opcode
SUB, Opcode
XOR, Opcode
CMP]


parseGrp1A :: Word8 -> Word8Parser Instr
parseGrp1A Word8
b = do
   InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
   (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
   case Word8
reg of
     Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
POP InstrOperandSize
opsize [Operand
op1]
     Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp2 :: a -> Word8Parser Instr
parseGrp2 a
0xc0 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Word8
immb <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OP8 
      [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
immb)]
parseGrp2 a
0xc1 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word8
imm <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
opsize
      [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
parseGrp2 a
0xd0 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OP8 [Operand
op1, Word32 -> Operand
OpImm Word32
1]
parseGrp2 a
0xd1 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm Word32
1]
parseGrp2 a
0xd2 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
OP8 [Operand
op1, String -> Int -> Operand
OpReg String
"cl" Int
1]
parseGrp2 a
0xd3 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr ([Opcode]
shiftOps [Opcode] -> Int -> Opcode
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg) InstrOperandSize
opsize [Operand
op1, String -> Int -> Operand
OpReg String
"cl" Int
1]
shiftOps :: [Opcode]
shiftOps = [Opcode
ROL, Opcode
ROR, Opcode
RCL, Opcode
RCR, Opcode
SHL, Opcode
SHR, Opcode
InvalidOpcode, Opcode
SAR]

parseGrp3 :: a -> Word8Parser Instr
parseGrp3 a
0xf6 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  case Word8
reg of
    Word8
0 -> do Word8
imm <- Word8Parser Word8
anyWord8
            Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
OP8 [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
    Word8
1 -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xf6
    Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
NOT InstrOperandSize
OP8 [Operand
op1]
    Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
NEG InstrOperandSize
OP8 [Operand
op1]
    Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MUL InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Operand
op1]
    Word8
5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IMUL InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Operand
op1]
    Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
DIV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Operand
op1]
    Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IDIV InstrOperandSize
OP8 [String -> Int -> Operand
OpReg String
"al" Int
0, Operand
op1]
parseGrp3 a
0xf7 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  String
rn <- Int -> ParsecT [Word8] PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName Int
0
  case Word8
reg of
    Word8
0 -> do Word32
imm <- ParsecT [Word8] PState Identity Word32
anyWordZ
            Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
TEST InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
imm)]
    Word8
1 -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
0xf6
    Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
NOT InstrOperandSize
opsize [Operand
op1]
    Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
NEG InstrOperandSize
opsize [Operand
op1]
    Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MUL InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Operand
op1]
    Word8
5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IMUL InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Operand
op1]
    Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
DIV InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Operand
op1]
    Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
IDIV InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
rn Int
0, Operand
op1]

parseGrp4 :: Word8 -> Word8Parser Instr
parseGrp4 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  case Word8
reg of
    Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INC InstrOperandSize
OP8 [Operand
op1]
    Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
DEC InstrOperandSize
OP8 [Operand
op1]
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp5 :: Word8 -> Word8Parser Instr
parseGrp5 Word8
b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  case Word8
reg of
    Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INC InstrOperandSize
opsize [Operand
op1]
    Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
DEC InstrOperandSize
opsize [Operand
op1]
    Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CALL InstrOperandSize
OPNONE [Operand
op1]
    Word8
3 -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
            Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CALLF InstrOperandSize
OPNONE [Word32 -> InstrOperandSize -> Operand
OpAddr (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w) InstrOperandSize
OPNONE, Operand
op1]
    Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
JMPN InstrOperandSize
OPNONE [Operand
op1]
    Word8
5 -> do Word16
w <- ParsecT [Word8] PState Identity Word16
anyWord16
            Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
JMPF InstrOperandSize
OPNONE [Word32 -> InstrOperandSize -> Operand
OpAddr (Word16 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w) InstrOperandSize
OPNONE, Operand
op1]
    Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PUSH InstrOperandSize
opsize [Operand
op1]
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp6 :: Word8 -> Word8Parser Instr
parseGrp6 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  case Word8
reg of
    Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SLDT InstrOperandSize
OPNONE [Operand
op1]
    Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STR InstrOperandSize
OPNONE [Operand
op1]
    Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LLDT InstrOperandSize
OPNONE [Operand
op1]
    Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LTR InstrOperandSize
OPNONE [Operand
op1]
    Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VERR InstrOperandSize
OPNONE [Operand
op1]
    Word8
5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VERW InstrOperandSize
OPNONE [Operand
op1]
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp7 :: Word8 -> Word8Parser Instr
parseGrp7 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  case Word8
mod of
    Word8
3 -> case Word8
reg of
           Word8
0 -> case Word8
rm of
       		  Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMCALL InstrOperandSize
OPNONE []
       		  Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMLAUNCH InstrOperandSize
OPNONE []
       		  Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMRESUME InstrOperandSize
OPNONE []
       		  Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMXOFF InstrOperandSize
OPNONE []
       		  Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
           Word8
1 -> case Word8
rm of
       		  Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MONITOR InstrOperandSize
OPNONE []
       		  Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MWAIT InstrOperandSize
OPNONE []
       		  Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
           Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SMSW InstrOperandSize
OPNONE [Operand
op1]
           Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LMSW InstrOperandSize
OPNONE [Operand
op1]
           Word8
7 -> case Word8
rm of
       		  Word8
0 -> (Word8 -> Word8Parser Instr) -> Word8 -> Word8Parser Instr
forall (m :: * -> *) s.
Monad m =>
(Word8 -> ParsecT s PState m Instr)
-> Word8 -> ParsecT s PState m Instr
onlyIn64BitMode
       	                 (\Word8
b -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SWAPGS InstrOperandSize
OPNONE []) Word8
b
       		  Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
           Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> case Word8
reg of
           Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SGDT InstrOperandSize
OPNONE [Operand
op1]
           Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SIDT InstrOperandSize
OPNONE [Operand
op1]
           Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LGDT InstrOperandSize
OPNONE [Operand
op1]
           Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LIDT InstrOperandSize
OPNONE [Operand
op1]
           Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SMSW InstrOperandSize
OPNONE [Operand
op1]
           Word8
5 -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
           Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LMSW InstrOperandSize
OPNONE [Operand
op1]
           Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
INVLPG InstrOperandSize
OPNONE [Operand
op1]

parseGrp8 :: Word8 -> Word8Parser Instr
parseGrp8 Word8
b = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word8
imm <- Word8Parser Word8
anyWord8
  case Word8
reg of
    Word8
4 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BT InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
    Word8
5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BTS InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
    Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BTR InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
    Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BTC InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp9 :: Word8 -> Word8Parser Instr
parseGrp9 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case Word8
mod of
    Word8
3 -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> case Word8
reg of
            Word8
1 -> if Word8 -> PState -> Bool
hasREX Word8
rex_W PState
st
                    then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CMPXCHG16B InstrOperandSize
OPNONE [Operand
op1]
                    else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CMPXCHG8B InstrOperandSize
OPNONE [Operand
op1]
            Word8
6 -> if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
                   then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMCLEAR InstrOperandSize
OPNONE [Operand
op1]
       	     else if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
       	          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMXON InstrOperandSize
OPNONE [Operand
op1]
       	          else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMPTRLD InstrOperandSize
OPNONE [Operand
op1]
            Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMPTRST InstrOperandSize
OPNONE [Operand
op1]
            Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp10 :: Word8 -> Word8Parser Instr
parseGrp10 = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode

parseGrp11 :: a -> Word8Parser Instr
parseGrp11 a
0xc6 = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  Word8
imm <- Word8Parser Word8
anyWord8
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OP8 [Operand
op1, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
parseGrp11 a
0xc7 = do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Word32
imm <- ParsecT [Word8] PState Identity Word32
anyWordZ
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
opsize [Operand
op1, Word32 -> Operand
OpImm (Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
imm)]

mmxInstr :: p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr p
op1 p
mod p
reg a
rm Opcode
name = do
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Word8
imm <- Word8Parser Word8
anyWord8
  if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
     then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP128
           [String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
rm) (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
rm),
	    Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
     else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
name InstrOperandSize
OP64
           [String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
rm) (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
rm),
	    Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
imm)]
       	
parseGrp12 :: Word8 -> Word8Parser Instr
parseGrp12 Word8
b = do
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let opsize :: InstrOperandSize
opsize = if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st then InstrOperandSize
OP128 else InstrOperandSize
OP64
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  case Word8
mod of
    Word8
3 -> case Word8
reg of
           Word8
2 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRLW
           Word8
4 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRAW
           Word8
6 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSLLW
           Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
parseGrp13 :: Word8 -> Word8Parser Instr
parseGrp13 Word8
b = do
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let opsize :: InstrOperandSize
opsize = if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st then InstrOperandSize
OP128 else InstrOperandSize
OP64
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  case Word8
mod of
    Word8
3 -> case Word8
reg of
           Word8
2 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRLD
           Word8
4 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRAD
           Word8
6 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSLLD
           Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
parseGrp14 :: Word8 -> Word8Parser Instr
parseGrp14 Word8
b = do
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let opsize :: InstrOperandSize
opsize = if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st then InstrOperandSize
OP128 else InstrOperandSize
OP64
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case Word8
mod of
    Word8
3 -> case Word8
reg of
           Word8
2 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRLQ
           Word8
3 -> if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
		   then Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSRLDQ
       		   else Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
           Word8
6 -> Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSLLQ
           Word8
7 -> if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
                   then Operand -> Word8 -> Word8 -> Word8 -> Opcode -> Word8Parser Instr
forall a p p p.
Integral a =>
p -> p -> p -> a -> Opcode -> Word8Parser Instr
mmxInstr Operand
op1 Word8
mod Word8
reg Word8
rm Opcode
PSLLDQ
       	           else Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
	   Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseGrp15 :: Word8 -> Word8Parser Instr
parseGrp15 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  case Word8
mod of
    Word8
3 -> case Word8
reg of
            Word8
5 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LFENCE InstrOperandSize
OPNONE []
            Word8
6 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MFENCE InstrOperandSize
OPNONE []
            Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SFENCE InstrOperandSize
OPNONE []
            Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> case Word8
reg of
            Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FXSAVE InstrOperandSize
OPNONE [Operand
op1]
            Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
FXRSTOR InstrOperandSize
OPNONE [Operand
op1]
            Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LDMXCSR InstrOperandSize
OPNONE [Operand
op1]
            Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
STMXCSR InstrOperandSize
OPNONE [Operand
op1]
            Word8
7 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
CLFLUSH InstrOperandSize
OPNONE [Operand
op1]
            Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
parseGrp16 :: Word8 -> Word8Parser Instr
parseGrp16 Word8
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OPNONE
  case Word8
mod of
    Word8
3 -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
    Word8
_ -> case Word8
reg of
            Word8
0 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PREFETCHNTA InstrOperandSize
OPNONE [Operand
op1]
            Word8
1 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PREFETCHT0 InstrOperandSize
OPNONE [Operand
op1]
            Word8
2 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PREFETCHT1 InstrOperandSize
OPNONE [Operand
op1]
            Word8
3 -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PREFETCHT2 InstrOperandSize
OPNONE [Operand
op1]
            Word8
_ -> Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b

parseXmmVW :: Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
p Opcode
p0xf3 Opcode
p0x66 Opcode
p0xf2 p
b =
    do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP128
       PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       let v :: Operand
v = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
       let w :: Operand
w = case Operand
op1 of
	         OpReg String
_ Int
num -> String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num
		 Operand
op -> Operand
op
       if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
	  then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf3 InstrOperandSize
OP128 [Operand
v, Operand
w]
	  else if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0x66 InstrOperandSize
OP128 [Operand
v, Operand
w]
		  else if Word8 -> PState -> Bool
hasPrefix Word8
0xf2 PState
st
		          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf2 InstrOperandSize
OP128 [Operand
v, Operand
w]
			  else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p InstrOperandSize
OP128 [Operand
v, Operand
w]
parseXmmWV :: Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmWV Opcode
p Opcode
p0xf3 Opcode
p0x66 Opcode
p0xf2 p
b =
    do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP128
       PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       let w :: Operand
w = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
       let v :: Operand
v = case Operand
op1 of
	         OpReg String
_ Int
num -> String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num
		 Operand
op -> Operand
op
       if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
	  then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf3 InstrOperandSize
OP128 [Operand
v, Operand
w]
	  else if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0x66 InstrOperandSize
OP128 [Operand
v, Operand
w]
		  else if Word8 -> PState -> Bool
hasPrefix Word8
0xf2 PState
st
		          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf2 InstrOperandSize
OP128 [Operand
v, Operand
w]
			  else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p InstrOperandSize
OP128 [Operand
v, Operand
w]

parseXmmGU :: Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmGU Opcode
p Opcode
p0xf3 Opcode
p0x66 Opcode
p0xf2 p
b =
    do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       let g :: Operand
g = String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
       let u :: Operand
u = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
       if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
	  then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf3 InstrOperandSize
OP32 [Operand
g, Operand
u]
	  else if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0x66 InstrOperandSize
OP32 [Operand
g, Operand
u]
		  else if Word8 -> PState -> Bool
hasPrefix Word8
0xf2 PState
st
		          then Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p0xf2 InstrOperandSize
OP32 [Operand
g, Operand
u]
			  else Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
p InstrOperandSize
OP32 [Operand
g, Operand
u]

parseMOVUPS :: p -> Word8Parser Instr
parseMOVUPS b :: p
b@p
0x10 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MOVUPS Opcode
MOVSS Opcode
MOVUPD Opcode
MOVSD p
b
parseMOVUPS b :: p
b@p
0x11 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmWV Opcode
MOVUPS Opcode
MOVSS Opcode
MOVUPD Opcode
MOVSD p
b
parseMOVLPS :: p -> Word8Parser Instr
parseMOVLPS b :: p
b@p
0x12 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmWV Opcode
MOVLPS Opcode
MOVSLDUP Opcode
MOVLPD Opcode
MOVDDUP p
b
parseMOVLPS b :: p
b@p
0x13 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MOVLPS Opcode
InvalidOpcode Opcode
MOVLPD Opcode
InvalidOpcode p
b
parseUNPCKLPS :: p -> Word8Parser Instr
parseUNPCKLPS b :: p
b@p
0x14 =
    Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
UNPCKLPS Opcode
InvalidOpcode Opcode
UNPCKLPD Opcode
InvalidOpcode p
b
parseUNPCKHPS :: p -> Word8Parser Instr
parseUNPCKHPS b :: p
b@p
0x15 = 
    Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
UNPCKHPS Opcode
InvalidOpcode Opcode
UNPCKHPD Opcode
InvalidOpcode p
b
parseMOVHPS :: p -> Word8Parser Instr
parseMOVHPS b :: p
b@p
0x16 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MOVHPS Opcode
MOVLSDUP Opcode
MOVHPD Opcode
MOVLHPS p
b
parseMOVHPS b :: p
b@p
0x17 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MOVHPS Opcode
InvalidOpcode Opcode
MOVHPD Opcode
InvalidOpcode p
b

parseMOVCtrlDebug :: a -> Word8Parser Instr
parseMOVCtrlDebug a
0x20 = 
    do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OPNONE [String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
				  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm),
				  String -> Int -> Operand
OpReg (String
"cr" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
reg) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseMOVCtrlDebug a
0x21 = 
    do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OPNONE [String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
				  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm),
				  String -> Int -> Operand
OpReg (String
"db" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
reg) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)]
parseMOVCtrlDebug a
0x22 = 
    do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OPNONE [String -> Int -> Operand
OpReg (String
"cr" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
reg) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
				  String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
				  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
parseMOVCtrlDebug a
0x23 = 
    do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOV InstrOperandSize
OPNONE [String -> Int -> Operand
OpReg (String
"db" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
reg) (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
				  String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)
				  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
  

parseMOVAPS :: p -> Word8Parser Instr
parseMOVAPS b :: p
b@p
0x28 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MOVAPS Opcode
InvalidOpcode Opcode
MOVAPD Opcode
InvalidOpcode p
b
parseMOVAPS b :: p
b@p
0x29 = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmWV Opcode
MOVAPS Opcode
InvalidOpcode Opcode
MOVAPD Opcode
InvalidOpcode p
b
parseCVTI2PS :: Word8 -> Word8Parser Instr
parseCVTI2PS = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseMOVNTPS :: p -> Word8Parser Instr
parseMOVNTPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmWV Opcode
MOVNTPS Opcode
InvalidOpcode Opcode
MOVNTPD Opcode
InvalidOpcode
parseCVTPS2PI :: Word8 -> Word8Parser Instr
parseCVTPS2PI = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseCVTTPS2PI :: Word8 -> Word8Parser Instr
parseCVTTPS2PI = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseUCOMISS :: p -> Word8Parser Instr
parseUCOMISS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
UCOMISS Opcode
InvalidOpcode Opcode
UCOMISD Opcode
InvalidOpcode
parseCOMISS :: p -> Word8Parser Instr
parseCOMISS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
COMISS Opcode
InvalidOpcode Opcode
COMISD Opcode
InvalidOpcode

parseCMOVcc :: a -> Word8Parser Instr
parseCMOVcc a
b= do
  InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr (a -> Opcode
forall a. (Eq a, Num a) => a -> Opcode
cmovccname (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf)) InstrOperandSize
OPNONE [Operand
op2, Operand
op1]
  
parseMOVSKPS :: p -> Word8Parser Instr
parseMOVSKPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmGU Opcode
MOVMSKPS Opcode
InvalidOpcode Opcode
MOVMSKPD Opcode
InvalidOpcode

parseSQRTPS :: p -> Word8Parser Instr
parseSQRTPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
SQRTPS Opcode
SQRTSS Opcode
SQRTPD Opcode
SQRTSD
parseRSQRTPS :: p -> Word8Parser Instr
parseRSQRTPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
RSQRTPS Opcode
RSQRTSS Opcode
InvalidOpcode Opcode
InvalidOpcode
parseRCPPS :: p -> Word8Parser Instr
parseRCPPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
RCPPS Opcode
RCPSS Opcode
InvalidOpcode Opcode
InvalidOpcode
parseCVTPS2PD :: Word8 -> Word8Parser Instr
parseCVTPS2PD = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseANDNPS :: p -> Word8Parser Instr
parseANDNPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
ANDNPS Opcode
InvalidOpcode Opcode
ANDNPD Opcode
InvalidOpcode
parseANDPS :: p -> Word8Parser Instr
parseANDPS =  Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
ANDPS Opcode
InvalidOpcode Opcode
ANDPD Opcode
InvalidOpcode
parseORPS :: p -> Word8Parser Instr
parseORPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
ORPS Opcode
InvalidOpcode Opcode
ORPD Opcode
InvalidOpcode
parseXORPS :: p -> Word8Parser Instr
parseXORPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
XORPS Opcode
InvalidOpcode Opcode
XORPD Opcode
InvalidOpcode
parseADDPS :: p -> Word8Parser Instr
parseADDPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
ADDPS Opcode
ADDSS Opcode
ADDPD Opcode
ADDSD
parseMULPS :: p -> Word8Parser Instr
parseMULPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MULPS Opcode
MULSS Opcode
MULPD Opcode
MULSD
parseCVTDQ2PS :: Word8 -> Word8Parser Instr
parseCVTDQ2PS = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKLWD :: Word8 -> Word8Parser Instr
parsePUNPCKLWD = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePACKSSWB :: Word8 -> Word8Parser Instr
parsePACKSSWB = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKHWD :: Word8 -> Word8Parser Instr
parsePUNPCKHWD = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseSUBPS :: p -> Word8Parser Instr
parseSUBPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
SUBPS Opcode
SUBSS Opcode
SUBPD Opcode
SUBSD
parseMINPS :: p -> Word8Parser Instr
parseMINPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MINPS Opcode
MINSS Opcode
MINPD Opcode
MINSD
parseDIVPS :: p -> Word8Parser Instr
parseDIVPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
DIVPS Opcode
DIVSS Opcode
DIVPD Opcode
DIVSD
parseMAXPS :: p -> Word8Parser Instr
parseMAXPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
MAXPS Opcode
MAXSS Opcode
MAXPD Opcode
MAXSD
parsePUNPCKLBW :: Word8 -> Word8Parser Instr
parsePUNPCKLBW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKLDQ :: Word8 -> Word8Parser Instr
parsePUNPCKLDQ = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePACKUSWB :: Word8 -> Word8Parser Instr
parsePACKUSWB = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPGTB :: Word8 -> Word8Parser Instr
parsePCMPGTB = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPGTW :: Word8 -> Word8Parser Instr
parsePCMPGTW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPGTD :: Word8 -> Word8Parser Instr
parsePCMPGTD = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKHBW :: Word8 -> Word8Parser Instr
parsePUNPCKHBW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKHDQ :: Word8 -> Word8Parser Instr
parsePUNPCKHDQ = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePACKSSDW :: Word8 -> Word8Parser Instr
parsePACKSSDW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKLQDQ :: Word8 -> Word8Parser Instr
parsePUNPCKLQDQ = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePUNPCKHQDQ :: Word8 -> Word8Parser Instr
parsePUNPCKHQDQ = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePSHUFW :: Word8 -> Word8Parser Instr
parsePSHUFW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPEQB :: Word8 -> Word8Parser Instr
parsePCMPEQB = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPEQW :: Word8 -> Word8Parser Instr
parsePCMPEQW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePCMPEQD :: Word8 -> Word8Parser Instr
parsePCMPEQD = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented

parseVMREAD :: p -> Word8Parser Instr
parseVMREAD p
b = 
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if PState -> Bool
in64BitMode PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMREAD InstrOperandSize
OP64 [Operand
op1, Operand
op2]
	  else do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP32
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMREAD InstrOperandSize
OP32 [Operand
op1, Operand
op2]
parseVMWRITE :: p -> Word8Parser Instr
parseVMWRITE p
b = 
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if PState -> Bool
in64BitMode PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMWRITE InstrOperandSize
OP64 [Operand
op1, Operand
op2]
	  else do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP32
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
VMWRITE InstrOperandSize
OP32 [Operand
op1, Operand
op2]

parseHADDPS :: p -> Word8Parser Instr
parseHADDPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
InvalidOpcode Opcode
InvalidOpcode Opcode
HADDPD Opcode
HADDPS
parseHSUBPS :: p -> Word8Parser Instr
parseHSUBPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
InvalidOpcode Opcode
InvalidOpcode Opcode
HSUBPS Opcode
HSUBPD

parseMOVD_Q :: Word8 -> Word8Parser Instr
parseMOVD_Q = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented

parseJccLong :: a -> Word8Parser Instr
parseJccLong a
b = do
  Int32
disp <- Word8Parser Int32
anyIntZ
  let disp' :: Int
      disp' :: Int
disp' = Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
disp
  SourcePos
pos <- ParsecT [Word8] PState Identity SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr (a -> Opcode
forall a. (Eq a, Num a) => a -> Opcode
jccname (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf)) InstrOperandSize
OPNONE
        [Word32 -> InstrOperandSize -> Operand
OpAddr (Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
disp' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ SourcePos -> Int
sourceColumn SourcePos
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+
                (PState -> Word32
startAddr PState
st)) InstrOperandSize
OPNONE]

parseSETcc :: a -> Word8Parser Instr
parseSETcc a
b = do
  (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP8
  case Operand
op1 of
    OpReg String
name Int
num -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr (a -> Opcode
forall a. (Eq a, Num a) => a -> Opcode
setccname (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf)) InstrOperandSize
OPNONE 
		      [String -> Int -> Operand
OpReg ([String]
regnames8 [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
num) Int
num]
    Operand
_ -> Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr (a -> Opcode
forall a. (Eq a, Num a) => a -> Opcode
setccname (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf)) InstrOperandSize
OPNONE [Operand
op1]

parseSHLD :: a -> Word8Parser Instr
parseSHLD a
0xa4 = 
    do InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
       Word8
b <- Word8Parser Word8
anyWord8
       InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SHLD InstrOperandSize
opsize [Operand
op1, Operand
op2, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]
parseSHLD a
0xa5 = 
    do InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
       InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SHLD InstrOperandSize
opsize [Operand
op1, Operand
op2, String -> Int -> Operand
OpReg String
"cl" Int
1]
parseSHRD :: a -> Word8Parser Instr
parseSHRD a
0xac = 
    do InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
       Word8
b <- Word8Parser Word8
anyWord8
       InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SHRD InstrOperandSize
opsize [Operand
op1, Operand
op2, Word32 -> Operand
OpImm (Word8 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)]
parseSHRD a
0xad = 
    do InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
opsize
       InstrOperandSize
opsize <- ParsecT [Word8] PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
SHRD InstrOperandSize
opsize [Operand
op1, Operand
op2, String -> Int -> Operand
OpReg String
"cl" Int
1]

parseCMPPS :: Word8 -> Word8Parser Instr
parseCMPPS = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseMOVNTI :: Word8 -> Word8Parser Instr
parseMOVNTI = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePINSRW :: Word8 -> Word8Parser Instr
parsePINSRW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePEXTRW :: Word8 -> Word8Parser Instr
parsePEXTRW = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parseSHUFPS :: Word8 -> Word8Parser Instr
parseSHUFPS = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented

parseBSWAP :: a -> ParsecT s PState Identity Instr
parseBSWAP a
b = 
    do let reg :: a
reg = (a
b a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
0xf) a -> a -> a
forall a. Num a => a -> a -> a
- a
8
       String
r <- Int -> ParsecT s PState Identity String
forall (m :: * -> *) s. Monad m => Int -> ParsecT s PState m String
registerName (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)
       InstrOperandSize
opsize <- ParsecT s PState Identity InstrOperandSize
forall s. ParsecT s PState Identity InstrOperandSize
instrOperandSize
       Instr -> ParsecT s PState Identity Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> ParsecT s PState Identity Instr)
-> Instr -> ParsecT s PState Identity Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
BSWAP InstrOperandSize
opsize [String -> Int -> Operand
OpReg String
r (a -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
reg)]

parseADDSUBPS :: p -> Word8Parser Instr
parseADDSUBPS = Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
forall p.
Opcode -> Opcode -> Opcode -> Opcode -> p -> Word8Parser Instr
parseXmmVW Opcode
InvalidOpcode Opcode
InvalidOpcode Opcode
ADDSUBPD Opcode
ADDUBPS

parseMmxXmmPQVW :: Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
opcode p
b =
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP128
		  let v :: Operand
v = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  let w :: Operand
w = case Operand
op1 of
			    OpReg String
_ Int
num -> String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num
			    Operand
op -> Operand
op
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode InstrOperandSize
OP128 [Operand
v, Operand
w]
	  else do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  let p :: Operand
p = String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  let q :: Operand
q = case Operand
op1 of
			    OpReg String
_ Int
num -> String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! Int
num) Int
num
			    Operand
op -> Operand
op
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode InstrOperandSize
OP128 [Operand
p, Operand
q]

parseMmxXmmMPMV :: Opcode -> Opcode -> p -> Word8Parser Instr
parseMmxXmmMPMV Opcode
opcode1 Opcode
opcode2 p
b =
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP128
		  let v :: Operand
v = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode2 InstrOperandSize
OP128 [Operand
op1, Operand
v]
	  else do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  let p :: Operand
p = String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode1 InstrOperandSize
OP128 [Operand
op1, Operand
p]

parseMmxXmmPNVU :: Opcode -> p -> Word8Parser Instr
parseMmxXmmPNVU Opcode
opcode p
b =
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	  then do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
		  let v :: Operand
v = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  let u :: Operand
u = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode InstrOperandSize
OP128 [Operand
v, Operand
u]
	  else do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  let p :: Operand
p = String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)) 
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  let n :: Operand
n = String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
			  (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
opcode InstrOperandSize
OP128 [Operand
p, Operand
n]

parsePSRLW :: p -> Word8Parser Instr
parsePSRLW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSRLW
parsePSRLD :: p -> Word8Parser Instr
parsePSRLD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSRLD
parsePSRLQ :: p -> Word8Parser Instr
parsePSRLQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSRLQ
parsePADDQ :: p -> Word8Parser Instr
parsePADDQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDQ
parsePMULLW :: p -> Word8Parser Instr
parsePMULLW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMULLW
parseMOVQ :: Word8 -> Word8Parser Instr
parseMOVQ b :: Word8
b@Word8
0x6f = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented Word8
b
parseMOVQ b :: Word8
b@Word8
0x7f = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented Word8
b
parseMOVQ b :: Word8
b@Word8
0xd6 = 
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP64
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVQ InstrOperandSize
OP64 [Operand
op1, Operand
op2]
	  else if Word8 -> PState -> Bool
hasPrefix Word8
0xf3 PState
st
	          then do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
			  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVQ InstrOperandSize
OPNONE 
				     [String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
				      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
				      String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
				      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
		  else
		    if Word8 -> PState -> Bool
hasPrefix Word8
0xf2 PState
st
		       then do (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
			       Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
MOVQ InstrOperandSize
OPNONE
				[String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
				 (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
				 String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
				 (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
		       else Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
			  
parsePMOVMSKB :: p -> Word8Parser Instr
parsePMOVMSKB p
b = 
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       (Word8
mod, Word8
reg, Word8
rm) <- ParsecT [Word8] PState Identity (Word8, Word8, Word8)
parseModRM
       if Word8 -> PState -> Bool
hasPrefix Word8
0x66 PState
st
	  then do Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PMOVMSKB InstrOperandSize
OPNONE 
			     [String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
			      String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
	  else do Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
PMOVMSKB InstrOperandSize
OPNONE 
			     [String -> Int -> Operand
OpReg ([String]
regnames32 [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg),
			      String -> Int -> Operand
OpReg ([String]
mmxregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm))
			      (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
rm)]
parsePSUBUSB :: p -> Word8Parser Instr
parsePSUBUSB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBUSB
parsePSUBUSW :: p -> Word8Parser Instr
parsePSUBUSW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBUSW
parsePMINUB :: p -> Word8Parser Instr
parsePMINUB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMINUB
parsePAND :: p -> Word8Parser Instr
parsePAND = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PAND
parsePADDUSB :: p -> Word8Parser Instr
parsePADDUSB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDUSB
parsePADDUSW :: p -> Word8Parser Instr
parsePADDUSW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDUSW
parsePMAXUB :: p -> Word8Parser Instr
parsePMAXUB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMAXUB
parsePANDN :: p -> Word8Parser Instr
parsePANDN = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PANDN
parsePAVGB :: p -> Word8Parser Instr
parsePAVGB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PAVGB
parsePSRAW :: p -> Word8Parser Instr
parsePSRAW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSRAW
parsePSRAD :: p -> Word8Parser Instr
parsePSRAD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSRAD
parsePAVGW :: p -> Word8Parser Instr
parsePAVGW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PAVGW
parseCVTPD2DQ :: Word8 -> Word8Parser Instr
parseCVTPD2DQ = Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseUnimplemented
parsePMULHUW :: p -> Word8Parser Instr
parsePMULHUW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMULHUW
parsePMULHW :: p -> Word8Parser Instr
parsePMULHW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMULHW
parseMOVNTQ :: p -> Word8Parser Instr
parseMOVNTQ = Opcode -> Opcode -> p -> Word8Parser Instr
forall p. Opcode -> Opcode -> p -> Word8Parser Instr
parseMmxXmmMPMV Opcode
MOVNTQ Opcode
MOVNTDQ
parsePSUBSB :: p -> Word8Parser Instr
parsePSUBSB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBSB
parsePSUBSQ :: p -> Word8Parser Instr
parsePSUBSQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBSQ
parsePMINSW :: p -> Word8Parser Instr
parsePMINSW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMINSW
parsePOR :: p -> Word8Parser Instr
parsePOR = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
POR
parsePADDSB :: p -> Word8Parser Instr
parsePADDSB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDSB
parsePADDSW :: p -> Word8Parser Instr
parsePADDSW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDSW
parsePMAXSW :: p -> Word8Parser Instr
parsePMAXSW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMAXSW
parsePXOR :: p -> Word8Parser Instr
parsePXOR = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PXOR
parseLDDQU :: Word8 -> Word8Parser Instr
parseLDDQU Word8
b = 
    do PState
st <- ParsecT [Word8] PState Identity PState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
       if Word8 -> PState -> Bool
hasPrefix Word8
0xf2 PState
st
	  then do (Operand
op1, Operand
op2, Word8
mod, Word8
reg, Word8
rm) <- InstrOperandSize
-> Word8Parser (Operand, Operand, Word8, Word8, Word8)
parseAddress32 InstrOperandSize
OP128
		  let v :: Operand
v = String -> Int -> Operand
OpReg ([String]
xmmregs [String] -> Int -> String
forall a. [a] -> Int -> a
!! (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg))
		          (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
reg)
		  Instr -> Word8Parser Instr
forall (m :: * -> *) a. Monad m => a -> m a
return (Instr -> Word8Parser Instr) -> Instr -> Word8Parser Instr
forall a b. (a -> b) -> a -> b
$ Opcode -> InstrOperandSize -> [Operand] -> Instr
Instr Opcode
LDDQU InstrOperandSize
OP128 [Operand
v, Operand
op1]
	  else Word8 -> Word8Parser Instr
forall (m :: * -> *). Monad m => Word8 -> m Instr
parseInvalidOpcode Word8
b
parsePSLLW :: p -> Word8Parser Instr
parsePSLLW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSLLW
parsePSLLD :: p -> Word8Parser Instr
parsePSLLD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSLLD
parsePSLLQ :: p -> Word8Parser Instr
parsePSLLQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSLLQ
parsePMULUDQ :: p -> Word8Parser Instr
parsePMULUDQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMULUDQ
parsePMADDWD :: p -> Word8Parser Instr
parsePMADDWD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PMADDWD
parsePSADBW :: p -> Word8Parser Instr
parsePSADBW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSADBW
parseMASKMOVQ :: p -> Word8Parser Instr
parseMASKMOVQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPNVU Opcode
MASKMOVQ
parsePSUBB :: p -> Word8Parser Instr
parsePSUBB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBB
parsePSUBW :: p -> Word8Parser Instr
parsePSUBW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBW
parsePSUBD :: p -> Word8Parser Instr
parsePSUBD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBD
parsePSUBQ :: p -> Word8Parser Instr
parsePSUBQ = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PSUBQ
parsePADDB :: p -> Word8Parser Instr
parsePADDB = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDB
parsePADDW :: p -> Word8Parser Instr
parsePADDW = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDW
parsePADDD :: p -> Word8Parser Instr
parsePADDD = Opcode -> p -> Word8Parser Instr
forall p. Opcode -> p -> Word8Parser Instr
parseMmxXmmPQVW Opcode
PADDD