x86-64bit 0.4.2 → 0.4.3
raw patch · 6 files changed
+191/−170 lines, 6 files
Files
- CHANGELOG.md +4/−0
- CodeGen/X86.hs +163/−163
- CodeGen/X86/CallConv.hs +19/−3
- CodeGen/X86/FFI.hs +3/−2
- Control/DeeperSeq.hs +1/−1
- x86-64bit.cabal +1/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+# Version 0.4.3 + +- fixes to compile on GHC 7.10 and on Windows + # Version 0.4.2 - fix OSX compilation
CodeGen/X86.hs view
@@ -1,163 +1,163 @@-{-# language PatternSynonyms #-} -module CodeGen.X86 - ( - -- * Byte sequences - Bytes (..) - , HasBytes (..) - -- * Sizes (in bits) - , Size (..) - , HasSize (..) - , IsSize - -- * Registers - -- ** 64 bit registers - , rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15 - -- ** 32 bit registers - , eax, ecx, edx, ebx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d - -- ** 16 bit registers - , ax, cx, dx, bx, sp, bp, si, di, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w - -- ** 8 bit low registers - , al, cl, dl, bl, spl, bpl, sil, dil, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b - -- ** 8 bit high registers - , ah, ch, dh, bh - -- ** SSE registers - , xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7 - -- * Addresses - , addr - , addr8 - , addr16 - , addr32 - , addr64 - , ipRel - , ipRel8 - -- * Operands - , Access (..) - , Operand - , resizeOperand - , ipRelValue - -- * Conditions - , Condition - , pattern N - , pattern O - , pattern NO - , pattern B, pattern C - , pattern NB, pattern NC - , pattern E, pattern Z - , pattern NE, pattern NZ - , pattern NA, pattern BE - , pattern A, pattern NBE - , pattern S - , pattern NS - , pattern P - , pattern NP - , pattern L - , pattern NL - , pattern NG, pattern LE - , pattern G, pattern NLE - -- * Instructions - , Code, CodeM - -- ** Pseudo instructions - , db - , align - , Label - , label - -- ** Control - , j - , jmp - , jmpq - , call - , ret - -- ** Flags - , cmc - , clc - , stc - , cli - , sti - , cld - , std - , pushf - , popf - , cmp - , test - -- ** Arithmetic - , inc - , dec - , not_ - , neg - , add - , adc - , sub - , sbb - , and_ - , or_ - , xor_ - , rol - , ror - , rcl - , rcr - , shl - , shr - , sar - , lea - -- ** Other - , nop - , xchg - , mov - , cmov - , pop - , push - -- ** SSE - , movd - , movq - , movdqa - , paddb - , paddw - , paddd - , paddq - , psubb - , psubw - , psubd - , psubq - , pxor - , psllw - , pslld - , psllq - , pslldq - , psrlw - , psrld - , psrlq - , psrldq - , psraw - , psrad - -- * Compound instructions - , unless - , doWhile - , if_ - , leaData - , traceReg - -- * Compilation - , compile - , preBuild - -- * Calling convention - , saveNonVolatile - , arg1, arg2, arg3, arg4 - , result - -- * Calling C and Haskell from Assembly - , Callable (..) - , CallableHs (..) - , callFun - , printf - , hsPtr - , CString (..) - -- * Misc - , runTests - ) where - -import Data.Monoid - -import CodeGen.X86.Asm -import CodeGen.X86.CodeGen -import CodeGen.X86.FFI -import CodeGen.X86.CallConv -import CodeGen.X86.Utils -import CodeGen.X86.Tests - +{-# language PatternSynonyms #-}+module CodeGen.X86+ (+ -- * Byte sequences+ Bytes (..)+ , HasBytes (..)+ -- * Sizes (in bits)+ , Size (..)+ , HasSize (..)+ , IsSize+ -- * Registers+ -- ** 64 bit registers+ , rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15+ -- ** 32 bit registers+ , eax, ecx, edx, ebx, esp, ebp, esi, edi, r8d, r9d, r10d, r11d, r12d, r13d, r14d, r15d+ -- ** 16 bit registers+ , ax, cx, dx, bx, sp, bp, si, di, r8w, r9w, r10w, r11w, r12w, r13w, r14w, r15w+ -- ** 8 bit low registers+ , al, cl, dl, bl, spl, bpl, sil, dil, r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b+ -- ** 8 bit high registers+ , ah, ch, dh, bh+ -- ** SSE registers+ , xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7+ -- * Addresses+ , addr+ , addr8+ , addr16+ , addr32+ , addr64+ , ipRel+ , ipRel8+ -- * Operands+ , Access (..)+ , Operand+ , resizeOperand+ , ipRelValue+ -- * Conditions+ , Condition+ , pattern N+ , pattern O+ , pattern NO+ , pattern B, pattern C+ , pattern NB, pattern NC+ , pattern E, pattern Z+ , pattern NE, pattern NZ+ , pattern NA, pattern BE+ , pattern A, pattern NBE+ , pattern S+ , pattern NS+ , pattern P+ , pattern NP+ , pattern L+ , pattern NL+ , pattern NG, pattern LE+ , pattern G, pattern NLE+ -- * Instructions+ , Code, CodeM+ -- ** Pseudo instructions+ , db+ , align+ , Label+ , label+ -- ** Control+ , j+ , jmp+ , jmpq+ , call+ , ret+ -- ** Flags+ , cmc+ , clc+ , stc+ , cli+ , sti+ , cld+ , std+ , pushf+ , popf+ , cmp+ , test+ -- ** Arithmetic+ , inc+ , dec+ , not_+ , neg+ , add+ , adc+ , sub+ , sbb+ , and_+ , or_+ , xor_+ , rol+ , ror+ , rcl+ , rcr+ , shl+ , shr+ , sar+ , lea+ -- ** Other+ , nop+ , xchg+ , mov+ , cmov+ , pop+ , push+ -- ** SSE+ , movd+ , movq+ , movdqa+ , paddb+ , paddw+ , paddd+ , paddq+ , psubb+ , psubw+ , psubd+ , psubq+ , pxor+ , psllw+ , pslld+ , psllq+ , pslldq+ , psrlw+ , psrld+ , psrlq+ , psrldq+ , psraw+ , psrad+ -- * Compound instructions+ , unless+ , doWhile+ , if_+ , leaData+ , traceReg+ -- * Compilation+ , compile+ , preBuild+ -- * Calling convention+ , saveNonVolatile, saveR12R15+ , arg1, arg2, arg3, arg4+ , result+ -- * Calling C and Haskell from Assembly+ , Callable (..)+ , CallableHs (..)+ , callFun+ , printf+ , hsPtr+ , CString (..)+ -- * Misc+ , runTests+ ) where++import Data.Monoid++import CodeGen.X86.Asm+import CodeGen.X86.CodeGen+import CodeGen.X86.FFI+import CodeGen.X86.CallConv+import CodeGen.X86.Utils+import CodeGen.X86.Tests+
CodeGen/X86/CallConv.hs view
@@ -51,13 +51,29 @@ ------------------------------------------------------------------------------ --- | Save the non-volatile registers +-- | 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.--- This is the responsability of the user (this won't save them).+-- 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). -- saveNonVolatile :: Code -> Code saveNonVolatile code = prologue >> code >> epilogue >> ret++-- | Saves R12, R13, R14 and R15 (on the stack).+saveR12R15 :: Code -> Code+saveR12R15 code = do+ push r12+ push r13+ push r14+ push r15+ code+ pop r15+ pop r14+ pop r13+ pop r12 ------------------------------------------------------------------------------ -- calling conventions
CodeGen/X86/FFI.hs view
@@ -39,8 +39,9 @@ {-# NOINLINE callForeignPtr #-} callForeignPtr :: Callable a => IO (ForeignPtr a) -> a-callForeignPtr p_ = mapResult f (dynCCall $ castPtrToFunPtr $ unsafeForeignPtrToPtr p)+callForeignPtr p_ = mapResult f (dynCCall $ cast $ unsafeForeignPtrToPtr p) where+ cast = castPtrToFunPtr :: Ptr a -> FunPtr a p = unsafePerformIO p_ {-# NOINLINE f #-} f x = unsafePerformIO $ evaluate (force x) <* touchForeignPtr p@@ -88,7 +89,7 @@ {-# NOINLINE compile #-} compile :: Callable a => Code -> a compile x = callForeignPtr $ do- let (bytes, fromIntegral -> size) = buildTheCode x+ let (bytes, size) = buildTheCode x arr <- c_aligned_malloc (fromIntegral size) PAGE_SIZE _ <- virtualProtect (castPtr arr) (fromIntegral size) flag_PAGE_EXECUTE_READWRITE forM_ [p | Right p <- bytes] $ uncurry $ pokeByteOff arr
Control/DeeperSeq.hs view
@@ -12,7 +12,7 @@ type family SetResult a b where SetResult x (IO a) = IO (SetResult x a) SetResult x (b -> a) = b -> SetResult x a- SetResult x _ = x+ SetResult x y = x class (SetResult (Result a) a ~ a) => MapResult a where mapResult :: (Result a -> b) -> a -> SetResult b a
x86-64bit.cabal view
@@ -1,5 +1,5 @@ name: x86-64bit -version: 0.4.2 +version: 0.4.3 homepage: https://github.com/divipp/x86-64 synopsis: Runtime code generation for x86 64 bit machine code description: The primary goal of x86-64bit is to provide a lightweight assembler for machine generated 64 bit x86 assembly instructions. See README.md for further details.