Skip to content

Commit aa98054

Browse files
Implement rest of formats for RV32I
1 parent 90068d0 commit aa98054

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

documentation/Spec/Instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Instruction List](https://msyksphinz-self.github.io/riscv-isadoc/)

src/main/scala/RISCV/Decoder.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ object InstructionFormat extends ChiselEnum {
99
val R, I, S, B, U, J = Value
1010
}
1111

12-
object Opcode extends ChiselEnum {
13-
val ADDI = Value(0b0010011.U)
14-
val AUIPC = Value(0b0010111.U)
15-
val LUI = Value(0b0110111.U)
16-
}
17-
1812
/**
1913
* @param width Bit width (default: 32 bits)
2014
*/
@@ -36,12 +30,22 @@ class Decoder(val width: Int = 32) extends Module {
3630
format := InstructionFormat.R;
3731

3832
val opcode = io.instruction(6,0);
33+
val func3 = io.instruction(14,12);
34+
val func7 = io.instruction(31,25);
3935

4036
switch(opcode) {
41-
is(Opcode.LUI.asUInt) { format := InstructionFormat.U; }
42-
is(Opcode.AUIPC.asUInt) { format := InstructionFormat.U; }
43-
is(Opcode.ADDI.asUInt) { format := InstructionFormat.I; }
44-
}
37+
is(0b0110111.U) { format := InstructionFormat.U; } // lui
38+
is(0b0010111.U) { format := InstructionFormat.U; } // auipc
39+
is(0b0010011.U) { format := InstructionFormat.I; } // addi, slti, sltiu, xori, ori, andi, slli, srli, srai
40+
is(0b0110011.U) { format := InstructionFormat.R; } // add, sub, sll, slt, sltu, xor, srl, sra, or, and
41+
is(0b0001111.U) { format := InstructionFormat.I; } // fence, fence.i
42+
is(0b1110011.U) { format := InstructionFormat.S; } // ecall, ebreak, sret, mret, wfi, sfence.vma | the format for these is not within the standard formats but we can basically achieve the same thing with S type and then using the immediate, rs2, and rs1 to differentiate the calls. Also technically sret, mret, and wfi come from the privelleged spec but we'll just include them here.
43+
is(0b0000011.U) { format := InstructionFormat.I; } // lb, lh, lw, lbu, lhu
44+
is(0b0100011.U) { format := InstructionFormat.S; } // sb, sh, sw
45+
is(0b1101111.U) { format := InstructionFormat.U; } // jal
46+
is(0b1100111.U) { format := InstructionFormat.I; } // jalr
47+
is(0b1100011.U) { format := InstructionFormat.B; } // beq, bne, blt, bge, bltu, bgeu
48+
4549

4650
io.operation := 0.U;
4751
io.immediate := 0.U;

0 commit comments

Comments
 (0)