1//===- RISCVSystemOperands.td ----------------------------*- tablegen -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the symbolic operands permitted for various kinds of
11// RISC-V system instruction.
12//
13//===----------------------------------------------------------------------===//
14
15include "llvm/TableGen/SearchableTable.td"
16
17//===----------------------------------------------------------------------===//
18// CSR (control and status register read/write) instruction options.
19//===----------------------------------------------------------------------===//
20
21class SysReg<string name, bits<12> op> {
22  string Name = name;
23  bits<12> Encoding = op;
24  // FIXME: add these additional fields when needed.
25  // Privilege Access: Read and Write = 0, 1, 2; Read-Only = 3.
26  // Privilege Mode: User = 0, System = 1 or Machine = 3.
27  // bits<2> ReadWrite = op{11 - 10};
28  // bits<2> XMode = op{9 - 8};
29  // Check Extra field name and what bits 7-6 correspond to.
30  // bits<2> Extra = op{7 - 6};
31  // Register number without the privilege bits.
32  // bits<6> Number = op{5 - 0};
33  code FeaturesRequired = [{ {} }];
34  bit isRV32Only = 0;
35}
36
37def SysRegsList : GenericTable {
38  let FilterClass = "SysReg";
39  // FIXME: add "ReadWrite", "Mode", "Extra", "Number" fields when needed.
40  let Fields = [ "Name", "Encoding", "FeaturesRequired", "isRV32Only" ];
41
42  let PrimaryKey = [ "Encoding" ];
43  let PrimaryKeyName = "lookupSysRegByEncoding";
44}
45
46def lookupSysRegByName : SearchIndex {
47  let Table = SysRegsList;
48  let Key = [ "Name" ];
49}
50
51// The following CSR encodings match those given in Tables 2.2,
52// 2.3, 2.4 and  2.5 in the RISC-V Instruction Set Manual
53// Volume II: Privileged Architecture.
54
55//===--------------------------
56// User Trap Setup
57//===--------------------------
58def : SysReg<"ustatus", 0x000>;
59def : SysReg<"uie", 0x004>;
60def : SysReg<"utvec", 0x005>;
61
62//===--------------------------
63// User Trap Handling
64//===--------------------------
65def : SysReg<"uscratch", 0x040>;
66def : SysReg<"uepc", 0x041>;
67def : SysReg<"ucause", 0x042>;
68def : SysReg<"utval", 0x043>;
69def : SysReg<"uip", 0x044>;
70
71//===--------------------------
72// User Floating-Point CSRs
73//===--------------------------
74
75let FeaturesRequired = [{ {RISCV::FeatureStdExtF} }] in {
76def : SysReg<"fflags", 0x001>;
77def : SysReg<"frm", 0x002>;
78def : SysReg<"fcsr", 0x003>;
79}
80
81//===--------------------------
82// User Counter/Timers
83//===--------------------------
84def : SysReg<"cycle", 0xC00>;
85def : SysReg<"time", 0xC01>;
86def : SysReg<"instret", 0xC02>;
87
88def : SysReg<"hpmcounter3", 0xC03>;
89def : SysReg<"hpmcounter4", 0xC04>;
90def : SysReg<"hpmcounter5", 0xC05>;
91def : SysReg<"hpmcounter6", 0xC06>;
92def : SysReg<"hpmcounter7", 0xC07>;
93def : SysReg<"hpmcounter8", 0xC08>;
94def : SysReg<"hpmcounter9", 0xC09>;
95def : SysReg<"hpmcounter10", 0xC0A>;
96def : SysReg<"hpmcounter11", 0xC0B>;
97def : SysReg<"hpmcounter12", 0xC0C>;
98def : SysReg<"hpmcounter13", 0xC0D>;
99def : SysReg<"hpmcounter14", 0xC0E>;
100def : SysReg<"hpmcounter15", 0xC0F>;
101def : SysReg<"hpmcounter16", 0xC10>;
102def : SysReg<"hpmcounter17", 0xC11>;
103def : SysReg<"hpmcounter18", 0xC12>;
104def : SysReg<"hpmcounter19", 0xC13>;
105def : SysReg<"hpmcounter20", 0xC14>;
106def : SysReg<"hpmcounter21", 0xC15>;
107def : SysReg<"hpmcounter22", 0xC16>;
108def : SysReg<"hpmcounter23", 0xC17>;
109def : SysReg<"hpmcounter24", 0xC18>;
110def : SysReg<"hpmcounter25", 0xC19>;
111def : SysReg<"hpmcounter26", 0xC1A>;
112def : SysReg<"hpmcounter27", 0xC1B>;
113def : SysReg<"hpmcounter28", 0xC1C>;
114def : SysReg<"hpmcounter29", 0xC1D>;
115def : SysReg<"hpmcounter30", 0xC1E>;
116def : SysReg<"hpmcounter31", 0xC1F>;
117
118let isRV32Only = 1 in {
119def: SysReg<"cycleh", 0xC80>;
120def: SysReg<"timeh", 0xC81>;
121def: SysReg<"instreth", 0xC82>;
122
123def: SysReg<"hpmcounter3h", 0xC83>;
124def: SysReg<"hpmcounter4h", 0xC84>;
125def: SysReg<"hpmcounter5h", 0xC85>;
126def: SysReg<"hpmcounter6h", 0xC86>;
127def: SysReg<"hpmcounter7h", 0xC87>;
128def: SysReg<"hpmcounter8h", 0xC88>;
129def: SysReg<"hpmcounter9h", 0xC89>;
130def: SysReg<"hpmcounter10h", 0xC8A>;
131def: SysReg<"hpmcounter11h", 0xC8B>;
132def: SysReg<"hpmcounter12h", 0xC8C>;
133def: SysReg<"hpmcounter13h", 0xC8D>;
134def: SysReg<"hpmcounter14h", 0xC8E>;
135def: SysReg<"hpmcounter15h", 0xC8F>;
136def: SysReg<"hpmcounter16h", 0xC90>;
137def: SysReg<"hpmcounter17h", 0xC91>;
138def: SysReg<"hpmcounter18h", 0xC92>;
139def: SysReg<"hpmcounter19h", 0xC93>;
140def: SysReg<"hpmcounter20h", 0xC94>;
141def: SysReg<"hpmcounter21h", 0xC95>;
142def: SysReg<"hpmcounter22h", 0xC96>;
143def: SysReg<"hpmcounter23h", 0xC97>;
144def: SysReg<"hpmcounter24h", 0xC98>;
145def: SysReg<"hpmcounter25h", 0xC99>;
146def: SysReg<"hpmcounter26h", 0xC9A>;
147def: SysReg<"hpmcounter27h", 0xC9B>;
148def: SysReg<"hpmcounter28h", 0xC9C>;
149def: SysReg<"hpmcounter29h", 0xC9D>;
150def: SysReg<"hpmcounter30h", 0xC9E>;
151def: SysReg<"hpmcounter31h", 0xC9F>;
152}
153
154//===--------------------------
155// Supervisor Trap Setup
156//===--------------------------
157def : SysReg<"sstatus", 0x100>;
158def : SysReg<"sedeleg", 0x102>;
159def : SysReg<"sideleg", 0x103>;
160def : SysReg<"sie", 0x104>;
161def : SysReg<"stvec", 0x105>;
162def : SysReg<"scounteren", 0x106>;
163
164//===--------------------------
165// Supervisor Trap Handling
166//===--------------------------
167def : SysReg<"sscratch", 0x140>;
168def : SysReg<"sepc", 0x141>;
169def : SysReg<"scause", 0x142>;
170def : SysReg<"stval", 0x143>;
171def : SysReg<"sip", 0x144>;
172
173//===-------------------------------------
174// Supervisor Protection and Translation
175//===-------------------------------------
176def : SysReg<"satp", 0x180>;
177
178//===-----------------------------
179// Machine Information Registers
180//===-----------------------------
181
182def : SysReg<"mvendorid", 0xF11>;
183def : SysReg<"marchid", 0xF12>;
184def : SysReg<"mimpid", 0xF13>;
185def : SysReg<"mhartid", 0xF14>;
186
187//===-----------------------------
188// Machine Trap Setup
189//===-----------------------------
190def : SysReg<"mstatus", 0x300>;
191def : SysReg<"misa", 0x301>;
192def : SysReg<"medeleg", 0x302>;
193def : SysReg<"mideleg", 0x303>;
194def : SysReg<"mie", 0x304>;
195def : SysReg<"mtvec", 0x305>;
196def : SysReg<"mcounteren", 0x306>;
197
198//===-----------------------------
199// Machine Trap Handling
200//===-----------------------------
201def : SysReg<"mscratch", 0x340>;
202def : SysReg<"mepc", 0x341>;
203def : SysReg<"mcause", 0x342>;
204def : SysReg<"mtval", 0x343>;
205def : SysReg<"mip", 0x344>;
206
207//===----------------------------------
208// Machine Protection and Translation
209//===----------------------------------
210def : SysReg<"pmpcfg0", 0x3A0>;
211def : SysReg<"pmpcfg2", 0x3A2>;
212let isRV32Only = 1 in {
213def : SysReg<"pmpcfg1", 0x3A1>;
214def : SysReg<"pmpcfg3", 0x3A3>;
215}
216
217def : SysReg<"pmpaddr0", 0x3B0>;
218def : SysReg<"pmpaddr1", 0x3B1>;
219def : SysReg<"pmpaddr2", 0x3B2>;
220def : SysReg<"pmpaddr3", 0x3B3>;
221def : SysReg<"pmpaddr4", 0x3B4>;
222def : SysReg<"pmpaddr5", 0x3B5>;
223def : SysReg<"pmpaddr6", 0x3B6>;
224def : SysReg<"pmpaddr7", 0x3B7>;
225def : SysReg<"pmpaddr8", 0x3B8>;
226def : SysReg<"pmpaddr9", 0x3B9>;
227def : SysReg<"pmpaddr10", 0x3BA>;
228def : SysReg<"pmpaddr11", 0x3BB>;
229def : SysReg<"pmpaddr12", 0x3BC>;
230def : SysReg<"pmpaddr13", 0x3BD>;
231def : SysReg<"pmpaddr14", 0x3BE>;
232def : SysReg<"pmpaddr15", 0x3BF>;
233
234
235//===--------------------------
236// Machine Counter and Timers
237//===--------------------------
238def : SysReg<"mcycle", 0xB00>;
239def : SysReg<"minstret", 0xB02>;
240
241def : SysReg<"mhpmcounter3", 0xB03>;
242def : SysReg<"mhpmcounter4", 0xB04>;
243def : SysReg<"mhpmcounter5", 0xB05>;
244def : SysReg<"mhpmcounter6", 0xB06>;
245def : SysReg<"mhpmcounter7", 0xB07>;
246def : SysReg<"mhpmcounter8", 0xB08>;
247def : SysReg<"mhpmcounter9", 0xB09>;
248def : SysReg<"mhpmcounter10", 0xB0A>;
249def : SysReg<"mhpmcounter11", 0xB0B>;
250def : SysReg<"mhpmcounter12", 0xB0C>;
251def : SysReg<"mhpmcounter13", 0xB0D>;
252def : SysReg<"mhpmcounter14", 0xB0E>;
253def : SysReg<"mhpmcounter15", 0xB0F>;
254def : SysReg<"mhpmcounter16", 0xB10>;
255def : SysReg<"mhpmcounter17", 0xB11>;
256def : SysReg<"mhpmcounter18", 0xB12>;
257def : SysReg<"mhpmcounter19", 0xB13>;
258def : SysReg<"mhpmcounter20", 0xB14>;
259def : SysReg<"mhpmcounter21", 0xB15>;
260def : SysReg<"mhpmcounter22", 0xB16>;
261def : SysReg<"mhpmcounter23", 0xB17>;
262def : SysReg<"mhpmcounter24", 0xB18>;
263def : SysReg<"mhpmcounter25", 0xB19>;
264def : SysReg<"mhpmcounter26", 0xB1A>;
265def : SysReg<"mhpmcounter27", 0xB1B>;
266def : SysReg<"mhpmcounter28", 0xB1C>;
267def : SysReg<"mhpmcounter29", 0xB1D>;
268def : SysReg<"mhpmcounter30", 0xB1E>;
269def : SysReg<"mhpmcounter31", 0xB1F>;
270
271let isRV32Only = 1 in {
272def: SysReg<"mcycleh", 0xB80>;
273def: SysReg<"minstreth", 0xB82>;
274
275def: SysReg<"mhpmcounter3h", 0xB83>;
276def: SysReg<"mhpmcounter4h", 0xB84>;
277def: SysReg<"mhpmcounter5h", 0xB85>;
278def: SysReg<"mhpmcounter6h", 0xB86>;
279def: SysReg<"mhpmcounter7h", 0xB87>;
280def: SysReg<"mhpmcounter8h", 0xB88>;
281def: SysReg<"mhpmcounter9h", 0xB89>;
282def: SysReg<"mhpmcounter10h", 0xB8A>;
283def: SysReg<"mhpmcounter11h", 0xB8B>;
284def: SysReg<"mhpmcounter12h", 0xB8C>;
285def: SysReg<"mhpmcounter13h", 0xB8D>;
286def: SysReg<"mhpmcounter14h", 0xB8E>;
287def: SysReg<"mhpmcounter15h", 0xB8F>;
288def: SysReg<"mhpmcounter16h", 0xB90>;
289def: SysReg<"mhpmcounter17h", 0xB91>;
290def: SysReg<"mhpmcounter18h", 0xB92>;
291def: SysReg<"mhpmcounter19h", 0xB93>;
292def: SysReg<"mhpmcounter20h", 0xB94>;
293def: SysReg<"mhpmcounter21h", 0xB95>;
294def: SysReg<"mhpmcounter22h", 0xB96>;
295def: SysReg<"mhpmcounter23h", 0xB97>;
296def: SysReg<"mhpmcounter24h", 0xB98>;
297def: SysReg<"mhpmcounter25h", 0xB99>;
298def: SysReg<"mhpmcounter26h", 0xB9A>;
299def: SysReg<"mhpmcounter27h", 0xB9B>;
300def: SysReg<"mhpmcounter28h", 0xB9C>;
301def: SysReg<"mhpmcounter29h", 0xB9D>;
302def: SysReg<"mhpmcounter30h", 0xB9E>;
303def: SysReg<"mhpmcounter31h", 0xB9F>;
304}
305
306//===--------------------------
307// Machine Counter Setup
308//===--------------------------
309def : SysReg<"mhpmevent3", 0x323>;
310def : SysReg<"mhpmevent4", 0x324>;
311def : SysReg<"mhpmevent5", 0x325>;
312def : SysReg<"mhpmevent6", 0x326>;
313def : SysReg<"mhpmevent7", 0x327>;
314def : SysReg<"mhpmevent8", 0x328>;
315def : SysReg<"mhpmevent9", 0x329>;
316def : SysReg<"mhpmevent10", 0x32A>;
317def : SysReg<"mhpmevent11", 0x32B>;
318def : SysReg<"mhpmevent12", 0x32C>;
319def : SysReg<"mhpmevent13", 0x32D>;
320def : SysReg<"mhpmevent14", 0x32E>;
321def : SysReg<"mhpmevent15", 0x32F>;
322def : SysReg<"mhpmevent16", 0x330>;
323def : SysReg<"mhpmevent17", 0x331>;
324def : SysReg<"mhpmevent18", 0x332>;
325def : SysReg<"mhpmevent19", 0x333>;
326def : SysReg<"mhpmevent20", 0x334>;
327def : SysReg<"mhpmevent21", 0x335>;
328def : SysReg<"mhpmevent22", 0x336>;
329def : SysReg<"mhpmevent23", 0x337>;
330def : SysReg<"mhpmevent24", 0x338>;
331def : SysReg<"mhpmevent25", 0x339>;
332def : SysReg<"mhpmevent26", 0x33A>;
333def : SysReg<"mhpmevent27", 0x33B>;
334def : SysReg<"mhpmevent28", 0x33C>;
335def : SysReg<"mhpmevent29", 0x33D>;
336def : SysReg<"mhpmevent30", 0x33E>;
337def : SysReg<"mhpmevent31", 0x33F>;
338
339//===-----------------------------------------------
340// Debug/ Trace Registers (shared with Debug Mode)
341//===-----------------------------------------------
342def : SysReg<"tselect", 0x7A0>;
343def : SysReg<"tdata1", 0x7A1>;
344def : SysReg<"tdata2", 0x7A2>;
345def : SysReg<"tdata3", 0x7A3>;
346
347//===-----------------------------------------------
348// Debug Mode Registers
349//===-----------------------------------------------
350def : SysReg<"dcsr", 0x7B0>;
351def : SysReg<"dpc", 0x7B1>;
352def : SysReg<"dscratch", 0x7B2>;
353