Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macaw-ppc: Don't assume absolute IP addresses when decoding #350

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading