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