riscv-sodor-rv32_2stage(2)

riscv-sodor-rv32_2stage(2)

在这里插入图片描述
接着分析的是dpath.scala。riscv-sodor-rv32_2stage dpath.scala与riscv-sodor-rv32_1stage dpath.scala的差异在于取指后加了一级执行的寄存器。当在执行的时候,取指寄存器可以预先取指,这样能提高系统的效率。如果没有执行阶段的寄存器(riscv-sodor-rv32_1stage),在执行非单步指令时(multi-cycle的指令),cpu流水线要暂停取指,等当前指令完成执行后才能进行下一步的取指操作,这样会大大降低系统的效率。

package Sodor
{

import chisel3._
import chisel3.util._


import Constants._
import Common._
import Common.Constants._

//定义dpath到cpath的一些控制信号
//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中定义 ,是memory端口的定义
//dmem是dpath取数据的memory,MemPortIo()在/commo/memory.scala中定义,是memory端口的定义
//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

   //**********************************
   // Pipeline State Registers
   //声明一个if_reg_pc的寄存器,初始值为START_ADDR,用于取指阶段
   val if_reg_pc = Reg(init = START_ADDR) 
   
   //声明一个exe_reg_pc的寄存器,初始值为0,位宽为conf.xprlen.W,用于执行阶段
   val exe_reg_pc       = Reg(init=0.asUInt(conf.xprlen.W))
   //声明一个exe_reg_pc_plus4的寄存器,初始值为0,位宽为conf.xprlen.W,用于执行阶段,是图中PC+4的位置
   val exe_reg_pc_plus4 = Reg(init=0.asUInt(conf.xprlen.W))
   //声明一个exe_reg_inst的寄存器,初始值为BUBBLE,用于执行阶段,是图中IR的位置
   val exe_reg_inst     = Reg(init=BUBBLE)
   
   //定义几个32位、wire类型的信号
   //if_pc_next:下一个pc的值
   //exe_br_target:分支判断的目标
   //exe_jmp_target:直接跳转的目标
   //exe_jump_reg_target:以寄存器的值为地址的跳转
   //exception_target:异常的跳转
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值