added needed context and getting ready to implement execute

This commit is contained in:
Yehowshua Immanuel 2025-03-10 22:26:38 -04:00
parent b95b2b962a
commit 69f5cdee6a
7 changed files with 115 additions and 87 deletions

View file

@ -20,32 +20,32 @@ import BusTypes(
import Exceptions(Exception(..))
import Util((|>))
data FetchResult = Instruction Insn
| InstructionException Exception
data FetchResult = Instruction {insn :: Insn, insnAddr :: Addr}
| InstructionException {exception :: Exception, addr :: Addr}
deriving (Generic, Show, Eq, NFDataX)
fetchInstruction :: Peripherals -> Addr -> IO FetchResult
fetchInstruction peripherals addr =
do
readReasponse <-Bus.read (BusTypes.Request addr BusTypes.SizeFullWord) peripherals
readReasponse <-Bus.read (BusTypes.ReadRequest addr BusTypes.SizeFullWord) peripherals
case readReasponse of
Right (BusFullWord insn) ->
pure |> Instruction insn
pure |> Instruction insn addr
Left UnAligned ->
pure |> InstructionException (InstructionAddressMisaligned addr)
pure |> InstructionException InstructionAddressMisaligned addr
Left UnMapped ->
pure |> InstructionException (InstructionAccessFault addr)
pure |> InstructionException InstructionAccessFault addr
Right _ ->
pure |> InstructionException (InstructionAccessFault addr)
pure |> InstructionException InstructionAccessFault addr
debugInsn :: FetchResult -> String
debugInsn fetchResult =
case fetchResult of
Instruction insn ->
"Instruction raw binary | "
P.++ binaryInsn
P.++ " (" P.++ show insn P.++ ")"
where
binaryInsn = show (bitCoerce insn :: BitVector 32)
InstructionException e -> show e
debugInsn = show
-- case fetchResult of
-- Instruction insn ->
-- "Instruction raw binary | "
-- P.++ binaryInsn
-- P.++ " (" P.++ show insn P.++ ")"
-- where
-- binaryInsn = show (bitCoerce insn :: BitVector 32)
-- InstructionException e -> show e