From 4d9c7cd02818823053960f86f8e9b3a9c877052f Mon Sep 17 00:00:00 2001 From: Tristan Ravitch Date: Mon, 2 Oct 2017 11:19:34 -0700 Subject: [PATCH] Split up the functions that will comprise ppc_linux_info --- macaw-ppc/macaw-ppc.cabal | 8 ++- macaw-ppc/src/Data/Macaw/PPC.hs | 71 ++++----------------- macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs | 18 ++++++ macaw-ppc/src/Data/Macaw/PPC/Eval.hs | 38 +++++++++++ macaw-ppc/src/Data/Macaw/PPC/Identify.hs | 22 +++++++ macaw-ppc/src/Data/Macaw/PPC/Rewrite.hs | 23 +++++++ 6 files changed, 121 insertions(+), 59 deletions(-) create mode 100644 macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs create mode 100644 macaw-ppc/src/Data/Macaw/PPC/Eval.hs create mode 100644 macaw-ppc/src/Data/Macaw/PPC/Identify.hs create mode 100644 macaw-ppc/src/Data/Macaw/PPC/Rewrite.hs diff --git a/macaw-ppc/macaw-ppc.cabal b/macaw-ppc/macaw-ppc.cabal index 9f7d621e..68889f16 100644 --- a/macaw-ppc/macaw-ppc.cabal +++ b/macaw-ppc/macaw-ppc.cabal @@ -16,9 +16,13 @@ extra-source-files: ChangeLog.md cabal-version: >=1.10 library - exposed-modules: Data.Macaw.PPC, - Data.Macaw.PPC.ArchTypes, + exposed-modules: Data.Macaw.PPC + Data.Macaw.PPC.ArchTypes + Data.Macaw.PPC.Disassemble + Data.Macaw.PPC.Eval + Data.Macaw.PPC.Identify Data.Macaw.PPC.PPCReg + Data.Macaw.PPC.Rewrite -- other-modules: -- other-extensions: build-depends: base >=4.9 && <5, diff --git a/macaw-ppc/src/Data/Macaw/PPC.hs b/macaw-ppc/src/Data/Macaw/PPC.hs index 856de773..8f37f383 100644 --- a/macaw-ppc/src/Data/Macaw/PPC.hs +++ b/macaw-ppc/src/Data/Macaw/PPC.hs @@ -33,8 +33,21 @@ import qualified SemMC.Architecture.PPC32 as PPC32 import qualified SemMC.Architecture.PPC64 as PPC64 import Data.Macaw.PPC.ArchTypes +import Data.Macaw.PPC.Disassemble ( disassembleFn ) +import Data.Macaw.PPC.Eval ( mkInitialAbsState, + absEvalArchFn, + absEvalArchStmt, + postCallAbsState, + preserveRegAcrossSyscall + ) +import Data.Macaw.PPC.Identify ( identifyCall, + identifyReturn + ) import Data.Macaw.PPC.PPCReg --- import Data.Macaw.PPC.Rewrite +import Data.Macaw.PPC.Rewrite ( rewriteArchFn, + rewriteArchStmt, + rewriteArchTermStmt + ) data Hole = Hole @@ -137,62 +150,6 @@ getReg r = PPCGenerator $ St.StateT $ \genState -> do let expr = ValueExpr (genState ^. blockState ^. pBlockState ^. boundValue r) return (expr, genState) -disassembleFn :: proxy ppc -> MM.Memory (ArchAddrWidth ppc) - -> NC.NonceGenerator (ST ids) ids - -> ArchSegmentOff ppc - -> ArchAddrWord ppc - -> MA.AbsBlockState (ArchReg ppc) - -- ^ NOTE: We are leaving the type function ArchReg here because - -- we need to generalize over PPC64 vs PPC32 - -> ST ids ([Block ppc ids], MM.MemWord (ArchAddrWidth ppc), Maybe String) -disassembleFn = undefined - -preserveRegAcrossSyscall :: proxy ppc -> ArchReg ppc tp -> Bool -preserveRegAcrossSyscall = undefined - -mkInitialAbsState :: proxy ppc -> MM.Memory (RegAddrWidth (ArchReg ppc)) - -> ArchSegmentOff ppc - -> MA.AbsBlockState (ArchReg ppc) -mkInitialAbsState = undefined - -absEvalArchFn :: proxy ppc -> AbsProcessorState (ArchReg ppc) ids - -> ArchFn ppc (Value ppc ids) tp - -> AbsValue (RegAddrWidth (ArchReg ppc)) tp -absEvalArchFn = undefined - -absEvalArchStmt :: proxy ppc -> AbsProcessorState (ArchReg ppc) ids - -> ArchStmt ppc ids - -> AbsProcessorState (ArchReg ppc) ids -absEvalArchStmt = undefined - -postCallAbsState :: proxy ppc -> AbsBlockState (ArchReg ppc) - -> ArchSegmentOff ppc - -> AbsBlockState (ArchReg ppc) -postCallAbsState = undefined - -identifyCall :: proxy ppc -> MM.Memory (ArchAddrWidth ppc) - -> [Stmt ppc ids] - -> RegState (ArchReg ppc) (Value ppc ids) - -> Maybe (Seq.Seq (Stmt ppc ids), ArchSegmentOff ppc) -identifyCall = undefined - -identifyReturn :: proxy ppc -> [Stmt ppc ids] - -> RegState (ArchReg ppc) (Value ppc ids) - -> Maybe [Stmt ppc ids] -identifyReturn = undefined - -rewriteArchFn :: proxy ppc -> ArchFn ppc (Value ppc src) tp - -> Rewriter ppc src tgt (Value ppc tgt tp) -rewriteArchFn = undefined - -rewriteArchStmt :: proxy ppc -> ArchStmt ppc src - -> Rewriter ppc src tgt () -rewriteArchStmt = undefined - -rewriteArchTermStmt :: proxy ppc -> ArchTermStmt ppc src - -> Rewriter ppc src tgt (ArchTermStmt ppc tgt) -rewriteArchTermStmt = undefined - archDemandContext :: proxy ppc -> MDS.DemandContext ppc ids archDemandContext = undefined diff --git a/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs b/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs new file mode 100644 index 00000000..cc535bad --- /dev/null +++ b/macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs @@ -0,0 +1,18 @@ +module Data.Macaw.PPC.Disassemble ( disassembleFn ) where + +import Control.Monad.ST ( ST ) + +import Data.Macaw.AbsDomain.AbsState as MA +import Data.Macaw.CFG +import Data.Macaw.CFG.Block +import qualified Data.Macaw.Memory as MM +import qualified Data.Parameterized.Nonce as NC + +disassembleFn :: proxy ppc + -> MM.Memory (ArchAddrWidth ppc) + -> NC.NonceGenerator (ST ids) ids + -> ArchSegmentOff ppc + -> ArchAddrWord ppc + -> MA.AbsBlockState (ArchReg ppc) + -> ST ids ([Block ppc ids], MM.MemWord (ArchAddrWidth ppc), Maybe String) +disassembleFn = undefined diff --git a/macaw-ppc/src/Data/Macaw/PPC/Eval.hs b/macaw-ppc/src/Data/Macaw/PPC/Eval.hs new file mode 100644 index 00000000..4278c5bb --- /dev/null +++ b/macaw-ppc/src/Data/Macaw/PPC/Eval.hs @@ -0,0 +1,38 @@ +module Data.Macaw.PPC.Eval ( + mkInitialAbsState, + absEvalArchFn, + absEvalArchStmt, + postCallAbsState, + preserveRegAcrossSyscall + ) where + +import Data.Macaw.AbsDomain.AbsState as MA +import Data.Macaw.CFG +import qualified Data.Macaw.Memory as MM + +preserveRegAcrossSyscall :: proxy ppc -> ArchReg ppc tp -> Bool +preserveRegAcrossSyscall = undefined + +mkInitialAbsState :: proxy ppc + -> MM.Memory (RegAddrWidth (ArchReg ppc)) + -> ArchSegmentOff ppc + -> MA.AbsBlockState (ArchReg ppc) +mkInitialAbsState = undefined + +absEvalArchFn :: proxy ppc + -> AbsProcessorState (ArchReg ppc) ids + -> ArchFn ppc (Value ppc ids) tp + -> AbsValue (RegAddrWidth (ArchReg ppc)) tp +absEvalArchFn = undefined + +absEvalArchStmt :: proxy ppc + -> AbsProcessorState (ArchReg ppc) ids + -> ArchStmt ppc ids + -> AbsProcessorState (ArchReg ppc) ids +absEvalArchStmt = undefined + +postCallAbsState :: proxy ppc + -> AbsBlockState (ArchReg ppc) + -> ArchSegmentOff ppc + -> AbsBlockState (ArchReg ppc) +postCallAbsState = undefined diff --git a/macaw-ppc/src/Data/Macaw/PPC/Identify.hs b/macaw-ppc/src/Data/Macaw/PPC/Identify.hs new file mode 100644 index 00000000..3f1e9210 --- /dev/null +++ b/macaw-ppc/src/Data/Macaw/PPC/Identify.hs @@ -0,0 +1,22 @@ +module Data.Macaw.PPC.Identify ( + identifyCall, + identifyReturn + ) where + +import qualified Data.Sequence as Seq + +import Data.Macaw.CFG +import qualified Data.Macaw.Memory as MM + +identifyCall :: proxy ppc + -> MM.Memory (ArchAddrWidth ppc) + -> [Stmt ppc ids] + -> RegState (ArchReg ppc) (Value ppc ids) + -> Maybe (Seq.Seq (Stmt ppc ids), ArchSegmentOff ppc) +identifyCall = undefined + +identifyReturn :: proxy ppc + -> [Stmt ppc ids] + -> RegState (ArchReg ppc) (Value ppc ids) + -> Maybe [Stmt ppc ids] +identifyReturn = undefined diff --git a/macaw-ppc/src/Data/Macaw/PPC/Rewrite.hs b/macaw-ppc/src/Data/Macaw/PPC/Rewrite.hs new file mode 100644 index 00000000..03b1ccbd --- /dev/null +++ b/macaw-ppc/src/Data/Macaw/PPC/Rewrite.hs @@ -0,0 +1,23 @@ +module Data.Macaw.PPC.Rewrite ( + rewriteArchFn, + rewriteArchStmt, + rewriteArchTermStmt + ) where + +import Data.Macaw.CFG +import Data.Macaw.CFG.Rewriter + +rewriteArchFn :: proxy ppc + -> ArchFn ppc (Value ppc src) tp + -> Rewriter ppc src tgt (Value ppc tgt tp) +rewriteArchFn = undefined + +rewriteArchStmt :: proxy ppc + -> ArchStmt ppc src + -> Rewriter ppc src tgt () +rewriteArchStmt = undefined + +rewriteArchTermStmt :: proxy ppc + -> ArchTermStmt ppc src + -> Rewriter ppc src tgt (ArchTermStmt ppc tgt) +rewriteArchTermStmt = undefined