Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compliance condition Updated #82

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,10 @@ project/plugins/project/
hs_err_pid*

.venv
compliance/
compliance/

# Compliance
config.ini
nucleusrv/
spike/
riscof_work/
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ asmtohex:

dv:
$(MAKE) asmtohex
$(MAKE) IMEM=assembly.hex sim
$(MAKE) IMEM=assembly.hex sim

modify_top:
(echo '/* verilator lint_off ASSIGNDLY */' && \
echo '/* verilator lint_off UNUSED */' && \
echo '/* verilator lint_off BLKSEQ */' && \
echo '/* verilator lint_off DECLFILENAME */' && \
echo '/* verilator lint_off EOFNEWLINE */' && \
echo '/* verilator lint_off WIDTH */' && \
cat Top.v) > temp && mv temp Top.v

sim-compliance:
sbt "runMain nucleusrv.components.NRVDriver $(IMEM) $(DMEM)"
make modify_top
@if [ ! -d obj_dir ]; then mkdir obj_dir; fi
verilator -Wall --cc Top.v --exe tb_Top.cpp > $(PTH)/ver_output.log 2>&1
make -C obj_dir -f VTop.mk VTop
@obj_dir/VTop > $(PTH)/trace.log 2>&1
9 changes: 9 additions & 0 deletions run_riscof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cd ../../../../../..
riscv64-unknown-elf-objcopy -O binary -j .text.init $1/my.elf $1/DUT-nucleusrv.text.bin
riscv64-unknown-elf-objcopy -O binary -j .data $1/my.elf $1/DUT-nucleusrv.data.bin
hexdump -v -e '"%08x\n"' $1/DUT-nucleusrv.text.bin > $1/DUT-nucleusrv.program.hex
hexdump -v -e '"%08x\n"' $1/DUT-nucleusrv.text.bin > $1/DUT-nucleusrv.data.hex
make sim-compliance IMEM=$1/DUT-nucleusrv.program.hex DMEM=$1/DUT-nucleusrv.data.hex PTH=$1
grep '^[a-f0-9]\+$' $1/trace.log > $1/DUT-nucleusrv.signature
146 changes: 129 additions & 17 deletions src/main/scala/components/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Core(implicit val config:Configs) extends Module{

val fcsr_o_data = Output(UInt(32.W))
})

