x86-64bit-0.4.6.1: Runtime code generation for x86 64 bit machine code

Safe HaskellNone
LanguageHaskell2010

CodeGen.X86

Contents

Synopsis

Byte sequences

type Bytes = [Word8] Source #

class HasBytes a where Source #

Methods

toBytes :: a -> Bytes Source #

Instances
HasBytes Int8 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Int8 -> Bytes Source #

HasBytes Int16 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Int16 -> Bytes Source #

HasBytes Int32 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Int32 -> Bytes Source #

HasBytes Int64 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Int64 -> Bytes Source #

HasBytes Word8 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Word8 -> Bytes Source #

HasBytes Word16 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Word16 -> Bytes Source #

HasBytes Word32 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Word32 -> Bytes Source #

HasBytes Word64 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

toBytes :: Word64 -> Bytes Source #

HasBytes CString Source # 
Instance details

Defined in CodeGen.X86.Utils

Sizes (in bits)

data Size Source #

The size of a register (in bits)

Constructors

S1 
S8 
S16 
S32 
S64 
S128 
Instances
Eq Size Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(==) :: Size -> Size -> Bool #

(/=) :: Size -> Size -> Bool #

Ord Size Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

compare :: Size -> Size -> Ordering #

(<) :: Size -> Size -> Bool #

(<=) :: Size -> Size -> Bool #

(>) :: Size -> Size -> Bool #

(>=) :: Size -> Size -> Bool #

max :: Size -> Size -> Size #

min :: Size -> Size -> Size #

Show Size Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

showsPrec :: Int -> Size -> ShowS #

show :: Size -> String #

showList :: [Size] -> ShowS #

class HasSize a where Source #

Methods

size :: a -> Size Source #

Instances
HasSize Int8 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Int8 -> Size Source #

HasSize Int16 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Int16 -> Size Source #

HasSize Int32 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Int32 -> Size Source #

HasSize Int64 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Int64 -> Size Source #

HasSize Word8 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Word8 -> Size Source #

HasSize Word16 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Word16 -> Size Source #

HasSize Word32 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Word32 -> Size Source #

HasSize Word64 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Word64 -> Size Source #

