# GEM5 RISCV
## 安裝WSL
```
wsl --install
```
安裝完後重新啟動後查看有哪些WSL環境,通常預設都會幫你安裝Ubuntu,不過通常重起後可以直接跳到第一步去設定USERNAME和PASSWD
```
wsl --list
```
進入WSL環境
```
wsl -d Ubuntu
```
## 1. 更新Ubuntu環境
```
sudo apt update && sudo apt upgrade
```
## 2. GEM5環境下載
```
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev \
libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \
python3-dev libboost-all-dev pkg-config python3-tk
```
## 3.GEM5下載
```
git clone https://github.com/gem5/gem5
```
## 4.Building GEM5
```
cd gem5
scons build/RISCV/gem5.fast -j 6
```
>build後面資料夾是可以選的,有X86、ARM、RISCV
>-j 後面的數字則是使用CPU的數量
>gem5的副檔名有fast、opt和debug三種,這有不同的功能
## 5.Test GEM5
```
build/RISCV/gem5.fast configs/learning_gem5/part1/simple-riscv.py
```
成功執行後的結果如下
```
gem5 Simulator System. https://www.gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 version 24.0.0.0
gem5 compiled Jul 8 2024 18:46:17
gem5 started Jul 9 2024 11:34:54
gem5 executing on DESKTOP-4DAKVQL, pid 218883
command line: build/RISCV/gem5.fast configs/learning_gem5/part1/simple-riscv.py
Global frequency set at 1000000000000 ticks per second
warn: No dot file generated. Please install pydot to generate the dot file and pdf.
src/mem/dram_interface.cc:690: warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
src/arch/riscv/isa.cc:276: info: RVV enabled, VLEN = 256 bits, ELEN = 64 bits
src/base/statistics.hh:279: warn: One of the stats is a legacy stat. Legacy stat is a stat that does not belong to any statistics::Group. Legacy stat is deprecated.
system.remote_gdb: Listening for connections on port 7000
Beginning simulation!
src/sim/simulate.cc:199: info: Entering event queue @ 0. Starting simulation...
src/sim/syscall_emul.hh:1075: warn: readlink() called on '/proc/self/exe' may yield unexpected results in various settings.
Returning '/mnt/d/gem5/gem5/tests/test-progs/hello/bin/riscv/linux/hello'
src/sim/mem_state.cc:448: info: Increasing stack size by one page.
Hello world!
Exiting @ tick 490357000 because exiting with last active thread context
```
## Reference
- [教學網址](https://bayareanotes.com/wsl-installation/)
- [build gem5](https://www.gem5.org/documentation/learning_gem5/part1/building/)