cisen / blog

Time waits for no one.
133 stars 20 forks source link

XiangShan/香山 相关 #1047

Open cisen opened 3 years ago

cisen commented 3 years ago

总结

git clone https://github.com/verilator/verilator # Only first time

Every time you need to build:

unsetenv VERILATOR_ROOT # For csh; ignore error if on bash unset VERILATOR_ROOT # For bash cd verilator git pull # Make sure git repository is up-to-date git tag # See what versions exist

git checkout master # Use development branch (e.g. recent bug fixes)

git checkout stable # Use most recent stable release

git checkout v{version} # Switch to specified release version

autoconf # Create ./configure script ./configure # Configure and create Makefile make -j nproc # Build Verilator itself (if error, try just 'make') sudo make install

- libsdl2不要用apt安装,直接自己编译:https://www.libsdl.org/index.php

```sh
make init
make verilog
make verilog CONFIG=MinimalConfig
make emu EMU_THREADS=16 -j40
make emu CONFIG=MinimalConfig EMU_THREADS=2 -j8
mill XiangShan.test.runMain top.TopMain -td build --config DefaultConfig --full-stacktrace --output-file XSTop.v --disable-all --remove-assert --infer-rw --repl-seq-mem -c:top.TopMain:-o:build/XSTop.v.conf
mill -i
make emu CONFIG=MinimalConfig
make emu EMU_TRACE=1 -j32 

make emu CONFIG=MinimalConfig EMU_THREADS=2 -j10
./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so

# We recommend using stable verison verilator, like v4.204. Verilator v4.210 has performance issues on XiangShan.
verilator --version
make simv
# In NEMU repo, run
make riscv64-xs-ref_defconfig
make -jN # N is the number of threads for C++ compiling
sudo apt-get install libsdl2-2.0
sudo apt-get install libsdl2-dev
sudo apt install g++-riscv64-linux-gnu
sudo apt install g++-riscv64-linux-gnu binutils-riscv64-linux-gnu
sudo apt-get install clang
sudo apt-get install libsqlite3-dev
make emu CONFIG=MinimalConfig EMU_THREADS=2 -j10 ./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so
#risc-v cpu full project, I use root login ubuntu 16.04
apt install verilog
sh -c "curl -L https://github.com/com-lihaoyi/mill/releases/download/0.9.9/0.9.9 > /usr/local/bin/mill && chmod +x /usr/local/bin/mill"
mill version

mkdir -p /root/riscv_cpu
cd /root/riscv_cpu

git clone --recursive https://github.com/OpenXiangShan/NEMU.git
git clone --recursive https://github.com/OpenXiangShan/nexus-am.git
git clone --recursive https://github.com/OpenXiangShan/XiangShan.git
git clone --recursive https://github.com/verilator/verilator

#absolute path
export NEMU_HOME="/root/riscv_cpu/NEMU"
export AM_HOME="/root/riscv_cpu/nexus-am"
export NOOP_HOME="/root/riscv_cpu/XiangShan"

cd verilator
autoconf
./configure
make -j8 && make install

cd /root/riscv_cpu/XiangShan
make init

gedit /root/riscv_cpu/XiangShan/build.sc
#find all
-Xmx64G
#change to
-Xmx16G
(my pc is 16g ram 16g swap ubuntu 16.04.7)

#generate .v
make verilog -j8

#simulation
make emu CONFIG=MinimalConfig SIM_ARGS=--disable-log EMU_THREADS=2 -j8
./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so

外设是0x0 - 0x80000000 内存是0x80000000往上,最大支持36bit物理地址(可配置,按照PAddrBits) DMA支持从0x80000000往上的地址空间,访问DDR和Cache内的数据

问答

sbt还是mill?

怎么初始化?

NEMU是什么?

NOOP是什么?

命令

make emu CONFIG=MinimalConfig SIM_ARGS=--disable-log EMU_THREADS=2 -j10
mill -i

make verilog 错误解决:

试试运行下面这条命令后再make。 'export _JAVA_OPTIONS='-XX:-UseGCOverheadLimit -Xms256m -Xmx30g -Xss256K'

JVM heap size不足导致的编译失败是由于之前的build.sc没能正确的将JVM Xmx参数传递下去, https://github.com/OpenXiangShan/XiangShan/pull/842 可以修复该问题,经过测试10G heap足够编译香山,如果大家仍有问题请继续在issue中反馈,谢谢!

Done elaborating 之后就会生成 Verilog 了,确实需要很久(我的电脑上就要差不多半小时),另外如果电脑内存不够的话可能会时不时卡在 GC 上导致特别慢,可以试试多等一会或者把内存调大一点。最小内存的话没试过,但最好还是给个 5-6 GB 以上的吧。

(1) 再次make init (2) rm -rf out之后,重新make init (3) 删除rocket-chip, berkeley-hardfloat等submodule目录,重新make init