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