1 //===- RISCVSystemOperands.td ------------------------------*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the symbolic operands permitted for various kinds of
10 // RISC-V system instruction.
12 //===----------------------------------------------------------------------===//
14 include "llvm/TableGen/SearchableTable.td"
16 //===----------------------------------------------------------------------===//
17 // CSR (control and status register read/write) instruction options.
18 //===----------------------------------------------------------------------===//
20 class SysReg<string name, bits<12> op> {
22 // A maximum of one alias is supported right now.
23 string AltName = name;
24 // A maximum of one deprecated name is supported right now. Unlike the
25 // `AltName` alias, a `DeprecatedName` generates a diagnostic when the name is
26 // used to encourage software to migrate away from the name.
27 string DeprecatedName = "";
28 bits<12> Encoding = op;
29 // FIXME: add these additional fields when needed.
30 // Privilege Access: Read and Write = 0, 1, 2; Read-Only = 3.
31 // Privilege Mode: User = 0, System = 1 or Machine = 3.
32 // bits<2> ReadWrite = op{11 - 10};
33 // bits<2> XMode = op{9 - 8};
34 // Check Extra field name and what bits 7-6 correspond to.
35 // bits<2> Extra = op{7 - 6};
36 // Register number without the privilege bits.
37 // bits<6> Number = op{5 - 0};
38 code FeaturesRequired = [{ {} }];
42 def SysRegsList : GenericTable {
43 let FilterClass = "SysReg";
44 // FIXME: add "ReadWrite", "Mode", "Extra", "Number" fields when needed.
46 "Name", "AltName", "DeprecatedName", "Encoding", "FeaturesRequired",
50 let PrimaryKey = [ "Encoding" ];
51 let PrimaryKeyName = "lookupSysRegByEncoding";
54 def lookupSysRegByName : SearchIndex {
55 let Table = SysRegsList;
59 def lookupSysRegByAltName : SearchIndex {
60 let Table = SysRegsList;
61 let Key = [ "AltName" ];
64 def lookupSysRegByDeprecatedName : SearchIndex {
65 let Table = SysRegsList;
66 let Key = [ "DeprecatedName" ];
69 // The following CSR encodings match those given in Tables 2.2,
70 // 2.3, 2.4, 2.5 and 2.6 in the RISC-V Instruction Set Manual
71 // Volume II: Privileged Architecture.
73 //===----------------------------------------------------------------------===//
74 // User Floating-Point CSRs
75 //===----------------------------------------------------------------------===//
77 def SysRegFFLAGS : SysReg<"fflags", 0x001>;
78 def SysRegFRM : SysReg<"frm", 0x002>;
79 def SysRegFCSR : SysReg<"fcsr", 0x003>;
81 //===----------------------------------------------------------------------===//
82 // User Counter/Timers
83 //===----------------------------------------------------------------------===//
84 def CYCLE : SysReg<"cycle", 0xC00>;
85 def TIME : SysReg<"time", 0xC01>;
86 def INSTRET : SysReg<"instret", 0xC02>;
88 // hpmcounter3-hpmcounter31 at 0xC03-0xC1F.
90 def : SysReg<"hpmcounter"#i, !add(0xC03, !sub(i, 3))>;
92 let isRV32Only = 1 in {
93 def CYCLEH : SysReg<"cycleh", 0xC80>;
94 def TIMEH : SysReg<"timeh", 0xC81>;
95 def INSTRETH : SysReg<"instreth", 0xC82>;
97 // hpmcounter3h-hpmcounter31h at 0xC83-0xC9F.
99 def : SysReg<"hpmcounter"#i#"h", !add(0xC83, !sub(i, 3))>;
102 //===----------------------------------------------------------------------===//
103 // Supervisor Trap Setup
104 //===----------------------------------------------------------------------===//
105 def : SysReg<"sstatus", 0x100>;
106 def : SysReg<"sie", 0x104>;
107 def : SysReg<"stvec", 0x105>;
108 def : SysReg<"scounteren", 0x106>;
109 def : SysReg<"stimecmp", 0x14D>;
110 let isRV32Only = 1 in
111 def : SysReg<"stimecmph", 0x15D>;
113 //===----------------------------------------------------------------------===//
114 // Supervisor Configuration
115 //===----------------------------------------------------------------------===//
117 def : SysReg<"senvcfg", 0x10A>;
119 //===----------------------------------------------------------------------===//
120 // Supervisor Trap Handling
121 //===----------------------------------------------------------------------===//
122 def : SysReg<"sscratch", 0x140>;
123 def : SysReg<"sepc", 0x141>;
124 def : SysReg<"scause", 0x142>;
125 let DeprecatedName = "sbadaddr" in
126 def : SysReg<"stval", 0x143>;
127 def : SysReg<"sip", 0x144>;
129 //===----------------------------------------------------------------------===//
130 // Supervisor Protection and Translation
131 //===----------------------------------------------------------------------===//
132 let DeprecatedName = "sptbr" in
133 def : SysReg<"satp", 0x180>;
135 //===----------------------------------------------------------------------===//
136 // Debug/Trace Registers
137 //===----------------------------------------------------------------------===//
139 def : SysReg<"scontext", 0x5A8>;
141 //===----------------------------------------------------------------------===//
142 // Supervisor Count Overflow (defined in Sscofpmf)
143 //===----------------------------------------------------------------------===//
145 def : SysReg<"scountovf", 0xDA0>;
147 //===----------------------------------------------------------------------===//
148 // Hypervisor Trap Setup
149 //===----------------------------------------------------------------------===//
151 def : SysReg<"hstatus", 0x600>;
152 def : SysReg<"hedeleg", 0x602>;
153 def : SysReg<"hideleg", 0x603>;
154 def : SysReg<"hie", 0x604>;
155 def : SysReg<"hcounteren", 0x606>;
156 def : SysReg<"hgeie", 0x607>;
158 //===----------------------------------------------------------------------===//
159 // Hypervisor Trap Handling
160 //===----------------------------------------------------------------------===//
162 def : SysReg<"htval", 0x643>;
163 def : SysReg<"hip", 0x644>;
164 def : SysReg<"hvip", 0x645>;
165 def : SysReg<"htinst", 0x64A>;
166 def : SysReg<"hgeip", 0xE12>;
168 //===----------------------------------------------------------------------===//
169 // Hypervisor Configuration
170 //===----------------------------------------------------------------------===//
172 def : SysReg<"henvcfg", 0x60A>;
173 let isRV32Only = 1 in
174 def : SysReg<"henvcfgh", 0x61A>;
176 //===----------------------------------------------------------------------===//
177 // Hypervisor Protection and Translation
178 //===----------------------------------------------------------------------===//
180 def : SysReg<"hgatp", 0x680>;
182 //===----------------------------------------------------------------------===//
183 // Debug/Trace Registers
184 //===----------------------------------------------------------------------===//
186 def : SysReg<"hcontext", 0x6A8>;
188 //===----------------------------------------------------------------------===//
189 // Hypervisor Counter/Timer Virtualization Registers
190 //===----------------------------------------------------------------------===//
192 def : SysReg<"htimedelta", 0x605>;
193 let isRV32Only = 1 in
194 def : SysReg<"htimedeltah", 0x615>;
196 //===----------------------------------------------------------------------===//
197 // Virtual Supervisor Registers
198 //===----------------------------------------------------------------------===//
200 def : SysReg<"vsstatus", 0x200>;
201 def : SysReg<"vsie", 0x204>;
202 def : SysReg<"vstvec", 0x205>;
203 def : SysReg<"vsscratch", 0x240>;
204 def : SysReg<"vsepc", 0x241>;
205 def : SysReg<"vscause", 0x242>;
206 def : SysReg<"vstval", 0x243>;
207 def : SysReg<"vsip", 0x244>;
208 def : SysReg<"vstimecmp", 0x24D>;
209 let isRV32Only = 1 in
210 def : SysReg<"vstimecmph", 0x25D>;
211 def : SysReg<"vsatp", 0x280>;
213 //===----------------------------------------------------------------------===//
214 // Machine Information Registers
215 //===----------------------------------------------------------------------===//
217 def : SysReg<"mvendorid", 0xF11>;
218 def : SysReg<"marchid", 0xF12>;
219 def : SysReg<"mimpid", 0xF13>;
220 def : SysReg<"mhartid", 0xF14>;
221 def : SysReg<"mconfigptr", 0xF15>;
223 //===----------------------------------------------------------------------===//
224 // Machine Trap Setup
225 //===----------------------------------------------------------------------===//
226 def : SysReg<"mstatus", 0x300>;
227 def : SysReg<"misa", 0x301>;
228 def : SysReg<"medeleg", 0x302>;
229 def : SysReg<"mideleg", 0x303>;
230 def : SysReg<"mie", 0x304>;
231 def : SysReg<"mtvec", 0x305>;
232 def : SysReg<"mcounteren", 0x306>;
233 let isRV32Only = 1 in
234 def : SysReg<"mstatush", 0x310>;
236 //===----------------------------------------------------------------------===//
237 // Machine Trap Handling
238 //===----------------------------------------------------------------------===//
239 def : SysReg<"mscratch", 0x340>;
240 def : SysReg<"mepc", 0x341>;
241 def : SysReg<"mcause", 0x342>;
242 let DeprecatedName = "mbadaddr" in
243 def : SysReg<"mtval", 0x343>;
244 def : SysReg<"mip", 0x344>;
245 def : SysReg<"mtinst", 0x34A>;
246 def : SysReg<"mtval2", 0x34B>;
248 //===----------------------------------------------------------------------===//
249 // Machine Configuration
250 //===----------------------------------------------------------------------===//
252 def : SysReg<"menvcfg", 0x30A>;
253 let isRV32Only = 1 in
254 def : SysReg<"menvcfgh", 0x31A>;
255 def : SysReg<"mseccfg", 0x747>;
256 let isRV32Only = 1 in
257 def : SysReg<"mseccfgh", 0x757>;
259 //===----------------------------------------------------------------------===//
260 // Machine Protection and Translation
261 //===----------------------------------------------------------------------===//
263 // pmpcfg0-pmpcfg15 at 0x3A0-0x3AF. Odd-numbered registers are RV32-only.
264 foreach i = 0...15 in {
265 let isRV32Only = !and(i, 1) in
266 def : SysReg<"pmpcfg"#i, !add(0x3A0, i)>;
269 // pmpaddr0-pmpaddr63 at 0x3B0-0x3EF.
270 foreach i = 0...63 in
271 def : SysReg<"pmpaddr"#i, !add(0x3B0, i)>;
273 //===----------------------------------------------------------------------===//
274 // Machine Counter and Timers
275 //===----------------------------------------------------------------------===//
276 def : SysReg<"mcycle", 0xB00>;
277 def : SysReg<"minstret", 0xB02>;
279 // mhpmcounter3-mhpmcounter31 at 0xB03-0xB1F.
280 foreach i = 3...31 in
281 def : SysReg<"mhpmcounter"#i, !add(0xB03, !sub(i, 3))>;
283 let isRV32Only = 1 in {
284 def: SysReg<"mcycleh", 0xB80>;
285 def: SysReg<"minstreth", 0xB82>;
287 // mhpmcounter3h-mhpmcounter31h at 0xB83-0xB9F.
288 foreach i = 3...31 in
289 def : SysReg<"mhpmcounter"#i#"h", !add(0xB83, !sub(i, 3))>;
292 //===----------------------------------------------------------------------===//
293 // Machine Counter Setup
294 //===----------------------------------------------------------------------===//
295 let AltName = "mucounteren" in // Privileged spec v1.9.1 Name
296 def : SysReg<"mcountinhibit", 0x320>;
298 // mhpmevent3-mhpmevent31 at 0x323-0x33F.
299 foreach i = 3...31 in
300 def : SysReg<"mhpmevent"#i, !add(0x323, !sub(i, 3))>;
302 // mhpmevent3h-mhpmevent31h at 0x723-0x73F
303 foreach i = 3...31 in {
304 let isRV32Only = 1 in
305 def : SysReg<"mhpmevent"#i#"h", !add(0x723, !sub(i, 3))>;
308 //===----------------------------------------------------------------------===//
309 // Debug/ Trace Registers (shared with Debug Mode)
310 //===----------------------------------------------------------------------===//
311 def : SysReg<"tselect", 0x7A0>;
312 def : SysReg<"tdata1", 0x7A1>;
313 def : SysReg<"tdata2", 0x7A2>;
314 def : SysReg<"tdata3", 0x7A3>;
315 def : SysReg<"mcontext", 0x7A8>;
317 //===----------------------------------------------------------------------===//
318 // Debug Mode Registers
319 //===----------------------------------------------------------------------===//
320 def : SysReg<"dcsr", 0x7B0>;
321 def : SysReg<"dpc", 0x7B1>;
323 // "dscratch" is an alternative name for "dscratch0" which appeared in earlier
324 // drafts of the RISC-V debug spec
325 let AltName = "dscratch" in
326 def : SysReg<"dscratch0", 0x7B2>;
327 def : SysReg<"dscratch1", 0x7B3>;
329 //===----------------------------------------------------------------------===//
331 //===----------------------------------------------------------------------===//
332 def : SysReg<"vstart", 0x008>;
333 def : SysReg<"vxsat", 0x009>;
334 def SysRegVXRM : SysReg<"vxrm", 0x00A>;
335 def : SysReg<"vcsr", 0x00F>;
336 def SysRegVL : SysReg<"vl", 0xC20>;
337 def : SysReg<"vtype", 0xC21>;
338 def SysRegVLENB: SysReg<"vlenb", 0xC22>;
340 //===----------------------------------------------------------------------===//
341 // State Enable Extension (Smstateen)
342 //===----------------------------------------------------------------------===//
344 // sstateen0-sstateen3 at 0x10C-0x10F, mstateen0-mstateen3 at 0x30C-0x30F,
345 // mstateen0h-mstateen3h at 0x31C-0x31F, hstateen0-hstateen3 at 0x60C-0x60F,
346 // and hstateen0h-hstateen3h at 0x61C-0x61F.
347 foreach i = 0...3 in {
348 def : SysReg<"sstateen"#i, !add(0x10C, i)>;
349 def : SysReg<"mstateen"#i, !add(0x30C, i)>;
350 let isRV32Only = 1 in
351 def : SysReg<"mstateen"#i#"h", !add(0x31C, i)>;
352 def : SysReg<"hstateen"#i, !add(0x60C, i)>;
353 let isRV32Only = 1 in
354 def : SysReg<"hstateen"#i#"h", !add(0x61C, i)>;
357 //===-----------------------------------------------
358 // Entropy Source CSR
359 //===-----------------------------------------------
361 def SEED : SysReg<"seed", 0x015>;
363 //===-----------------------------------------------
364 // Advanced Interrupt Architecture
365 //===-----------------------------------------------
367 // Machine-level CSRs
368 def : SysReg<"miselect", 0x350>;
369 def : SysReg<"mireg", 0x351>;
370 def : SysReg<"mtopei", 0x35C>;
371 def : SysReg<"mtopi", 0xFB0>;
372 def : SysReg<"mvien", 0x308>;
373 def : SysReg<"mvip", 0x309>;
374 let isRV32Only = 1 in {
375 def : SysReg<"midelegh", 0x313>;
376 def : SysReg<"mieh", 0x314>;
377 def : SysReg<"mvienh", 0x318>;
378 def : SysReg<"mviph", 0x319>;
379 def : SysReg<"miph", 0x354>;
382 // Supervisor-level CSRs
383 def : SysReg<"siselect", 0x150>;
384 def : SysReg<"sireg", 0x151>;
385 def : SysReg<"stopei", 0x15C>;
386 def : SysReg<"stopi", 0xDB0>;
387 let isRV32Only = 1 in {
388 def : SysReg<"sieh", 0x114>;
389 def : SysReg<"siph", 0x154>;
392 // Hypervisor and VS CSRs
393 def : SysReg<"hvien", 0x608>;
394 def : SysReg<"hvictl", 0x609>;
395 def : SysReg<"hviprio1", 0x646>;
396 def : SysReg<"hviprio2", 0x647>;
397 def : SysReg<"vsiselect", 0x250>;
398 def : SysReg<"vsireg", 0x251>;
399 def : SysReg<"vstopei", 0x25C>;
400 def : SysReg<"vstopi", 0xEB0>;
401 let isRV32Only = 1 in {
402 def : SysReg<"hidelegh", 0x613>;
403 def : SysReg<"hvienh", 0x618>;
404 def : SysReg<"hviph", 0x655>;
405 def : SysReg<"hviprio1h", 0x656>;
406 def : SysReg<"hviprio2h", 0x657>;
407 def : SysReg<"vsieh", 0x214>;
408 def : SysReg<"vsiph", 0x254>;
411 // Jump Vector Table CSR
412 //===-----------------------------------------------
414 def : SysReg<"jvt", 0x017>;