xref: /XiangShan/README.md (revision 57bb43b5f11c3f1e89ac52f232fe73056b35d9bd)
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
7*57bb43b5SwakafaCopyright 2020-2022 by Institute of Computing Technology, Chinese Academy of Sciences.
864fc9c9dSZihao Yu
9*57bb43b5SwakafaCopyright 2020-2022 by Peng Cheng Laboratory.
10f320e0f0SYinan Xu
11770ded88SLingrui98## Docs and slides
1240adeb5aSwangkaifan
13*57bb43b5Swakafa[XiangShan-doc](https://github.com/OpenXiangShan/XiangShan-doc) is our official documentation repository. It contains design spec., technical slides, tutorial and more.
14*57bb43b5Swakafa
15*57bb43b5Swakafa* Micro-architecture documentation of XiangShan has been published. Please check out https://xiangshan-doc.readthedocs.io
1640adeb5aSwangkaifan
17708ceed4SYinan Xu## Follow us
18708ceed4SYinan Xu
19708ceed4SYinan XuWechat/微信:香山开源处理器
20708ceed4SYinan Xu
21708ceed4SYinan Xu<div align=left><img width="340" height="117" src="images/wechat.png"/></div>
22708ceed4SYinan Xu
23708ceed4SYinan XuZhihu/知乎:[香山开源处理器](https://www.zhihu.com/people/openxiangshan)
24708ceed4SYinan Xu
25708ceed4SYinan XuWeibo/微博:[香山开源处理器](https://weibo.com/u/7706264932)
26708ceed4SYinan Xu
27770ded88SLingrui98You 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]/).
28770ded88SLingrui98
2940adeb5aSwangkaifan## Architecture
3040adeb5aSwangkaifan
318c0a01afSClSlaidThe 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.
3240adeb5aSwangkaifan
33*57bb43b5SwakafaThe micro-architecture overview of Nanhu (南湖) is shown below.
3440adeb5aSwangkaifan
35*57bb43b5Swakafa![xs-arch-nanhu](images/xs-arch-nanhu.svg)
3640adeb5aSwangkaifan
3740adeb5aSwangkaifan
3840adeb5aSwangkaifan
3940adeb5aSwangkaifan## Sub-directories Overview
4040adeb5aSwangkaifan
4140adeb5aSwangkaifanSome of the key directories are shown below.
4240adeb5aSwangkaifan
4340adeb5aSwangkaifan```
4440adeb5aSwangkaifan.
45*57bb43b5Swakafa├── src
46*57bb43b5Swakafa│   └── main/scala         # design files
47*57bb43b5Swakafa│       ├── device         # virtual device for simulation
48*57bb43b5Swakafa│       ├── system         # SoC wrapper
49*57bb43b5Swakafa│       ├── top            # top module
50*57bb43b5Swakafa│       ├── utils          # utilization code
51*57bb43b5Swakafa│       ├── xiangshan      # main design code
52*57bb43b5Swakafa│       └── xstransforms   # some useful firrtl transforms
5340adeb5aSwangkaifan├── scripts                # scripts for agile development
54*57bb43b5Swakafa├── fudian                 # floating unit submodule of XiangShan
55*57bb43b5Swakafa├── huancun                # L2/L3 cache submodule of XiangShan
56*57bb43b5Swakafa├── difftest               # difftest co-simulation framework
57*57bb43b5Swakafa└── ready-to-run           # pre-built simulation images
5840adeb5aSwangkaifan```
5940adeb5aSwangkaifan
600af3f746SJiawei Lin## IDE Support
610af3f746SJiawei Lin
620af3f746SJiawei Lin### bsp
630af3f746SJiawei Lin```
640af3f746SJiawei Linmake bsp
650af3f746SJiawei Lin```
660af3f746SJiawei Lin
670af3f746SJiawei Lin### IDEA
680af3f746SJiawei Lin```
690af3f746SJiawei Linmake idea
700af3f746SJiawei Lin```
7140adeb5aSwangkaifan
7240adeb5aSwangkaifan
7340adeb5aSwangkaifan## Generate Verilog
7440adeb5aSwangkaifan
7540adeb5aSwangkaifan* Run `make verilog` to generate verilog code. The output file is `build/XSTop.v`.
7640adeb5aSwangkaifan* Refer to `Makefile` for more information.
7740adeb5aSwangkaifan
7840adeb5aSwangkaifan
7940adeb5aSwangkaifan
8040adeb5aSwangkaifan## Run Programs by Simulation
8140adeb5aSwangkaifan
8240adeb5aSwangkaifan### Prepare environment
8364fc9c9dSZihao Yu
84a2ba9cdcSYinan Xu* Set environment variable `NEMU_HOME` to the **absolute path** of the [NEMU project](https://github.com/OpenXiangShan/NEMU).
85a2ba9cdcSYinan Xu* Set environment variable `NOOP_HOME` to the **absolute path** of the XiangShan project.
86a2ba9cdcSYinan Xu* Set environment variable `AM_HOME` to the **absolute path** of the [AM project](https://github.com/OpenXiangShan/nexus-am).
87a2ba9cdcSYinan Xu* Install `mill`. Refer to [the Manual section in this guide](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html#_installation).
8840adeb5aSwangkaifan* Clone this project and run `make init` to initialize submodules.
8964fc9c9dSZihao Yu
9040adeb5aSwangkaifan### Run with simulator
9105f23f57SWilliam Wang
92a2ba9cdcSYinan Xu* Install [Verilator](https://verilator.org/guide/latest/), the open-source Verilog simulator.
93a2ba9cdcSYinan Xu* Run `make emu` to build the C++ simulator `./build/emu` with Verilator.
94a2ba9cdcSYinan Xu* Refer to `./build/emu --help` for run-time arguments of the simulator.
95a2ba9cdcSYinan Xu* Refer to `Makefile` and `verilator.mk` for more information.
9605f23f57SWilliam Wang
9705f23f57SWilliam WangExample:
988c0a01afSClSlaid
99a2ba9cdcSYinan Xu```bash
1001545277aSYinan Xumake emu CONFIG=MinimalConfig EMU_THREADS=2 -j10
1012f256e1dSwakafa./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so
1025c647eb5SZihao Yu```
1035c647eb5SZihao Yu
1042d02df72SWilliam Wang## Troubleshooting Guide
1052d02df72SWilliam Wang
1062d02df72SWilliam Wang[Troubleshooting Guide](https://github.com/OpenXiangShan/XiangShan/wiki/Troubleshooting-Guide)
1072d02df72SWilliam Wang
108d8e5e781Swakafa## Acknowledgement
109d8e5e781Swakafa
1108c0a01afSClSlaidIn the development of XiangShan, some sub-modules from the open-source community are employed. All relevant usage is listed below.
111d8e5e781Swakafa
112d8e5e781Swakafa| Sub-module         | Source                                                       | Detail                                                       |
113d8e5e781Swakafa| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
11472060888SJiawei Lin| L2 Cache/LLC       | [Sifive block-inclusivecache](https://github.com/ucb-bar/block-inclusivecache-sifive) | Our new L2/L3 design are inspired by Sifive's `block-inclusivecache`. |
115*57bb43b5Swakafa| 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. |
116d8e5e781Swakafa
1178c0a01afSClSlaidWe 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).
118d8e5e781Swakafa
119