nios2.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #ifndef __NIOS2_H__
  2. #define __NIOS2_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. ******************************************************************************/
  32. /*
  33. * This header provides processor specific macros for accessing the Nios2
  34. * control registers.
  35. */
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif /* __cplusplus */
  40. /*
  41. * Number of available IRQs in internal interrupt controller.
  42. */
  43. #define NIOS2_NIRQ 32
  44. /*
  45. * Macros for accessing select Nios II general-purpose registers.
  46. */
  47. /* ET (Exception Temporary) register */
  48. #define NIOS2_READ_ET(et) \
  49. do { __asm ("mov %0, et" : "=r" (et) ); } while (0)
  50. #define NIOS2_WRITE_ET(et) \
  51. do { __asm volatile ("mov et, %z0" : : "rM" (et)); } while (0)
  52. /* SP (Stack Pointer) register */
  53. #define NIOS2_READ_SP(sp) \
  54. do { __asm ("mov %0, sp" : "=r" (sp) ); } while (0)
  55. /*
  56. * Macros for useful processor instructions.
  57. */
  58. #define NIOS2_BREAK() \
  59. do { __asm volatile ("break"); } while (0)
  60. #define NIOS2_REPORT_STACK_OVERFLOW() \
  61. do { __asm volatile("break 3"); } while (0)
  62. /*
  63. * Macros for accessing Nios II control registers.
  64. */
  65. #define NIOS2_READ_STATUS(dest) \
  66. do { dest = __builtin_rdctl(0); } while (0)
  67. #define NIOS2_WRITE_STATUS(src) \
  68. do { __builtin_wrctl(0, src); } while (0)
  69. #define NIOS2_READ_ESTATUS(dest) \
  70. do { dest = __builtin_rdctl(1); } while (0)
  71. #define NIOS2_READ_BSTATUS(dest) \
  72. do { dest = __builtin_rdctl(2); } while (0)
  73. #define NIOS2_READ_IENABLE(dest) \
  74. do { dest = __builtin_rdctl(3); } while (0)
  75. #define NIOS2_WRITE_IENABLE(src) \
  76. do { __builtin_wrctl(3, src); } while (0)
  77. #define NIOS2_READ_IPENDING(dest) \
  78. do { dest = __builtin_rdctl(4); } while (0)
  79. #define NIOS2_READ_CPUID(dest) \
  80. do { dest = __builtin_rdctl(5); } while (0)
  81. #define NIOS2_READ_EXCEPTION(dest) \
  82. do { dest = __builtin_rdctl(7); } while (0)
  83. #define NIOS2_READ_PTEADDR(dest) \
  84. do { dest = __builtin_rdctl(8); } while (0)
  85. #define NIOS2_WRITE_PTEADDR(src) \
  86. do { __builtin_wrctl(8, src); } while (0)
  87. #define NIOS2_READ_TLBACC(dest) \
  88. do { dest = __builtin_rdctl(9); } while (0)
  89. #define NIOS2_WRITE_TLBACC(src) \
  90. do { __builtin_wrctl(9, src); } while (0)
  91. #define NIOS2_READ_TLBMISC(dest) \
  92. do { dest = __builtin_rdctl(10); } while (0)
  93. #define NIOS2_WRITE_TLBMISC(src) \
  94. do { __builtin_wrctl(10, src); } while (0)
  95. #define NIOS2_READ_ECCINJ(dest) \
  96. do { dest = __builtin_rdctl(11); } while (0)
  97. #define NIOS2_WRITE_ECCINJ(src) \
  98. do { __builtin_wrctl(11, src); } while (0)
  99. #define NIOS2_READ_BADADDR(dest) \
  100. do { dest = __builtin_rdctl(12); } while (0)
  101. #define NIOS2_WRITE_CONFIG(src) \
  102. do { __builtin_wrctl(13, src); } while (0)
  103. #define NIOS2_READ_CONFIG(dest) \
  104. do { dest = __builtin_rdctl(13); } while (0)
  105. #define NIOS2_WRITE_MPUBASE(src) \
  106. do { __builtin_wrctl(14, src); } while (0)
  107. #define NIOS2_READ_MPUBASE(dest) \
  108. do { dest = __builtin_rdctl(14); } while (0)
  109. #define NIOS2_WRITE_MPUACC(src) \
  110. do { __builtin_wrctl(15, src); } while (0)
  111. #define NIOS2_READ_MPUACC(dest) \
  112. do { dest = __builtin_rdctl(15); } while (0)
  113. /*
  114. * Nios II control registers that are always present
  115. */
  116. #define NIOS2_STATUS status
  117. #define NIOS2_ESTATUS estatus
  118. #define NIOS2_BSTATUS bstatus
  119. #define NIOS2_IENABLE ienable
  120. #define NIOS2_IPENDING ipending
  121. #define NIOS2_CPUID cpuid
  122. /*
  123. * Bit masks & offsets for Nios II control registers.
  124. * The presence and size of a field is sometimes dependent on the Nios II
  125. * configuration. Bit masks for every possible field and the maximum size of
  126. * that field are defined.
  127. *
  128. * All bit-masks are expressed relative to the position
  129. * of the data with a register. To read data that is LSB-
  130. * aligned, the register read data should be masked, then
  131. * right-shifted by the designated "OFST" macro value. The
  132. * opposite should be used for register writes when starting
  133. * with LSB-aligned data.
  134. */
  135. /* STATUS, ESTATUS, BSTATUS, and SSTATUS registers */
  136. #define NIOS2_STATUS_PIE_MSK (0x00000001)
  137. #define NIOS2_STATUS_PIE_OFST (0)
  138. #define NIOS2_STATUS_U_MSK (0x00000002)
  139. #define NIOS2_STATUS_U_OFST (1)
  140. #define NIOS2_STATUS_EH_MSK (0x00000004)
  141. #define NIOS2_STATUS_EH_OFST (2)
  142. #define NIOS2_STATUS_IH_MSK (0x00000008)
  143. #define NIOS2_STATUS_IH_OFST (3)
  144. #define NIOS2_STATUS_IL_MSK (0x000003f0)
  145. #define NIOS2_STATUS_IL_OFST (4)
  146. #define NIOS2_STATUS_CRS_MSK (0x0000fc00)
  147. #define NIOS2_STATUS_CRS_OFST (10)
  148. #define NIOS2_STATUS_PRS_MSK (0x003f0000)
  149. #define NIOS2_STATUS_PRS_OFST (16)
  150. #define NIOS2_STATUS_NMI_MSK (0x00400000)
  151. #define NIOS2_STATUS_NMI_OFST (22)
  152. #define NIOS2_STATUS_RSIE_MSK (0x00800000)
  153. #define NIOS2_STATUS_RSIE_OFST (23)
  154. #define NIOS2_STATUS_SRS_MSK (0x80000000)
  155. #define NIOS2_STATUS_SRS_OFST (31)
  156. /* EXCEPTION register */
  157. #define NIOS2_EXCEPTION_REG_CAUSE_MASK (0x0000007c)
  158. #define NIOS2_EXCEPTION_REG_CAUSE_OFST (2)
  159. #define NIOS2_EXCEPTION_REG_ECCFTL_MASK (0x80000000)
  160. #define NIOS2_EXCEPTION_REG_ECCFTL_OFST (31)
  161. /* PTEADDR (Page Table Entry Address) register */
  162. #define NIOS2_PTEADDR_REG_VPN_OFST 2
  163. #define NIOS2_PTEADDR_REG_VPN_MASK 0x3ffffc
  164. #define NIOS2_PTEADDR_REG_PTBASE_OFST 22
  165. #define NIOS2_PTEADDR_REG_PTBASE_MASK 0xffc00000
  166. /* TLBACC (TLB Access) register */
  167. #define NIOS2_TLBACC_REG_PFN_OFST 0
  168. #define NIOS2_TLBACC_REG_PFN_MASK 0xfffff
  169. #define NIOS2_TLBACC_REG_G_OFST 20
  170. #define NIOS2_TLBACC_REG_G_MASK 0x100000
  171. #define NIOS2_TLBACC_REG_X_OFST 21
  172. #define NIOS2_TLBACC_REG_X_MASK 0x200000
  173. #define NIOS2_TLBACC_REG_W_OFST 22
  174. #define NIOS2_TLBACC_REG_W_MASK 0x400000
  175. #define NIOS2_TLBACC_REG_R_OFST 23
  176. #define NIOS2_TLBACC_REG_R_MASK 0x800000
  177. #define NIOS2_TLBACC_REG_C_OFST 24
  178. #define NIOS2_TLBACC_REG_C_MASK 0x1000000
  179. #define NIOS2_TLBACC_REG_IG_OFST 25
  180. #define NIOS2_TLBACC_REG_IG_MASK 0xfe000000
  181. /* TLBMISC (TLB Miscellaneous) register */
  182. #define NIOS2_TLBMISC_REG_D_OFST 0
  183. #define NIOS2_TLBMISC_REG_D_MASK 0x1
  184. #define NIOS2_TLBMISC_REG_PERM_OFST 1
  185. #define NIOS2_TLBMISC_REG_PERM_MASK 0x2
  186. #define NIOS2_TLBMISC_REG_BAD_OFST 2
  187. #define NIOS2_TLBMISC_REG_BAD_MASK 0x4
  188. #define NIOS2_TLBMISC_REG_DBL_OFST 3
  189. #define NIOS2_TLBMISC_REG_DBL_MASK 0x8
  190. #define NIOS2_TLBMISC_REG_PID_OFST 4
  191. #define NIOS2_TLBMISC_REG_PID_MASK 0x3fff0
  192. #define NIOS2_TLBMISC_REG_WE_OFST 18
  193. #define NIOS2_TLBMISC_REG_WE_MASK 0x40000
  194. #define NIOS2_TLBMISC_REG_RD_OFST 19
  195. #define NIOS2_TLBMISC_REG_RD_MASK 0x80000
  196. #define NIOS2_TLBMISC_REG_WAY_OFST 20
  197. #define NIOS2_TLBMISC_REG_WAY_MASK 0xf00000
  198. #define NIOS2_TLBMISC_REG_EE_OFST 24
  199. #define NIOS2_TLBMISC_REG_EE_MASK 0x1000000
  200. /* ECCINJ (ECC Inject) register */
  201. #define NIOS2_ECCINJ_REG_RF_OFST 0
  202. #define NIOS2_ECCINJ_REG_RF_MASK 0x3
  203. #define NIOS2_ECCINJ_REG_ICTAG_OFST 2
  204. #define NIOS2_ECCINJ_REG_ICTAG_MASK 0xc
  205. #define NIOS2_ECCINJ_REG_ICDAT_OFST 4
  206. #define NIOS2_ECCINJ_REG_ICDAT_MASK 0x30
  207. #define NIOS2_ECCINJ_REG_DCTAG_OFST 6
  208. #define NIOS2_ECCINJ_REG_DCTAG_MASK 0xc0
  209. #define NIOS2_ECCINJ_REG_DCDAT_OFST 8
  210. #define NIOS2_ECCINJ_REG_DCDAT_MASK 0x300
  211. #define NIOS2_ECCINJ_REG_TLB_OFST 10
  212. #define NIOS2_ECCINJ_REG_TLB_MASK 0xc00
  213. #define NIOS2_ECCINJ_REG_DTCM0_OFST 12
  214. #define NIOS2_ECCINJ_REG_DTCM0_MASK 0x3000
  215. #define NIOS2_ECCINJ_REG_DTCM1_OFST 14
  216. #define NIOS2_ECCINJ_REG_DTCM1_MASK 0xc000
  217. #define NIOS2_ECCINJ_REG_DTCM2_OFST 16
  218. #define NIOS2_ECCINJ_REG_DTCM2_MASK 0x30000
  219. #define NIOS2_ECCINJ_REG_DTCM3_OFST 18
  220. #define NIOS2_ECCINJ_REG_DTCM3_MASK 0xc0000
  221. /* CONFIG register */
  222. #define NIOS2_CONFIG_REG_PE_MASK (0x00000001)
  223. #define NIOS2_CONFIG_REG_PE_OFST (0)
  224. #define NIOS2_CONFIG_REG_ANI_MASK (0x00000002)
  225. #define NIOS2_CONFIG_REG_ANI_OFST (1)
  226. #define NIOS2_CONFIG_REG_ECCEN_MASK (0x00000004)
  227. #define NIOS2_CONFIG_REG_ECCEN_OFST (2)
  228. #define NIOS2_CONFIG_REG_ECCEXC_MASK (0x00000008)
  229. #define NIOS2_CONFIG_REG_ECCEXC_OFST (3)
  230. /* MPUBASE (MPU Base Address) Register */
  231. #define NIOS2_MPUBASE_D_MASK (0x00000001)
  232. #define NIOS2_MPUBASE_D_OFST (0)
  233. #define NIOS2_MPUBASE_INDEX_MASK (0x0000003e)
  234. #define NIOS2_MPUBASE_INDEX_OFST (1)
  235. #define NIOS2_MPUBASE_BASE_ADDR_MASK (0xffffffc0)
  236. #define NIOS2_MPUBASE_BASE_ADDR_OFST (6)
  237. /* MPUACC (MPU Access) Register */
  238. #define NIOS2_MPUACC_LIMIT_MASK (0xffffffc0)
  239. #define NIOS2_MPUACC_LIMIT_OFST (6)
  240. #define NIOS2_MPUACC_MASK_MASK (0xffffffc0)
  241. #define NIOS2_MPUACC_MASK_OFST (6)
  242. #define NIOS2_MPUACC_C_MASK (0x00000020)
  243. #define NIOS2_MPUACC_C_OFST (5)
  244. #define NIOS2_MPUACC_PERM_MASK (0x0000001c)
  245. #define NIOS2_MPUACC_PERM_OFST (2)
  246. #define NIOS2_MPUACC_RD_MASK (0x00000002)
  247. #define NIOS2_MPUACC_RD_OFST (1)
  248. #define NIOS2_MPUACC_WR_MASK (0x00000001)
  249. #define NIOS2_MPUACC_WR_OFST (0)
  250. #ifdef __cplusplus
  251. }
  252. #endif /* __cplusplus */
  253. #endif /* __NIOS2_H__ */