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 and 2.5 in the RISC-V Instruction Set Manual
71 // Volume II: Privileged Architecture.
73 //===--------------------------
75 //===--------------------------
76 def : SysReg<"ustatus", 0x000>;
77 def : SysReg<"uie", 0x004>;
78 def : SysReg<"utvec", 0x005>;
80 //===--------------------------
82 //===--------------------------
83 def : SysReg<"uscratch", 0x040>;
84 def : SysReg<"uepc", 0x041>;
85 def : SysReg<"ucause", 0x042>;
86 let DeprecatedName = "ubadaddr" in
87 def : SysReg<"utval", 0x043>;
88 def : SysReg<"uip", 0x044>;
90 //===--------------------------
91 // User Floating-Point CSRs
92 //===--------------------------
94 def SysRegFFLAGS : SysReg<"fflags", 0x001>;
95 def SysRegFRM : SysReg<"frm", 0x002>;
96 def SysRegFCSR : SysReg<"fcsr", 0x003>;
98 //===--------------------------
99 // User Counter/Timers
100 //===--------------------------
101 def CYCLE : SysReg<"cycle", 0xC00>;
102 def TIME : SysReg<"time", 0xC01>;
103 def INSTRET : SysReg<"instret", 0xC02>;
105 def : SysReg<"hpmcounter3", 0xC03>;
106 def : SysReg<"hpmcounter4", 0xC04>;
107 def : SysReg<"hpmcounter5", 0xC05>;
108 def : SysReg<"hpmcounter6", 0xC06>;
109 def : SysReg<"hpmcounter7", 0xC07>;
110 def : SysReg<"hpmcounter8", 0xC08>;
111 def : SysReg<"hpmcounter9", 0xC09>;
112 def : SysReg<"hpmcounter10", 0xC0A>;
113 def : SysReg<"hpmcounter11", 0xC0B>;
114 def : SysReg<"hpmcounter12", 0xC0C>;
115 def : SysReg<"hpmcounter13", 0xC0D>;
116 def : SysReg<"hpmcounter14", 0xC0E>;
117 def : SysReg<"hpmcounter15", 0xC0F>;
118 def : SysReg<"hpmcounter16", 0xC10>;
119 def : SysReg<"hpmcounter17", 0xC11>;
120 def : SysReg<"hpmcounter18", 0xC12>;
121 def : SysReg<"hpmcounter19", 0xC13>;
122 def : SysReg<"hpmcounter20", 0xC14>;
123 def : SysReg<"hpmcounter21", 0xC15>;
124 def : SysReg<"hpmcounter22", 0xC16>;
125 def : SysReg<"hpmcounter23", 0xC17>;
126 def : SysReg<"hpmcounter24", 0xC18>;
127 def : SysReg<"hpmcounter25", 0xC19>;
128 def : SysReg<"hpmcounter26", 0xC1A>;
129 def : SysReg<"hpmcounter27", 0xC1B>;
130 def : SysReg<"hpmcounter28", 0xC1C>;
131 def : SysReg<"hpmcounter29", 0xC1D>;
132 def : SysReg<"hpmcounter30", 0xC1E>;
133 def : SysReg<"hpmcounter31", 0xC1F>;
135 let isRV32Only = 1 in {
136 def CYCLEH : SysReg<"cycleh", 0xC80>;
137 def TIMEH : SysReg<"timeh", 0xC81>;
138 def INSTRETH : SysReg<"instreth", 0xC82>;
140 def: SysReg<"hpmcounter3h", 0xC83>;
141 def: SysReg<"hpmcounter4h", 0xC84>;
142 def: SysReg<"hpmcounter5h", 0xC85>;
143 def: SysReg<"hpmcounter6h", 0xC86>;
144 def: SysReg<"hpmcounter7h", 0xC87>;
145 def: SysReg<"hpmcounter8h", 0xC88>;
146 def: SysReg<"hpmcounter9h", 0xC89>;
147 def: SysReg<"hpmcounter10h", 0xC8A>;
148 def: SysReg<"hpmcounter11h", 0xC8B>;
149 def: SysReg<"hpmcounter12h", 0xC8C>;
150 def: SysReg<"hpmcounter13h", 0xC8D>;
151 def: SysReg<"hpmcounter14h", 0xC8E>;
152 def: SysReg<"hpmcounter15h", 0xC8F>;
153 def: SysReg<"hpmcounter16h", 0xC90>;
154 def: SysReg<"hpmcounter17h", 0xC91>;
155 def: SysReg<"hpmcounter18h", 0xC92>;
156 def: SysReg<"hpmcounter19h", 0xC93>;
157 def: SysReg<"hpmcounter20h", 0xC94>;
158 def: SysReg<"hpmcounter21h", 0xC95>;
159 def: SysReg<"hpmcounter22h", 0xC96>;
160 def: SysReg<"hpmcounter23h", 0xC97>;
161 def: SysReg<"hpmcounter24h", 0xC98>;
162 def: SysReg<"hpmcounter25h", 0xC99>;
163 def: SysReg<"hpmcounter26h", 0xC9A>;
164 def: SysReg<"hpmcounter27h", 0xC9B>;
165 def: SysReg<"hpmcounter28h", 0xC9C>;
166 def: SysReg<"hpmcounter29h", 0xC9D>;
167 def: SysReg<"hpmcounter30h", 0xC9E>;
168 def: SysReg<"hpmcounter31h", 0xC9F>;
171 //===--------------------------
172 // Supervisor Trap Setup
173 //===--------------------------
174 def : SysReg<"sstatus", 0x100>;
175 def : SysReg<"sedeleg", 0x102>;
176 def : SysReg<"sideleg", 0x103>;
177 def : SysReg<"sie", 0x104>;
178 def : SysReg<"stvec", 0x105>;
179 def : SysReg<"scounteren", 0x106>;
181 //===--------------------------
182 // Supervisor Trap Handling
183 //===--------------------------
184 def : SysReg<"sscratch", 0x140>;
185 def : SysReg<"sepc", 0x141>;
186 def : SysReg<"scause", 0x142>;
187 let DeprecatedName = "sbadaddr" in
188 def : SysReg<"stval", 0x143>;
189 def : SysReg<"sip", 0x144>;
191 //===-------------------------------------
192 // Supervisor Protection and Translation
193 //===-------------------------------------
194 let DeprecatedName = "sptbr" in
195 def : SysReg<"satp", 0x180>;
197 //===-----------------------------
198 // Machine Information Registers
199 //===-----------------------------
201 def : SysReg<"mvendorid", 0xF11>;
202 def : SysReg<"marchid", 0xF12>;
203 def : SysReg<"mimpid", 0xF13>;
204 def : SysReg<"mhartid", 0xF14>;
206 //===-----------------------------
207 // Machine Trap Setup
208 //===-----------------------------
209 def : SysReg<"mstatus", 0x300>;
210 def : SysReg<"misa", 0x301>;
211 def : SysReg<"medeleg", 0x302>;
212 def : SysReg<"mideleg", 0x303>;
213 def : SysReg<"mie", 0x304>;
214 def : SysReg<"mtvec", 0x305>;
215 def : SysReg<"mcounteren", 0x306>;
217 //===-----------------------------
218 // Machine Trap Handling
219 //===-----------------------------
220 def : SysReg<"mscratch", 0x340>;
221 def : SysReg<"mepc", 0x341>;
222 def : SysReg<"mcause", 0x342>;
223 let DeprecatedName = "mbadaddr" in
224 def : SysReg<"mtval", 0x343>;
225 def : SysReg<"mip", 0x344>;
227 //===----------------------------------
228 // Machine Protection and Translation
229 //===----------------------------------
230 def : SysReg<"pmpcfg0", 0x3A0>;
231 def : SysReg<"pmpcfg2", 0x3A2>;
232 let isRV32Only = 1 in {
233 def : SysReg<"pmpcfg1", 0x3A1>;
234 def : SysReg<"pmpcfg3", 0x3A3>;
237 def : SysReg<"pmpaddr0", 0x3B0>;
238 def : SysReg<"pmpaddr1", 0x3B1>;
239 def : SysReg<"pmpaddr2", 0x3B2>;
240 def : SysReg<"pmpaddr3", 0x3B3>;
241 def : SysReg<"pmpaddr4", 0x3B4>;
242 def : SysReg<"pmpaddr5", 0x3B5>;
243 def : SysReg<"pmpaddr6", 0x3B6>;
244 def : SysReg<"pmpaddr7", 0x3B7>;
245 def : SysReg<"pmpaddr8", 0x3B8>;
246 def : SysReg<"pmpaddr9", 0x3B9>;
247 def : SysReg<"pmpaddr10", 0x3BA>;
248 def : SysReg<"pmpaddr11", 0x3BB>;
249 def : SysReg<"pmpaddr12", 0x3BC>;
250 def : SysReg<"pmpaddr13", 0x3BD>;
251 def : SysReg<"pmpaddr14", 0x3BE>;
252 def : SysReg<"pmpaddr15", 0x3BF>;
255 //===--------------------------
256 // Machine Counter and Timers
257 //===--------------------------
258 def : SysReg<"mcycle", 0xB00>;
259 def : SysReg<"minstret", 0xB02>;
261 def : SysReg<"mhpmcounter3", 0xB03>;
262 def : SysReg<"mhpmcounter4", 0xB04>;
263 def : SysReg<"mhpmcounter5", 0xB05>;
264 def : SysReg<"mhpmcounter6", 0xB06>;
265 def : SysReg<"mhpmcounter7", 0xB07>;
266 def : SysReg<"mhpmcounter8", 0xB08>;
267 def : SysReg<"mhpmcounter9", 0xB09>;
268 def : SysReg<"mhpmcounter10", 0xB0A>;
269 def : SysReg<"mhpmcounter11", 0xB0B>;
270 def : SysReg<"mhpmcounter12", 0xB0C>;
271 def : SysReg<"mhpmcounter13", 0xB0D>;
272 def : SysReg<"mhpmcounter14", 0xB0E>;
273 def : SysReg<"mhpmcounter15", 0xB0F>;
274 def : SysReg<"mhpmcounter16", 0xB10>;
275 def : SysReg<"mhpmcounter17", 0xB11>;
276 def : SysReg<"mhpmcounter18", 0xB12>;
277 def : SysReg<"mhpmcounter19", 0xB13>;
278 def : SysReg<"mhpmcounter20", 0xB14>;
279 def : SysReg<"mhpmcounter21", 0xB15>;
280 def : SysReg<"mhpmcounter22", 0xB16>;
281 def : SysReg<"mhpmcounter23", 0xB17>;
282 def : SysReg<"mhpmcounter24", 0xB18>;
283 def : SysReg<"mhpmcounter25", 0xB19>;
284 def : SysReg<"mhpmcounter26", 0xB1A>;
285 def : SysReg<"mhpmcounter27", 0xB1B>;
286 def : SysReg<"mhpmcounter28", 0xB1C>;
287 def : SysReg<"mhpmcounter29", 0xB1D>;
288 def : SysReg<"mhpmcounter30", 0xB1E>;
289 def : SysReg<"mhpmcounter31", 0xB1F>;
291 let isRV32Only = 1 in {
292 def: SysReg<"mcycleh", 0xB80>;
293 def: SysReg<"minstreth", 0xB82>;
295 def: SysReg<"mhpmcounter3h", 0xB83>;
296 def: SysReg<"mhpmcounter4h", 0xB84>;
297 def: SysReg<"mhpmcounter5h", 0xB85>;
298 def: SysReg<"mhpmcounter6h", 0xB86>;
299 def: SysReg<"mhpmcounter7h", 0xB87>;
300 def: SysReg<"mhpmcounter8h", 0xB88>;
301 def: SysReg<"mhpmcounter9h", 0xB89>;
302 def: SysReg<"mhpmcounter10h", 0xB8A>;
303 def: SysReg<"mhpmcounter11h", 0xB8B>;
304 def: SysReg<"mhpmcounter12h", 0xB8C>;
305 def: SysReg<"mhpmcounter13h", 0xB8D>;
306 def: SysReg<"mhpmcounter14h", 0xB8E>;
307 def: SysReg<"mhpmcounter15h", 0xB8F>;
308 def: SysReg<"mhpmcounter16h", 0xB90>;
309 def: SysReg<"mhpmcounter17h", 0xB91>;
310 def: SysReg<"mhpmcounter18h", 0xB92>;
311 def: SysReg<"mhpmcounter19h", 0xB93>;
312 def: SysReg<"mhpmcounter20h", 0xB94>;
313 def: SysReg<"mhpmcounter21h", 0xB95>;
314 def: SysReg<"mhpmcounter22h", 0xB96>;
315 def: SysReg<"mhpmcounter23h", 0xB97>;
316 def: SysReg<"mhpmcounter24h", 0xB98>;
317 def: SysReg<"mhpmcounter25h", 0xB99>;
318 def: SysReg<"mhpmcounter26h", 0xB9A>;
319 def: SysReg<"mhpmcounter27h", 0xB9B>;
320 def: SysReg<"mhpmcounter28h", 0xB9C>;
321 def: SysReg<"mhpmcounter29h", 0xB9D>;
322 def: SysReg<"mhpmcounter30h", 0xB9E>;
323 def: SysReg<"mhpmcounter31h", 0xB9F>;
326 //===--------------------------
327 // Machine Counter Setup
328 //===--------------------------
329 let AltName = "mucounteren" in // Privileged spec v1.9.1 Name
330 def : SysReg<"mcountinhibit", 0x320>;
332 def : SysReg<"mhpmevent3", 0x323>;
333 def : SysReg<"mhpmevent4", 0x324>;
334 def : SysReg<"mhpmevent5", 0x325>;
335 def : SysReg<"mhpmevent6", 0x326>;
336 def : SysReg<"mhpmevent7", 0x327>;
337 def : SysReg<"mhpmevent8", 0x328>;
338 def : SysReg<"mhpmevent9", 0x329>;
339 def : SysReg<"mhpmevent10", 0x32A>;
340 def : SysReg<"mhpmevent11", 0x32B>;
341 def : SysReg<"mhpmevent12", 0x32C>;
342 def : SysReg<"mhpmevent13", 0x32D>;
343 def : SysReg<"mhpmevent14", 0x32E>;
344 def : SysReg<"mhpmevent15", 0x32F>;
345 def : SysReg<"mhpmevent16", 0x330>;
346 def : SysReg<"mhpmevent17", 0x331>;
347 def : SysReg<"mhpmevent18", 0x332>;
348 def : SysReg<"mhpmevent19", 0x333>;
349 def : SysReg<"mhpmevent20", 0x334>;
350 def : SysReg<"mhpmevent21", 0x335>;
351 def : SysReg<"mhpmevent22", 0x336>;
352 def : SysReg<"mhpmevent23", 0x337>;
353 def : SysReg<"mhpmevent24", 0x338>;
354 def : SysReg<"mhpmevent25", 0x339>;
355 def : SysReg<"mhpmevent26", 0x33A>;
356 def : SysReg<"mhpmevent27", 0x33B>;
357 def : SysReg<"mhpmevent28", 0x33C>;
358 def : SysReg<"mhpmevent29", 0x33D>;
359 def : SysReg<"mhpmevent30", 0x33E>;
360 def : SysReg<"mhpmevent31", 0x33F>;
362 //===-----------------------------------------------
363 // Debug/ Trace Registers (shared with Debug Mode)
364 //===-----------------------------------------------
365 def : SysReg<"tselect", 0x7A0>;
366 def : SysReg<"tdata1", 0x7A1>;
367 def : SysReg<"tdata2", 0x7A2>;
368 def : SysReg<"tdata3", 0x7A3>;
370 //===-----------------------------------------------
371 // Debug Mode Registers
372 //===-----------------------------------------------
373 def : SysReg<"dcsr", 0x7B0>;
374 def : SysReg<"dpc", 0x7B1>;
376 // "dscratch" is an alternative name for "dscratch0" which appeared in earlier
377 // drafts of the RISC-V debug spec
378 let AltName = "dscratch" in
379 def : SysReg<"dscratch0", 0x7B2>;
380 def : SysReg<"dscratch1", 0x7B3>;
382 //===-----------------------------------------------
384 //===-----------------------------------------------
385 def : SysReg<"vstart", 0x008>;
386 def : SysReg<"vxsat", 0x009>;
387 def : SysReg<"vxrm", 0x00A>;
388 def : SysReg<"vl", 0xC20>;
389 def : SysReg<"vtype", 0xC21>;
390 def : SysReg<"vlenb", 0xC22>;