now using bus and new FetchResult type
This commit is contained in:
parent
4729d79b23
commit
eb79210863
|
@ -32,7 +32,7 @@ data RISCVCPU = RISCVCPU
|
||||||
riscvCPUInit :: RISCVCPU
|
riscvCPUInit :: RISCVCPU
|
||||||
riscvCPUInit =
|
riscvCPUInit =
|
||||||
RISCVCPU
|
RISCVCPU
|
||||||
{ pc = 0 -- 0x8000_0000
|
{ pc = 0x8000_0000
|
||||||
, gpr = gprInit
|
, gpr = gprInit
|
||||||
, fpr = fprInit
|
, fpr = fprInit
|
||||||
, csr = csrInit
|
, csr = csrInit
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
module Fetch(
|
module Fetch(
|
||||||
fetchInstruction,
|
fetchInstruction,
|
||||||
FetchResult(..)) where
|
fetchInstruction1,
|
||||||
|
FetchResult(..),
|
||||||
|
FetchResult1(..)) where
|
||||||
|
|
||||||
import Clash.Prelude
|
import Clash.Prelude
|
||||||
import Types(Mem, Addr, Insn)
|
import Types(Mem, Addr, Insn)
|
||||||
|
|
|
@ -19,11 +19,12 @@ import Bus(Peripherals(..))
|
||||||
import Cpu(
|
import Cpu(
|
||||||
RISCVCPU(..),
|
RISCVCPU(..),
|
||||||
riscvCPUInit)
|
riscvCPUInit)
|
||||||
import Fetch(fetchInstruction, FetchResult (Instruction, Misaligned))
|
import Fetch(fetchInstruction, FetchResult (Instruction, Misaligned), fetchInstruction1, FetchResult1(..))
|
||||||
import Isa.Decode(decode)
|
import Isa.Decode(decode)
|
||||||
|
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
import Types (Insn)
|
import Types (Insn)
|
||||||
|
import Control.Monad.RWS (MonadState(put))
|
||||||
|
|
||||||
data Args = Args {
|
data Args = Args {
|
||||||
firmware :: FilePath
|
firmware :: FilePath
|
||||||
|
@ -39,9 +40,6 @@ data Machine = Machine
|
||||||
}
|
}
|
||||||
deriving (Generic, Show, Eq, NFDataX)
|
deriving (Generic, Show, Eq, NFDataX)
|
||||||
|
|
||||||
-- machine :: Machine
|
|
||||||
-- machine = machineInit
|
|
||||||
|
|
||||||
machine' :: Machine -> Machine
|
machine' :: Machine -> Machine
|
||||||
machine' machine =
|
machine' machine =
|
||||||
let
|
let
|
||||||
|
@ -63,12 +61,33 @@ machine' machine =
|
||||||
opcode = decode insn
|
opcode = decode insn
|
||||||
Misaligned addr -> undefined
|
Misaligned addr -> undefined
|
||||||
|
|
||||||
|
debugInsn :: FetchResult1 -> String
|
||||||
|
debugInsn fetchResult =
|
||||||
|
case fetchResult of
|
||||||
|
Instruction1 insn ->
|
||||||
|
"Decoded instruction: " P.++ show opcode
|
||||||
|
P.++ " | Binary: " P.++ binaryInsn
|
||||||
|
P.++ " (" P.++ show insn P.++ ")"
|
||||||
|
where
|
||||||
|
binaryInsn = show (bitCoerce insn :: BitVector 32)
|
||||||
|
opcode = decode insn
|
||||||
|
InstructionException e -> show e
|
||||||
|
|
||||||
simulationLoop :: Int -> Machine -> IO [Machine]
|
simulationLoop :: Int -> Machine -> IO [Machine]
|
||||||
simulationLoop 0 state = return [state]
|
simulationLoop 0 machine = return [machine]
|
||||||
simulationLoop n state = do
|
simulationLoop n machine = do
|
||||||
let newState = machine' state
|
-- let newState = machine' machine
|
||||||
rest <- simulationLoop (n - 1) newState
|
let machinePeripherals = peripherals machine
|
||||||
return (state : rest)
|
currPc = pc $ cpu machine
|
||||||
|
fetchResult <- fetchInstruction1 machinePeripherals currPc
|
||||||
|
putStrLn $ debugInsn fetchResult
|
||||||
|
let pc' = currPc + 4
|
||||||
|
cpu' = (cpu machine) { pc = pc' }
|
||||||
|
machine' = machine { cpu = cpu' }
|
||||||
|
-- let machine' = machine { cpu = cpu $ machine { pc = pc $ cpu machine + 4 } }
|
||||||
|
rest <- simulationLoop (n - 1) machine'
|
||||||
|
return (machine : rest)
|
||||||
|
|
||||||
|
|
||||||
simulation :: Args -> IO Simulation
|
simulation :: Args -> IO Simulation
|
||||||
simulation args = do
|
simulation args = do
|
||||||
|
|
Loading…
Reference in a new issue