IsSize s => HasSize (Address s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Address s -> Size Source #

IsSize s => HasSize (IndexReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: IndexReg s -> Size Source #

IsSize s => HasSize (BaseReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: BaseReg s -> Size Source #

IsSize s => HasSize (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Addr s -> Size Source #

IsSize s => HasSize (Reg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Reg s -> Size Source #

IsSize s => HasSize (Operand a s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Operand a s -> Size Source #

class IsSize (s :: Size) Source #

Minimal complete definition

ssize

Instances
IsSize S1 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S1

IsSize S8 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S8

IsSize S16 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S16

IsSize S32 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S32

IsSize S64 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S64

IsSize S128 Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

ssize :: SSize S128

data EqT s s' where Source #

Constructors

Refl :: EqT s s 

sizeEqCheck :: forall s s' f g. (IsSize s, IsSize s') => f s -> g s' -> Maybe (EqT s s') Source #

Registers

data Reg :: Size -> * where Source #

A register.

Constructors

NormalReg :: Word8 -> Reg s 
HighReg :: Word8 -> Reg S8 
XMM :: Word8 -> Reg S128 
Instances
FromReg Reg Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Reg s Source #

Eq (Reg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(==) :: Reg s -> Reg s -> Bool #

(/=) :: Reg s -> Reg s -> Bool #

Ord (Reg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

compare :: Reg s -> Reg s -> Ordering #

(<) :: Reg s -> Reg s -> Bool #

(<=) :: Reg s -> Reg s -> Bool #

(>) :: Reg s -> Reg s -> Bool #

(>=) :: Reg s -> Reg s -> Bool #

max :: Reg s -> Reg s -> Reg s #

min :: Reg s -> Reg s -> Reg s #

IsSize s => Show (Reg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

showsPrec :: Int -> Reg s -> ShowS #

show :: Reg s -> String #

showList :: [Reg s] -> ShowS #

IsSize s => HasSize (BaseReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: BaseReg s -> Size Source #

IsSize s => HasSize (Reg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Reg s -> Size Source #

class FromReg c where Source #

Methods

fromReg :: Reg s -> c s Source #

Instances
FromReg Address Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Address s Source #

FromReg Reg Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Reg s Source #

FromReg (Operand r) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Operand r s Source #

64 bit registers

rax :: FromReg c => c S64 Source #

rcx :: FromReg c => c S64 Source #

rdx :: FromReg c => c S64 Source #

rbx :: FromReg c => c S64 Source #

rsp :: FromReg c => c S64 Source #

rbp :: FromReg c => c S64 Source #

rsi :: FromReg c => c S64 Source #

rdi :: FromReg c => c S64 Source #

r8 :: FromReg c => c S64 Source #

r9 :: FromReg c => c S64 Source #

r10 :: FromReg c => c S64 Source #

r11 :: FromReg c => c S64 Source #

r12 :: FromReg c => c S64 Source #

r13 :: FromReg c => c S64 Source #

r14 :: FromReg c => c S64 Source #

r15 :: FromReg c => c S64 Source #

32 bit registers

eax :: FromReg c => c S32 Source #

ecx :: FromReg c => c S32 Source #

edx :: FromReg c => c S32 Source #

ebx :: FromReg c => c S32 Source #

esp :: FromReg c => c S32 Source #

ebp :: FromReg c => c S32 Source #

esi :: FromReg c => c S32 Source #

edi :: FromReg c => c S32 Source #

r8d :: FromReg c => c S32 Source #

r9d :: FromReg c => c S32 Source #

r10d :: FromReg c => c S32 Source #

r11d :: FromReg c => c S32 Source #

r12d :: FromReg c => c S32 Source #

r13d :: FromReg c => c S32 Source #

r14d :: FromReg c => c S32 Source #

r15d :: FromReg c => c S32 Source #

16 bit registers

ax :: FromReg c => c S16 Source #

cx :: FromReg c => c S16 Source #

dx :: FromReg c => c S16 Source #

bx :: FromReg c => c S16 Source #

sp :: FromReg c => c S16 Source #

bp :: FromReg c => c S16 Source #

si :: FromReg c => c S16 Source #

di :: FromReg c => c S16 Source #

r8w :: FromReg c => c S16 Source #

r9w :: FromReg c => c S16 Source #

r10w :: FromReg c => c S16 Source #

r11w :: FromReg c => c S16 Source #

r12w :: FromReg c => c S16 Source #

r13w :: FromReg c => c S16 Source #

r14w :: FromReg c => c S16 Source #

r15w :: FromReg c => c S16 Source #

8 bit low registers

al :: FromReg c => c S8 Source #

cl :: FromReg c => c S8 Source #

dl :: FromReg c => c S8 Source #

bl :: FromReg c => c S8 Source #

spl :: FromReg c => c S8 Source #

bpl :: FromReg c => c S8 Source #

sil :: FromReg c => c S8 Source #

dil :: FromReg c => c S8 Source #

r8b :: FromReg c => c S8 Source #

r9b :: FromReg c => c S8 Source #

r10b :: FromReg c => c S8 Source #

r11b :: FromReg c => c S8 Source #

r12b :: FromReg c => c S8 Source #

r13b :: FromReg c => c S8 Source #

r14b :: FromReg c => c S8 Source #

r15b :: FromReg c => c S8 Source #

8 bit high registers

ah :: FromReg c => c S8 Source #

ch :: FromReg c => c S8 Source #

dh :: FromReg c => c S8 Source #

bh :: FromReg c => c S8 Source #

SSE registers

Addresses

data Addr s Source #

A (relative) address is made up base a base register, a displacement, and a (scaled) index. For example in [eax+4*ecx+20] the base register is eax, the displacement is 20 and the index is 4*ecx.

Constructors

Addr 
Instances
Eq (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(==) :: Addr s -> Addr s -> Bool #

(/=) :: Addr s -> Addr s -> Bool #

IsSize s => Show (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

showsPrec :: Int -> Addr s -> ShowS #

show :: Addr s -> String #

showList :: [Addr s] -> ShowS #

Semigroup (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(<>) :: Addr s -> Addr s -> Addr s #

sconcat :: NonEmpty (Addr s) -> Addr s #

stimes :: Integral b => b -> Addr s -> Addr s #

Monoid (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

mempty :: Addr s #

mappend :: Addr s -> Addr s -> Addr s #

mconcat :: [Addr s] -> Addr s #

IsSize s => HasSize (Addr s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Addr s -> Size Source #

type BaseReg s = Maybe (Reg s) Source #

data IndexReg s Source #

Constructors

NoIndex 
IndexReg Scale (Reg s) 
Instances
Eq (IndexReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(==) :: IndexReg s -> IndexReg s -> Bool #

(/=) :: IndexReg s -> IndexReg s -> Bool #

Semigroup (IndexReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(<>) :: IndexReg s -> IndexReg s -> IndexReg s #

sconcat :: NonEmpty (IndexReg s) -> IndexReg s #

stimes :: Integral b => b -> IndexReg s -> IndexReg s #

Monoid (IndexReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

mempty :: IndexReg s #

mappend :: IndexReg s -> IndexReg s -> IndexReg s #

mconcat :: [IndexReg s] -> IndexReg s #

IsSize s => HasSize (IndexReg s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: IndexReg s -> Size Source #

data Scale Source #

The scaling of an index. (replace with Size?)

Instances
Eq Scale Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(==) :: Scale -> Scale -> Bool #

(/=) :: Scale -> Scale -> Bool #

data Address :: Size -> * Source #

Instances
FromReg Address Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Address s Source #

Num (Address s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(+) :: Address s -> Address s -> Address s #

(-) :: Address s -> Address s -> Address s #

(*) :: Address s -> Address s -> Address s #

negate :: Address s -> Address s #

abs :: Address s -> Address s #

signum :: Address s -> Address s #

fromInteger :: Integer -> Address s #

IsSize s => HasSize (Address s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Address s -> Size Source #

addr :: IsSize s => Address s -> Operand rw s' Source #

addr8 :: IsSize s => Address s -> Operand rw S8 Source #

addr with specialized type

addr16 :: IsSize s => Address s -> Operand rw S16 Source #

addr with specialized type

addr32 :: IsSize s => Address s -> Operand rw S32 Source #

addr with specialized type

addr64 :: IsSize s => Address s -> Operand rw S64 Source #

addr with specialized type

ipRel :: Label -> Operand rw s Source #

intruction pointer (RIP) relative address

ipRel8 :: Label -> Operand rw S8 Source #

ipRel with specialized type

Operands

data Access Source #

Operand access modes

Constructors

R

readable operand

RW

readable and writeable operand

data Operand :: Access -> Size -> * where Source #

An operand can be an immediate, a register, a memory address or RIP-relative (memory address relative to the instruction pointer)

Constructors

ImmOp :: Immediate Int64 -> Operand R s 
RegOp :: Reg s -> Operand rw s 
MemOp :: IsSize s' => Addr s' -> Operand rw s 
IPMemOp :: Immediate Int32 -> Operand rw s 
Instances
FromReg (Operand r) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

fromReg :: Reg s -> Operand r s Source #

rw ~ R => Num (Operand rw s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

(+) :: Operand rw s -> Operand rw s -> Operand rw s #

(-) :: Operand rw s -> Operand rw s -> Operand rw s #

(*) :: Operand rw s -> Operand rw s -> Operand rw s #

negate :: Operand rw s -> Operand rw s #

abs :: Operand rw s -> Operand rw s #

signum :: Operand rw s -> Operand rw s #

fromInteger :: Integer -> Operand rw s #

IsSize s => Show (Operand a s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

showsPrec :: Int -> Operand a s -> ShowS #

show :: Operand a s -> String #

showList :: [Operand a s] -> ShowS #

IsSize s => HasSize (Operand a s) Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

size :: Operand a s -> Size Source #

Conditions

data Condition Source #

Instances
Show Condition Source # 
Instance details

Defined in CodeGen.X86.Asm

pattern N :: Condition -> Condition Source #

pattern O :: Condition Source #

pattern NO :: Condition Source #

pattern B :: Condition Source #

pattern C :: Condition Source #

pattern NB :: Condition Source #

pattern NC :: Condition Source #

pattern E :: Condition Source #

pattern Z :: Condition Source #

pattern NE :: Condition Source #

pattern NZ :: Condition Source #

pattern NA :: Condition Source #

pattern BE :: Condition Source #

pattern A :: Condition Source #

pattern NBE :: Condition Source #

pattern S :: Condition Source #

pattern NS :: Condition Source #

pattern P :: Condition Source #

pattern NP :: Condition Source #

pattern L :: Condition Source #

pattern NL :: Condition Source #

pattern NG :: Condition Source #

pattern LE :: Condition Source #

pattern G :: Condition Source #

pattern NLE :: Condition Source #

Instructions

type Code = CodeM () Source #

data CodeM a Source #

Instances
Monad CodeM Source # 
Instance details

Defined in CodeGen.X86.CodeGen

Methods

(>>=) :: CodeM a -> (a -> CodeM b) -> CodeM b #

(>>) :: CodeM a -> CodeM b -> CodeM b #

return :: a -> CodeM a #

fail :: String -> CodeM a #

Functor CodeM Source # 
Instance details

Defined in CodeGen.X86.CodeGen

Methods

fmap :: (a -> b) -> CodeM a -> CodeM b #

(<$) :: a -> CodeM b -> CodeM a #

Show Code Source # 
Instance details

Defined in CodeGen.X86.CodeGen

Methods

showsPrec :: Int -> Code -> ShowS #

show :: Code -> String #

showList :: [Code] -> ShowS #

MonadFix CodeM Source # 
Instance details

Defined in CodeGen.X86.CodeGen

Methods

mfix :: (a -> CodeM a) -> CodeM a #

Applicative CodeM Source # 
Instance details

Defined in CodeGen.X86.CodeGen

Methods

pure :: a -> CodeM a #

(<*>) :: CodeM (a -> b) -> CodeM a -> CodeM b #

liftA2 :: (a -> b -> c) -> CodeM a -> CodeM b -> CodeM c #

(*>) :: CodeM a -> CodeM b -> CodeM b #

(<*) :: CodeM a -> CodeM b -> CodeM a #

Pseudo instructions

data Label Source #

Instances
Show Label Source # 
Instance details

Defined in CodeGen.X86.Asm

Methods

showsPrec :: Int -> Label -> ShowS #

show :: Label -> String #

showList :: [Label] -> ShowS #

Control instructions

Flag manipulation

Conditionals

cmp :: IsSize s => Operand RW s -> Operand r s -> Code Source #

test :: IsSize s => Operand RW s -> Operand r s -> Code Source #

bt :: IsSize s => Operand r s -> Operand RW s -> Code Source #

bsf :: IsSize s => Operand RW s -> Operand r s -> Code Source #

bsr :: IsSize s => Operand RW s -> Operand r s -> Code Source #

Arithmetic

add :: IsSize s => Operand RW s -> Operand r s -> Code Source #

adc :: IsSize s => Operand RW s -> Operand r s -> Code Source #

sub :: IsSize s => Operand RW s -> Operand r s -> Code Source #

sbb :: IsSize s => Operand RW s -> Operand r s -> Code Source #

lea :: (IsSize s, IsSize s') => Operand RW s -> Operand RW s' -> Code Source #

Bit manipulation

and_ :: IsSize s => Operand RW s -> Operand r s -> Code Source #

or_ :: IsSize s => Operand RW s -> Operand r s -> Code Source #

xor_ :: IsSize s => Operand RW s -> Operand r s -> Code Source #

rol :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

ror :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

rcl :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

rcr :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

shl :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

shr :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

sar :: IsSize s => Operand RW s -> Operand r S8 -> Code Source #

Byte manipulation/move

xchg :: IsSize s => Operand RW s -> Operand RW s -> Code Source #

mov :: IsSize s => Operand RW s -> Operand r s -> Code Source #

SSE

movd :: (IsSize s, IsSize s') => Operand RW s -> Operand r s' -> Code Source #

movq :: (IsSize s, IsSize s') => Operand RW s -> Operand r s' -> Code Source #

Compound instructions

unless :: Condition -> CodeM a -> CodeM () Source #

execute code unless condition is true

doWhile :: Condition -> CodeM a -> CodeM () Source #

do while loop construction

if_ :: Condition -> CodeM a1 -> CodeM a2 -> CodeM () Source #

if-then-else

leaData :: (IsSize s, HasBytes a) => Operand RW s -> a -> CodeM () Source #

Compilation

Calling convention

saveNonVolatile :: Code -> Code Source #

Save the non-volatile registers, execute the code, restore the registers and return after.

Note: R12..R15 should be preserved on both Windows and Linux (or System V convention in general). This is the responsability of the user (this function won't save them, but you can use "saveR12R15" in addition to this).

saveR12R15 :: Code -> Code Source #

Saves R12, R13, R14 and R15 (on the stack).

arg1 :: FromReg c => c S64 Source #

arg2 :: FromReg c => c S64 Source #

arg3 :: FromReg c => c S64 Source #

arg4 :: FromReg c => c S64 Source #

Calling C and Haskell from Assembly

class (MapResult a, NFData (Result a)) => Callable a where Source #

Methods

dynCCall :: FunPtr a -> a Source #

class MapResult a => CallableHs a where Source #

Methods

createHsPtr :: a -> IO (FunPtr a) Source #

hsPtr :: CallableHs a => a -> FunPtr a Source #

newtype CString Source #

Constructors

CString String 
Instances
HasBytes CString Source # 
Instance details

Defined in CodeGen.X86.Utils