riscv-sodor-rv32_1stage(2)
接riscv-sodor-rv32_1stage(1)的内容,先放rv32_1stage的结构图:

下面进行说明的是dpath.scala:
package Sodor
{
import chisel3._
import chisel3.util._
import Constants._
import Common._
import Common.Constants._
//定义cpath到dpath的一些控制信号
//inst:从memory中读取的instruction
//br_eq:分支判断条件,当判断为相等时
//br_lt:分支判断条件,当有符号数,判断为小于时
//br_ltu:分支判断条件,当无符号数,判断为小于时
//csr_eret:当当前的执行指令为csr的call/break/ret时,该位置1
class DatToCtlIo(implicit conf: SodorConfiguration) extends Bundle()
{
val inst = Output(UInt(32.W))
val br_eq = Output(Bool())
val br_lt = Output(Bool())
val br_ltu = Output(Bool())
val csr_eret = Output(Bool())
override def cloneType = { new DatToCtlIo().asInstanceOf[this.type] }
}
//定义dpath的端口部分
//Flipped是反转的作用,将DebugCPath()中定义的端口反过来,并在cpath模块中命名为dcpath,即input在这边边ouput
//imem是cpath取指令的memory,MemPortIo()在/commo/memory.scala中定义,后面再说明吧,在这里知道它是声明了一片sram就可以了
//dmem是cpath出来数据的memory,MemPortIo()在/commo/memory.scala中定义,后面再说明吧,在这里知道它是声明了一片sram就可以了
//dat是在DatToCtlIo()的调用,DatToCtlIo()在上面已经做了说明
//ctl是CtlToDatIo()的调用,利用Flipped将端口的方向翻转
class DpathIo(implicit conf: SodorConfiguration) extends Bundle()
{
val ddpath = Flipped(new DebugDPath())
val imem = new MemPortIo(conf.xprlen)
val dmem = new MemPortIo(conf.xprlen)
val ctl = Flipped(new CtlToDatIo())
val dat = new DatToCtlIo()
}
//主体部分,DatPath的主要逻辑
class DatPath(implicit conf: SodorConfiguration) extends Module
{
//先声明一个io的端口,调用上面的DpathIo(),并赋随机值
val io = IO(new DpathIo())
io := DontCare
//定义几个32位、wire类型的信号
//pc_next:下一个pc的值
//pc_plus4:当前pc+4
//br_target:分支判断的目标
//jmp_target:直接跳转的目标
//jump_reg_target:以寄存器的值为地址的跳转
// exception_target:异常的跳转
// Instruction Fetch
val pc_next = Wire(UInt(32.W))
val pc_plus4 = Wire(UInt(32.W))
val br_target = Wire(UInt(32.W))
val jmp_target = Wire(UInt(32.W))
val jump_reg_target = Wire(UInt(32.W))
val exception_target = Wire(UInt(32.W))
//pc_next的变化情

本文深入解析RISC-V架构的Sodor RV32_1stage处理器设计,涵盖Chisel硬件描述语言的应用,数据路径(Dpath)的详细逻辑流程,包括指令获取、寄存器文件操作、ALU运算、跳转目标计算及CSR寄存器交互。
最低0.47元/天 解锁文章
2272

被折叠的 条评论
为什么被折叠?



