         t <- fromIntegral <$> {#get cs_xcore_op->type#} p
         let bP = plusPtr p 4
         case toEnum t of
-          XcoreOpReg -> Reg <$> peek bP
+          XcoreOpReg -> (Reg . toEnum . fromIntegral) <$> (peek bP :: IO Int32)
           XcoreOpImm -> Imm <$> peek bP
           XcoreOpMem -> Mem <$> peek bP
           _ -> return Undefined

        let bP = plusPtr p 4
            setType = {#set cs_xcore_op->type#} p . fromIntegral . fromEnum
        case op of
          Reg r -> poke bP r >> setType XcoreOpReg
          Imm i -> poke bP i >> setType XcoreOpImm
          Mem m -> poke bP m >> setType XcoreOpMem
          _ -> setType XcoreOpInvalid

{#enum xcore_op_type as XCoreOpType {underscoreToCase}
    deriving (Show, Eq, Bounded)#}

-- | XCore registers
{#enum xcore_reg as XCoreReg {underscoreToCase}
    deriving (Show, Eq, Bounded)#}

-- | memory access operands
-- associated with 'XcoreOpMem' operand type
data XCoreOpMemStruct = XCoreOpMemStruct
