Skip to content

Commit c386c70

Browse files
feat: Add GPR Information to UDB
Implements General Purpose Register (GPR) support in the Unified Database as requested in issue #1085. Changes: - spec/schemas/register_schema.json: New schema defining structure for register files - spec/schemas/schema_defs.json: Add register-specific schema definition - spec/std/isa/register/gpr.yaml: New register file implementing all 32 RISC-V general purpose registers with proper ABI mnemonics, calling convention roles, and conditional support for RV32E - spec/std/isa/README.adoc: Update architecture documentation to include register files - tools/ruby-gems/udb/lib/udb/obj/register_file.rb: New RegisterFile class extending TopLevelDatabaseObject - tools/ruby-gems/udb/lib/udb/obj/database_obj.rb: Add RegisterFile kind to DatabaseObject::Kind enum for type system integration - tools/ruby-gems/udb/lib/udb/architecture.rb: Add register file loading support to architecture The implementation follows RISC-V ABI specifications and provides a single source of truth for GPR information. Resolves Issue: #1085
1 parent 5d6c397 commit c386c70

File tree

7 files changed

+520
-2
lines changed

7 files changed

+520
-2
lines changed

spec/schemas/register_schema.json

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
4+
"title": "Register File Schema",
5+
"description": "Schema for describing a register file",
6+
7+
"$defs": {
8+
"count_variant": {
9+
"type": "object",
10+
"required": ["value", "when"],
11+
"additionalProperties": false,
12+
"properties": {
13+
"value": {
14+
"type": "integer",
15+
"description": "Override count when condition is satisfied"
16+
},
17+
"when": {
18+
"$ref": "schema_defs.json#/$defs/requires_entry"
19+
},
20+
"description": {
21+
"$ref": "schema_defs.json#/$defs/spec_text"
22+
}
23+
}
24+
},
25+
"register_entry": {
26+
"type": "object",
27+
"required": ["name", "index"],
28+
"additionalProperties": false,
29+
"properties": {
30+
"name": {
31+
"$ref": "schema_defs.json#/$defs/register_name"
32+
},
33+
"abi_mnemonic": {
34+
"$ref": "schema_defs.json#/$defs/register_alias"
35+
},
36+
"index": {
37+
"type": "integer",
38+
"minimum": 0,
39+
"description": "Register index"
40+
},
41+
"description": {
42+
"$ref": "schema_defs.json#/$defs/spec_text"
43+
},
44+
"definedBy": {
45+
"$ref": "schema_defs.json#/$defs/requires_entry"
46+
},
47+
"when": {
48+
"$ref": "schema_defs.json#/$defs/requires_entry"
49+
},
50+
"length": {
51+
"$ref": "schema_defs.json#/$defs/bit_length_value"
52+
},
53+
"roles": {
54+
"type": "array",
55+
"items": {
56+
"type": "string",
57+
"enum": [
58+
"zero",
59+
"return_address",
60+
"stack_pointer",
61+
"global_pointer",
62+
"thread_pointer",
63+
"frame_pointer",
64+
"return_value",
65+
"argument",
66+
"caller_saved",
67+
"callee_saved",
68+
"temporary"
69+
]
70+
},
71+
"uniqueItems": true
72+
}
73+
}
74+
},
75+
"register_file": {
76+
"type": "object",
77+
"required": [
78+
"$schema",
79+
"kind",
80+
"name",
81+
"long_name",
82+
"description",
83+
"length",
84+
"registers"
85+
],
86+
"additionalProperties": false,
87+
"properties": {
88+
"$schema": {
89+
"type": "string",
90+
"format": "uri-reference",
91+
"const": "register_schema.json#",
92+
"description": "Path to schema, relative to <UDB ROOT>/schemas"
93+
},
94+
"kind": {
95+
"type": "string",
96+
"const": "register_file"
97+
},
98+
"name": {
99+
"$ref": "schema_defs.json#/$defs/register_name"
100+
},
101+
"long_name": {
102+
"type": "string"
103+
},
104+
"description": {
105+
"$ref": "schema_defs.json#/$defs/spec_text"
106+
},
107+
"definedBy": {
108+
"$ref": "schema_defs.json#/$defs/requires_entry"
109+
},
110+
"register_class": {
111+
"type": "string",
112+
"enum": ["general_purpose", "floating_point", "vector"]
113+
},
114+
"length": {
115+
"$ref": "schema_defs.json#/$defs/bit_length_value"
116+
},
117+
"count": {
118+
"oneOf": [
119+
{
120+
"type": "integer",
121+
"minimum": 0
122+
},
123+
{
124+
"type": "object",
125+
"required": ["default"],
126+
"additionalProperties": false,
127+
"properties": {
128+
"default": {
129+
"type": "integer",
130+
"minimum": 0
131+
},
132+
"variants": {
133+
"type": "array",
134+
"items": {
135+
"$ref": "#/$defs/count_variant"
136+
}
137+
}
138+
}
139+
}
140+
]
141+
},
142+
"registers": {
143+
"type": "array",
144+
"minItems": 1,
145+
"items": {
146+
"$ref": "#/$defs/register_entry"
147+
}
148+
},
149+
"$source": {
150+
"type": "string",
151+
"format": "uri-reference"
152+
}
153+
}
154+
}
155+
},
156+
"$ref": "#/$defs/register_file"
157+
}

spec/schemas/schema_defs.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@
4343
],
4444
"description": "Location of a field in a register"
4545
},
46+
"bit_length_value": {
47+
"description": "Bit width value for a register or field",
48+
"oneOf": [
49+
{
50+
"type": "integer",
51+
"minimum": 1
52+
},
53+
{
54+
"type": "string",
55+
"minLength": 1
56+
}
57+
]
58+
},
59+
"register_name": {
60+
"type": "string",
61+
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
62+
"description": "Register name"
63+
},
64+
"register_alias": {
65+
"type": "string",
66+
"pattern": "^[A-Za-z][A-Za-z0-9_.-]*$",
67+
"description": "Register alias or ABI mnemonic"
68+
},
4669
"possibly_split_field_location": {
4770
"description": "Location specifier for a field",
4871
"oneOf": [

spec/std/isa/README.adoc

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Three standard configs are present:
2929
* `rv64`: A configuration where only `MXLEN` is known to be 64, i.e., the RV64 ISA.
3030

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

3535
== Flow
3636

@@ -142,6 +142,39 @@ H: # <1>
142142

143143
=== Instructions
144144

145+
=== Registers
146+
147+
.Example register file specification
148+
[source,yaml]
149+
----
150+
$schema: register_schema.json#
151+
kind: register_file
152+
name: X
153+
long_name: Integer General Purpose Registers
154+
definedBy: I
155+
register_class: general_purpose
156+
length: XLEN # <1>
157+
count:
158+
default: 32
159+
variants:
160+
- value: 16
161+
when: { name: E } # <2>
162+
registers:
163+
- name: x0
164+
index: 0
165+
abi_mnemonic: zero # <3>
166+
roles: [zero]
167+
- name: x1
168+
index: 1
169+
abi_mnemonic: ra
170+
roles: [return_address]
171+
----
172+
173+
<1> Register files are defined independently of the resolved XLEN; individual register entries
174+
may override the default bit length when necessary.
175+
<2> Conditional presence uses the same `when`/`definedBy` semantics as other database objects.
176+
<3> Entries can record ABI mnemonics and semantic roles.
177+
145178
[source,yaml]
146179
----
147180
add: # <1>

0 commit comments

Comments
 (0)