[otbn] A simple binutils-based assembler for OTBN

This acts as a sort of frontend for GNU as, transforming its input and
then getting binutils to do the actual assembly. The advantage of this
is that we'll be able to do linking properly (because binutils' as
will generate the relocations etc.).

The reason it's "simple" is that the parsing isn't particularly
clever. We don't support arbitrary immediates for expressions like

    ADDI x8, x0, 1 + 2 + 3

In fact, an operand has to match the regular expression:

    [^ ,+\-]+|[+\-]+

This matches things like:

    1
    x0
    my_weird_symbol
    ++
    --

but (obviously) doesn't match "1 + 2 + 3".

We could theoretically support more complicated immediates, but the
parsing would get rather harder: we'd basically have to put in a
proper context free language and recognise all the usual unary,
binary, ternary operators and so on. For extra pain, this would be in
combination with the user-supplied syntax from insns.yml... and it
looks pretty hard. So we're punting on that for now!

How it works
============

For anyone reviewing the code, or looking at this in the future,
here's a quick run-down of what happens.

  1. In otbn-as's main function, we load up the ISA database from
     insns.yml.

  2. We then iterate over the input files, parsing them in a simple
     fashion to split out the assembly statements. The binutils manual
     actually explains this quite well, but it's rather complicated.
     Any directives (.word, .line etc.) or uses of RV32I instructions
     are passed straight through. On an actual instruction, we end up
     in _end_stmt_line() with the mnemonic in self.key_sym and the
     rest of the line in self.acc.

  3. From each instruction's syntax (in insn.yml) we've derived a regex
     that matches valid assembly lines for that instruction. We match
     the line against that, and generate a map called op_to_val which
     maps operand name to the (string) expression that it got in the
     file.

  4. We then call gen_rve_line or gen_raw_line.

  5. If we're lucky and the instruction encoding looks something like
     a RV32I instruction, we can generate assembly using the .insn
     directive. This is dealt with in gen_rve_line, using some
     pre-computed information that we generated in find_insn_schemes
     at the start.

  6. If not, we have to use gen_raw_line. This actually assembles the
     instruction to a .word. The disadvantage of this is that we can't
     include any symbols in the result, so won't be able to use relocs
     for this instruction.

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
3 files changed
tree: 98c30b92392f8674e01be692ea67b4887fb5827e
  1. .github/
  2. ci/
  3. doc/
  4. hw/
  5. site/
  6. sw/
  7. test/
  8. util/
  9. .clang-format
  10. .dockerignore
  11. .flake8
  12. .gitignore
  13. .style.yapf
  14. _index.md
  15. apt-requirements.txt
  16. azure-pipelines.yml
  17. check_tool_requirements.core
  18. CLA
  19. COMMITTERS
  20. CONTRIBUTING.md
  21. LICENSE
  22. meson.build
  23. meson_init.sh
  24. meson_options.txt
  25. python-requirements.txt
  26. README.md
  27. tool_requirements.py
  28. toolchain.txt
README.md

OpenTitan

OpenTitan logo

About the project

OpenTitan is an open source silicon Root of Trust (RoT) project. OpenTitan will make the silicon RoT design and implementation more transparent, trustworthy, and secure for enterprises, platform providers, and chip manufacturers. OpenTitan is administered by lowRISC CIC as a collaborative project to produce high quality, open IP for instantiation as a full-featured product. See the OpenTitan site and OpenTitan docs for more information about the project.

About this repository

This repository contains hardware, software and utilities written as part of the OpenTitan project. It is structured as monolithic repository, or “monorepo”, where all components live in one repository. It exists to enable collaboration across partners participating in the OpenTitan project.

Documentation

The project contains comprehensive documentation of all IPs and tools. You can access it online at docs.opentitan.org.

How to contribute

Have a look at CONTRIBUTING for guidelines on how to contribute code to this repository.

Licensing

Unless otherwise noted, everything in this repository is covered by the Apache License, Version 2.0 (see LICENSE for full text).