val dccm_stall = WireInit(0.B)
// IF-ID Registers
val if_reg_pc = RegInit(0.U(32.W))
val if_reg_ins = RegInit(0.U(32.W))
Expand Down Expand Up @@ -156,23 +156,28 @@ class Core(implicit val config:Configs) extends Module{
IF.stall := io.stall || EX.stall || ID.stall || IF_stall //stall signal from outside

// pc.io.halt := Mux(io.imemReq.valid || ~EX.stall || ~ID.stall, 0.B, 1.B)
pc.io.halt := Mux(((EX.stall || ID.stall || IF_stall || ~io.imemReq.valid) | ral_halt_o), 1.B, 0.B)
pc.io.halt := Mux(((EX.stall || ID.stall || IF_stall || ~io.imemReq.valid || dccm_stall) | ral_halt_o), 1.B, 0.B)
val npc = Mux(ID.hdu_pcWrite, Mux(ID.pcSrc, ID.pcPlusOffset.asSInt(), Mux(is_comp, pc.io.pc2, pc.io.pc4)), pc.io.out)
pc.io.in := npc

when(ID.hdu_if_reg_write) {
if_reg_pc := pc.io.out.asUInt()
if_reg_ins := instruction
}
when(ID.ifid_flush) {
if_reg_ins := 0.U
}

when(!dccm_stall){
when(ID.hdu_if_reg_write) {
if_reg_pc := pc.io.out.asUInt()
if_reg_ins := instruction
}
when(ID.ifid_flush) {
if_reg_ins := 0.U
}
}
.otherwise{
if_reg_ins := if_reg_ins
if_reg_pc := if_reg_pc
}

/****************
* Decode Stage *
****************/

when(!dccm_stall){
id_reg_rd1 := ID.readData1
id_reg_rd2 := ID.readData2
id_reg_imm := ID.immediate
Expand All @@ -192,6 +197,28 @@ class Core(implicit val config:Configs) extends Module{
id_reg_ctl_aluSrc1 := ID.ctl_aluSrc1
id_reg_is_csr := ID.is_csr
id_reg_csr_data := ID.csr_o_data
}.otherwise{
id_reg_rd1 := id_reg_rd1
id_reg_rd2 := id_reg_rd2
id_reg_imm := id_reg_imm
id_reg_wra := id_reg_wra
id_reg_f3 := id_reg_f3
id_reg_f7 := id_reg_f7
id_reg_ins := id_reg_ins
id_reg_pc := id_reg_pc
id_reg_ctl_aluSrc := id_reg_ctl_aluSrc
id_reg_ctl_memToReg := id_reg_ctl_memToReg
id_reg_ctl_regWrite := id_reg_ctl_regWrite
id_reg_ctl_memRead := id_reg_ctl_memRead
id_reg_ctl_memWrite := id_reg_ctl_memWrite
id_reg_ctl_branch := id_reg_ctl_branch
id_reg_ctl_aluOp := id_reg_ctl_aluOp
id_reg_ctl_jump := id_reg_ctl_jump
id_reg_ctl_aluSrc1 := id_reg_ctl_aluSrc1
id_reg_is_csr := id_reg_is_csr
id_reg_csr_data := id_reg_csr_data
// IF.PcWrite := ID.hdu_pcWrite
}
// IF.PcWrite := ID.hdu_pcWrite
ID.id_instruction := if_reg_ins
ID.pcAddress := if_reg_pc
Expand All @@ -208,6 +235,43 @@ class Core(implicit val config:Configs) extends Module{
ID.id_ex_regWr := id_reg_ctl_regWrite
ID.ex_mem_regWr := ex_reg_ctl_regWrite

// .otherwise{
// id_reg_rd1 := id_reg_rd1
// id_reg_rd2 := id_reg_rd2
// id_reg_imm := id_reg_imm
// id_reg_wra := ID.writeRegAddress
// id_reg_f3 := ID.func3
// id_reg_f7 := ID.func7
// id_reg_ins := if_reg_ins
// id_reg_pc := if_reg_pc
// id_reg_ctl_aluSrc := ID.ctl_aluSrc
// id_reg_ctl_memToReg := ID.ctl_memToReg
// id_reg_ctl_regWrite := ID.ctl_regWrite
// id_reg_ctl_memRead := ID.ctl_memRead
// id_reg_ctl_memWrite := ID.ctl_memWrite
// id_reg_ctl_branch := ID.ctl_branch
// id_reg_ctl_aluOp := ID.ctl_aluOp
// id_reg_ctl_jump := ID.ctl_jump
// id_reg_ctl_aluSrc1 := ID.ctl_aluSrc1
// id_reg_is_csr := ID.is_csr
// id_reg_csr_data := ID.csr_o_data
// // IF.PcWrite := ID.hdu_pcWrite
// ID.id_instruction := if_reg_ins
// ID.pcAddress := if_reg_pc
// ID.dmem_resp_valid := io.dmemRsp.valid
// // IF.PcSrc := ID.pcSrc
// // IF.PCPlusOffset := ID.pcPlusOffset
// ID.ex_ins := id_reg_ins
// ID.ex_mem_ins := ex_reg_ins
// ID.mem_wb_ins := mem_reg_ins
// ID.ex_mem_result := ex_reg_result

// ID.csr_i_misa := DontCare
// ID.csr_i_mhartid := DontCare
// ID.id_ex_regWr := id_reg_ctl_regWrite
// ID.ex_mem_regWr := ex_reg_ctl_regWrite
// }

shahzaibk23 marked this conversation as resolved.
Show resolved Hide resolved
/*****************
* Execute Stage *
******************/
Expand All @@ -225,6 +289,8 @@ class Core(implicit val config:Configs) extends Module{
EX.ctl_aluSrc := id_reg_ctl_aluSrc
EX.ctl_aluOp := id_reg_ctl_aluOp
EX.ctl_aluSrc1 := id_reg_ctl_aluSrc1

when (!dccm_stall) {
//EX.ctl_branch := id_reg_ctl_branch
//EX.ctl_jump := id_reg_ctl_jump
ex_reg_pc := id_reg_pc
Expand All @@ -236,6 +302,17 @@ class Core(implicit val config:Configs) extends Module{
ex_reg_csr_data := id_reg_csr_data
// ex_reg_ctl_memRead := id_reg_ctl_memRead
// ex_reg_ctl_memWrite := id_reg_ctl_memWrite
}.otherwise{
ex_reg_pc := ex_reg_pc
ex_reg_wra := ex_reg_wra
ex_reg_ins := ex_reg_ins
ex_reg_ctl_memToReg := ex_reg_ctl_memToReg
ex_reg_ctl_regWrite := ex_reg_ctl_regWrite
ex_reg_is_csr := ex_reg_is_csr
ex_reg_csr_data := ex_reg_csr_data
// ex_reg_ctl_memRead := id_reg_ctl_memRead
// ex_reg_ctl_memWrite := id_reg_ctl_memWrite
}
ID.id_ex_mem_read := id_reg_ctl_memRead
ID.ex_mem_mem_read := ex_reg_ctl_memRead
// ID.ex_mem_mem_write := ex_reg_ctl_memWrite
Expand All @@ -256,12 +333,18 @@ class Core(implicit val config:Configs) extends Module{
id_reg_ctl_regWrite := id_reg_ctl_regWrite
}

when(EX.stall){
id_reg_wra := id_reg_wra
id_reg_ctl_regWrite := id_reg_ctl_regWrite
}

/****************
* Memory Stage *
****************/

io.dmemReq <> MEM.io.dccmReq
MEM.io.dccmRsp <> io.dmemRsp
dccm_stall := MEM.io.stall
// val stall = Wire(Bool())
// stall := (ex_reg_ctl_memWrite || ex_reg_ctl_memRead) && !io.dmemRsp.valid
// when(MEM.io.stall){
Expand All @@ -282,6 +365,8 @@ class Core(implicit val config:Configs) extends Module{
//// ex_reg_result := 0.U
//
// } otherwise{

when(!dccm_stall) {
mem_reg_rd := MEM.io.readData
mem_reg_result := ex_reg_result
// mem_reg_ctl_memToReg := ex_reg_ctl_memToReg
Expand All @@ -294,10 +379,29 @@ class Core(implicit val config:Configs) extends Module{
ex_reg_wd := EX.writeData
ex_reg_result := EX.ALUresult
// }
mem_reg_wra := ex_reg_wra
mem_reg_ctl_memToReg := ex_reg_ctl_memToReg
mem_reg_is_csr := ex_reg_is_csr
mem_reg_csr_data := ex_reg_csr_data
mem_reg_wra := ex_reg_wra
mem_reg_ctl_memToReg := ex_reg_ctl_memToReg
mem_reg_is_csr := ex_reg_is_csr
mem_reg_csr_data := ex_reg_csr_data

}.otherwise{
mem_reg_rd := mem_reg_rd
mem_reg_result := mem_reg_result
// mem_reg_ctl_memToReg := ex_reg_ctl_memToReg
mem_reg_ctl_regWrite := mem_reg_ctl_regWrite
mem_reg_ins := mem_reg_ins
mem_reg_pc := mem_reg_pc
mem_reg_wra := mem_reg_wra
ex_reg_ctl_memRead := ex_reg_ctl_memRead
ex_reg_ctl_memWrite := ex_reg_ctl_memWrite
ex_reg_wd := ex_reg_wd
ex_reg_result := ex_reg_result
// }
mem_reg_wra := mem_reg_wra
mem_reg_ctl_memToReg := mem_reg_ctl_memToReg
mem_reg_is_csr := mem_reg_is_csr
mem_reg_csr_data := mem_reg_csr_data
}
EX.ex_mem_regWrite := ex_reg_ctl_regWrite
MEM.io.aluResultIn := ex_reg_result
MEM.io.writeData := ex_reg_wd
Expand Down Expand Up @@ -327,6 +431,15 @@ class Core(implicit val config:Configs) extends Module{
wb_addr := mem_reg_wra
}


//when (!dccm_stall) {
// io.pin := wb_data
//}.otherwise{
// io.pin := io.pin
//}
shahzaibk23 marked this conversation as resolved.
Show resolved Hide resolved

io.pin := wb_data

ID.mem_wb_result := wb_data
ID.writeData := wb_data
EX.wb_result := wb_data
Expand All @@ -336,7 +449,6 @@ class Core(implicit val config:Configs) extends Module{
ID.csr_Wb := mem_reg_is_csr
ID.csr_Wb_data := mem_reg_csr_data
ID.dmem_data := io.dmemRsp.bits.dataResponse
io.pin := wb_data

/**************
** RVFI PINS **
Expand Down Expand Up @@ -398,4 +510,4 @@ class Core(implicit val config:Configs) extends Module{
tr => tr._1 := tr._2
)
}
}
}
12 changes: 10 additions & 2 deletions src/main/scala/components/MemoryFetch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,19 @@ class MemoryFetch extends Module {
io.dccmReq.bits.activeByteLane := "b1111".U
}

//val reqvalid = WireInit(0.B)

io.dccmReq.bits.dataRequest := wdata.asUInt()
io.dccmReq.bits.addrRequest := (io.aluResultIn & "h00001fff".U) >> 2
io.dccmReq.bits.isWrite := io.writeEnable
io.dccmReq.valid := Mux(io.writeEnable | io.readEnable, true.B, false.B)

when(io.stall) {
io.dccmRsp.ready := false.B
}.otherwise {
io.dccmRsp.ready := true.B
}

io.dccmReq.valid := Mux(io.writeEnable | io.readEnable, true.B, false.B)
io.stall := (io.writeEnable || io.readEnable) && !io.dccmRsp.valid

rdata := Mux(io.dccmRsp.valid, io.dccmRsp.bits.dataResponse, DontCare)
Expand Down Expand Up @@ -185,7 +193,7 @@ class MemoryFetch extends Module {
}


when(io.writeEnable && io.aluResultIn(31, 28) === "h8".asUInt()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SyedHassanUlHaq don't we need the second condition to be there, for compliance?
removing it doesn't break compliance?

when(io.writeEnable && ~io.stall){
printf("%x\n", io.writeData)
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/components/Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object NRVDriver {
// generate verilog
def main(args: Array[String]): Unit = {
val IMem = if (args.length > 0) args(0) else "program.hex"
new ChiselStage().emitVerilog(new Top(Some(IMem), Some("data.hex")))
val DMem = if (args.length > 1) args(1) else "data.hex"
new ChiselStage().emitVerilog(new Top(Some(IMem), Some(DMem)))
}
}