Skip to content

Latest commit

 

History

History
398 lines (239 loc) · 5.59 KB

README_Zh.md

File metadata and controls

398 lines (239 loc) · 5.59 KB

指令流

新指令通过LSQ与外界交流。

首先修改新指令的属性,必须要是inst->isMemRef(),才能在execute:issue中push到inFUMemInsts

isMemRef()定义在dyn_inst.hh:259

    bool isMemRef() const { return isInst() && staticInst->isMemRef(); }

isMemRef定义在src/cpu/static_inst.hh:static_inst.hh:142

isMemRef() const
{
        return flags[IsLoad] || flags[IsStore] || flags[IsAtomic];
}

属性定义在static_inst:207:setFlag

枚举量Flag的定义在src/cpu/StaticInstFlags.py:49

setFlagsrc/arch/riscv/isa/formats/amo.isa中被调用。

先修改浮点指令,在src/cpu/minor/fetch2.cc:423

else if (decoded_inst->isFloating())
	stats.fpInstructions++;

作废

issue

execute:issue中修改isFloating的分支,也送入InFuMemInst

issued_mem_ref = inst->isMemRef() || inst->isFloating();

commit

pop LSQ阶段:

  if (completed_inst && (inst->isMemRef() || inst->isFloating() ))

添加函数

void SendToCustom();

commitInst

gem5系统

MinorCPU

execute.cc

在execute的构造函数中添加rtl目录下的构造函数

    custom(name_ + ".custom", name_ + ".custominst_port",
        cpu_, *this,

        ),

execute的include

#include "debug/MemObject.hh"

在execute的.hh函数中声明rtl目录下的函数

#include "cpu/minor/custom.hh"

//添加新函数

    /* Send To MemObject */
    void SendToCustom(MinorDynInstPtr inst)
    /* Custom Inst */
    Custom custom;

在execute的SConscript文件中添加

    Source('custom.cc')

    DebugFlag('Custom', 'CustomInstPort')

作废

src/cpu/minor/BaseMinorCPU.py中添加

custominst_port = RequestPort("CustomInst Port")

作废

src/cpu/BaseCPU.py中添加

custominst_port = RequestPort("CustomInst Port")

      _cached_ports = ["icache_port", "dcache_port", "custominst_port"]

src/cpu/base.ccgetPort函数添加:

else if (if_name == "custominst_port")
  return getCustPort();



getCustPort().takeOverFrom(&oldCPU->getCustPort());

src/cpu/base.hh中添加getCustPort()

/** Custom*/
virtual Port &getCustPort() = 0;



作废

src/cpu/kvm/base.hh中添加

Port &getCustPort()  { return custPort; }



/** Unused port*/
KVMCpuPort custPort;

貌似不用再bash里面改。

直接在minor/cpu里面加一个getPort

src/cpu/minor/cpu.hh

Port &getPort(const std::string &if_name, PortID idx=InvalidPortID) override;

.cc

Port &
MinorCPU::getPort(const std::string &if_name, PortID idx)
{
    if (if_name == "custominst_port")
        return getCustPort();
    else
        return getCustPort();
}

src/cpu/minor/cpu.hh中添加getCustPort()

    /** Return a reference to custom*/
    Port &getCustPort() override;

src/cpu/minor/cpu.cc中添加getCustPort()

Port &
MinorCPU::getCustPort()
{
    return pipeline->getCustPort();
}

src/cpu/minor/pipeline.cc中添加getCustPort()

MinorCPU::MinorCPUPort &
Pipeline::getCustPort()
{
    return execute.getCustPort();
}

src/cpu/minor/pipeline.hh中添加getCustPort()

    /** Return the CustomInstPort belonging to Execute for the CPU */
    MinorCPU::MinorCPUPort &getCustPort();

src/cpu/minor/execute.hh中添加getCustPort()

    /** Return the CustomPort*/
    MinorCPU::MinorCPUPort &getCustPort();

src/cpu/minor/execute.cc中添加getCustPort()

MinorCPU::MinorCPUPort &
Execute::getCustPort()
{
    return custom.getCustPort();
}

src/cpu/minor/lsq.hh中添加getCustPort()

    /** Return the CustomInst port */
    MinorCPU::MinorCPUPort &getCustPort() { return custmoInstPort; }

RTL

添加src/cpu/rtl文件夹

修改rtl目录下的SConscript:50

添加debug标志:DebugFlag('MemObject', 'Custom inst')

交叉工具链编译

交叉工具链安装

cd ~/Work/riscv/riscv-gnu-toolchain
./configure --prefix=/home/yangchun/Work/riscv/rv64g-linux-gnu --disable-gdb --with-arch=rv64g --with-gcc-src=/home/yangchun/Work/riscv/gcc-11.2.0 --with-binutils-src=/home/yangchun/Work/riscv/binutils-2.35 --with-glibc-src=/home/yangchun/Work/riscv/glibc-2.35
make linux -j $(nproc)

编译文件

/home/csx/sw/riscv/rv64g-linux-gnu/bin/riscv64-unknown-linux-gnu-gcc -static -v -o [outfile] [infile]

重新构建gem5

scons build/RISCV/gem5.opt

运行gem5

build/RISCV/gem5.opt configs/custom/riscv-floating.py

打开debug

build/RISCV/gem5.opt --debug-flags=CustomObj configs/custom/riscv-floating.py

运行counter

build/RISCV/gem5.opt --debug-flags=CustomObj configs/custom/riscv-floating-counter.py

运行counter

有一些编译的小问题

第一个

ext/custom/SConscript里面库路径还用的绝对路径,还待解决

第二个

报错

root@CsxDesktop:/home/csx/workland/mycode/gem5-custom# build/RISCV/gem5.opt --debug-flags=CustomObj configs/custom/riscv-floating-counter.py
build/RISCV/gem5.opt: error while loading shared libraries: libVerilatorCounter.so: cannot open shared object file: No such file or directory

找不到这个动态链接库,强行加一下:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/csx/workland/mycode/gem5_custom/ext/custom