RISCVSystemOperands.td 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. include "llvm/TableGen/SearchableTable.td"
  14. //===----------------------------------------------------------------------===//
  15. // CSR (control and status register read/write) instruction options.
  16. //===----------------------------------------------------------------------===//
  17. class SysReg<string name, bits<12> op> {
  18. string Name = name;
  19. // A maximum of one alias is supported right now.
  20. string AltName = name;
  21. // A maximum of one deprecated name is supported right now. Unlike the
  22. // `AltName` alias, a `DeprecatedName` generates a diagnostic when the name is
  23. // used to encourage software to migrate away from the name.
  24. string DeprecatedName = "";
  25. bits<12> Encoding = op;
  26. // FIXME: add these additional fields when needed.
  27. // Privilege Access: Read and Write = 0, 1, 2; Read-Only = 3.
  28. // Privilege Mode: User = 0, System = 1 or Machine = 3.
  29. // bits<2> ReadWrite = op{11 - 10};
  30. // bits<2> XMode = op{9 - 8};
  31. // Check Extra field name and what bits 7-6 correspond to.
  32. // bits<2> Extra = op{7 - 6};
  33. // Register number without the privilege bits.
  34. // bits<6> Number = op{5 - 0};
  35. code FeaturesRequired = [{ {} }];
  36. bit isRV32Only = 0;
  37. }
  38. def SysRegsList : GenericTable {
  39. let FilterClass = "SysReg";
  40. // FIXME: add "ReadWrite", "Mode", "Extra", "Number" fields when needed.
  41. let Fields = [
  42. "Name", "AltName", "DeprecatedName", "Encoding", "FeaturesRequired",
  43. "isRV32Only",
  44. ];
  45. let PrimaryKey = [ "Encoding" ];
  46. let PrimaryKeyName = "lookupSysRegByEncoding";
  47. }
  48. def lookupSysRegByName : SearchIndex {
  49. let Table = SysRegsList;
  50. let Key = [ "Name" ];
  51. }
  52. def lookupSysRegByAltName : SearchIndex {
  53. let Table = SysRegsList;
  54. let Key = [ "AltName" ];
  55. }
  56. def lookupSysRegByDeprecatedName : SearchIndex {
  57. let Table = SysRegsList;
  58. let Key = [ "DeprecatedName" ];
  59. }
  60. // The following CSR encodings match those given in Tables 2.2,
  61. // 2.3, 2.4 and 2.5 in the RISC-V Instruction Set Manual
  62. // Volume II: Privileged Architecture.
  63. //===----------------------------------------------------------------------===//
  64. // User Trap Setup
  65. //===----------------------------------------------------------------------===//
  66. def : SysReg<"ustatus", 0x000>;
  67. def : SysReg<"uie", 0x004>;
  68. def : SysReg<"utvec", 0x005>;
  69. //===----------------------------------------------------------------------===//
  70. // User Trap Handling
  71. //===----------------------------------------------------------------------===//
  72. def : SysReg<"uscratch", 0x040>;
  73. def : SysReg<"uepc", 0x041>;
  74. def : SysReg<"ucause", 0x042>;
  75. let DeprecatedName = "ubadaddr" in
  76. def : SysReg<"utval", 0x043>;
  77. def : SysReg<"uip", 0x044>;
  78. //===----------------------------------------------------------------------===//
  79. // User Floating-Point CSRs
  80. //===----------------------------------------------------------------------===//
  81. def SysRegFFLAGS : SysReg<"fflags", 0x001>;
  82. def SysRegFRM : SysReg<"frm", 0x002>;
  83. def SysRegFCSR : SysReg<"fcsr", 0x003>;
  84. //===----------------------------------------------------------------------===//
  85. // User Counter/Timers
  86. //===----------------------------------------------------------------------===//
  87. def CYCLE : SysReg<"cycle", 0xC00>;
  88. def TIME : SysReg<"time", 0xC01>;
  89. def INSTRET : SysReg<"instret", 0xC02>;
  90. // hpmcounter3-hpmcounter31 at 0xC03-0xC1F.
  91. foreach i = 3...31 in
  92. def : SysReg<"hpmcounter"#i, !add(0xC03, !sub(i, 3))>;
  93. let isRV32Only = 1 in {
  94. def CYCLEH : SysReg<"cycleh", 0xC80>;
  95. def TIMEH : SysReg<"timeh", 0xC81>;
  96. def INSTRETH : SysReg<"instreth", 0xC82>;
  97. // hpmcounter3h-hpmcounter31h at 0xC83-0xC9F.
  98. foreach i = 3...31 in
  99. def : SysReg<"hpmcounter"#i#"h", !add(0xC83, !sub(i, 3))>;
  100. }
  101. //===----------------------------------------------------------------------===//
  102. // Supervisor Trap Setup
  103. //===----------------------------------------------------------------------===//
  104. def : SysReg<"sstatus", 0x100>;
  105. def : SysReg<"sedeleg", 0x102>;
  106. def : SysReg<"sideleg", 0x103>;
  107. def : SysReg<"sie", 0x104>;
  108. def : SysReg<"stvec", 0x105>;
  109. def : SysReg<"scounteren", 0x106>;
  110. def : SysReg<"stimecmp", 0x14D>;
  111. let isRV32Only = 1 in
  112. def : SysReg<"stimecmph", 0x15D>;
  113. //===----------------------------------------------------------------------===//
  114. // Supervisor Configuration
  115. //===----------------------------------------------------------------------===//
  116. def : SysReg<"senvcfg", 0x10A>;
  117. //===----------------------------------------------------------------------===//
  118. // Supervisor Trap Handling
  119. //===----------------------------------------------------------------------===//
  120. def : SysReg<"sscratch", 0x140>;
  121. def : SysReg<"sepc", 0x141>;
  122. def : SysReg<"scause", 0x142>;
  123. let DeprecatedName = "sbadaddr" in
  124. def : SysReg<"stval", 0x143>;
  125. def : SysReg<"sip", 0x144>;
  126. //===----------------------------------------------------------------------===//
  127. // Supervisor Protection and Translation
  128. //===----------------------------------------------------------------------===//
  129. let DeprecatedName = "sptbr" in
  130. def : SysReg<"satp", 0x180>;
  131. //===----------------------------------------------------------------------===//
  132. // Debug/Trace Registers
  133. //===----------------------------------------------------------------------===//
  134. def : SysReg<"scontext", 0x5A8>;
  135. //===----------------------------------------------------------------------===//
  136. // Supervisor Count Overflow (defined in Sscofpmf)
  137. //===----------------------------------------------------------------------===//
  138. def : SysReg<"scountovf", 0xDA0>;
  139. //===----------------------------------------------------------------------===//
  140. // Hypervisor Trap Setup
  141. //===----------------------------------------------------------------------===//
  142. def : SysReg<"hstatus", 0x600>;
  143. def : SysReg<"hedeleg", 0x602>;
  144. def : SysReg<"hideleg", 0x603>;
  145. def : SysReg<"hie", 0x604>;
  146. def : SysReg<"hcounteren", 0x606>;
  147. def : SysReg<"hgeie", 0x607>;
  148. //===----------------------------------------------------------------------===//
  149. // Hypervisor Trap Handling
  150. //===----------------------------------------------------------------------===//
  151. def : SysReg<"htval", 0x643>;
  152. def : SysReg<"hip", 0x644>;
  153. def : SysReg<"hvip", 0x645>;
  154. def : SysReg<"htinst", 0x64A>;
  155. def : SysReg<"hgeip", 0xE12>;
  156. //===----------------------------------------------------------------------===//
  157. // Hypervisor Configuration
  158. //===----------------------------------------------------------------------===//
  159. def : SysReg<"henvcfg", 0x60A>;
  160. let isRV32Only = 1 in
  161. def : SysReg<"henvcfgh", 0x61A>;
  162. //===----------------------------------------------------------------------===//
  163. // Hypervisor Protection and Translation
  164. //===----------------------------------------------------------------------===//
  165. def : SysReg<"hgatp", 0x680>;
  166. //===----------------------------------------------------------------------===//
  167. // Debug/Trace Registers
  168. //===----------------------------------------------------------------------===//
  169. def : SysReg<"hcontext", 0x6A8>;
  170. //===----------------------------------------------------------------------===//
  171. // Hypervisor Counter/Timer Virtualization Registers
  172. //===----------------------------------------------------------------------===//
  173. def : SysReg<"htimedelta", 0x605>;
  174. let isRV32Only = 1 in
  175. def : SysReg<"htimedeltah", 0x615>;
  176. //===----------------------------------------------------------------------===//
  177. // Virtual Supervisor Registers
  178. //===----------------------------------------------------------------------===//
  179. def : SysReg<"vsstatus", 0x200>;
  180. def : SysReg<"vsie", 0x204>;
  181. def : SysReg<"vstvec", 0x205>;
  182. def : SysReg<"vsscratch", 0x240>;
  183. def : SysReg<"vsepc", 0x241>;
  184. def : SysReg<"vscause", 0x242>;
  185. def : SysReg<"vstval", 0x243>;
  186. def : SysReg<"vsip", 0x244>;
  187. def : SysReg<"vstimecmp", 0x24D>;
  188. let isRV32Only = 1 in
  189. def : SysReg<"vstimecmph", 0x25D>;
  190. def : SysReg<"vsatp", 0x280>;
  191. //===----------------------------------------------------------------------===//
  192. // Machine Information Registers
  193. //===----------------------------------------------------------------------===//
  194. def : SysReg<"mvendorid", 0xF11>;
  195. def : SysReg<"marchid", 0xF12>;
  196. def : SysReg<"mimpid", 0xF13>;
  197. def : SysReg<"mhartid", 0xF14>;
  198. def : SysReg<"mconfigptr", 0xF15>;
  199. //===----------------------------------------------------------------------===//
  200. // Machine Trap Setup
  201. //===----------------------------------------------------------------------===//
  202. def : SysReg<"mstatus", 0x300>;
  203. def : SysReg<"misa", 0x301>;
  204. def : SysReg<"medeleg", 0x302>;
  205. def : SysReg<"mideleg", 0x303>;
  206. def : SysReg<"mie", 0x304>;
  207. def : SysReg<"mtvec", 0x305>;
  208. def : SysReg<"mcounteren", 0x306>;
  209. let isRV32Only = 1 in
  210. def : SysReg<"mstatush", 0x310>;
  211. //===----------------------------------------------------------------------===//
  212. // Machine Trap Handling
  213. //===----------------------------------------------------------------------===//
  214. def : SysReg<"mscratch", 0x340>;
  215. def : SysReg<"mepc", 0x341>;
  216. def : SysReg<"mcause", 0x342>;
  217. let DeprecatedName = "mbadaddr" in
  218. def : SysReg<"mtval", 0x343>;
  219. def : SysReg<"mip", 0x344>;
  220. def : SysReg<"mtinst", 0x34A>;
  221. def : SysReg<"mtval2", 0x34B>;
  222. //===----------------------------------------------------------------------===//
  223. // Machine Configuration
  224. //===----------------------------------------------------------------------===//
  225. def : SysReg<"menvcfg", 0x30A>;
  226. let isRV32Only = 1 in
  227. def : SysReg<"menvcfgh", 0x31A>;
  228. def : SysReg<"mseccfg", 0x747>;
  229. let isRV32Only = 1 in
  230. def : SysReg<"mseccfgh", 0x757>;
  231. //===----------------------------------------------------------------------===//
  232. // Machine Protection and Translation
  233. //===----------------------------------------------------------------------===//
  234. // pmpcfg0-pmpcfg15 at 0x3A0-0x3AF. Odd-numbered registers are RV32-only.
  235. foreach i = 0...15 in {
  236. let isRV32Only = !and(i, 1) in
  237. def : SysReg<"pmpcfg"#i, !add(0x3A0, i)>;
  238. }
  239. // pmpaddr0-pmpaddr63 at 0x3B0-0x3EF.
  240. foreach i = 0...63 in
  241. def : SysReg<"pmpaddr"#i, !add(0x3B0, i)>;
  242. //===----------------------------------------------------------------------===//
  243. // Machine Counter and Timers
  244. //===----------------------------------------------------------------------===//
  245. def : SysReg<"mcycle", 0xB00>;
  246. def : SysReg<"minstret", 0xB02>;
  247. // mhpmcounter3-mhpmcounter31 at 0xB03-0xB1F.
  248. foreach i = 3...31 in
  249. def : SysReg<"mhpmcounter"#i, !add(0xB03, !sub(i, 3))>;
  250. let isRV32Only = 1 in {
  251. def: SysReg<"mcycleh", 0xB80>;
  252. def: SysReg<"minstreth", 0xB82>;
  253. // mhpmcounter3h-mhpmcounter31h at 0xB83-0xB9F.
  254. foreach i = 3...31 in
  255. def : SysReg<"mhpmcounter"#i#"h", !add(0xB83, !sub(i, 3))>;
  256. }
  257. //===----------------------------------------------------------------------===//
  258. // Machine Counter Setup
  259. //===----------------------------------------------------------------------===//
  260. let AltName = "mucounteren" in // Privileged spec v1.9.1 Name
  261. def : SysReg<"mcountinhibit", 0x320>;
  262. // mhpmevent3-mhpmevent31 at 0x323-0x33F.
  263. foreach i = 3...31 in
  264. def : SysReg<"mhpmevent"#i, !add(0x323, !sub(i, 3))>;
  265. // mhpmevent3h-mhpmevent31h at 0x723-0x73F
  266. foreach i = 3...31 in {
  267. let isRV32Only = 1 in
  268. def : SysReg<"mhpmevent"#i#"h", !add(0x723, !sub(i, 3))>;
  269. }
  270. //===----------------------------------------------------------------------===//
  271. // Debug/ Trace Registers (shared with Debug Mode)
  272. //===----------------------------------------------------------------------===//
  273. def : SysReg<"tselect", 0x7A0>;
  274. def : SysReg<"tdata1", 0x7A1>;
  275. def : SysReg<"tdata2", 0x7A2>;
  276. def : SysReg<"tdata3", 0x7A3>;
  277. def : SysReg<"mcontext", 0x7A8>;
  278. //===----------------------------------------------------------------------===//
  279. // Debug Mode Registers
  280. //===----------------------------------------------------------------------===//
  281. def : SysReg<"dcsr", 0x7B0>;
  282. def : SysReg<"dpc", 0x7B1>;
  283. // "dscratch" is an alternative name for "dscratch0" which appeared in earlier
  284. // drafts of the RISC-V debug spec
  285. let AltName = "dscratch" in
  286. def : SysReg<"dscratch0", 0x7B2>;
  287. def : SysReg<"dscratch1", 0x7B3>;
  288. //===----------------------------------------------------------------------===//
  289. // User Vector CSRs
  290. //===----------------------------------------------------------------------===//
  291. def : SysReg<"vstart", 0x008>;
  292. def : SysReg<"vxsat", 0x009>;
  293. def : SysReg<"vxrm", 0x00A>;
  294. def : SysReg<"vcsr", 0x00F>;
  295. def : SysReg<"vl", 0xC20>;
  296. def : SysReg<"vtype", 0xC21>;
  297. def SysRegVLENB: SysReg<"vlenb", 0xC22>;
  298. //===----------------------------------------------------------------------===//
  299. // State Enable Extension (Smstateen)
  300. //===----------------------------------------------------------------------===//
  301. // sstateen0-sstateen3 at 0x10C-0x10F, mstateen0-mstateen3 at 0x30C-0x30F,
  302. // mstateen0h-mstateen3h at 0x31C-0x31F, hstateen0-hstateen3 at 0x60C-0x60F,
  303. // and hstateen0h-hstateen3h at 0x61C-0x61F.
  304. foreach i = 0...3 in {
  305. def : SysReg<"sstateen"#i, !add(0x10C, i)>;
  306. def : SysReg<"mstateen"#i, !add(0x30C, i)>;
  307. let isRV32Only = 1 in
  308. def : SysReg<"mstateen"#i#"h", !add(0x31C, i)>;
  309. def : SysReg<"hstateen"#i, !add(0x60C, i)>;
  310. let isRV32Only = 1 in
  311. def : SysReg<"hstateen"#i#"h", !add(0x61C, i)>;
  312. }
  313. //===-----------------------------------------------
  314. // Entropy Source CSR
  315. //===-----------------------------------------------
  316. def SEED : SysReg<"seed", 0x015>;