spr.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /****************************************************************************
  2. * arch/or1k/include/spr.h
  3. *
  4. * Copyright (C) 2018 Extent3D. All rights reserved.
  5. * Author: Matt Thompson <matt@extent3d.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __ARCH_OR1K_INCLUDE_SPR_H
  36. #define __ARCH_OR1K_INCLUDE_SPR_H
  37. /****************************************************************************
  38. * Pre-processor Definitions
  39. ****************************************************************************/
  40. /* Move a register to an SPR */
  41. #define mtspr(_spr, _val) __asm__ __volatile__ ( \
  42. "l.mtspr r0,%1,%0" \
  43. : : "K" (_spr), "r" (_val))
  44. /* Move an SPR into a register */
  45. #define mfspr(_spr, _val) __asm__ __volatile__ ( \
  46. "l.mfspr %0,r0,%1" \
  47. : "=r" (_val) : "K" (_spr))
  48. /* Special Purpose Registers
  49. *
  50. * A 16-bit SPR address is comprised of a 5-bit group index and an
  51. * 11-bit register index
  52. *
  53. */
  54. #define SPR_GROUP_SHIFT (11)
  55. #define SPR_GROUP_MASK (0x1f << SPR_GROUP_SHIFT)
  56. /* Group index definitions.
  57. * OpenRISC 1000 Architecture Manual Table 4-1
  58. */
  59. #define SPR_GROUP_SYS (0 << SPR_GROUP_SHIFT)
  60. #define SPR_GROUP_DMMU (1 << SPR_GROUP_SHIFT)
  61. #define SPR_GROUP_IMMU (2 << SPR_GROUP_SHIFT)
  62. #define SPR_GROUP_DCACHE (3 << SPR_GROUP_SHIFT)
  63. #define SPR_GROUP_ICACHE (4 << SPR_GROUP_SHIFT)
  64. #define SPR_GROUP_MAC (5 << SPR_GROUP_SHIFT)
  65. #define SPR_GROUP_DEBUG (6 << SPR_GROUP_SHIFT)
  66. #define SPR_GROUP_PERF (7 << SPR_GROUP_SHIFT)
  67. #define SPR_GROUP_PM (8 << SPR_GROUP_SHIFT)
  68. #define SPR_GROUP_PIC (9 << SPR_GROUP_SHIFT)
  69. #define SPR_GROUP_TICK (10 << SPR_GROUP_SHIFT)
  70. #define SPR_GROUP_FPU (11 << SPR_GROUP_SHIFT)
  71. /* System Group Registers */
  72. #define SPR_SYS_VR (SPR_GROUP_SYS | 0) /* Version Register */
  73. #define SPR_SYS_UPR (SPR_GROUP_SYS | 1) /* Unit Present Register */
  74. #define SPR_SYS_CPUCFGR (SPR_GROUP_SYS | 2) /* CPU Configuration */
  75. #define SPR_SYS_DMMUCFGR (SPR_GROUP_SYS | 3) /* Data MMU Configuration */
  76. #define SPR_SYS_IMMUCFGR (SPR_GROUP_SYS | 4) /* Instruction MMU Config */
  77. #define SPR_SYS_DCCFGR (SPR_GROUP_SYS | 5) /* Data Cache Configuration */
  78. #define SPR_SYS_ICCFGR (SPR_GROUP_SYS | 6) /* Instruction Cache Config */
  79. #define SPR_SYS_DCFGR (SPR_GROUP_SYS | 7) /* Debug Configuration */
  80. #define SPR_SYS_PCCFGR (SPR_GROUP_SYS | 8) /* Performance Counter Config */
  81. #define SPR_SYS_VR2 (SPR_GROUP_SYS | 9) /* Version Register 2 */
  82. #define SPR_SYS_AVR (SPR_GROUP_SYS | 10) /* Architecture Version */
  83. #define SPR_SYS_EVBAR (SPR_GROUP_SYS | 11) /* Exception vector base */
  84. #define SPR_SYS_AECR (SPR_GROUP_SYS | 12) /* Arithmetic exception control */
  85. #define SPR_SYS_AESR (SPR_GROUP_SYS | 13) /* Arithmetic exception status */
  86. #define SPR_SYS_NPC (SPR_GROUP_SYS | 16) /* PC mapped to SPR - next PC */
  87. #define SPR_SYS_SR (SPR_GROUP_SYS | 17) /* Supervision register */
  88. #define SPR_SYS_PPC (SPR_GROUP_SYS | 18) /* PC mapped to SPR space */
  89. #define SPR_SYS_FPCSR (SPR_GROUP_SYS | 20) /* FP Control Status */
  90. #define SPR_SYS_ISR0 (SPR_GROUP_SYS | 21) /* Implementation specific */
  91. #define SPR_SYS_ISR1 (SPR_GROUP_SYS | 22) /* Implementation specific */
  92. #define SPR_SYS_ISR2 (SPR_GROUP_SYS | 23) /* Implementation specific */
  93. #define SPR_SYS_ISR3 (SPR_GROUP_SYS | 24) /* Implementation specific */
  94. #define SPR_SYS_ISR4 (SPR_GROUP_SYS | 25) /* Implementation specific */
  95. #define SPR_SYS_ISR5 (SPR_GROUP_SYS | 26) /* Implementation specific */
  96. #define SPR_SYS_ISR6 (SPR_GROUP_SYS | 27) /* Implementation specific */
  97. #define SPR_SYS_ISR7 (SPR_GROUP_SYS | 28) /* Implementation specific */
  98. #define SPR_SYS_EPCR0 (SPR_GROUP_SYS | 32) /* Exception PC register */
  99. #define SPR_SYS_EPCR1 (SPR_GROUP_SYS | 33) /* Exception PC register */
  100. #define SPR_SYS_EPCR2 (SPR_GROUP_SYS | 34) /* Exception PC register */
  101. #define SPR_SYS_EPCR3 (SPR_GROUP_SYS | 35) /* Exception PC register */
  102. #define SPR_SYS_EPCR4 (SPR_GROUP_SYS | 36) /* Exception PC register */
  103. #define SPR_SYS_EPCR5 (SPR_GROUP_SYS | 37) /* Exception PC register */
  104. #define SPR_SYS_EPCR6 (SPR_GROUP_SYS | 38) /* Exception PC register */
  105. #define SPR_SYS_EPCR7 (SPR_GROUP_SYS | 39) /* Exception PC register */
  106. #define SPR_SYS_EPCR8 (SPR_GROUP_SYS | 40) /* Exception PC register */
  107. #define SPR_SYS_EPCR9 (SPR_GROUP_SYS | 41) /* Exception PC register */
  108. #define SPR_SYS_EPCR10 (SPR_GROUP_SYS | 42) /* Exception PC register */
  109. #define SPR_SYS_EPCR11 (SPR_GROUP_SYS | 43) /* Exception PC register */
  110. #define SPR_SYS_EPCR12 (SPR_GROUP_SYS | 44) /* Exception PC register */
  111. #define SPR_SYS_EPCR13 (SPR_GROUP_SYS | 45) /* Exception PC register */
  112. #define SPR_SYS_EPCR14 (SPR_GROUP_SYS | 46) /* Exception PC register */
  113. #define SPR_SYS_EPCR15 (SPR_GROUP_SYS | 47) /* Exception PC register */
  114. #define SPR_SYS_EEAR0 (SPR_GROUP_SYS | 48) /* Exception EA register */
  115. #define SPR_SYS_EEAR1 (SPR_GROUP_SYS | 49) /* Exception EA register */
  116. #define SPR_SYS_EEAR2 (SPR_GROUP_SYS | 50) /* Exception EA register */
  117. #define SPR_SYS_EEAR3 (SPR_GROUP_SYS | 51) /* Exception EA register */
  118. #define SPR_SYS_EEAR4 (SPR_GROUP_SYS | 52) /* Exception EA register */
  119. #define SPR_SYS_EEAR5 (SPR_GROUP_SYS | 53) /* Exception EA register */
  120. #define SPR_SYS_EEAR6 (SPR_GROUP_SYS | 54) /* Exception EA register */
  121. #define SPR_SYS_EEAR7 (SPR_GROUP_SYS | 55) /* Exception EA register */
  122. #define SPR_SYS_EEAR8 (SPR_GROUP_SYS | 56) /* Exception EA register */
  123. #define SPR_SYS_EEAR9 (SPR_GROUP_SYS | 57) /* Exception EA register */
  124. #define SPR_SYS_EEAR10 (SPR_GROUP_SYS | 58) /* Exception EA register */
  125. #define SPR_SYS_EEAR11 (SPR_GROUP_SYS | 59) /* Exception EA register */
  126. #define SPR_SYS_EEAR12 (SPR_GROUP_SYS | 60) /* Exception EA register */
  127. #define SPR_SYS_EEAR13 (SPR_GROUP_SYS | 61) /* Exception EA register */
  128. #define SPR_SYS_EEAR14 (SPR_GROUP_SYS | 62) /* Exception EA register */
  129. #define SPR_SYS_EEAR15 (SPR_GROUP_SYS | 63) /* Exception EA register */
  130. #define SPR_SYS_ESR0 (SPR_GROUP_SYS | 64) /* Exception SR register */
  131. #define SPR_SYS_ESR1 (SPR_GROUP_SYS | 65) /* Exception SR register */
  132. #define SPR_SYS_ESR2 (SPR_GROUP_SYS | 66) /* Exception SR register */
  133. #define SPR_SYS_ESR3 (SPR_GROUP_SYS | 67) /* Exception SR register */
  134. #define SPR_SYS_ESR4 (SPR_GROUP_SYS | 68) /* Exception SR register */
  135. #define SPR_SYS_ESR5 (SPR_GROUP_SYS | 69) /* Exception SR register */
  136. #define SPR_SYS_ESR6 (SPR_GROUP_SYS | 70) /* Exception SR register */
  137. #define SPR_SYS_ESR7 (SPR_GROUP_SYS | 71) /* Exception SR register */
  138. #define SPR_SYS_ESR8 (SPR_GROUP_SYS | 72) /* Exception SR register */
  139. #define SPR_SYS_ESR9 (SPR_GROUP_SYS | 73) /* Exception SR register */
  140. #define SPR_SYS_ESR10 (SPR_GROUP_SYS | 74) /* Exception SR register */
  141. #define SPR_SYS_ESR11 (SPR_GROUP_SYS | 75) /* Exception SR register */
  142. #define SPR_SYS_ESR12 (SPR_GROUP_SYS | 76) /* Exception SR register */
  143. #define SPR_SYS_ESR13 (SPR_GROUP_SYS | 77) /* Exception SR register */
  144. #define SPR_SYS_ESR14 (SPR_GROUP_SYS | 78) /* Exception SR register */
  145. #define SPR_SYS_ESR15 (SPR_GROUP_SYS | 79) /* Exception SR register */
  146. #define SPR_SYS_COREID (SPR_GROUP_SYS | 128) /* Core Identifier */
  147. #define SPR_SYS_NUMCORES (SPR_GROUP_SYS | 129) /* Number of cores */
  148. #define SPR_SYS_GPR(n) (SPR_GROUP_SYS | 1024+(n)) /* GPRs mapped to SPR */
  149. /* Data MMU Group Registers */
  150. #define SPR_DMMU_CR (SPR_GROUP_DMMU | 0) /* DMMU Control Register */
  151. #define SPR_DMMU_PR (SPR_GROUP_DMMU | 1) /* DMMU Protection Register */
  152. #define SPR_DMMU_DTLBEIR (SPR_GROUP_DMMU | 2) /* TLB invalidate register */
  153. #define SPR_DMMU_DATBMR0 (SPR_GROUP_DMMU | 4) /* Data ATB match register */
  154. #define SPR_DMMU_DATBMR1 (SPR_GROUP_DMMU | 5) /* Data ATB match register */
  155. #define SPR_DMMU_DATBMR2 (SPR_GROUP_DMMU | 6) /* Data ATB match register */
  156. #define SPR_DMMU_DATBMR3 (SPR_GROUP_DMMU | 7) /* Data ATB match register */
  157. /* DCACHE Group Registers */
  158. #define SPR_DCACHE_CR (SPR_GROUP_DCACHE | 0)
  159. #define SPR_DCACHE_BPR (SPR_GROUP_DCACHE | 1)
  160. #define SPR_DCACHE_BFR (SPR_GROUP_DCACHE | 2)
  161. #define SPR_DCACHE_BIR (SPR_GROUP_DCACHE | 3)
  162. #define SPR_DCACHE_BWR (SPR_GROUP_DCACHE | 4)
  163. #define SPR_DCACHE_BLR (SPR_GROUP_DCACHE | 5)
  164. /* ICACHE Group Registers */
  165. #define SPR_ICACHE_CR (SPR_GROUP_DCACHE | 0)
  166. #define SPR_ICACHE_BPR (SPR_GROUP_DCACHE | 1)
  167. #define SPR_ICACHE_BIR (SPR_GROUP_DCACHE | 2)
  168. #define SPR_ICACHE_BLR (SPR_GROUP_DCACHE | 3)
  169. /* Programmable Interrupt Controller */
  170. #define SPR_PIC_MR (SPR_GROUP_PIC | 0) /* PIC Mask Register */
  171. #define SPR_PIC_SR (SPR_GROUP_PIC | 2) /* PIC Status Register */
  172. /* Tick Timer Group Registers */
  173. #define SPR_TICK_TTMR (SPR_GROUP_TICK | 0) /* Tick Timer Mode Register */
  174. #define SPR_TICK_TTCR (SPR_GROUP_TICK | 1) /* Tick Timer Count Register */
  175. /* Version Register Bits */
  176. #define SPR_VR_REV_SHIFT (0)
  177. #define SPR_VR_REV_MASK (0x3f << SPR_VR_REV_SHIFT) /* CPU Revision */
  178. #define SPR_VR_UVRP (1 << 6) /* VR2 Register Present */
  179. #define SPR_VR_CFG_SHIFT (16)
  180. #define SPR_VR_CFG_MASK (0xff << SPR_VR_CFG_SHIFT) /* Configuration Template */
  181. #define SPR_VR_VER_SHIFT (24)
  182. #define SPR_VR_VER_MASK (0xff << SPR_VR_VER_SHIFT) /* CPU Version */
  183. /* VR2 Register Bits */
  184. #define SPR_VR2_VER_SHIFT (0)
  185. #define SPR_VR2_VER_MASK (0xfffff << SPR_VR2_VER_SHIFT)
  186. #define SPR_VR2_CPUID_SHIFT (24)
  187. #define SPR_VR2_CPUID_MASK (0xff << SPR_VR2_CPUID_SHIFT)
  188. /* Unit Present Register Bits */
  189. #define SPR_UPR_UP (1 << 0) /* UPR present */
  190. #define SPR_UPR_DCP (1 << 1) /* Data Cache present */
  191. #define SPR_UPR_ICP (1 << 2) /* Instruction Cache present */
  192. #define SPR_UPR_DMP (1 << 3) /* Data MMU present */
  193. #define SPR_UPR_IMP (1 << 4) /* Instruction MMU present */
  194. #define SPR_UPR_MP (1 << 5) /* MAC present */
  195. #define SPR_UPR_DUP (1 << 6) /* Debug unit present */
  196. #define SPR_UPR_PCUP (1 << 7) /* Performance counters present */
  197. #define SPR_UPR_PICP (1 << 8) /* Interrupt controller present */
  198. #define SPR_UPR_PMP (1 << 9) /* Power Management present */
  199. #define SPR_UPR_TTP (1 << 10) /* Tick timer present */
  200. #define SPR_UPR_CUP_SHIFT (24)
  201. #define SPR_UPR_CUP_MASK (0xff << SPR_UPR_CUP_SHIFT) /* Context units present mask */
  202. /* CPU Configuration Register Bits */
  203. #define SPR_CPUCFGR_NSGF_SHIFT (0)
  204. #define SPR_CPUCFGR_NSGF_MASK (0xf << SPR_CPUCFGR_NSGF_SHIFT)
  205. #define SPR_CPUCFGR_CGF (1 << 4)
  206. #define SPR_CPUCFGR_OB32S (1 << 5) /* ORBIS32 Supported */
  207. #define SPR_CPUCFGR_OB64S (1 << 6) /* ORBIS64 Supported */
  208. #define SPR_CPUCFGR_OF32S (1 << 7) /* ORFPX32 Supported */
  209. #define SPR_CPUCFGR_OF64S (1 << 8) /* ORFPX64 Supported */
  210. #define SPR_CPUCFGR_OV64S (1 << 9) /* ORVDX64 Supported */
  211. #define SPR_CPUCFGR_ND (1 << 10) /* No delay slot */
  212. #define SPR_CPUCFGR_AVRP (1 << 11) /* Arch Version Register present */
  213. #define SPR_CPUCFGR_EVBARP (1 << 12) /* Exception Vector Base Addr */
  214. #define SPR_CPUCFGR_ISRP (1 << 13) /* Implementation specific present */
  215. #define SPR_CPUCFGR_AECSRP (1 << 14) /* Arithmetic Exception Status present */
  216. /* DMMU Register Bits */
  217. /* IMMU Register Bits */
  218. /* Data Cache Configurtion Register Bits */
  219. #define SPR_DCCFGR_NCW_SHIFT (0)
  220. #define SPR_DCCFGR_NCW_MASK (0x7 << SPR_DCCFGR_NCW_SHIFT)
  221. #define SPR_DCCFGR_NCS_SHIFT (3)
  222. #define SPR_DCCFGR_NCS_MASK (0xf << SPR_DCCFGR_NCS_SHIFT)
  223. #define SPR_DCCFGR_CBS (1 << 7)
  224. #define SPR_DCCFGR_CWS (1 << 8)
  225. #define SPR_DCCFGR_CCRI (1 << 9)
  226. #define SPR_DCCFGR_CBIRI (1 << 10)
  227. #define SPR_DCCFGR_CBPRI (1 << 11)
  228. #define SPR_DCCFGR_CBLRI (1 << 12)
  229. #define SPR_DCCFGR_CBFRI (1 << 13)
  230. #define SPR_DCCFGR_CBWBRI (1 << 14)
  231. /* Instruction Cache Configuration Register Bits */
  232. #define SPR_ICCFGR_NCW_SHIFT (0)
  233. #define SPR_ICCFGR_NCW_MASK (0x7 << SPR_ICCFGR_NCW_SHIFT)
  234. #define SPR_ICCFGR_NCS_SHIFT (3)
  235. #define SPR_ICCFGR_NCS_MASK (0xf << SPR_ICCFGR_NCS_SHIFT)
  236. #define SPR_ICCFGR_CBS (1 << 7)
  237. #define SPR_ICCFGR_CCRI (1 << 9)
  238. #define SPR_ICCFGR_CBIRI (1 << 10)
  239. #define SPR_ICCFGR_CBPRI (1 << 11)
  240. #define SPR_ICCFGR_CBLRI (1 << 12)
  241. /* Supervision Register Bits */
  242. #define SPR_SR_SM 0x00000001 /* Supervisor Mode */
  243. #define SPR_SR_TEE 0x00000002 /* Tick timer Exception Enable */
  244. #define SPR_SR_IEE 0x00000004 /* Interrupt Exception Enable */
  245. #define SPR_SR_DCE 0x00000008 /* Data Cache Enable */
  246. #define SPR_SR_ICE 0x00000010 /* Instruction Cache Enable */
  247. #define SPR_SR_DME 0x00000020 /* Data MMU Enable */
  248. #define SPR_SR_IME 0x00000040 /* Instruction MMU Enable */
  249. #define SPR_SR_LEE 0x00000080 /* Little Endian Enable */
  250. #define SPR_SR_CE 0x00000100 /* CID Enable */
  251. #define SPR_SR_F 0x00000200 /* Condition Flag */
  252. #define SPR_SR_CY 0x00000400 /* Carry flag */
  253. #define SPR_SR_OV 0x00000800 /* Overflow flag */
  254. #define SPR_SR_OVE 0x00001000 /* Overflow flag Exception */
  255. #define SPR_SR_DSX 0x00002000 /* Delay Slot Exception */
  256. #define SPR_SR_EPH 0x00004000 /* Exception Prefix High */
  257. #define SPR_SR_FO 0x00008000 /* Fixed one */
  258. #define SPR_SR_SUMRA 0x00010000 /* Supervisor SPR read access */
  259. #define SPR_SR_RES 0x0ffe0000 /* Reserved */
  260. #define SPR_SR_CID 0xf0000000 /* Context ID */
  261. #define SPR_TTMR_TP_MASK (0xFFFFFFF)
  262. #define SPR_TTMR_IP (1<<28)
  263. #define SPR_TTMR_IE (1<<29)
  264. #define SPR_TTMR_M (1<<30)
  265. #endif /* __ARCH_OR1K_INCLUDE_SPR_H */