Go to file
Haoyuan Feng 2e46f3f810
EMU Test / Changes Detection (push) Has been cancelled Details
Release Jobs / build-xsdev-image (push) Has been cancelled Details
EMU Test / Generate Verilog (push) Has been cancelled Details
EMU Test / EMU - Basics (push) Has been cancelled Details
EMU Test / EMU - CHI (push) Has been cancelled Details
EMU Test / Docker Build (push) Has been cancelled Details
EMU Test / EMU - Performance (push) Has been cancelled Details
EMU Test / EMU - MC (push) Has been cancelled Details
EMU Test / SIMV - Basics (push) Has been cancelled Details
EMU Test / Upload Artifacts (push) Has been cancelled Details
EMU Test / Check Submodules (push) Has been cancelled Details
EMU Test / Check Format (push) Has been cancelled Details
fix(TLB): fix incorrect TLB level refill when has exception (#5087)
In previous design, the smaller value between the stage1 and stage2
levels was always written back into the TLB entry. However, this
approach caused issues when exceptions occurred: a larger page could
mistakenly be treated as a smaller one. During TLB lookups this would
only result in performance bugs, for example:

(1) The first lookup of vpn 0x0 should return a 1 GB page, but instead a
2 MB page is written back. (2) The second lookup of vpn 0x0 + 4 MB
should hit, but because the level written back last time was incorrect,
it actually misses, triggering another PTW. (3) After the PTW completes,
a new 2 MB page starting at vpn 0x0 + 4 MB is written back.

However, this handling leads to a functional bug in the sfence scenario.
For a 1 GB page, an sfence with any address within the 1 GB range should
be able to invalidate the page. If the page is mistakenly treated as
only 2 MB, the sfence may fail to invalidate the page as expected,
causing a functional bug.

Specifically, for allStage with exceptions:

1. If stage1 encounters an exception, the entry’s level should be
written back as s1_level.
2. If stage2 encounters an exception: (1) If stage1 is a fakePTE, the
entry’s level should be written back as the maximum value (indicating
vsatp is misconfigured). (2) If stage1 is a non-leaf node, the entry’s
level should be written back as s1_level. (3) If stage1 is a leaf node,
the entry’s level should be written back as the smaller value of stage1
and stage2.

In fact, the stage1_level min stage2_level logic is used in multiple
places in the code. But in those other cases, it is only used for
lookups and does not affect sfence invalidation. Therefore, for now,
only this particular case needs to be fixed.
2025-09-30 14:07:17 +08:00
.github feat(CLINT): add new clint to match 1:1 ration between CLINT and HART (#4991) 2025-09-27 16:23:08 +08:00
ChiselAIA@458f94be4c submodule(ChiselAIA):bump ChiselAIA to fix lose interrupt (#4732) 2025-05-26 19:44:38 +08:00
coupledL2@abf2f7467f build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
debug bump difftest & mkdir for wave/perf for local-ci script's run-mode (#1927) 2023-02-21 12:49:41 +08:00
difftest@0af0fec699 fix(difftest): bump and align parseArg return values (#5009) 2025-09-08 10:00:02 +08:00
fudian@e1bd4695ca chore: bump chisel 6.0.0 (#2654) 2024-01-19 15:05:34 +08:00
huancun@65ef077373 build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
images docs(readme): update kunminghu architecture graph (#3910) 2024-11-21 16:24:27 +08:00
macros/src/main/scala NewCSR: fix unprivileged CSRs and permission check 2024-07-17 10:42:14 +08:00
openLLC@9e6f78209b build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
project update sbt version 2019-03-03 16:54:26 +08:00
ready-to-run@2ea9d84709 fix(CSR): initialize [m|h|s]context to 0 (#4915) 2025-07-31 18:25:39 +08:00
rocket-chip@46f1efefa1 build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
scripts feat(pdb): Add XSPdb, a GDB-like interactive debugger for XiangShan (#4906) 2025-08-23 00:59:13 +08:00
src fix(TLB): fix incorrect TLB level refill when has exception (#5087) 2025-09-30 14:07:17 +08:00
tools/readmemh misc: update PCL information (#899) 2021-07-24 23:26:38 +08:00
utility@c8d424348b build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
yunsuan@955921186e build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
.dockerignore fix(docker): fix docker image build by moving MILL_OUTPUT_DIR to tmpfs (#4679) 2025-05-10 14:22:26 +08:00
.gitignore feat(build): Build docker image for XiangShan development 2025-05-09 21:02:02 +08:00
.gitmodules misc(submodule): correct case seneitivity in url (#4585) 2025-04-18 10:34:02 +08:00
.mill-version build: bump mill to 0.12.3 (#3933) 2024-11-26 16:12:10 +08:00
.scalafmt.conf style(Frontend): use scalafmt formatting frontend (#3370) 2024-10-25 23:08:56 +08:00
Dockerfile fix(docker): fix docker image build by moving MILL_OUTPUT_DIR to tmpfs (#4679) 2025-05-10 14:22:26 +08:00
LICENSE Add MulanPSL-2.0 License (#824) 2021-06-04 09:06:35 +08:00
Makefile feat(build): add `DISABLE_XMR` to use `bore` instead of `tapAndRead` (#4976) 2025-09-15 13:18:32 +08:00
Makefile.test test: add example of chiseltest's unit-test and generating verilog for xs' module (#1890) 2023-02-14 09:52:51 +08:00
README.md feat(pdb): Add XSPdb, a GDB-like interactive debugger for XiangShan (#4906) 2025-08-23 00:59:13 +08:00
build.sbt Add sbt build support (#857) 2021-07-03 09:34:31 +08:00
build.sc build: bump chisel 6.7.0 (#5069) 2025-09-26 12:19:30 +08:00
readme.zh-cn.md feat(pdb): Add XSPdb, a GDB-like interactive debugger for XiangShan (#4906) 2025-08-23 00:59:13 +08:00
scalastyle-config.xml chore(scalastyle): allow ([a-z][0-9]|perf|debug)_ prefix (#4838) 2025-06-27 18:52:10 +08:00
scalastyle-test-config.xml chore(scalastyle): allow ([a-z][0-9]|perf|debug)_ prefix (#4838) 2025-06-27 18:52:10 +08:00

README.md

XiangShan

XiangShan (香山) is an open-source high-performance RISC-V processor project.

中文说明在此

Documentation

XiangShan's documentation is available at docs.xiangshan.cc.

XiangShan Design Document for Kunminghu V2R2 has been published separately. You can find it at docs.xiangshan.cc/projects/design.

XiangShan User Guide has been published separately. You can find it at docs.xiangshan.cc/projects/user-guide or XiangShan-User-Guide/releases.

We are using Weblate to translate documentation into English and other languages. Your contributions are welcome—come and help us improve it!

All XiangShan documents are licensed under the CC-BY-4.0.

Publications

MICRO 2022: Towards Developing High Performance RISC-V Processors Using Agile Methodology

Our paper introduces XiangShan and the practice of agile development methodology on high performance RISC-V processors. It covers some representative tools we have developed and used to accelerate the chip development process, including design, functional verification, debugging, performance validation, etc. This paper is awarded all three available badges for artifact evaluation (Available, Functional, and Reproduced).

Artifacts Available Artifacts Evaluated — Functional Results Reproduced

Paper PDF | IEEE Xplore | BibTeX | Presentation Slides | Presentation Video

Follow us

Wechat/微信:香山开源处理器

Zhihu/知乎:香山开源处理器

Weibo/微博:香山开源处理器

You can contact us through our mailing list. All mails from this list will be archived here.

Architecture

The first stable micro-architecture of XiangShan is called Yanqihu (雁栖湖) and is on the yanqihu branch, which has been developed since June 2020.

The second stable micro-architecture of XiangShan is called Nanhu (南湖) and is on the nanhu branch.

The current version of XiangShan, also known as Kunminghu (昆明湖), is still under development on the master branch.

The micro-architecture overview of Kunminghu (昆明湖) is shown below.

xs-arch-kunminghu

Sub-directories Overview

Some of the key directories are shown below.

.
├── src
│   └── main/scala         # design files
│       ├── device         # virtual device for simulation
│       ├── system         # SoC wrapper
│       ├── top            # top module
│       ├── utils          # utilization code
│       └── xiangshan      # main design code
│           └── transforms # some useful firrtl transforms
├── scripts                # scripts for agile development
├── fudian                 # floating unit submodule of XiangShan
├── huancun                # L2/L3 cache submodule of XiangShan
├── difftest               # difftest co-simulation framework
└── ready-to-run           # pre-built simulation images

IDE Support

bsp

make bsp

IDEA

make idea

Generate Verilog

  • Run make verilog to generate verilog code. This generates multiple .sv files in the build/rtl/ folder (e.g., build/rtl/XSTop.sv).
  • Refer to Makefile for more information.

Run Programs by Simulation

Prepare environment

  • Set environment variable NEMU_HOME to the absolute path of the NEMU project.
  • Set environment variable NOOP_HOME to the absolute path of the XiangShan project.
  • Set environment variable AM_HOME to the absolute path of the AM project.
  • Install mill. Refer to the Manual section in this guide.
  • Clone this project and run make init to initialize submodules.

Run with simulator

  • Install Verilator, the open-source Verilog simulator.
  • Run make emu to build the C++ simulator ./build/emu with Verilator.
  • Refer to ./build/emu --help for run-time arguments of the simulator.
  • Refer to Makefile and verilator.mk for more information.

Example:

make emu CONFIG=MinimalConfig EMU_THREADS=2 -j10
./build/emu -b 0 -e 0 -i ./ready-to-run/coremark-2-iteration.bin --diff ./ready-to-run/riscv64-nemu-interpreter-so

Run with xspdb

  • Install picker, a verifaction tool that supports high-level languages.
  • Run make pdb to build XiangShan Python binaries.
  • Run make pdb-run to run XiangShan binaries.

Example output and interaction:

$ make pdb-run
[Info] Set PMEM_BASE to 0x80000000 (Current: 0x80000000)
[Info] Set FIRST_INST_ADDRESS to 0x80000000 (Current: 0x80000000)
Using simulated 32768B flash
[Info] reset dut complete
> XiangShan/scripts/pdb-run.py(13)run()
-> while True:
(XiangShan) xload ready-to-run/microbench.bin   # Load binary (Tab-compatible)
(XiangShan) xwatch_commit_pc 0x80000004         # set watch point,  
(XiangShan) xistep 3                            # Step to next three instruction commit, it will stop at watch point 
[Info] Find break point (Inst commit), break (step 2107 cycles) at cycle: 2207 (0x89f)
[Info] Find break point (Inst commit, Target commit), break (step 2108 cycles) at cycle: 2208 (0x8a0)
(XiangShan) xpc                                 # print pc info
PC[0]: 0x80000000    Instr: 0x00000093
PC[1]: 0x80000004    Instr: 0x00000113
PC[2]: 0x0    Instr: 0x0
...
PC[7]: 0x0    Instr: 0x0
(XiangShan) xistep 1000000                      # Execute to binary end
[Info] Find break point (Inst commit), break (step 2037 cycles) at cycle: 2207 (0x89f)
[Info] Find break point (Inst commit), break (step 2180 cycles) at cycle: 2207 (0x89f)
...
HIT GOOD LOOP at pc = 0xf0001cb0

Troubleshooting Guide

Troubleshooting Guide

Acknowledgement

The implementation of XiangShan is inspired by several key papers. We list these papers in XiangShan document, see: Acknowledgements. We very much encourage and expect that more academic innovations can be realised based on XiangShan in the future.

LICENSE

Copyright © 2020-2025 Institute of Computing Technology, Chinese Academy of Sciences.

Copyright © 2021-2025 Beijing Institute of Open Source Chip

Copyright © 2020-2022 by Peng Cheng Laboratory.

XiangShan is licensed under Mulan PSL v2.