Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISA Extension Manager class #30

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

bdutro
Copy link

@bdutro bdutro commented Dec 5, 2024

Buckle up, this one is a doozy...

Per sparcians/atlas#5, we want Mavis to have the ability to parse an ISA string and query what extensions it enables. This PR adds two major classes:

  • ExtensionManager: Implements the ISA-independent logic necessary to wrangle dependencies between extensions
  • RISCVExtensionManager: Provides a RISC-V implementation of ExtensionManager that extracts enabled ISA extensions from RISC-V ISA strings (either directly or from an ELF file)

After a ExtensionManager object has been initialized with an ISA string, you can call the constructMavis method to construct a Mavis instance with all of the relevant opcode JSONs automatically specified.

ISA extension dependencies are defined in an ISA specification JSON (json/riscv_isa_spec.json). This will need to be updated whenever a new extension is added to Mavis in order for the extension manager to handle it.

There are 3 types of extensions:

  • meta_extensions: These are extensions that are defined as a collection of other extensions, but provide no unique opcodes or configs of their own. Examples in RISC-V include g, v, b, etc.
  • config_extensions: These are extensions that indicate an architectural configuration but provide no opcodes (e.g., zvl32b, zvl128b, etc.)
  • extensions: These are ISA extensions that provide opcodes. Each extension should map to a Mavis opcode JSON file.

Each extension type key maps to an array of JSON objects describing the extensions:

{
  "meta_extensions": [
    { ... },
  ],
  "config_extensions": [
    { ... },
  ],
  "extensions": [
    { ... },
  ]
}

Required Fields

  • extension: The extension name (e.g. "i", "zbb", etc.)
  • xlen: This is either a single int or an array of ints that specifies which XLENs the extension applies to.
  • json: Every non-meta, non-config extension must specify. Points to the Mavis JSON containing the opcodes for the extension.

Optional Fields (allowed for any type)

  • meta_extension: Either a single string or an array of strings. Specifies which meta extensions contain the current extension.

Optional Fields (only allowed for meta_extensions and extensions types)

  • is_base_extension: Bool (defaults to false). If true, defines this extension as a RISC-V base extension. Only used for validating the ISA string.

Optional Fields (only allowed for extension type)

  • requires: String or array of strings. Specifies one or more extensions that must be explicitly enabled when this extension is enabled.
  • enabled_by: Array of arrays of strings. Specifies combinations of other extensions that automatically enable this extension.
  • enables: String or array of strings. Specifies extensions that should be implicitly enabled when this extension is enabled.
  • conflicts: String or array of strings. Specifies extensions that must not be present when this extension is enabled.

If the implementation of an extension changes based on the XLEN, it should be specified multiple times with different JSONs like so:

{
  "extensions": [
    {
      "extension": "x",
      "xlen": 32,
      "json": "isa_rv32x.json"
    },
    {
      "extension": "x",
      "xlen": 64,
      "json": "isa_rv64x.json"
    },
    ...
  ]
}

bdutro and others added 22 commits November 19, 2024 18:14
and automatically create a Mavis instance with the relevant ISA JSONs
    - Still need to add constraints to most of them
    - Break larger extensions into individual components where possible
Fix some ISA JSON errors
Now using a single ISA spec JSON for specifying relationships between
extensions and ISA JSONs
    - Needed to support extensions that don't have opcodes associated
      with them (e.g. sstc)
 - These need double-checking, I'm not sure I have them all categorized
   correctly
Add config extension concept
    - Used to define extensions that don't enable ISA JSONs but indicate
      some sort of architectural config (e.g. zvl128b)
Make it possible to reuse an ExtensionManager by resetting the ISA
string
Copy link
Author

@bdutro bdutro Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the ISA specification JSON. The rest of the JSONs were reorganized so that there was a 1:1 correspondence between each ISA extension and its Mavis JSON.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header contains all of the RISC-V specific features, including the ISA string parser and the ELF ISA parser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header handles processing the ISA spec JSON and setting up all of the dependencies between the ISA extensions.

@klingaard
Copy link
Member

Hey @bdutro are there missing files? I don't see a use of ELFIO...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants