105f23f57SWilliam Wang# XiangShan 264fc9c9dSZihao Yu 340adeb5aSwangkaifanXiangShan (香山) is an open-source high-performance RISC-V processor project. 464fc9c9dSZihao Yu 540adeb5aSwangkaifanDetailed documents will be released in the near future. 664fc9c9dSZihao Yu 7a2ba9cdcSYinan XuCopyright 2020-2021 by Institute of Computing Technology, Chinese Academy of Sciences. 864fc9c9dSZihao Yu 940adeb5aSwangkaifan 1040adeb5aSwangkaifan 1140adeb5aSwangkaifan## === Tutorial is Comming! === 1240adeb5aSwangkaifan 1340adeb5aSwangkaifanA tutorial on XiangShan is held at RISC-V World Conference China 2021 in June. Multiple technical reports will be included in the conference as well. Stay tuned! 1440adeb5aSwangkaifan 1540adeb5aSwangkaifanFor more information, please refer to [this link](https://openxiangshan.github.io). 1640adeb5aSwangkaifan 1740adeb5aSwangkaifan 1840adeb5aSwangkaifan 1940adeb5aSwangkaifan## Architecture 2040adeb5aSwangkaifan 2140adeb5aSwangkaifanThe 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 master branch. 2240adeb5aSwangkaifan 2340adeb5aSwangkaifanThe micro-architecture overview is shown below. 2440adeb5aSwangkaifan 256d529dd2Swangkaifan 2640adeb5aSwangkaifan 2740adeb5aSwangkaifan 2840adeb5aSwangkaifan 2940adeb5aSwangkaifan## Sub-directories Overview 3040adeb5aSwangkaifan 3140adeb5aSwangkaifanSome of the key directories are shown below. 3240adeb5aSwangkaifan 3340adeb5aSwangkaifan``` 3440adeb5aSwangkaifan. 3540adeb5aSwangkaifan├── fpga # supported FPGA boards and files to build a Vivado project 3640adeb5aSwangkaifan├── read-to-run # pre-built simulation images 3740adeb5aSwangkaifan├── scripts # scripts for agile development 3840adeb5aSwangkaifan└── src 3940adeb5aSwangkaifan ├── test # test files (including diff-test, module-test, etc.) 4040adeb5aSwangkaifan └── main/scala # design files 4140adeb5aSwangkaifan ├── bus/tilelink # tilelink utils 4240adeb5aSwangkaifan ├── device # virtual device for simulation 4340adeb5aSwangkaifan ├── difftest # diff-test chisel interface 4440adeb5aSwangkaifan ├── system # SoC wrapper 4540adeb5aSwangkaifan ├── top # top module 4640adeb5aSwangkaifan ├── utils # utilization code 4740adeb5aSwangkaifan ├── xiangshan # main design code 4840adeb5aSwangkaifan └── xstransforms # some useful firrtl transforms 4940adeb5aSwangkaifan``` 5040adeb5aSwangkaifan 5140adeb5aSwangkaifan 5240adeb5aSwangkaifan 5340adeb5aSwangkaifan## Generate Verilog 5440adeb5aSwangkaifan 5540adeb5aSwangkaifan* Run `make verilog` to generate verilog code. The output file is `build/XSTop.v`. 5640adeb5aSwangkaifan* Refer to `Makefile` for more information. 5740adeb5aSwangkaifan 5840adeb5aSwangkaifan 5940adeb5aSwangkaifan 6040adeb5aSwangkaifan## Run Programs by Simulation 6140adeb5aSwangkaifan 6240adeb5aSwangkaifan### Prepare environment 6364fc9c9dSZihao Yu 64a2ba9cdcSYinan Xu* Set environment variable `NEMU_HOME` to the **absolute path** of the [NEMU project](https://github.com/OpenXiangShan/NEMU). 65a2ba9cdcSYinan Xu* Set environment variable `NOOP_HOME` to the **absolute path** of the XiangShan project. 66a2ba9cdcSYinan Xu* Set environment variable `AM_HOME` to the **absolute path** of the [AM project](https://github.com/OpenXiangShan/nexus-am). 67a2ba9cdcSYinan Xu* Install `mill`. Refer to [the Manual section in this guide](https://com-lihaoyi.github.io/mill/mill/Intro_to_Mill.html#_installation). 6840adeb5aSwangkaifan* Clone this project and run `make init` to initialize submodules. 6964fc9c9dSZihao Yu 7040adeb5aSwangkaifan### Run with simulator 7105f23f57SWilliam Wang 72a2ba9cdcSYinan Xu* Install [Verilator](https://verilator.org/guide/latest/), the open-source Verilog simulator. 73a2ba9cdcSYinan Xu* Run `make emu` to build the C++ simulator `./build/emu` with Verilator. 74a2ba9cdcSYinan Xu* Refer to `./build/emu --help` for run-time arguments of the simulator. 75a2ba9cdcSYinan Xu* Refer to `Makefile` and `verilator.mk` for more information. 7605f23f57SWilliam Wang 7705f23f57SWilliam WangExample: 78a2ba9cdcSYinan Xu```bash 79a2ba9cdcSYinan Xumake emu CONFIG=MinimalConfig SIM_ARGS=--disable-log EMU_THREADS=2 -j10 80*2f256e1dSwakafa./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so 815c647eb5SZihao Yu``` 825c647eb5SZihao Yu 83d8e5e781Swakafa 84d8e5e781Swakafa 85d8e5e781Swakafa## Acknowledgement 86d8e5e781Swakafa 87d8e5e781SwakafaIn the development of XiangShan, some sub-modules from open source community are employed. All relavant usage is listed below. 88d8e5e781Swakafa 89d8e5e781Swakafa| Sub-module | Source | Detail | 90d8e5e781Swakafa| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | 91d8e5e781Swakafa| 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. | 92d8e5e781Swakafa| 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. | 93d8e5e781Swakafa| FPU | [Berkeley hardfloat](https://github.com/ucb-bar/berkeley-hardfloat) | We use Berkeley-hardfloat as our FPU and implement a SRT-4 div/sqrt unit for it. Additionally, we split the FMA pipeline to optimize the timing. | 94d8e5e781Swakafa 95d8e5e781SwakafaWe 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). 96d8e5e781Swakafa 97