forked from Yehowshua/RiscV-Formal
works even better now
This commit is contained in:
parent
f9248057f9
commit
003a1c8545
|
@ -58,25 +58,32 @@ getRs1 instr = bitCoerce $ slice d19 d15 (pack instr)
|
|||
|
||||
decodeRType :: Insn -> Opcode
|
||||
decodeRType insn =
|
||||
case funct3 of
|
||||
0x00 -> ADD (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x00 -> SUB (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x04 -> XOR (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x06 -> OR (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x07 -> AND (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x01 -> SLL (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x05 -> SRL (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x05 -> SRA (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x02 -> SLT (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x03 -> SLTU (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
_ -> Unimplemented
|
||||
case opcode of
|
||||
0b0110011 ->
|
||||
case funct3 of
|
||||
0x00 -> case funct7 of
|
||||
0x00 -> ADD (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x20 -> SUB (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
_ -> Unimplemented
|
||||
0x04 -> XOR (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x06 -> OR (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x07 -> AND (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x01 -> SLL (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x05 -> case funct7 of
|
||||
0x00 -> SRL (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x20 -> SRA (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
_ -> Unimplemented
|
||||
0x02 -> SLT (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
0x03 -> SLTU (RTypeFields opcode rd funct3 rs1 rs2 funct7)
|
||||
_ -> Unimplemented
|
||||
_ -> Unimplemented
|
||||
where
|
||||
opcode = getOpcode insn
|
||||
rd = getRd insn
|
||||
funct3 = getFunct3 insn
|
||||
rs1 = getRs1 insn
|
||||
rs2 = getRs2 insn
|
||||
funct7 = getFunct7 insn
|
||||
opcode = getOpcode insn
|
||||
rd = getRd insn
|
||||
funct3 = getFunct3 insn
|
||||
rs1 = getRs1 insn
|
||||
rs2 = getRs2 insn
|
||||
funct7 = getFunct7 insn
|
||||
|
||||
decodeIType :: Insn -> Opcode
|
||||
decodeIType insn = case opcode of
|
||||
|
@ -122,11 +129,14 @@ decodeIType insn = case opcode of
|
|||
imm = getImm12 insn
|
||||
|
||||
decodeSType :: Insn -> Opcode
|
||||
decodeSType insn = case funct3 of
|
||||
0x0 -> SB (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Byte
|
||||
0x1 -> SH (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Halfword
|
||||
0x2 -> SW (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Word
|
||||
_ -> Unimplemented
|
||||
decodeSType insn =
|
||||
case opcode of
|
||||
0b0100011 -> case funct3 of
|
||||
0x0 -> SB (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Byte
|
||||
0x1 -> SH (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Halfword
|
||||
0x2 -> SW (STypeFields opcode funct3 rs1 rs2 imm12) -- Store Word
|
||||
_ -> Unimplemented
|
||||
_ -> Unimplemented
|
||||
where
|
||||
opcode = getOpcode insn
|
||||
funct3 = getFunct3 insn
|
||||
|
@ -135,14 +145,17 @@ decodeSType insn = case funct3 of
|
|||
imm12 = getImm12SType insn
|
||||
|
||||
decodeBType :: Insn -> Opcode
|
||||
decodeBType insn = case funct3 of
|
||||
0x0 -> BEQ (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if equal
|
||||
0x1 -> BNE (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if not equal
|
||||
0x4 -> BLT (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if less than
|
||||
0x5 -> BGE (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if greater or equal
|
||||
0x6 -> BLTU (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if less than (unsigned)
|
||||
0x7 -> BGEU (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if greater or equal (unsigned)
|
||||
_ -> Unimplemented
|
||||
decodeBType insn =
|
||||
case opcode of
|
||||
0b1100011 -> case funct3 of
|
||||
0x0 -> BEQ (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if equal
|
||||
0x1 -> BNE (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if not equal
|
||||
0x4 -> BLT (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if less than
|
||||
0x5 -> BGE (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if greater or equal
|
||||
0x6 -> BLTU (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if less than (unsigned)
|
||||
0x7 -> BGEU (BTypeFields opcode funct3 rs1 rs2 imm13) -- Branch if greater or equal (unsigned)
|
||||
_ -> Unimplemented
|
||||
_ -> Unimplemented
|
||||
where
|
||||
opcode = getOpcode insn
|
||||
funct3 = getFunct3 insn
|
||||
|
@ -170,7 +183,8 @@ getImm21JType instr = bitCoerce $ imm20 ++# imm10_1 ++# imm11 ++# imm19_12 ++# z
|
|||
zero = 0 :: BitVector 1 -- LSB always zero for J-type
|
||||
|
||||
decodeJType :: Insn -> Opcode
|
||||
decodeJType insn = case getOpcode insn of
|
||||
decodeJType insn =
|
||||
case opcode of
|
||||
0b1101111 -> JAL (JTypeFields opcode rd imm21) -- JAL
|
||||
_ -> Unimplemented
|
||||
where
|
||||
|
|
|
@ -79,6 +79,6 @@ simulation args = do
|
|||
InitializedPeripherals ram -> do
|
||||
|
||||
let initState = machineInit $ Machine.Peripherals ram
|
||||
sim <- simulationLoop 5 initState
|
||||
sim <- simulationLoop 15 initState
|
||||
teardownPeripherals
|
||||
return $ Success sim
|
||||
|
|
Loading…
Reference in a new issue