clash-vexriscv: VexRiscv CPU core for use in Clash designs

[ apache, development, library ] [ Propose Tags ] [ Report a vulnerability ]

Provides the tooling to integrate a VexRiscv CPU core into a Clash design. The package does not offer a CPU directly; instead it provides Cabal Setup.hs hooks that generate a CPU from a Scala-based configuration at build time, together with the Haskell bindings (FFI, blackboxes, simulation helpers) needed to use the resulting core from Clash.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1
Change log CHANGELOG.md
Dependencies async, base (>=4.18 && <4.22), bytestring (>=0.10 && <0.13), Cabal (>=3.14 && <4), clash-lib, clash-prelude (>=1.10 && <1.12), clash-protocols, containers (>=0.6 && <0.9), deepseq, directory (>=1.3 && <1.4), extra, filepath, ghc-typelits-extra, ghc-typelits-knownnat, ghc-typelits-natnormalise, Glob, hashable, infinite-list, interpolate, mtl, network, pretty-show, process (>=1.6 && <1.8), random, tagged, template-haskell, temporary, text [details]
License Apache-2.0
Copyright Copyright © 2022 Google LLC
Author QBayLogic B.V.
Maintainer devops@qbaylogic.com
Uploaded by martijnbastiaan at 2026-05-19T12:13:54Z
Category Development
Distributions
Downloads 1 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for clash-vexriscv-0.1

[back to package description]

clash-vexriscv

This package provides a VexRiscv CPU core for use in Clash designs.

Dependencies

For building the CPU, the following software needs to be installed and available in the PATH:

  • a recent JDK installation
  • SBT, the scala build tool
  • a recent C compiler
  • verilator
  • make for building the verilated library and FFI code

Limitations

  • The core will generate as part of your project's setup. This means that configuration cannot be based on parts of your design. E.g., whether or not to activate the floating point extension on the CPU will have to be decided before integration in the project.
  • The package is currently hardcoded to expect a Wishbone and JTAG bus.
  • The setup procedure currently compiles the Verilated Verilog itself, bypassing Cabal. This means Cabal compiler flags have no effect.

Integration

This package does not give you a VexRiscv core directly, but offers the necessary tools to generate one as part of a Cabal package. You will have to do two things:

  • Provide a (Scala-based) configuration file for the VexRiscv
  • Integrate clash-vexriscv with your Cabal project

Example project

A complete example project is provided in the ../clash-vexriscv-example/ directory. This example demonstrates:

  • A minimal Cabal project setup for using clash-vexriscv
  • A VexRiscv CPU configuration file (data/MyProject.scala) with:
    • Basic RiscV ISA components (IBus, DBus, CSR, decoder, register file, ALU)
    • Simple hazard handling
    • Branch prediction
    • JTAG debug interface
    • Wishbone memory buses for instruction and data access

You can use this as a template for your own integration project.

CPU configuration

VexRiscv is a very configurable CPU as shown by a great number of demo configurations. This package is currently hardcoded to need two things:

  • A Wishbone interface
  • A debug (JTAG) interface

It also expects SpinalHDL to generate all Verilog names with a certain prefix. This is all handled by this example configuration. Place the configuration in a folder, e.g. data and give it a recognizable name. In our example, this is MyProject. If you change the filename, don't forget to change the object name in the configuration file too.

Cabal integration

In the root of your package, add Setup.hs:

import Distribution.Simple
import VexRiscv.Setup (addVexRiscvHooks)

main :: IO ()
main = defaultMainWithHooks (addVexRiscvHooks simpleUserHooks "data" ["MyProject"])

Then, in your Cabal file, set the build type to Custom, add your configuration, and add a custom-setup:

build-type: Custom

extra-source-files:
  data/*.Scala

custom-setup
  setup-depends:
    base,
    Cabal,
    clash-vexriscv

In your library section, add the following:

  other-modules:
    VexRiscv_MyProject
  autogen-modules:
    VexRiscv_MyProject

If you picked another name than MyProject, replace that part of the module name. The module will export a single function:

vexRiscv ::
  forall dom.
  (HasCallStack, KnownDomain dom) =>
  DumpVcd ->
  Clock dom ->
  MinCyclesReset dom 2 ->
  Signal dom CpuIn ->
  Signal dom JtagIn ->
  ( Signal dom CpuOut
  , Signal dom JtagOut
  )

Good luck!

Notes for using the core:

  • The contents of memories need to be stored in little endian. This means that for example the contents of an ELF file need to be endian-swapped before being used as the contents of the instruction storage. This applies to all storages.