npc,ci: add npc to nix packages
Some checks failed
Run CTests within npc / npc-test (flow) (push) Failing after 8s
Build abstract machine with nix / build-packages (abstract-machine) (push) Failing after 14s
Build abstract machine with nix / build-packages (nemu) (push) Successful in 41s
Build abstract machine with nix / build-packages (nemu-lib) (push) Successful in 9s
Build abstract machine with nix / build-packages (rv32Cross.abstract-machine) (push) Successful in 8s
Run CTests within npc / npc-test (flow-simlib) (push) Failing after 7s

This commit is contained in:
xinyangli 2024-08-14 17:01:37 +08:00
parent 8ee1551dc2
commit 64aee9ae21
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
12 changed files with 423 additions and 157 deletions

View file

@ -0,0 +1,106 @@
package flow.components
import chisel3.util.BitPat
object RV32Inst {
private val bp = BitPat
// format: off
val lui = this.bp("b???????_?????_?????_???_?????_01101_11")
val auipc = this.bp("b???????_?????_?????_???_?????_00101_11")
val jal = this.bp("b???????_?????_?????_???_?????_11011_11")
val jalr = this.bp("b???????_?????_?????_???_?????_11001_11")
val beq = this.bp("b???????_?????_?????_000_?????_11000_11")
val bne = this.bp("b???????_?????_?????_001_?????_11000_11")
val blt = this.bp("b???????_?????_?????_100_?????_11000_11")
val bge = this.bp("b???????_?????_?????_101_?????_11000_11")
val bltu = this.bp("b???????_?????_?????_110_?????_11000_11")
val bgeu = this.bp("b???????_?????_?????_111_?????_11000_11")
val lb = this.bp("b???????_?????_?????_000_?????_00000_11")
val lh = this.bp("b???????_?????_?????_001_?????_00000_11")
val lw = this.bp("b???????_?????_?????_010_?????_00000_11")
val lbu = this.bp("b???????_?????_?????_100_?????_00000_11")
val lhu = this.bp("b???????_?????_?????_101_?????_00000_11")
val sb = this.bp("b???????_?????_?????_000_?????_01000_11")
val sh = this.bp("b???????_?????_?????_001_?????_01000_11")
val sw = this.bp("b???????_?????_?????_010_?????_01000_11")
val addi = this.bp("b???????_?????_?????_000_?????_00100_11")
val slti = this.bp("b???????_?????_?????_010_?????_00100_11")
val sltiu = this.bp("b???????_?????_?????_011_?????_00100_11")
val xori = this.bp("b???????_?????_?????_100_?????_00100_11")
val ori = this.bp("b???????_?????_?????_110_?????_00100_11")
val andi = this.bp("b???????_?????_?????_111_?????_00100_11")
val slli = this.bp("b0000000_?????_?????_001_?????_00100_11")
val srli = this.bp("b0000000_?????_?????_101_?????_00100_11")
val srai = this.bp("b0100000_?????_?????_101_?????_00100_11")
val add = this.bp("b0000000_?????_?????_000_?????_01100_11")
val sub = this.bp("b0100000_?????_?????_000_?????_01100_11")
val sll = this.bp("b0000000_?????_?????_001_?????_01100_11")
val slt = this.bp("b0000000_?????_?????_010_?????_01100_11")
val sltu = this.bp("b0000000_?????_?????_011_?????_01100_11")
val xor = this.bp("b0000000_?????_?????_100_?????_01100_11")
val srl = this.bp("b0000000_?????_?????_101_?????_01100_11")
val sra = this.bp("b0100000_?????_?????_101_?????_01100_11")
val or = this.bp("b0000000_?????_?????_110_?????_01100_11")
val and = this.bp("b0000000_?????_?????_111_?????_01100_11")
val ebreak = this.bp("b0000000_00001_00000_000_00000_11100_11")
val csrrw = this.bp("b???????_?????_?????_001_?????_11100_11")
val mul = this.bp("b0000001_?????_?????_000_?????_01100_11")
val mulh = this.bp("b0000001_?????_?????_001_?????_01100_11")
val mulhsu = this.bp("b0000001_?????_?????_010_?????_01100_11")
val mulhu = this.bp("b0000001_?????_?????_011_?????_01100_11")
val div = this.bp("b0000001_?????_?????_100_?????_01100_11")
val divu = this.bp("b0000001_?????_?????_101_?????_01100_11")
val rem = this.bp("b0000001_?????_?????_110_?????_01100_11")
val remu = this.bp("b0000001_?????_?????_111_?????_01100_11")
val inv = this.bp("b???????_?????_?????_???_?????_?????_??")
// format: on
}
import chisel3._
import chisel3.util._
import flow.Params
object RV32InstSubfields {
implicit class ImmDecoder(val inst: UInt) extends AnyVal {
def immB: UInt = Cat(
Fill(20, inst(31)),
inst(7),
inst(30, 25),
inst(11, 8),
0.U(1.W)
)
def immI: UInt = Cat(Fill(20, inst(31)), inst(31, 20))
def immJ: UInt = Cat(
Fill(12, inst(31)),
inst(19, 12),
inst(20),
inst(30, 25),
inst(24, 21),
0.U(1.W)
)
def immS: UInt = Cat(
Fill(20, inst(31)),
inst(31),
inst(30, 25),
inst(11, 8),
inst(7)
)
def immU: UInt = Cat(inst(31, 12), 0.U(12.W))
def rd: UInt = inst(11, 7)
def rs1: UInt = inst(19, 15)
def rs2: UInt = inst(24, 20)
}
}

