Skip to content

Commit aac843c

Browse files
authored
[RISCV] Sort RISCVSystemOperands to match the RISC-V Privilege Specification. (#140967)
Use the order here https://github.com/riscv/riscv-isa-manual/blob/main/src/priv-csrs.adoc My hope is that by having the lists in sync, we can more easily compare them for missing or incorrect entries. Unfortunately, not all CSRs have been integrated there yet. I've filed issues in riscv-isa-manual to get them added.
1 parent edd4317 commit aac843c

File tree

1 file changed

+96
-68
lines changed

1 file changed

+96
-68
lines changed

llvm/lib/Target/RISCV/RISCVSystemOperands.td

Lines changed: 96 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,46 @@ def lookupSysRegByName : SearchIndex {
6767
// Volume II: Privileged Architecture.
6868

6969
//===----------------------------------------------------------------------===//
70-
// User Floating-Point CSRs
70+
// Unprivileged Floating-Point CSRs
7171
//===----------------------------------------------------------------------===//
7272

7373
def SysRegFFLAGS : SysReg<"fflags", 0x001>;
7474
def SysRegFRM : SysReg<"frm", 0x002>;
7575
def SysRegFCSR : SysReg<"fcsr", 0x003>;
7676

7777
//===----------------------------------------------------------------------===//
78-
// User Counter/Timers
78+
// Unprivileged Vector CSRs
7979
//===----------------------------------------------------------------------===//
80+
def : SysReg<"vstart", 0x008>;
81+
def : SysReg<"vxsat", 0x009>;
82+
def SysRegVXRM : SysReg<"vxrm", 0x00A>;
83+
def : SysReg<"vcsr", 0x00F>;
84+
def SysRegVL : SysReg<"vl", 0xC20>;
85+
def : SysReg<"vtype", 0xC21>;
86+
def SysRegVLENB: SysReg<"vlenb", 0xC22>;
87+
88+
//===----------------------------------------------------------------------===//
89+
// Unprivileged Zicfiss extension CSR
90+
//===----------------------------------------------------------------------===//
91+
92+
def : SysReg<"ssp", 0x011>;
93+
94+
//===-----------------------------------------------
95+
// Unprivileged Entropy Source Extension CSR
96+
//===-----------------------------------------------
97+
98+
def SEED : SysReg<"seed", 0x015>;
99+
100+
//===-----------------------------------------------
101+
// Unprivileged Zcmt Extension CSR
102+
//===-----------------------------------------------
103+
104+
def : SysReg<"jvt", 0x017>;
105+
106+
//===----------------------------------------------------------------------===//
107+
// Unprivileged Counter/Timers
108+
//===----------------------------------------------------------------------===//
109+
80110
def CYCLE : SysReg<"cycle", 0xC00>;
81111
def TIME : SysReg<"time", 0xC01>;
82112
def INSTRET : SysReg<"instret", 0xC02>;
@@ -98,42 +128,52 @@ foreach i = 3...31 in
98128
//===----------------------------------------------------------------------===//
99129
// Supervisor Trap Setup
100130
//===----------------------------------------------------------------------===//
131+
101132
def : SysReg<"sstatus", 0x100>;
102133
def : SysReg<"sie", 0x104>;
103134
def : SysReg<"stvec", 0x105>;
104135
def : SysReg<"scounteren", 0x106>;
105-
def : SysReg<"stimecmp", 0x14D>;
106-
let isRV32Only = 1 in
107-
def : SysReg<"stimecmph", 0x15D>;
108136

109137
//===----------------------------------------------------------------------===//
110138
// Supervisor Configuration
111139
//===----------------------------------------------------------------------===//
112140

113141
def : SysReg<"senvcfg", 0x10A>;
114142

143+
//===----------------------------------------------------------------------===//
144+
// Supervisor Counter Setup
145+
//===----------------------------------------------------------------------===//
146+
147+
def : SysReg<"scountinhibit", 0x120>;
148+
115149
//===----------------------------------------------------------------------===//
116150
// Supervisor Trap Handling
117151
//===----------------------------------------------------------------------===//
152+
118153
def : SysReg<"sscratch", 0x140>;
119154
def : SysReg<"sepc", 0x141>;
120155
def : SysReg<"scause", 0x142>;
121156
def : SysReg<"stval", 0x143>;
122157
let isDeprecatedName = 1 in
123158
def : SysReg<"sbadaddr", 0x143>;
124159
def : SysReg<"sip", 0x144>;
160+
def : SysReg<"scountovf", 0xDA0>;
125161

126162
//===----------------------------------------------------------------------===//
127163
// Supervisor Protection and Translation
128164
//===----------------------------------------------------------------------===//
165+
129166
def : SysReg<"satp", 0x180>;
130167
let isDeprecatedName = 1 in
131168
def : SysReg<"sptbr", 0x180>;
132169

133170
//===----------------------------------------------------------------------===//
134-
// Quality-of-Service(QoS) Identifiers (Ssqosid)
171+
// Supervisor Timer Compare
135172
//===----------------------------------------------------------------------===//
136-
def : SysReg<"srmcfg", 0x181>;
173+
174+
def : SysReg<"stimecmp", 0x14D>;
175+
let isRV32Only = 1 in
176+
def : SysReg<"stimecmph", 0x15D>;
137177

138178
//===----------------------------------------------------------------------===//
139179
// Debug/Trace Registers
@@ -142,10 +182,18 @@ def : SysReg<"srmcfg", 0x181>;
142182
def : SysReg<"scontext", 0x5A8>;
143183

144184
//===----------------------------------------------------------------------===//
145-
// Supervisor Count Overflow (defined in Sscofpmf)
185+
// Supervisor Resource Management Configuration
146186
//===----------------------------------------------------------------------===//
147187

148-
def : SysReg<"scountovf", 0xDA0>;
188+
def : SysReg<"srmcfg", 0x181>;
189+
190+
//===----------------------------------------------------------------------===//
191+
// Supervisor State Enable
192+
//===----------------------------------------------------------------------===//
193+
194+
foreach i = 0...3 in {
195+
def : SysReg<"sstateen"#i, !add(0x10C, i)>;
196+
}
149197

150198
//===----------------------------------------------------------------------===//
151199
// Hypervisor Trap Setup
@@ -198,6 +246,16 @@ def : SysReg<"htimedelta", 0x605>;
198246
let isRV32Only = 1 in
199247
def : SysReg<"htimedeltah", 0x615>;
200248

249+
//===----------------------------------------------------------------------===//
250+
// Hypervisor State Enable Registers
251+
//===----------------------------------------------------------------------===//
252+
253+
foreach i = 0...3 in {
254+
def : SysReg<"hstateen"#i, !add(0x60C, i)>;
255+
let isRV32Only = 1 in
256+
def : SysReg<"hstateen"#i#"h", !add(0x61C, i)>;
257+
}
258+
201259
//===----------------------------------------------------------------------===//
202260
// Virtual Supervisor Registers
203261
//===----------------------------------------------------------------------===//
@@ -210,10 +268,15 @@ def : SysReg<"vsepc", 0x241>;
210268
def : SysReg<"vscause", 0x242>;
211269
def : SysReg<"vstval", 0x243>;
212270
def : SysReg<"vsip", 0x244>;
271+
def : SysReg<"vsatp", 0x280>;
272+
273+
//===----------------------------------------------------------------------===//
274+
// Virtual Supervisor Timer Compare
275+
//===----------------------------------------------------------------------===//
276+
213277
def : SysReg<"vstimecmp", 0x24D>;
214278
let isRV32Only = 1 in
215279
def : SysReg<"vstimecmph", 0x25D>;
216-
def : SysReg<"vsatp", 0x280>;
217280

218281
//===----------------------------------------------------------------------===//
219282
// Machine Information Registers
@@ -228,6 +291,7 @@ def : SysReg<"mconfigptr", 0xF15>;
228291
//===----------------------------------------------------------------------===//
229292
// Machine Trap Setup
230293
//===----------------------------------------------------------------------===//
294+
231295
def : SysReg<"mstatus", 0x300>;
232296
def : SysReg<"misa", 0x301>;
233297
def : SysReg<"medeleg", 0x302>;
@@ -278,9 +342,28 @@ foreach i = 0...15 in {
278342
foreach i = 0...63 in
279343
def : SysReg<"pmpaddr"#i, !add(0x3B0, i)>;
280344

345+
//===----------------------------------------------------------------------===//
346+
// Machine State Enable Registers
347+
//===----------------------------------------------------------------------===//
348+
349+
foreach i = 0...3 in {
350+
def : SysReg<"mstateen"#i, !add(0x30C, i)>;
351+
let isRV32Only = 1 in
352+
def : SysReg<"mstateen"#i#"h", !add(0x31C, i)>;
353+
}
354+
355+
//===-----------------------------------------------
356+
// Resumable Non-Maskable Interrupts(Smrnmi) CSRs
357+
//===-----------------------------------------------
358+
def : SysReg<"mnscratch", 0x740>;
359+
def : SysReg<"mnepc", 0x741>;
360+
def : SysReg<"mncause", 0x742>;
361+
def : SysReg<"mnstatus", 0x744>;
362+
281363
//===----------------------------------------------------------------------===//
282364
// Machine Counter and Timers
283365
//===----------------------------------------------------------------------===//
366+
284367
def : SysReg<"mcycle", 0xB00>;
285368
def : SysReg<"minstret", 0xB02>;
286369

@@ -300,6 +383,7 @@ foreach i = 3...31 in
300383
//===----------------------------------------------------------------------===//
301384
// Machine Counter Setup
302385
//===----------------------------------------------------------------------===//
386+
303387
def : SysReg<"mcountinhibit", 0x320>;
304388

305389
// mhpmevent3-mhpmevent31 at 0x323-0x33F.
@@ -312,14 +396,10 @@ foreach i = 3...31 in {
312396
def : SysReg<"mhpmevent"#i#"h", !add(0x723, !sub(i, 3))>;
313397
}
314398

315-
//===----------------------------------------------------------------------===//
316-
// Supervisor Counter Setup
317-
//===----------------------------------------------------------------------===//
318-
def : SysReg<"scountinhibit", 0x120>;
319-
320399
//===----------------------------------------------------------------------===//
321400
// Debug/ Trace Registers (shared with Debug Mode)
322401
//===----------------------------------------------------------------------===//
402+
323403
def : SysReg<"tselect", 0x7A0>;
324404
def : SysReg<"tdata1", 0x7A1>;
325405
let isAltName = 1 in {
@@ -344,6 +424,7 @@ def : SysReg<"mscontext", 0x7AA>;
344424
//===----------------------------------------------------------------------===//
345425
// Debug Mode Registers
346426
//===----------------------------------------------------------------------===//
427+
347428
def : SysReg<"dcsr", 0x7B0>;
348429
def : SysReg<"dpc", 0x7B1>;
349430

@@ -354,45 +435,6 @@ let isAltName = 1 in
354435
def : SysReg<"dscratch", 0x7B2>;
355436
def : SysReg<"dscratch1", 0x7B3>;
356437

357-
//===----------------------------------------------------------------------===//
358-
// User Vector CSRs
359-
//===----------------------------------------------------------------------===//
360-
def : SysReg<"vstart", 0x008>;
361-
def : SysReg<"vxsat", 0x009>;
362-
def SysRegVXRM : SysReg<"vxrm", 0x00A>;
363-
def : SysReg<"vcsr", 0x00F>;
364-
def SysRegVL : SysReg<"vl", 0xC20>;
365-
def : SysReg<"vtype", 0xC21>;
366-
def SysRegVLENB: SysReg<"vlenb", 0xC22>;
367-
368-
//===----------------------------------------------------------------------===//
369-
// Shadow Stack CSR
370-
//===----------------------------------------------------------------------===//
371-
def : SysReg<"ssp", 0x011>;
372-
373-
//===----------------------------------------------------------------------===//
374-
// State Enable Extension (Smstateen)
375-
//===----------------------------------------------------------------------===//
376-
377-
// sstateen0-sstateen3 at 0x10C-0x10F, mstateen0-mstateen3 at 0x30C-0x30F,
378-
// mstateen0h-mstateen3h at 0x31C-0x31F, hstateen0-hstateen3 at 0x60C-0x60F,
379-
// and hstateen0h-hstateen3h at 0x61C-0x61F.
380-
foreach i = 0...3 in {
381-
def : SysReg<"sstateen"#i, !add(0x10C, i)>;
382-
def : SysReg<"mstateen"#i, !add(0x30C, i)>;
383-
let isRV32Only = 1 in
384-
def : SysReg<"mstateen"#i#"h", !add(0x31C, i)>;
385-
def : SysReg<"hstateen"#i, !add(0x60C, i)>;
386-
let isRV32Only = 1 in
387-
def : SysReg<"hstateen"#i#"h", !add(0x61C, i)>;
388-
}
389-
390-
//===-----------------------------------------------
391-
// Entropy Source CSR
392-
//===-----------------------------------------------
393-
394-
def SEED : SysReg<"seed", 0x015>;
395-
396438
//===-----------------------------------------------
397439
// Advanced Interrupt Architecture
398440
//===-----------------------------------------------
@@ -459,20 +501,6 @@ def : SysReg<"vsieh", 0x214>;
459501
def : SysReg<"vsiph", 0x254>;
460502
} // isRV32Only
461503

462-
//===-----------------------------------------------
463-
// Jump Vector Table CSR
464-
//===-----------------------------------------------
465-
466-
def : SysReg<"jvt", 0x017>;
467-
468-
//===-----------------------------------------------
469-
// Resumable Non-Maskable Interrupts(Smrnmi) CSRs
470-
//===-----------------------------------------------
471-
def : SysReg<"mnscratch", 0x740>;
472-
def : SysReg<"mnepc", 0x741>;
473-
def : SysReg<"mncause", 0x742>;
474-
def : SysReg<"mnstatus", 0x744>;
475-
476504
//===-----------------------------------------------
477505
// Control Transfer Records CSRs
478506
//===-----------------------------------------------

0 commit comments

Comments
 (0)