Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions spec/schemas/register_file_schema.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since CSRs are also "registers", maybe we use a slightly more specific file name, like "register_file_schema.json" or "regfile_schema.json"?

Copy link
Author

Choose a reason for hiding this comment

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

Sure.

Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",

"title": "Register File Schema",
"description": "Schema for describing a register file",

"$defs": {
"register_entry": {
"type": "object",
"required": ["name"],
"additionalProperties": false,
"properties": {
"name": {
"$ref": "schema_defs.json#/$defs/register_name"
},
"abi_mnemonics": {
"type": "array",
"items": {
"$ref": "schema_defs.json#/$defs/register_alias"
},
"minItems": 1,
"uniqueItems": true,
"description": "ABI mnemonic names for the register"
},
"description": {
"$ref": "schema_defs.json#/$defs/spec_text"
},
"when": {
"$ref": "schema_defs.json#/$defs/requires_entry"
},
"sw_read()": {
"type": "string",
"description": "Function that returns the value of the register when read by software. Use this to define special behavior for registers (e.g., x0 always reads as zero)."
},
"sw_write(value)": {
"type": "string",
"description": "Function implementing custom write behavior for the register. Given a 'value', return either the value to be written or a modified value. Use this to define special behavior for registers (e.g., x0 ignores writes)."
},
"caller_saved": {
"type": "boolean",
"default": false,
"description": "Whether the register is caller-saved"
},
"callee_saved": {
"type": "boolean",
"default": false,
"description": "Whether the register is callee-saved"
},
"roles": {
"type": "array",
"items": {
"type": "string",
"enum": [
"zero",
"return_address",
"stack_pointer",
"global_pointer",
"thread_pointer",
"frame_pointer",
"return_value",
"argument",
"temporary"
]
},
"uniqueItems": true
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't hurt. I don't think it will reject multiple register definitions with the same index if they have different names (or same name and different ABI mnemonics), right? We may want to validate that externally, OR, do we even need to have an index attribute, given that this is an (ordered) array?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's right. Duplicate indices would need to be validated outside JSON schema, especially since it might be valid to have entries with the same index before conditions are applied.

Copy link
Author

@AnimeshAgarwal28 AnimeshAgarwal28 Oct 6, 2025

Choose a reason for hiding this comment

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

Now when I think of it, index is not needed even if it is not an "ordered" array because we always have the register name as the "unique key".

}
}
},
"register_file": {
"type": "object",
"required": [
"$schema",
"kind",
"name",
"long_name",
"description",
"register_length",
"registers"
],
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string",
"format": "uri-reference",
"const": "register_file_schema.json#",
"description": "Path to schema, relative to <UDB ROOT>/schemas"
},
"kind": {
"type": "string",
"const": "register_file"
},
"name": {
"$ref": "schema_defs.json#/$defs/register_file_name"
},
"long_name": {
"type": "string"
},
"description": {
"$ref": "schema_defs.json#/$defs/spec_text"
},
"definedBy": {
"$ref": "schema_defs.json#/$defs/requires_entry"
},
"register_class": {
"type": "string",
"enum": ["general_purpose", "floating_point", "vector"]
},
"register_length": {
"$ref": "schema_defs.json#/$defs/bit_length_value"
},
"registers": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/$defs/register_entry"
}
},
"$source": {
"type": "string",
"format": "uri-reference"
}
}
}
}
}
29 changes: 29 additions & 0 deletions spec/schemas/schema_defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@
],
"description": "Location of a field in a register"
},
"bit_length_value": {
"description": "Bit width value for a register or field",
"oneOf": [
{
"type": "integer",
"minimum": 1
},
{
"type": "string",
"minLength": 1,
"enum": ["MXLEN"]
}
]
},
"register_name": {
"type": "string",
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
"description": "Register name"
},
"register_file_name": {
"type": "string",
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
"description": "Register file name"
},
"register_alias": {
"type": "string",
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
"description": "Register alias or ABI mnemonic"
},
"possibly_split_field_location": {
"description": "Location specifier for a field",
"oneOf": [
Expand Down
38 changes: 36 additions & 2 deletions spec/std/isa/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Three standard configs are present:
* `rv64`: A configuration where only `MXLEN` is known to be 64, i.e., the RV64 ISA.

The architecture is specified in a series of https://en.wikipedia.org/wiki/YAML[YAML]
files for _Extensions_, _Instructions_, and _Control and Status Registers (CSRs)_.
Each extension/instruction/CSR has its own file.
files for _Extensions_, _Instructions_, _RegFiles_, and _Control and Status Registers (CSRs)_.
Each extension/instruction/regfile/CSR has its own file.

== Flow

Expand Down Expand Up @@ -142,6 +142,40 @@ H: # <1>

=== Instructions

=== Register Files

.Example register file specification
[source,yaml]
----
$schema: register_file_schema.json#
kind: register_file
name: X
long_name: Integer General Purpose Registers
definedBy: I
register_class: general_purpose
register_length: MXLEN # <1>
registers:
- name: x0 # <2>
abi_mnemonics: [zero] # <3>
roles: [zero]
sw_read(): | # <4>
return 0;
sw_write(value): |
# x0 ignores all writes
- name: x1
abi_mnemonics: [ra]
roles: [return_address]
- name: x8
abi_mnemonics: [s0, fp] # <5>
roles: [callee_saved, frame_pointer]
----

<1> Registers can have either a fixed architecture width or take their width from a parameter (e.g., MXLEN, VLEN).
<2> Each register has a unique name (e.g., x0, x1, x2, etc.). The register's index is inferred from its position in the array (starting from 0).
<3> Registers can optionally have ABI mnemonics (e.g., ra, sp, fp, etc.).
<4> Individual registers can define `sw_read()` and `sw_write()` for special behavior (e.g., x0 hardwired to zero).
<5> A register can have multiple ABI mnemonics (e.g., x8 is known as both s0 and fp).

[source,yaml]
----
add: # <1>
Expand Down
Loading