View file

@ -18,5 +18,6 @@ import io.circe.generic.JsonCodec
import chisel3._
case class Params(
XLEN: Width,
arch: String,
csrAddrWidth: Width = 12.W
)

View file

@ -14,67 +14,8 @@ import chisel3.experimental.Trace
import scala.collection.IndexedSeqView
import shapeless.Poly1
import flow.components.RamControlInterface
object RV32Inst {
private val bp = BitPat
// format: off
val lui = this.bp("b???????_?????_?????_???_?????_01101_11")
val auipc = this.bp("b???????_?????_?????_???_?????_00101_11")
val jal = this.bp("b???????_?????_?????_???_?????_11011_11")
val jalr = this.bp("b???????_?????_?????_???_?????_11001_11")
val beq = this.bp("b???????_?????_?????_000_?????_11000_11")
val bne = this.bp("b???????_?????_?????_001_?????_11000_11")
val blt = this.bp("b???????_?????_?????_100_?????_11000_11")
val bge = this.bp("b???????_?????_?????_101_?????_11000_11")
val bltu = this.bp("b???????_?????_?????_110_?????_11000_11")
val bgeu = this.bp("b???????_?????_?????_111_?????_11000_11")
val lb = this.bp("b???????_?????_?????_000_?????_00000_11")
val lh = this.bp("b???????_?????_?????_001_?????_00000_11")
val lw = this.bp("b???????_?????_?????_010_?????_00000_11")
val lbu = this.bp("b???????_?????_?????_100_?????_00000_11")
val lhu = this.bp("b???????_?????_?????_101_?????_00000_11")
val sb = this.bp("b???????_?????_?????_000_?????_01000_11")
val sh = this.bp("b???????_?????_?????_001_?????_01000_11")
val sw = this.bp("b???????_?????_?????_010_?????_01000_11")
val addi = this.bp("b???????_?????_?????_000_?????_00100_11")
val slti = this.bp("b???????_?????_?????_010_?????_00100_11")
val sltiu = this.bp("b???????_?????_?????_011_?????_00100_11")
val xori = this.bp("b???????_?????_?????_100_?????_00100_11")
val ori = this.bp("b???????_?????_?????_110_?????_00100_11")
val andi = this.bp("b???????_?????_?????_111_?????_00100_11")
val slli = this.bp("b0000000_?????_?????_001_?????_00100_11")
val srli = this.bp("b0000000_?????_?????_101_?????_00100_11")
val srai = this.bp("b0100000_?????_?????_101_?????_00100_11")
val add = this.bp("b0000000_?????_?????_000_?????_01100_11")
val sub = this.bp("b0100000_?????_?????_000_?????_01100_11")
val sll = this.bp("b0000000_?????_?????_001_?????_01100_11")
val slt = this.bp("b0000000_?????_?????_010_?????_01100_11")
val sltu = this.bp("b0000000_?????_?????_011_?????_01100_11")
val xor = this.bp("b0000000_?????_?????_100_?????_01100_11")
val srl = this.bp("b0000000_?????_?????_101_?????_01100_11")
val sra = this.bp("b0100000_?????_?????_101_?????_01100_11")
val or = this.bp("b0000000_?????_?????_110_?????_01100_11")
val and = this.bp("b0000000_?????_?????_111_?????_01100_11")
val ebreak = this.bp("b0000000_00001_00000_000_00000_11100_11")
val mul = this.bp("b0000001_?????_?????_000_?????_01100_11")
val mulh = this.bp("b0000001_?????_?????_001_?????_01100_11")
val mulhsu = this.bp("b0000001_?????_?????_010_?????_01100_11")
val mulhu = this.bp("b0000001_?????_?????_011_?????_01100_11")
val div = this.bp("b0000001_?????_?????_100_?????_01100_11")
val divu = this.bp("b0000001_?????_?????_101_?????_01100_11")
val rem = this.bp("b0000001_?????_?????_110_?????_01100_11")
val remu = this.bp("b0000001_?????_?????_111_?????_01100_11")
val inv = this.bp("b???????_?????_?????_???_?????_?????_??")
// format: on
}
import flow.components.RV32Inst
import flow.components.RV32InstSubfields._
import flow.components.{RegControl, PcControlInterface, ALUControlInterface}
class Control(width: Int) extends RawModule {
@ -447,13 +388,7 @@ class Flow extends Module {
val npc = Wire(dataType)
npc := pc.out + 4.U
pc.in.exeOut := alu.out.result
pc.in.immB := Cat(
Fill(20, inst(31)),
inst(7),
inst(30, 25),
inst(11, 8),
0.U(1.W)
)
pc.in.immB := inst.immB
control.inst := inst
reg.control <> control.reg
@ -499,9 +434,9 @@ class Flow extends Module {
// printf(cf"maskedData = ${maskedData}, writeData = ${reg.in.writeData(lit(rMemOut))}\n")
reg.in.writeData(lit(rNpc)) := npc
reg.in.writeAddr := inst(11, 7)
reg.in.rs(0) := inst(19, 15) // rs1
reg.in.rs(1) := inst(24, 20) // rs2
reg.in.writeAddr := inst.rd
reg.in.rs(0) := inst.rs1
reg.in.rs(1) := inst.rs2
// TODO: Bulk connection here
ram.io.clock := clock
@ -521,23 +456,10 @@ class Flow extends Module {
alu.in.b(lit(aSrcBRs2)) := reg.out.src(1)
// alu.in.b(lit(aSrcBImmI)) := inst(31, 20).pad(aSrcBImmI.getWidth)
alu.in.b(lit(aSrcBImmI)) := Cat(Fill(20, inst(31)), inst(31, 20))
alu.in.b(lit(aSrcBImmJ)) := Cat(
Fill(12, inst(31)),
inst(19, 12),
inst(20),
inst(30, 25),
inst(24, 21),
0.U(1.W)
)
alu.in.b(lit(aSrcBImmS)) := Cat(
Fill(20, inst(31)),
inst(31),
inst(30, 25),
inst(11, 8),
inst(7)
)
alu.in.b(lit(aSrcBImmU)) := Cat(inst(31, 12), 0.U(12.W))
alu.in.b(lit(aSrcBImmI)) := inst.immI
alu.in.b(lit(aSrcBImmJ)) := inst.immJ
alu.in.b(lit(aSrcBImmS)) := inst.immS
alu.in.b(lit(aSrcBImmU)) := inst.immU
Trace.traceName(pc.out)
dontTouch(control.out)