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 757bb43b5SwakafaCopyright 2020-2022 by Institute of Computing Technology, Chinese Academy of Sciences. 864fc9c9dSZihao Yu 957bb43b5SwakafaCopyright 2020-2022 by Peng Cheng Laboratory. 10f320e0f0SYinan Xu 11770ded88SLingrui98## Docs and slides 1240adeb5aSwangkaifan 1357bb43b5Swakafa[XiangShan-doc](https://github.com/OpenXiangShan/XiangShan-doc) is our official documentation repository. It contains design spec., technical slides, tutorial and more. 1457bb43b5Swakafa 1557bb43b5Swakafa* Micro-architecture documentation of XiangShan has been published. Please check out https://xiangshan-doc.readthedocs.io 1640adeb5aSwangkaifan 175986560eSYinan Xu## Publications 185986560eSYinan Xu 195986560eSYinan Xu### MICRO 2022: Towards Developing High Performance RISC-V Processors Using Agile Methodology 205986560eSYinan Xu 215986560eSYinan XuOur paper introduces XiangShan and the practice of agile development methodology on high performance RISC-V processors. 225986560eSYinan XuIt covers some representative tools we have developed and used to accelerate the chip development process, including design, functional verification, debugging, performance validation, etc. 235986560eSYinan XuThis paper is awarded all three available badges for artifact evaluation (Available, Functional, and Reproduced). 245986560eSYinan Xu 255986560eSYinan Xu 265986560eSYinan Xu 275986560eSYinan Xu 285986560eSYinan Xu 29e2aeeb1fSYinan Xu[Paper PDF](https://github.com/OpenXiangShan/XiangShan-doc/blob/main/publications/micro2022-xiangshan.pdf) | [IEEE Xplore](https://ieeexplore.ieee.org/abstract/document/9923860) | [BibTeX](https://github.com/OpenXiangShan/XiangShan-doc/blob/main/publications/micro2022-xiangshan.bib) | [Presentation Slides](https://github.com/OpenXiangShan/XiangShan-doc/blob/main/publications/micro2022-xiangshan-slides.pdf) | [Presentation Video](https://www.bilibili.com/video/BV1FB4y1j7Jy) 305986560eSYinan Xu 31708ceed4SYinan Xu## Follow us 32708ceed4SYinan Xu 33708ceed4SYinan XuWechat/微信:香山开源处理器 34708ceed4SYinan Xu 35708ceed4SYinan Xu<div align=left><img width="340" height="117" src="images/wechat.png"/></div> 36708ceed4SYinan Xu 37708ceed4SYinan XuZhihu/知乎:[香山开源处理器](https://www.zhihu.com/people/openxiangshan) 38708ceed4SYinan Xu 39708ceed4SYinan XuWeibo/微博:[香山开源处理器](https://weibo.com/u/7706264932) 40708ceed4SYinan Xu 41770ded88SLingrui98You 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]/). 42770ded88SLingrui98 4340adeb5aSwangkaifan## Architecture 4440adeb5aSwangkaifan 458815ed52SYinan XuThe first stable micro-architecture of XiangShan is called Yanqihu (雁栖湖) [on the yanqihu branch](https://github.com/OpenXiangShan/XiangShan/tree/yanqihu), which has been developed since June 2020. 468815ed52SYinan Xu 478815ed52SYinan XuThe second stable micro-architecture of XiangShan is called Nanhu (南湖) [on the nanhu branch](https://github.com/OpenXiangShan/XiangShan/tree/nanhu). 488815ed52SYinan Xu 498815ed52SYinan XuThe current version of XiangShan, also known as Kunminghu (昆明湖), is still under development on the master branch. 5040adeb5aSwangkaifan 5157bb43b5SwakafaThe micro-architecture overview of Nanhu (南湖) is shown below. 5240adeb5aSwangkaifan 5357bb43b5Swakafa 5440adeb5aSwangkaifan 5540adeb5aSwangkaifan 5640adeb5aSwangkaifan 5740adeb5aSwangkaifan## Sub-directories Overview 5840adeb5aSwangkaifan 5940adeb5aSwangkaifanSome of the key directories are shown below. 6040adeb5aSwangkaifan 6140adeb5aSwangkaifan``` 6240adeb5aSwangkaifan. 6357bb43b5Swakafa├── src 6457bb43b5Swakafa│ └── main/scala # design files 6557bb43b5Swakafa│ ├── device # virtual device for simulation 6657bb43b5Swakafa│ ├── system # SoC wrapper 6757bb43b5Swakafa│ ├── top # top module 6857bb43b5Swakafa│ ├── utils # utilization code 69*5931ace3STang Haojin│ └── xiangshan # main design code 70*5931ace3STang Haojin│ └── transforms # some useful firrtl transforms 7140adeb5aSwangkaifan├── scripts # scripts for agile development 7257bb43b5Swakafa├── fudian # floating unit submodule of XiangShan 7357bb43b5Swakafa├── huancun # L2/L3 cache submodule of XiangShan 7457bb43b5Swakafa├── difftest # difftest co-simulation framework 7557bb43b5Swakafa└── ready-to-run # pre-built simulation images 7640adeb5aSwangkaifan``` 7740adeb5aSwangkaifan 780af3f746SJiawei Lin## IDE Support 790af3f746SJiawei Lin 800af3f746SJiawei Lin### bsp 810af3f746SJiawei Lin``` 820af3f746SJiawei Linmake bsp 830af3f746SJiawei Lin``` 840af3f746SJiawei Lin 850af3f746SJiawei Lin### IDEA 860af3f746SJiawei Lin``` 870af3f746SJiawei Linmake idea 880af3f746SJiawei Lin``` 8940adeb5aSwangkaifan 9040adeb5aSwangkaifan 9140adeb5aSwangkaifan## Generate Verilog 9240adeb5aSwangkaifan 9340adeb5aSwangkaifan* Run `make verilog` to generate verilog code. The output file is `build/XSTop.v`. 9440adeb5aSwangkaifan* Refer to `Makefile` for more information. 9540adeb5aSwangkaifan 9640adeb5aSwangkaifan 9740adeb5aSwangkaifan 9840adeb5aSwangkaifan## Run Programs by Simulation 9940adeb5aSwangkaifan 10040adeb5aSwangkaifan### Prepare environment 10164fc9c9dSZihao Yu 102a2ba9cdcSYinan Xu* Set environment variable `NEMU_HOME` to the **absolute path** of the [NEMU project](https://github.com/OpenXiangShan/NEMU). 103a2ba9cdcSYinan Xu* Set environment variable `NOOP_HOME` to the **absolute path** of the XiangShan project. 104a2ba9cdcSYinan Xu* Set environment variable `AM_HOME` to the **absolute path** of the [AM project](https://github.com/OpenXiangShan/nexus-am). 105a2ba9cdcSYinan Xu* Install `mill`. Refer to [the Manual section in this guide](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html#_installation). 10640adeb5aSwangkaifan* Clone this project and run `make init` to initialize submodules. 10764fc9c9dSZihao Yu 10840adeb5aSwangkaifan### Run with simulator 10905f23f57SWilliam Wang 110a2ba9cdcSYinan Xu* Install [Verilator](https://verilator.org/guide/latest/), the open-source Verilog simulator. 111a2ba9cdcSYinan Xu* Run `make emu` to build the C++ simulator `./build/emu` with Verilator. 112a2ba9cdcSYinan Xu* Refer to `./build/emu --help` for run-time arguments of the simulator. 113a2ba9cdcSYinan Xu* Refer to `Makefile` and `verilator.mk` for more information. 11405f23f57SWilliam Wang 11505f23f57SWilliam WangExample: 1168c0a01afSClSlaid 117a2ba9cdcSYinan Xu```bash 1181545277aSYinan Xumake emu CONFIG=MinimalConfig EMU_THREADS=2 -j10 1192f256e1dSwakafa./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so 1205c647eb5SZihao Yu``` 1215c647eb5SZihao Yu 1222d02df72SWilliam Wang## Troubleshooting Guide 1232d02df72SWilliam Wang 1242d02df72SWilliam Wang[Troubleshooting Guide](https://github.com/OpenXiangShan/XiangShan/wiki/Troubleshooting-Guide) 1252d02df72SWilliam Wang 126d8e5e781Swakafa## Acknowledgement 127d8e5e781Swakafa 1288c0a01afSClSlaidIn the development of XiangShan, some sub-modules from the open-source community are employed. All relevant usage is listed below. 129d8e5e781Swakafa 130d8e5e781Swakafa| Sub-module | Source | Detail | 131d8e5e781Swakafa| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | 13272060888SJiawei 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`. | 13357bb43b5Swakafa| 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. | 134d8e5e781Swakafa 1358c0a01afSClSlaidWe 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). 136