Skip to content

Commit b8660af

Browse files
committed
Split Leros into core (Leros) and top that contains the memories
1 parent 3478c30 commit b8660af

File tree

5 files changed

+79
-36
lines changed

5 files changed

+79
-36
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ swsim:
3232
sbt -Dprogram=$(APP) "testOnly leros.sim.LerosSimTest"
3333

3434
hw:
35-
sbt "runMain leros.Leros asm/$(APP).s"
35+
sbt "runMain leros.LerosTop asm/$(APP).s"
3636

3737
test-alu:
3838
sbt "test:runMain leros.AluTester"
@@ -59,7 +59,7 @@ synpath:
5959
source /home/shared/Xilinx/Vivado/2017.4/settings64.sh
6060

6161
synth:
62-
./vivado_synth -t Leros -p xc7a100tcsg324-1 -x nexysA7.xdc -o build generated/Leros.sv
62+
./vivado_synth -t LerosTop -p xc7a100tcsg324-1 -x nexysA7.xdc -o build generated/LerosTop.sv
6363

6464
cp-bit:
6565
-mkdir build

src/main/scala/leros/DataMem.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import chisel3._
44
import leros.util.Assembler
55

66

7+
class DataMemIO(memAddrWidth: Int) extends Bundle {
8+
val rdAddr = Input(UInt(memAddrWidth.W))
9+
val rdData = Output(UInt(32.W))
10+
val wrAddr = Input(UInt(memAddrWidth.W))
11+
val wrData = Input(UInt(32.W))
12+
val wr = Input(Bool())
13+
val wrMask = Input(UInt(4.W))
14+
}
15+
716
/**
817
* Data memory.
918
*/
1019
class DataMem(memAddrWidth: Int, debugMem: Boolean = false) extends Module {
11-
val io = IO(new Bundle {
12-
val rdAddr = Input(UInt(memAddrWidth.W))
13-
val rdData = Output(UInt(32.W))
14-
val wrAddr = Input(UInt(memAddrWidth.W))
15-
val wrData = Input(UInt(32.W))
16-
val wr = Input(Bool())
17-
val wrMask = Input(UInt(4.W))
18-
})
20+
val io = IO(new DataMemIO(memAddrWidth))
1921

2022
val entries = 1 << memAddrWidth
2123
val wrVec = Wire(Vec(4, UInt(8.W)))

src/main/scala/leros/Leros.scala

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import leros.State._
1212
*/
1313
class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module {
1414

15+
val imemIO = IO(new Bundle {
16+
val addr = Output(UInt(memAddrWidth.W))
17+
val instr = Input(UInt(16.W))
18+
})
19+
val dmemIO = IO(Flipped(new DataMemIO(memAddrWidth)))
20+
1521
val io = IO(new Bundle {
1622
// val dout = Output(UInt(32.W))
1723
// val sw = Input(UInt(4.W))
@@ -29,9 +35,8 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
2935
val pcNext = WireDefault(pcReg + 1.U)
3036

3137
// Fetch from instruction memory with an address register that is reset to 0
32-
val instrMem = Module(new InstrMem(memAddrWidth, prog))
33-
instrMem.io.addr := pcNext
34-
val instr = instrMem.io.instr
38+
imemIO.addr := pcNext
39+
val instr = imemIO.instr
3540

3641
// Decode
3742
val dec = Module(new Decode())
@@ -53,17 +58,16 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
5358

5459
// Data memory, including the register memory
5560
// read in fetch, write in execute
56-
val dataMem = Module(new DataMem((memAddrWidth), false))
5761

5862
val memAddr = Mux(decout.isDataAccess, effAddrWord, instr(7, 0))
5963
val memAddrReg = RegNext(memAddr)
6064
val effAddrOffReg = RegNext(effAddrOff)
61-
dataMem.io.rdAddr := memAddr
62-
val dataRead = dataMem.io.rdData
63-
dataMem.io.wrAddr := memAddrReg
64-
dataMem.io.wrData := accu
65-
dataMem.io.wr := false.B
66-
dataMem.io.wrMask := "b1111".U
65+
dmemIO.rdAddr := memAddr
66+
val dataRead = dmemIO.rdData
67+
dmemIO.wrAddr := memAddrReg
68+
dmemIO.wrData := accu
69+
dmemIO.wr := false.B
70+
dmemIO.wrMask := "b1111".U
6771

6872
// ALU connection
6973
alu.io.op := decReg.op
@@ -105,30 +109,30 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
105109
}
106110

107111
is (store) {
108-
dataMem.io.wr := true.B
112+
dmemIO.wr := true.B
109113
}
110114

111115
is (storeInd) {
112-
dataMem.io.wr := true.B
116+
dmemIO.wr := true.B
113117
// TODO: am I missing here something? See the other store indirect
114118
// TODO: this is a super quick hack to get the LED blinking
115119
outReg := accu
116120
}
117121

118122
is (storeIndB) {
119123
// wr and wrMask could be set in decode and registered
120-
dataMem.io.wr := true.B
121-
dataMem.io.wrMask := "b0001".U << effAddrOffReg
124+
dmemIO.wr := true.B
125+
dmemIO.wrMask := "b0001".U << effAddrOffReg
122126
vecAccu(effAddrOffReg) := accu(7, 0)
123-
dataMem.io.wrData := vecAccu(3) ## vecAccu(2) ## vecAccu(1) ## vecAccu(0)
127+
dmemIO.wrData := vecAccu(3) ## vecAccu(2) ## vecAccu(1) ## vecAccu(0)
124128
}
125129

126130
is (storeIndH) {
127-
dataMem.io.wr := true.B
128-
dataMem.io.wrMask := "b0011".U << effAddrOffReg
131+
dmemIO.wr := true.B
132+
dmemIO.wrMask := "b0011".U << effAddrOffReg
129133
vecAccu(effAddrOffReg) := accu(7, 0)
130134
vecAccu(effAddrOffReg | 1.U) := accu(15, 8)
131-
dataMem.io.wrData := vecAccu(3) ## vecAccu(2) ## vecAccu(1) ## vecAccu(0)
135+
dmemIO.wrData := vecAccu(3) ## vecAccu(2) ## vecAccu(1) ## vecAccu(0)
132136
}
133137

134138
is (branch) {
@@ -147,8 +151,8 @@ class Leros(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module
147151

148152
is (jal) {
149153
pcNext := accu
150-
dataMem.io.wr := true.B
151-
dataMem.io.wrData := pcReg + 1.U
154+
dmemIO.wr := true.B
155+
dmemIO.wrData := pcReg + 1.U
152156
}
153157

154158
is (scall) {

src/main/scala/leros/LerosTestTop.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class LerosTestTop(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends
2525
val dbg = new Debug(size, memAddrWidth)
2626
val led = Output(UInt(8.W))
2727
})
28-
val leros = Module(new Leros(prog))
29-
io.led := leros.io.led
28+
val lerosTop = Module(new LerosTop(prog))
29+
io.led := lerosTop.io.led
3030

3131
// Boring Utils for debugging
3232
io.dbg.accu := DontCare
3333
io.dbg.pc := DontCare
3434
io.dbg.instr := DontCare
3535
io.dbg.exit := DontCare
36-
BoringUtils.bore(leros.accu, Seq(io.dbg.accu))
37-
BoringUtils.bore(leros.pcReg, Seq(io.dbg.pc))
38-
BoringUtils.bore(leros.instr, Seq(io.dbg.instr))
39-
BoringUtils.bore(leros.exit, Seq(io.dbg.exit))
36+
BoringUtils.bore(lerosTop.leros.accu, Seq(io.dbg.accu))
37+
BoringUtils.bore(lerosTop.leros.pcReg, Seq(io.dbg.pc))
38+
BoringUtils.bore(lerosTop.leros.instr, Seq(io.dbg.instr))
39+
BoringUtils.bore(lerosTop.leros.exit, Seq(io.dbg.exit))
4040
}
4141

4242

src/main/scala/leros/LerosTop.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package leros
2+
3+
import chisel3._
4+
import chisel3.util._
5+
import leros.State._
6+
import leros.shared.Constants._
7+
8+
/**
9+
* Leros top level.
10+
*
11+
* Sequential implementation with two states.
12+
*/
13+
class LerosTop(prog: String, size: Int = 32, memAddrWidth: Int = 8) extends Module {
14+
15+
val io = IO(new Bundle {
16+
// val dout = Output(UInt(32.W))
17+
// val sw = Input(UInt(4.W))
18+
val led = Output(UInt(8.W))
19+
})
20+
21+
val leros = Module(new Leros(prog))
22+
// Fetch from instruction memory with an address register that is reset to 0
23+
val instrMem = Module(new InstrMem(memAddrWidth, prog))
24+
// Data memory, including the register memory
25+
// read in fetch, write in execute
26+
val dataMem = Module(new DataMem((memAddrWidth), false))
27+
28+
instrMem.io <> leros.imemIO
29+
dataMem.io <> leros.dmemIO
30+
31+
// TODO: LED and decoding for it
32+
io.led := leros.io.led
33+
}
34+
35+
object LerosTop extends App {
36+
emitVerilog(new LerosTop(args(0)), Array("--target-dir", "generated"))
37+
}

0 commit comments

Comments
 (0)