tinyriscv/tools/regtool/reggen
liangkangnan c178a8fbb2 tools: add regtool
Signed-off-by: liangkangnan <liangkangnan@163.com>
2021-08-07 15:07:44 +08:00
..
.gitignore tools: add regtool 2021-08-07 15:07:44 +08:00
Makefile tools: add regtool 2021-08-07 15:07:44 +08:00
README.md tools: add regtool 2021-08-07 15:07:44 +08:00
__init__.py tools: add regtool 2021-08-07 15:07:44 +08:00
access.py tools: add regtool 2021-08-07 15:07:44 +08:00
alert.py tools: add regtool 2021-08-07 15:07:44 +08:00
bits.py tools: add regtool 2021-08-07 15:07:44 +08:00
bus_interfaces.py tools: add regtool 2021-08-07 15:07:44 +08:00
clocking.py tools: add regtool 2021-08-07 15:07:44 +08:00
enum_entry.py tools: add regtool 2021-08-07 15:07:44 +08:00
field.py tools: add regtool 2021-08-07 15:07:44 +08:00
fpv_csr.sv.tpl tools: add regtool 2021-08-07 15:07:44 +08:00
gen_cfg_html.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_cheader.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_dv.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_fpv.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_html.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_json.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_rtl.py tools: add regtool 2021-08-07 15:07:44 +08:00
gen_selfdoc.py tools: add regtool 2021-08-07 15:07:44 +08:00
html_helpers.py tools: add regtool 2021-08-07 15:07:44 +08:00
inter_signal.py tools: add regtool 2021-08-07 15:07:44 +08:00
ip_block.py tools: add regtool 2021-08-07 15:07:44 +08:00
lib.py tools: add regtool 2021-08-07 15:07:44 +08:00
multi_register.py tools: add regtool 2021-08-07 15:07:44 +08:00
params.py tools: add regtool 2021-08-07 15:07:44 +08:00
reg_base.py tools: add regtool 2021-08-07 15:07:44 +08:00
reg_block.py tools: add regtool 2021-08-07 15:07:44 +08:00
reg_html.css tools: add regtool 2021-08-07 15:07:44 +08:00
reg_pkg.sv.tpl tools: add regtool 2021-08-07 15:07:44 +08:00
reg_top.sv.tpl tools: add regtool 2021-08-07 15:07:44 +08:00
register.py tools: add regtool 2021-08-07 15:07:44 +08:00
signal.py tools: add regtool 2021-08-07 15:07:44 +08:00
uvm_reg.sv.tpl tools: add regtool 2021-08-07 15:07:44 +08:00
uvm_reg_base.sv.tpl tools: add regtool 2021-08-07 15:07:44 +08:00
validate.py tools: add regtool 2021-08-07 15:07:44 +08:00
version.py tools: add regtool 2021-08-07 15:07:44 +08:00
window.py tools: add regtool 2021-08-07 15:07:44 +08:00

README.md

Register generator reggen and regtool

The utility script regtool.py and collateral under reggen are Python tools to read register descriptions in Hjson and generate various output formats. The tool can output HTML documentation, standard JSON, compact standard JSON (whitespace removed) and Hjson. The example commands assume $REPO_TOP is set to the toplevel directory of the repository.

Setup

If packages have not previously been installed you will need to set a few things up. First use pip3 to install some required packages:

$ pip3 install --user hjson
$ pip3 install --user mistletoe
$ pip3 install --user mako

Register JSON Format

For details on the register JSON format, see the [register tool documentation]({{< relref "doc/rm/register_tool/index.md" >}}). To ensure things stay up to date, the register JSON format information is documented by the tool itself. The documentation can be generated by running the following commands:

$ cd $REPO_TOP/util
$ ./build_docs.py

Under the hood, the build_docs.py tool will automatically use the reggen tool to produce Markdown and processing that into HTML.

Examples using standalone regtool

Normally for documentation the build_docs.py tool will automatically use reggen. The script regtool.py provides a standalone way to run reggen. See the [register tool documentation]({{< relref "doc/rm/register_tool/index.md" >}}) for details about how to invoke the tool.

The following shows an example of how to generate RTL from a register description:

$ cd $REPO_TOP/util
$ mkdir /tmp/rtl
$ ./regtool.py -r -t /tmp/rtl ../hw/ip/uart/data/uart.hjson
$ ls /tmp/rtl
    uart_reg_pkg.sv   uart_reg_top.sv

The following shows an example of how to generate a DV UVM class from a register description:

$ cd $REPO_TOP/util
$ mkdir /tmp/dv
$ ./regtool.py -s -t /tmp/dv ../hw/ip/uart/data/uart.hjson
$ ls /tmp/dv
    uart_ral_pkg.sv

By default, the generated block, register and field models are derived from dv_base_reg classes provided at hw/dv/sv/dv_base_reg. If required, the user can supply the --dv-base-prefix my_base switch to have the models derive from a custom, user-defined RAL classes instead:

$ cd $REPO_TOP/util
$ mkdir /tmp/dv
$ ./regtool.py -s -t /tmp/dv ../hw/ip/uart/data/uart.hjson \
  --dv-base-prefix my_base
$ ls /tmp/dv
    uart_ral_pkg.sv

This makes the following assumptions:

  • A FuseSoC core file aggregating the my_base RAL classes with the VLNV name lowrisc:dv:my_base_reg is provided in the cores search path.
  • These custom classes are derived from the corresponding dv_base_reg classes and have the following names:
    • my_base_reg_pkg.sv: The RAL package that includes the below sources
    • my_base_reg_block.sv: The register block abstraction
    • my_base_reg.sv: The register abstraction
    • my_base_reg_field.sv: The register field abstraction
    • my_base_mem.sv: The memory abstraction
  • If any of the above class specializations is not needed, it can be typedef'ed in my_base_reg_pkg:
    package my_base_reg_pkg;
      import dv_base_reg_pkg::*;
      typedef dv_base_reg_field my_base_reg_field;
      typedef dv_base_mem my_base_mem;
      `include "my_base_reg.sv"
      `include "my_base_reg_block.sv"
    endpackage
    

The following shows an example of how to generate a FPV csr read write assertion module from a register description:

$ cd $REPO_TOP/util
$ mkdir /tmp/fpv/vip
$ ./regtool.py -f -t /tmp/fpv/vip ../hw/ip/uart/data/uart.hjson
$ ls /tmp/fpv
    uart_csr_assert_fpv.sv

If the target directory is not specified, the tool creates the DV file under the hw/ip/{module}/dv/ directory.