replace/update relevant fetch types and functions

This commit is contained in:
Yehowshua Immanuel 2025-03-04 23:43:35 -05:00
parent eb79210863
commit 30650b870c
2 changed files with 8 additions and 48 deletions

View file

@ -3,9 +3,8 @@
module Fetch(
fetchInstruction,
fetchInstruction1,
FetchResult(..),
FetchResult1(..)) where
) where
import Clash.Prelude
import Types(Mem, Addr, Insn)
@ -22,31 +21,15 @@ import GHC.IO (IO)
import GHC.Base (Applicative(pure))
data FetchResult = Instruction Insn
| Misaligned Addr
data FetchResult1 = Instruction1 Insn
| InstructionException Exception
fetchInstruction :: KnownNat n => Mem n -> Addr -> FetchResult
fetchInstruction mem addr =
let
isWordAligned = addr .&. 3 == 0
addrWordAligned = addr `shiftR` 2
insn = mem !! addrWordAligned
-- TODO : check if instruction is word aligned and create type
-- to capture if its not.
in
case isWordAligned of
True -> Instruction insn
False -> Misaligned addr
fetchInstruction1 :: Peripherals -> Addr -> IO FetchResult1
fetchInstruction1 peripherals addr =
fetchInstruction :: Peripherals -> Addr -> IO FetchResult
fetchInstruction peripherals addr =
do
readReasponse <-Bus.read (BusTypes.Request addr BusTypes.SizeFullWord) peripherals
case readReasponse of
Right (BusFullWord insn) ->
pure $ Instruction1 insn
pure $ Instruction insn
Left UnAligned ->
pure $ InstructionException InstructionAddressMisaligned
Left UnMapped ->