> configure(npc)
ysyx_22040000 李心杨 Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar 1 12:35:11 UTC 2024 x86_64 GNU/Linux 12:37:35 up 0:27, 2 users, load average: 0.98, 0.35, 0.36
This commit is contained in:
parent
16c8af7dea
commit
9735a8a7bb
4 changed files with 57 additions and 24 deletions
|
@ -3,17 +3,21 @@ package npc.util
|
||||||
import chisel3._
|
import chisel3._
|
||||||
import chisel3.util._
|
import chisel3.util._
|
||||||
|
|
||||||
class ALUGenerator(width: Int) extends Module {
|
object ALUSel extends ChiselEnum {
|
||||||
require(width >= 0)
|
val add, sub, not, and, or, xor, slt, eq, nop = Value
|
||||||
|
}
|
||||||
|
|
||||||
|
class ALUGenerator[T <: ChiselEnum](width: Int, tpe: T = ALUSel) extends Module {
|
||||||
val io = IO(new Bundle {
|
val io = IO(new Bundle {
|
||||||
val a = Input(UInt(width.W))
|
val a = Input(UInt(tpe.getWidth.W))
|
||||||
val b = Input(UInt(width.W))
|
val b = Input(UInt(tpe.getWidth.W))
|
||||||
val op = Input(UInt(4.W))
|
val op = Input(ALUSel())
|
||||||
val out = Output(UInt(width.W))
|
val out = Output(UInt(tpe.getWidth.W))
|
||||||
})
|
})
|
||||||
|
|
||||||
val adder_b = (Fill(width, io.op(0)) ^ io.b) + io.op(0) // take (-b) if sub
|
// val adder_b = (Fill(tpe.getWidth, io.op(0)) ^ io.b) + io.op(0) // take (-b) if sub
|
||||||
val add = io.a + adder_b
|
val add = io.a + io.b
|
||||||
|
val sub = io.a - io.b
|
||||||
val and = io.a & io.b
|
val and = io.a & io.b
|
||||||
val not = ~io.a
|
val not = ~io.a
|
||||||
val or = io.a | io.b
|
val or = io.a | io.b
|
||||||
|
@ -21,14 +25,14 @@ class ALUGenerator(width: Int) extends Module {
|
||||||
val slt = io.a < io.b
|
val slt = io.a < io.b
|
||||||
val eq = io.a === io.b
|
val eq = io.a === io.b
|
||||||
|
|
||||||
io.out := MuxLookup(io.op, 0.U)(Seq(
|
io.out := MuxLookup(io.op, ALUSel.nop.asUInt)(Seq(
|
||||||
0.U -> add,
|
ALUSel.add -> add,
|
||||||
1.U -> add, // add with b reversed
|
ALUSel.sub -> sub,
|
||||||
2.U -> not,
|
ALUSel.not -> not,
|
||||||
3.U -> and,
|
ALUSel.and -> and,
|
||||||
4.U -> or,
|
ALUSel.or -> or,
|
||||||
5.U -> xor,
|
ALUSel.xor -> xor,
|
||||||
6.U -> slt,
|
ALUSel.slt -> slt,
|
||||||
7.U -> eq,
|
ALUSel.eq -> eq
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import chisel3.util.{MuxLookup, Fill, Decoupled, Counter, Queue, Reverse}
|
||||||
import chisel3.util.{SRAM}
|
import chisel3.util.{SRAM}
|
||||||
import chisel3.stage.ChiselOption
|
import chisel3.stage.ChiselOption
|
||||||
import npc.util.{ KeyboardSegController, RegisterFile }
|
import npc.util.{ KeyboardSegController, RegisterFile }
|
||||||
import flowpc.components.ProgramCounter
|
import flowpc.components.{ProgramCounter, ProgramCounterSel}
|
||||||
|
|
||||||
class Switch extends Module {
|
class Switch extends Module {
|
||||||
val io = IO(new Bundle {
|
val io = IO(new Bundle {
|
||||||
|
@ -33,8 +33,31 @@ class Keyboard extends Module {
|
||||||
io.segs := seg_handler.io.segs
|
io.segs := seg_handler.io.segs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Opcode extends ChiselEnum {
|
||||||
|
val addi = Value("b0010011".U)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Control extends Bundle {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class Flowpc extends Module {
|
class Flowpc extends Module {
|
||||||
val io = IO(new Bundle { })
|
val io = IO(new Bundle { })
|
||||||
val register_file = new RegisterFile(readPorts = 2);
|
val register_file = new RegisterFile(readPorts = 2)
|
||||||
val pc = new ProgramCounter(32);
|
val pc = new ProgramCounter(32)
|
||||||
|
val ram = SRAM(size=128*1024*1024, tpe=UInt(32.W), numReadPorts=2, numWritePorts=1,numReadwritePorts=0)
|
||||||
|
|
||||||
|
// Instruction Fetch
|
||||||
|
ram.readPorts(0).address := pc.io.pc
|
||||||
|
ram.readPorts(0).enable := true.B
|
||||||
|
val instruction = ram.readPorts(0).address
|
||||||
|
|
||||||
|
// Instruction Decode
|
||||||
|
val opcode = Opcode(instruction(7,0))
|
||||||
|
|
||||||
|
// Execution
|
||||||
|
|
||||||
|
// Next PC
|
||||||
|
pc.io.pc_srcs(ProgramCounterSel.selectPC.asUInt) := pc.io.pc + 4.U
|
||||||
|
// pc.io.pc_srcs(ProgramCounterSel.selectResult.asUInt) :=
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
package flowpc.components
|
package flowpc.components
|
||||||
import chisel3._
|
import chisel3._
|
||||||
import chisel3.util.{Valid}
|
import chisel3.util.{Valid, log2Ceil}
|
||||||
|
import chisel3.util.MuxLookup
|
||||||
|
|
||||||
|
object ProgramCounterSel extends ChiselEnum {
|
||||||
|
val selectPC, selectResult = Value
|
||||||
|
}
|
||||||
|
|
||||||
class ProgramCounter (width: Int) extends Module {
|
class ProgramCounter (width: Int) extends Module {
|
||||||
val io = new Bundle {
|
val io = new Bundle {
|
||||||
val next_pc = Input(Flipped(Valid(UInt(width.W))))
|
val pc_srcs = Input(Vec(1 << (ProgramCounterSel.getWidth - 1), UInt(width.W)))
|
||||||
|
val select = Input(UInt(ProgramCounterSel.getWidth.W))
|
||||||
val pc = Output(UInt(width.W))
|
val pc = Output(UInt(width.W))
|
||||||
}
|
}
|
||||||
io.pc := Mux(io.next_pc.valid, io.next_pc.bits, io.pc)
|
io.pc := io.pc_srcs(io.select)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ class ALUGeneratorSpec extends AnyFreeSpec with ChiselScalatestTester {
|
||||||
6 -> ((a, b) => if (a < b) 1 else 0),
|
6 -> ((a, b) => if (a < b) 1 else 0),
|
||||||
7 -> ((a, b) => if (a == b) 1 else 0),
|
7 -> ((a, b) => if (a == b) 1 else 0),
|
||||||
)
|
)
|
||||||
val validate = (c: ALUGenerator,op: Int, oprands: List[(BigInt, BigInt)]) => {
|
val validate = (c: ALUGenerator[32], op: Int, oprands: List[(BigInt, BigInt)]) => {
|
||||||
c.io.op.poke(op.U)
|
c.io.op.poke(op.U)
|
||||||
oprands.foreach({ case (a, b) =>
|
oprands.foreach({ case (a, b) =>
|
||||||
c.io.a.poke(a.U)
|
c.io.a.poke(a.U)
|
||||||
|
|
Loading…
Reference in a new issue