Skip to content

Commit b6e528b

Browse files
Start implementing Decoder
1 parent 7a3c770 commit b6e528b

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tasks": [
44
{
55
"label": "Test",
6-
"command": "sbt run test",
6+
"command": "sbt test",
77
"type": "shell",
88
"args": [],
99
"problemMatcher": [],

src/main/scala/RISCV/Decoder.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package RISCV
2+
3+
import chisel3._
4+
import chisel3.util._
5+
import _root_.circt.stage.ChiselStage
6+
7+
/**
8+
* @param width Bit width (default: 32 bits)
9+
*/
10+
class Decoder(val width: Int = 32) extends Module {
11+
val io = IO(new Bundle {
12+
val instruction = Input(UInt(32.W));
13+
val operation = Output(UInt(17.W));
14+
val rs1 = Output(UInt(5.W));
15+
val rs2 = Output(UInt(5.W));
16+
val rd = Output(UInt(5.W));
17+
val immediate = Output(UInt(32.W));
18+
})
19+
20+
io.rs1 := io.instruction(19, 15);
21+
io.rs2 := io.instruction(24, 20);
22+
io.rd := io.instruction(11, 7);
23+
24+
io.operation := 0.U;
25+
26+
io.immediate := 0.U;
27+
}
28+
29+
object Decoder extends App {
30+
ChiselStage.emitSystemVerilogFile(
31+
new Decoder(),
32+
firtoolOpts = Array(
33+
"-disable-all-randomization",
34+
"-strip-debug-info",
35+
"-default-layer-specialization=enable"
36+
),
37+
args = Array("--target-dir", "generated")
38+
)
39+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package RISCV
2+
3+
import chisel3._
4+
import chisel3.experimental.BundleLiterals._
5+
import chisel3.simulator.scalatest.ChiselSim
6+
import org.scalatest.freespec.AnyFreeSpec
7+
import org.scalatest.matchers.must.Matchers
8+
9+
class DecoderTest extends AnyFreeSpec with Matchers with ChiselSim {
10+
"Decoder should pass tests" in {
11+
simulate(new Decoder()) { dut =>
12+
dut.io.instruction.poke(0.U);
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)