Skip to content

Commit

Permalink
Merge pull request #350 from GaloisInc/macaw-ppc-pic-ip-addresses
Browse files Browse the repository at this point in the history
`macaw-ppc`: Don't assume absolute IP addresses when decoding
  • Loading branch information
RyanGlScott authored Nov 14, 2023
2 parents 0c6872a + ca64b56 commit 2e49eb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion macaw-aarch32/src/Data/Macaw/ARM/Disassemble.hs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ data TranslationError w = TranslationError { transErrorAddr :: MM.MemSegmentOff
data TranslationErrorReason w = InvalidNextPC (MM.MemAddr w) (MM.MemAddr w)
| DecodeError (ARMMemoryError w)
| UnsupportedInstruction InstructionSet
| InstructionAtUnmappedAddr InstructionSet
| GenerationError InstructionSet SG.GeneratorError
deriving (Show)

Expand Down
9 changes: 5 additions & 4 deletions macaw-ppc/src/Data/Macaw/PPC/Disassemble.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
Expand Down Expand Up @@ -34,6 +35,7 @@ import qualified Data.Macaw.Memory as MM
import qualified Data.Macaw.Memory.Permissions as MMP
import Data.Macaw.Types ( BVType )
import qualified Data.Parameterized.Map as MapF
import qualified Data.Parameterized.NatRepr as PN
import qualified Data.Parameterized.Nonce as NC

import qualified SemMC.Architecture.PPC as SP
Expand Down Expand Up @@ -127,9 +129,9 @@ disassembleBlock lookupSemantics gs curIPAddr blockOff maxOffset = do
-- Note: In PowerPC, the IP is incremented *after* an instruction
-- executes, rather than before as in X86. We have to pass in the
-- physical address of the instruction here.
ipVal <- case MM.asAbsoluteAddr (MM.segoffAddr curIPAddr) of
Nothing -> failAt gs blockOff curIPAddr (InstructionAtUnmappedAddr i)
Just addr -> return (BVValue (SP.addrWidth SP.knownVariant) (fromIntegral addr))
let ipVal = MC.BVValue
(PN.knownNat @(ArchAddrWidth ppc))
(fromIntegral (MM.addrOffset (MM.segoffAddr curIPAddr)))
case lookupSemantics ipVal i of
Nothing -> failAt gs blockOff curIPAddr (UnsupportedInstruction i)
Just transformer -> do
Expand Down Expand Up @@ -250,7 +252,6 @@ data TranslationError w = TranslationError { transErrorAddr :: MM.MemSegmentOff
data TranslationErrorReason w = InvalidNextIP Word64 Word64
| DecodeError (PPCMemoryError w)
| UnsupportedInstruction D.Instruction
| InstructionAtUnmappedAddr D.Instruction
| GenerationError D.Instruction GeneratorError
deriving (Show)

Expand Down

0 comments on commit 2e49eb5

Please sign in to comment.