xref: /XiangShan/README.md (revision 770ded88e6a8f74242f0b34b1414e4a33dc028ea)
105f23f57SWilliam Wang# XiangShan
264fc9c9dSZihao Yu
340adeb5aSwangkaifanXiangShan (香山) is an open-source high-performance RISC-V processor project.
464fc9c9dSZihao Yu
5f1d6f360SZibo Huang中文说明[在此](readme.zh-cn.md)。
664fc9c9dSZihao Yu
7a2ba9cdcSYinan XuCopyright 2020-2021 by Institute of Computing Technology, Chinese Academy of Sciences.
864fc9c9dSZihao Yu
9*770ded88SLingrui98## Docs and slides
1059381a79SYinan XuWe gave 20+ presentations on RISC-V World Conference China 2021. XiangShan tutorial was held at the same place. Our slides for RVWC2021 have been updated on [our doc repo](https://github.com/OpenXiangShan/XiangShan-doc) (in Chinese).
1140adeb5aSwangkaifan
1259381a79SYinan Xu我们在2021年RISC-V中国峰会的报告已经更新到[这里](https://github.com/OpenXiangShan/XiangShan-doc)。未来的文档和相关信息也将更新到相同的仓库。
1340adeb5aSwangkaifan
14*770ded88SLingrui98## Mail list
15*770ded88SLingrui98You can contact us through [our mail list](mailto:[email protected]). All mails from this list will be archived to [here](https://www.mail-archive.com/[email protected]/).
16*770ded88SLingrui98
1740adeb5aSwangkaifan## Architecture
1840adeb5aSwangkaifan
198c0a01afSClSlaidThe first stable micro-architecture of XiangShan is called Yanqihu (雁栖湖) on this [branch](https://github.com/OpenXiangShan/XiangShan/tree/yanqihu), which has been developed since June 2020. The current version of XiangShan, also known as Nanhu (南湖), is still under development on the master branch.
2040adeb5aSwangkaifan
2140adeb5aSwangkaifanThe micro-architecture overview is shown below.
2240adeb5aSwangkaifan
236d529dd2Swangkaifan![xs-arch-single](xs-arch-simple.svg)
2440adeb5aSwangkaifan
2540adeb5aSwangkaifan
2640adeb5aSwangkaifan
2740adeb5aSwangkaifan## Sub-directories Overview
2840adeb5aSwangkaifan
2940adeb5aSwangkaifanSome of the key directories are shown below.
3040adeb5aSwangkaifan
3140adeb5aSwangkaifan```
3240adeb5aSwangkaifan.
3340adeb5aSwangkaifan├── fpga                   # supported FPGA boards and files to build a Vivado project
3440adeb5aSwangkaifan├── read-to-run            # pre-built simulation images
3540adeb5aSwangkaifan├── scripts                # scripts for agile development
3640adeb5aSwangkaifan└── src
3740adeb5aSwangkaifan    ├── test               # test files (including diff-test, module-test, etc.)
3840adeb5aSwangkaifan    └── main/scala         # design files
3940adeb5aSwangkaifan        ├── bus/tilelink   # tilelink utils
4040adeb5aSwangkaifan        ├── device         # virtual device for simulation
4140adeb5aSwangkaifan        ├── difftest       # diff-test chisel interface
4240adeb5aSwangkaifan        ├── system         # SoC wrapper
4340adeb5aSwangkaifan        ├── top            # top module
4440adeb5aSwangkaifan        ├── utils          # utilization code
4540adeb5aSwangkaifan        ├── xiangshan      # main design code
4640adeb5aSwangkaifan        └── xstransforms   # some useful firrtl transforms
4740adeb5aSwangkaifan```
4840adeb5aSwangkaifan
4940adeb5aSwangkaifan
5040adeb5aSwangkaifan
5140adeb5aSwangkaifan## Generate Verilog
5240adeb5aSwangkaifan
5340adeb5aSwangkaifan* Run `make verilog` to generate verilog code. The output file is `build/XSTop.v`.
5440adeb5aSwangkaifan* Refer to `Makefile` for more information.
5540adeb5aSwangkaifan
5640adeb5aSwangkaifan
5740adeb5aSwangkaifan
5840adeb5aSwangkaifan## Run Programs by Simulation
5940adeb5aSwangkaifan
6040adeb5aSwangkaifan### Prepare environment
6164fc9c9dSZihao Yu
62a2ba9cdcSYinan Xu* Set environment variable `NEMU_HOME` to the **absolute path** of the [NEMU project](https://github.com/OpenXiangShan/NEMU).
63a2ba9cdcSYinan Xu* Set environment variable `NOOP_HOME` to the **absolute path** of the XiangShan project.
64a2ba9cdcSYinan Xu* Set environment variable `AM_HOME` to the **absolute path** of the [AM project](https://github.com/OpenXiangShan/nexus-am).
65a2ba9cdcSYinan Xu* Install `mill`. Refer to [the Manual section in this guide](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html#_installation).
6640adeb5aSwangkaifan* Clone this project and run `make init` to initialize submodules.
6764fc9c9dSZihao Yu
6840adeb5aSwangkaifan### Run with simulator
6905f23f57SWilliam Wang
70a2ba9cdcSYinan Xu* Install [Verilator](https://verilator.org/guide/latest/), the open-source Verilog simulator.
71a2ba9cdcSYinan Xu* Run `make emu` to build the C++ simulator `./build/emu` with Verilator.
72a2ba9cdcSYinan Xu* Refer to `./build/emu --help` for run-time arguments of the simulator.
73a2ba9cdcSYinan Xu* Refer to `Makefile` and `verilator.mk` for more information.
7405f23f57SWilliam Wang
7505f23f57SWilliam WangExample:
768c0a01afSClSlaid
77a2ba9cdcSYinan Xu```bash
78a2ba9cdcSYinan Xumake emu CONFIG=MinimalConfig SIM_ARGS=--disable-log EMU_THREADS=2 -j10
792f256e1dSwakafa./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so
805c647eb5SZihao Yu```
815c647eb5SZihao Yu
82d8e5e781Swakafa## Acknowledgement
83d8e5e781Swakafa
848c0a01afSClSlaidIn the development of XiangShan, some sub-modules from the open-source community are employed. All relevant usage is listed below.
85d8e5e781Swakafa
86d8e5e781Swakafa| Sub-module         | Source                                                       | Detail                                                       |
87d8e5e781Swakafa| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
88d8e5e781Swakafa| L2 Cache/LLC       | [Sifive block-inclusivecache](https://github.com/ucb-bar/block-inclusivecache-sifive) | We enhance the function and the timing of the original module, finally turning it into a Cache generator that can be configured as L2/LLC. |
89d8e5e781Swakafa| Diplomacy/TileLink | [Rocket-chip](https://github.com/chipsalliance/rocket-chip)  | We reused the diplomacy framework and TileLink utility that exist in rocket-chip to negotiate bus. |
908c0a01afSClSlaid| FPU                | [Berkeley hardfloat](https://github.com/ucb-bar/berkeley-hardfloat) | We use Berkeley-hardfloat as our FPU and implement an SRT-4 div/sqrt unit for it. Additionally, we split the FMA pipeline to optimize the timing. |
91d8e5e781Swakafa
928c0a01afSClSlaidWe are grateful for the support of the open-source community and encourage other open-source projects to reuse our code within the scope of the [license](LICENSE).
93d8e5e781Swakafa
94