added needed context and getting ready to implement execute
This commit is contained in:
parent
b95b2b962a
commit
69f5cdee6a
7 changed files with 115 additions and 87 deletions
104
hs/Read.hs
104
hs/Read.hs
|
@ -15,61 +15,65 @@ import Cpu(RISCVCPU(..))
|
|||
import RegFiles (RegVal(..), GPR)
|
||||
|
||||
read :: DecodeResult -> RISCVCPU -> DecodeResult
|
||||
read (Opcode opc) riscvCPU =
|
||||
let gprRegFile = gpr riscvCPU
|
||||
in case opc of
|
||||
-- R-Type
|
||||
ADD fields -> Opcode (ADD (readRTypeFields fields gprRegFile))
|
||||
SUB fields -> Opcode (SUB (readRTypeFields fields gprRegFile))
|
||||
XOR fields -> Opcode (XOR (readRTypeFields fields gprRegFile))
|
||||
OR fields -> Opcode (OR (readRTypeFields fields gprRegFile))
|
||||
AND fields -> Opcode (AND (readRTypeFields fields gprRegFile))
|
||||
SLL fields -> Opcode (SLL (readRTypeFields fields gprRegFile))
|
||||
SRL fields -> Opcode (SRL (readRTypeFields fields gprRegFile))
|
||||
SRA fields -> Opcode (SRA (readRTypeFields fields gprRegFile))
|
||||
SLT fields -> Opcode (SLT (readRTypeFields fields gprRegFile))
|
||||
SLTU fields -> Opcode (SLTU (readRTypeFields fields gprRegFile))
|
||||
read (Opcode opcode addr) riscvCPU =
|
||||
let
|
||||
gprRegFile = gpr riscvCPU
|
||||
opcode' = case opcode of
|
||||
-- R-Type
|
||||
ADD fields -> (ADD (readRTypeFields fields gprRegFile))
|
||||
SUB fields -> (SUB (readRTypeFields fields gprRegFile))
|
||||
XOR fields -> (XOR (readRTypeFields fields gprRegFile))
|
||||
OR fields -> (OR (readRTypeFields fields gprRegFile))
|
||||
AND fields -> (AND (readRTypeFields fields gprRegFile))
|
||||
SLL fields -> (SLL (readRTypeFields fields gprRegFile))
|
||||
SRL fields -> (SRL (readRTypeFields fields gprRegFile))
|
||||
SRA fields -> (SRA (readRTypeFields fields gprRegFile))
|
||||
SLT fields -> (SLT (readRTypeFields fields gprRegFile))
|
||||
SLTU fields -> (SLTU (readRTypeFields fields gprRegFile))
|
||||
|
||||
-- I-Type
|
||||
ADDI fields -> Opcode (ADDI (readITypeFields fields gprRegFile))
|
||||
XORI fields -> Opcode (XORI (readITypeFields fields gprRegFile))
|
||||
ORI fields -> Opcode (ORI (readITypeFields fields gprRegFile))
|
||||
ANDI fields -> Opcode (ANDI (readITypeFields fields gprRegFile))
|
||||
SLLI fields -> Opcode (SLLI (readITypeFields fields gprRegFile))
|
||||
SRLI fields -> Opcode (SRLI (readITypeFields fields gprRegFile))
|
||||
SRAI fields -> Opcode (SRAI (readITypeFields fields gprRegFile))
|
||||
SLTI fields -> Opcode (SLTI (readITypeFields fields gprRegFile))
|
||||
SLTIU fields -> Opcode (SLTIU (readITypeFields fields gprRegFile))
|
||||
LB fields -> Opcode (LB (readITypeFields fields gprRegFile))
|
||||
LH fields -> Opcode (LH (readITypeFields fields gprRegFile))
|
||||
LW fields -> Opcode (LW (readITypeFields fields gprRegFile))
|
||||
LBU fields -> Opcode (LBU (readITypeFields fields gprRegFile))
|
||||
LHU fields -> Opcode (LHU (readITypeFields fields gprRegFile))
|
||||
JALR fields -> Opcode (JALR (readITypeFields fields gprRegFile))
|
||||
ECALL fields -> Opcode (ECALL (readITypeFields fields gprRegFile)) -- No regs needed, but consistent
|
||||
EBREAK fields -> Opcode (EBREAK (readITypeFields fields gprRegFile)) -- Ditto
|
||||
-- I-Type
|
||||
ADDI fields -> (ADDI (readITypeFields fields gprRegFile))
|
||||
XORI fields -> (XORI (readITypeFields fields gprRegFile))
|
||||
ORI fields -> (ORI (readITypeFields fields gprRegFile))
|
||||
ANDI fields -> (ANDI (readITypeFields fields gprRegFile))
|
||||
SLLI fields -> (SLLI (readITypeFields fields gprRegFile))
|
||||
SRLI fields -> (SRLI (readITypeFields fields gprRegFile))
|
||||
SRAI fields -> (SRAI (readITypeFields fields gprRegFile))
|
||||
SLTI fields -> (SLTI (readITypeFields fields gprRegFile))
|
||||
SLTIU fields -> (SLTIU (readITypeFields fields gprRegFile))
|
||||
LB fields -> (LB (readITypeFields fields gprRegFile))
|
||||
LH fields -> (LH (readITypeFields fields gprRegFile))
|
||||
LW fields -> (LW (readITypeFields fields gprRegFile))
|
||||
LBU fields -> (LBU (readITypeFields fields gprRegFile))
|
||||
LHU fields -> (LHU (readITypeFields fields gprRegFile))
|
||||
JALR fields -> (JALR (readITypeFields fields gprRegFile))
|
||||
ECALL fields -> (ECALL (readITypeFields fields gprRegFile)) -- No regs needed, but consistent
|
||||
EBREAK fields -> (EBREAK (readITypeFields fields gprRegFile)) -- Ditto
|
||||
|
||||
-- S-Type
|
||||
SB fields -> Opcode (SB (readSTypeFields fields gprRegFile))
|
||||
SH fields -> Opcode (SH (readSTypeFields fields gprRegFile))
|
||||
SW fields -> Opcode (SW (readSTypeFields fields gprRegFile))
|
||||
-- S-Type
|
||||
SB fields -> (SB (readSTypeFields fields gprRegFile))
|
||||
SH fields -> (SH (readSTypeFields fields gprRegFile))
|
||||
SW fields -> (SW (readSTypeFields fields gprRegFile))
|
||||
|
||||
-- B-Type
|
||||
BEQ fields -> Opcode (BEQ (readBTypeFields fields gprRegFile))
|
||||
BNE fields -> Opcode (BNE (readBTypeFields fields gprRegFile))
|
||||
BLT fields -> Opcode (BLT (readBTypeFields fields gprRegFile))
|
||||
BGE fields -> Opcode (BGE (readBTypeFields fields gprRegFile))
|
||||
BLTU fields -> Opcode (BLTU (readBTypeFields fields gprRegFile))
|
||||
BGEU fields -> Opcode (BGEU (readBTypeFields fields gprRegFile))
|
||||
-- B-Type
|
||||
BEQ fields -> (BEQ (readBTypeFields fields gprRegFile))
|
||||
BNE fields -> (BNE (readBTypeFields fields gprRegFile))
|
||||
BLT fields -> (BLT (readBTypeFields fields gprRegFile))
|
||||
BGE fields -> (BGE (readBTypeFields fields gprRegFile))
|
||||
BLTU fields -> (BLTU (readBTypeFields fields gprRegFile))
|
||||
BGEU fields -> (BGEU (readBTypeFields fields gprRegFile))
|
||||
|
||||
-- U-Type
|
||||
LUI fields -> Opcode (LUI (readUTypeFields fields gprRegFile))
|
||||
AUIPC fields -> Opcode (AUIPC (readUTypeFields fields gprRegFile))
|
||||
-- U-Type
|
||||
LUI fields -> (LUI (readUTypeFields fields gprRegFile))
|
||||
AUIPC fields -> (AUIPC (readUTypeFields fields gprRegFile))
|
||||
|
||||
-- J-Type
|
||||
JAL fields -> Opcode (JAL (readJTypeFields fields gprRegFile))
|
||||
read (DecodeException e) _ = DecodeException e
|
||||
read (InstructionException e) _ = InstructionException e
|
||||
-- J-Type
|
||||
JAL fields -> (JAL (readJTypeFields fields gprRegFile))
|
||||
in
|
||||
Opcode opcode' addr
|
||||
|
||||
read (DecodeException e addr) _ = DecodeException e addr
|
||||
read (InstructionException e addr) _ = InstructionException e addr
|
||||
|
||||
readRTypeFields :: RTypeFields -> GPR -> RTypeFields
|
||||
readRTypeFields (RTypeFields rd funct3 rs1 rs2 funct7) gprRegFile =
|
||||
|
|
Reference in a new issue