新指令通过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
setFlag
在src/arch/riscv/isa/formats/amo.isa
中被调用。
先修改浮点指令,在src/cpu/minor/fetch2.cc:423
中
else if (decoded_inst->isFloating())
stats.fpInstructions++;
在
execute:issue
中修改isFloating
的分支,也送入InFuMemInst
issued_mem_ref = inst->isMemRef() || inst->isFloating();
pop LSQ阶段:
if (completed_inst && (inst->isMemRef() || inst->isFloating() ))
void SendToCustom();
MinorCPU
在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.cc
中getPort
函数添加: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; }
添加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]
scons build/RISCV/gem5.opt
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
有一些编译的小问题
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