This repository has been archived on 2025-06-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
RiscV-Formal/hs/Fetch.hs
2025-02-12 23:54:15 -05:00

24 lines
636 B
Haskell

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NumericUnderscores #-}
module Fetch(fetchInstruction) where
import Clash.Prelude
import Types(Mem, Addr, FullWord)
import Util(endianSwapWord)
data Insn = Instruction FullWord
| Misaligned Addr
fetchInstruction :: KnownNat n => Mem n -> Addr -> Insn
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