27 lines
673 B
Haskell
27 lines
673 B
Haskell
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE NumericUnderscores #-}
|
|
|
|
module Fetch(
|
|
fetchInstruction,
|
|
FetchResult(..)) where
|
|
|
|
import Clash.Prelude
|
|
import Types(Mem, Addr, Insn)
|
|
import Util(endianSwapWord)
|
|
|
|
data FetchResult = Instruction Insn
|
|
| Misaligned Addr
|
|
|
|
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
|