mips_regs.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*
  2. * File : mips_regs.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2016年9月7日 Urey the first version
  23. */
  24. #ifndef _MIPS_REGS_H_
  25. #define _MIPS_REGS_H_
  26. #if !defined(__ASSEMBLY__) && !defined(ASSEMBLY)
  27. #include <rtdef.h>
  28. #define MIPS_REG_NR 32
  29. typedef struct {
  30. rt_uint32_t regs[MIPS_REG_NR]; /* 32 个通用目的寄存器 */
  31. rt_uint32_t CP0Status; /* CP0 协处理器状态寄存器 */
  32. rt_uint32_t CP0DataHI; /* 除数高位寄存器 */
  33. rt_uint32_t CP0DataLO; /* 除数低位寄存器 */
  34. rt_uint32_t CP0BadVAddr; /* 出错地址寄存器 */
  35. rt_uint32_t CP0Cause; /* 产生中断或者异常查看的寄存器*/
  36. rt_uint32_t CP0EPC; /* 程序计数器寄存器 */
  37. } mips_reg_ctx;
  38. #define MIPS_ARG_REG_NR 4
  39. typedef struct
  40. {
  41. rt_uint32_t args[MIPS_ARG_REG_NR]; /* 4 个参数寄存器 */
  42. } mips_arg_ctx;
  43. struct linkctx
  44. {
  45. rt_uint32_t id;
  46. struct linkctx *next;
  47. };
  48. struct fpctx
  49. {
  50. struct linkctx link;
  51. rt_uint32_t fcsr;
  52. rt_uint32_t reserved;
  53. };
  54. struct fp32ctx
  55. {
  56. struct fpctx fp;
  57. union
  58. {
  59. double d[16]; /* even doubles */
  60. float s[32]; /* even singles, padded */
  61. };
  62. };
  63. struct fp64ctx
  64. {
  65. struct fpctx fp;
  66. union
  67. {
  68. double d[32]; /* even doubles, followed by odd doubles */
  69. float s[64]; /* even singles, followed by odd singles, padded */
  70. };
  71. };
  72. #endif /* !defined(__ASSEMBLY__) && !defined(ASSEMBLY) */
  73. #define MIPS_STK_CTX_WORD_SIZE 38
  74. #define SZREG 4
  75. /*********************************************************************************************************
  76. MIPS 的寄存器索引
  77. *********************************************************************************************************/
  78. #define REG_ZERO 0 /* wired zero */
  79. #define REG_AT 1 /* assembler temp */
  80. #define REG_V0 2 /* return reg 0 */
  81. #define REG_V1 3 /* return reg 1 */
  82. #define REG_A0 4 /* arg reg 0 */
  83. #define REG_A1 5 /* arg reg 1 */
  84. #define REG_A2 6 /* arg reg 2 */
  85. #define REG_A3 7 /* arg reg 3 */
  86. #define REG_T0 8 /* caller saved 0 */
  87. #define REG_T1 9 /* caller saved 1 */
  88. #define REG_T2 10 /* caller saved 2 */
  89. #define REG_T3 11 /* caller saved 3 */
  90. #define REG_T4 12 /* caller saved 4 */
  91. #define REG_T5 13 /* caller saved 5 */
  92. #define REG_T6 14 /* caller saved 6 */
  93. #define REG_T7 15 /* caller saved 7 */
  94. #define REG_S0 16 /* callee saved 0 */
  95. #define REG_S1 17 /* callee saved 1 */
  96. #define REG_S2 18 /* callee saved 2 */
  97. #define REG_S3 19 /* callee saved 3 */
  98. #define REG_S4 20 /* callee saved 4 */
  99. #define REG_S5 21 /* callee saved 5 */
  100. #define REG_S6 22 /* callee saved 6 */
  101. #define REG_S7 23 /* callee saved 7 */
  102. #define REG_T8 24 /* caller saved 8 */
  103. #define REG_T9 25 /* caller saved 9 */
  104. #define REG_K0 26 /* kernel temp 0 */
  105. #define REG_K1 27 /* kernel temp 1 */
  106. #define REG_GP 28 /* global pointer */
  107. #define REG_SP 29 /* stack pointer */
  108. #define REG_S8 30 /* callee saved 8 */
  109. #define REG_FP REG_S8 /* callee saved 8 */
  110. #define REG_RA 31 /* return address */
  111. #define STK_CTX_SIZE (MIPS_STK_CTX_WORD_SIZE * SZREG)
  112. #define STK_OFFSET_SR ((32 + 0) * SZREG)
  113. #define STK_OFFSET_HI ((32 + 1) * SZREG)
  114. #define STK_OFFSET_LO ((32 + 2) * SZREG)
  115. #define STK_OFFSET_BADVADDR ((32 + 3) * SZREG)
  116. #define STK_OFFSET_CAUSE ((32 + 4) * SZREG)
  117. #define STK_OFFSET_EPC ((32 + 5) * SZREG)
  118. #define STK_OFFSET_LAST ((MIPS_STK_CTX_WORD_SIZE - 1) * SZREG)
  119. #define FP32CTX_CSR ((SZREG)*2)
  120. #define FP64CTX_CSR ((SZREG)*2)
  121. #define LINKCTX_ID ((SZREG)*0)
  122. #define LINKCTX_NEXT ((SZREG)*1)
  123. #define LINKCTX_TYPE_MSA 0x004D5341
  124. #define LINKCTX_TYPE_FP32 0x46503332
  125. #define LINKCTX_TYPE_FP64 0x46503634
  126. #define LINKCTX_TYPE_FMSA 0x463D5341
  127. #define LINKCTX_TYPE_DSP 0x00445350
  128. #define LINKCTX_TYPE_STKSWP 0x53574150
  129. #define LINKCTX_TYPE_XPA 0x00585041
  130. #define FP32CTX_0 ((SZREG)*4)
  131. #define FP32CTX_2 (FP32CTX_0 + (1 * 8))
  132. #define FP32CTX_4 (FP32CTX_0 + (2 * 8))
  133. #define FP32CTX_6 (FP32CTX_0 + (3 * 8))
  134. #define FP32CTX_8 (FP32CTX_0 + (4 * 8))
  135. #define FP32CTX_10 (FP32CTX_0 + (5 * 8))
  136. #define FP32CTX_12 (FP32CTX_0 + (6 * 8))
  137. #define FP32CTX_14 (FP32CTX_0 + (7 * 8))
  138. #define FP32CTX_16 (FP32CTX_0 + (8 * 8))
  139. #define FP32CTX_18 (FP32CTX_0 + (9 * 8))
  140. #define FP32CTX_20 (FP32CTX_0 + (10 * 8))
  141. #define FP32CTX_22 (FP32CTX_0 + (11 * 8))
  142. #define FP32CTX_24 (FP32CTX_0 + (12 * 8))
  143. #define FP32CTX_26 (FP32CTX_0 + (13 * 8))
  144. #define FP32CTX_28 (FP32CTX_0 + (14 * 8))
  145. #define FP32CTX_30 (FP32CTX_0 + (15 * 8))
  146. #define FP32CTX_SIZE (FP32CTX_30 + (17 * 8))
  147. #define FP64CTX_0 ((SZREG)*4)
  148. #define FP64CTX_2 (FP64CTX_0 + (1 * 8))
  149. #define FP64CTX_4 (FP64CTX_0 + (2 * 8))
  150. #define FP64CTX_6 (FP64CTX_0 + (3 * 8))
  151. #define FP64CTX_8 (FP64CTX_0 + (4 * 8))
  152. #define FP64CTX_10 (FP64CTX_0 + (5 * 8))
  153. #define FP64CTX_12 (FP64CTX_0 + (6 * 8))
  154. #define FP64CTX_14 (FP64CTX_0 + (7 * 8))
  155. #define FP64CTX_16 (FP64CTX_0 + (8 * 8))
  156. #define FP64CTX_18 (FP64CTX_0 + (9 * 8))
  157. #define FP64CTX_20 (FP64CTX_0 + (10 * 8))
  158. #define FP64CTX_22 (FP64CTX_0 + (11 * 8))
  159. #define FP64CTX_24 (FP64CTX_0 + (12 * 8))
  160. #define FP64CTX_26 (FP64CTX_0 + (13 * 8))
  161. #define FP64CTX_28 (FP64CTX_0 + (14 * 8))
  162. #define FP64CTX_30 (FP64CTX_0 + (15 * 8))
  163. #define FP64CTX_1 (FP64CTX_30 + (1 * 8))
  164. #define FP64CTX_3 (FP64CTX_30 + (2 * 8))
  165. #define FP64CTX_5 (FP64CTX_30 + (3 * 8))
  166. #define FP64CTX_7 (FP64CTX_30 + (4 * 8))
  167. #define FP64CTX_9 (FP64CTX_30 + (5 * 8))
  168. #define FP64CTX_11 (FP64CTX_30 + (6 * 8))
  169. #define FP64CTX_13 (FP64CTX_30 + (7 * 8))
  170. #define FP64CTX_15 (FP64CTX_30 + (8 * 8))
  171. #define FP64CTX_17 (FP64CTX_30 + (9 * 8))
  172. #define FP64CTX_19 (FP64CTX_30 + (10 * 8))
  173. #define FP64CTX_21 (FP64CTX_30 + (11 * 8))
  174. #define FP64CTX_23 (FP64CTX_30 + (12 * 8))
  175. #define FP64CTX_25 (FP64CTX_30 + (13 * 8))
  176. #define FP64CTX_27 (FP64CTX_30 + (14 * 8))
  177. #define FP64CTX_29 (FP64CTX_30 + (15 * 8))
  178. #define FP64CTX_31 (FP64CTX_30 + (16 * 8))
  179. #define FP64CTX_SIZE (FP64CTX_31 + (17 * 8))
  180. #define FPCTX_SIZE() (mips_getsr() & ST0_FR ? FP64CTX_SIZE : FP32CTX_SIZE)
  181. /*
  182. * The following macros are especially useful for __asm__
  183. * inline assembler.
  184. */
  185. #ifndef __STR
  186. #define __STR(x) #x
  187. #endif
  188. #ifndef STR
  189. #define STR(x) __STR(x)
  190. #endif
  191. /*
  192. * Configure language
  193. */
  194. #ifdef __ASSEMBLY__
  195. #define _ULCAST_
  196. #else
  197. #define _ULCAST_ (unsigned long)
  198. #endif
  199. /*
  200. * Coprocessor 0 register names
  201. */
  202. #define CP0_INDEX $0
  203. #define CP0_RANDOM $1
  204. #define CP0_ENTRYLO0 $2
  205. #define CP0_ENTRYLO1 $3
  206. #define CP0_CONF $3
  207. #define CP0_CONTEXT $4
  208. #define CP0_PAGEMASK $5
  209. #define CP0_WIRED $6
  210. #define CP0_INFO $7
  211. #define CP0_BADVADDR $8
  212. #define CP0_COUNT $9
  213. #define CP0_ENTRYHI $10
  214. #define CP0_COMPARE $11
  215. #define CP0_STATUS $12
  216. #define CP0_CAUSE $13
  217. #define CP0_EPC $14
  218. #define CP0_PRID $15
  219. #define CP0_CONFIG $16
  220. #define CP0_LLADDR $17
  221. #define CP0_WATCHLO $18
  222. #define CP0_WATCHHI $19
  223. #define CP0_XCONTEXT $20
  224. #define CP0_FRAMEMASK $21
  225. #define CP0_DIAGNOSTIC $22
  226. #define CP0_DEBUG $23
  227. #define CP0_DEPC $24
  228. #define CP0_PERFORMANCE $25
  229. #define CP0_ECC $26
  230. #define CP0_CACHEERR $27
  231. #define CP0_TAGLO $28
  232. #define CP0_TAGHI $29
  233. #define CP0_ERROREPC $30
  234. #define CP0_DESAVE $31
  235. /*
  236. * R4640/R4650 cp0 register names. These registers are listed
  237. * here only for completeness; without MMU these CPUs are not useable
  238. * by Linux. A future ELKS port might take make Linux run on them
  239. * though ...
  240. */
  241. #define CP0_IBASE $0
  242. #define CP0_IBOUND $1
  243. #define CP0_DBASE $2
  244. #define CP0_DBOUND $3
  245. #define CP0_CALG $17
  246. #define CP0_IWATCH $18
  247. #define CP0_DWATCH $19
  248. /*
  249. * Coprocessor 0 Set 1 register names
  250. */
  251. #define CP0_S1_DERRADDR0 $26
  252. #define CP0_S1_DERRADDR1 $27
  253. #define CP0_S1_INTCONTROL $20
  254. /*
  255. * TX39 Series
  256. */
  257. #define CP0_TX39_CACHE $7
  258. /*
  259. * Coprocessor 1 (FPU) register names
  260. */
  261. #define CP1_REVISION $0
  262. #define CP1_STATUS $31
  263. /*
  264. * FPU Status Register Values
  265. */
  266. /*
  267. * Status Register Values
  268. */
  269. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  270. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  271. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  272. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  273. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  274. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  275. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  276. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  277. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  278. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  279. /*
  280. * X the exception cause indicator
  281. * E the exception enable
  282. * S the sticky/flag bit
  283. */
  284. #define FPU_CSR_ALL_X 0x0003f000
  285. #define FPU_CSR_UNI_X 0x00020000
  286. #define FPU_CSR_INV_X 0x00010000
  287. #define FPU_CSR_DIV_X 0x00008000
  288. #define FPU_CSR_OVF_X 0x00004000
  289. #define FPU_CSR_UDF_X 0x00002000
  290. #define FPU_CSR_INE_X 0x00001000
  291. #define FPU_CSR_ALL_E 0x00000f80
  292. #define FPU_CSR_INV_E 0x00000800
  293. #define FPU_CSR_DIV_E 0x00000400
  294. #define FPU_CSR_OVF_E 0x00000200
  295. #define FPU_CSR_UDF_E 0x00000100
  296. #define FPU_CSR_INE_E 0x00000080
  297. #define FPU_CSR_ALL_S 0x0000007c
  298. #define FPU_CSR_INV_S 0x00000040
  299. #define FPU_CSR_DIV_S 0x00000020
  300. #define FPU_CSR_OVF_S 0x00000010
  301. #define FPU_CSR_UDF_S 0x00000008
  302. #define FPU_CSR_INE_S 0x00000004
  303. /* rounding mode */
  304. #define FPU_CSR_RN 0x0 /* nearest */
  305. #define FPU_CSR_RZ 0x1 /* towards zero */
  306. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  307. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  308. /*
  309. * Values for PageMask register
  310. */
  311. #ifdef CONFIG_CPU_VR41XX
  312. /* Why doesn't stupidity hurt ... */
  313. #define PM_1K 0x00000000
  314. #define PM_4K 0x00001800
  315. #define PM_16K 0x00007800
  316. #define PM_64K 0x0001f800
  317. #define PM_256K 0x0007f800
  318. #else
  319. #define PM_4K 0x00000000
  320. #define PM_16K 0x00006000
  321. #define PM_64K 0x0001e000
  322. #define PM_256K 0x0007e000
  323. #define PM_1M 0x001fe000
  324. #define PM_4M 0x007fe000
  325. #define PM_16M 0x01ffe000
  326. #define PM_64M 0x07ffe000
  327. #define PM_256M 0x1fffe000
  328. #endif
  329. /*
  330. * Values used for computation of new tlb entries
  331. */
  332. #define PL_4K 12
  333. #define PL_16K 14
  334. #define PL_64K 16
  335. #define PL_256K 18
  336. #define PL_1M 20
  337. #define PL_4M 22
  338. #define PL_16M 24
  339. #define PL_64M 26
  340. #define PL_256M 28
  341. /*
  342. * R4x00 interrupt enable / cause bits
  343. */
  344. #define IE_SW0 (_ULCAST_(1) << 8)
  345. #define IE_SW1 (_ULCAST_(1) << 9)
  346. #define IE_IRQ0 (_ULCAST_(1) << 10)
  347. #define IE_IRQ1 (_ULCAST_(1) << 11)
  348. #define IE_IRQ2 (_ULCAST_(1) << 12)
  349. #define IE_IRQ3 (_ULCAST_(1) << 13)
  350. #define IE_IRQ4 (_ULCAST_(1) << 14)
  351. #define IE_IRQ5 (_ULCAST_(1) << 15)
  352. /*
  353. * R4x00 interrupt cause bits
  354. */
  355. #define C_SW0 (_ULCAST_(1) << 8)
  356. #define C_SW1 (_ULCAST_(1) << 9)
  357. #define C_IRQ0 (_ULCAST_(1) << 10)
  358. #define C_IRQ1 (_ULCAST_(1) << 11)
  359. #define C_IRQ2 (_ULCAST_(1) << 12)
  360. #define C_IRQ3 (_ULCAST_(1) << 13)
  361. #define C_IRQ4 (_ULCAST_(1) << 14)
  362. #define C_IRQ5 (_ULCAST_(1) << 15)
  363. /*
  364. * Bitfields in the R4xx0 cp0 status register
  365. */
  366. #define ST0_IE 0x00000001
  367. #define ST0_EXL 0x00000002
  368. #define ST0_ERL 0x00000004
  369. #define ST0_KSU 0x00000018
  370. # define KSU_USER 0x00000010
  371. # define KSU_SUPERVISOR 0x00000008
  372. # define KSU_KERNEL 0x00000000
  373. #define ST0_UX 0x00000020
  374. #define ST0_SX 0x00000040
  375. #define ST0_KX 0x00000080
  376. #define ST0_DE 0x00010000
  377. #define ST0_CE 0x00020000
  378. /*
  379. * Bitfields in the R[23]000 cp0 status register.
  380. */
  381. #define ST0_IEC 0x00000001
  382. #define ST0_KUC 0x00000002
  383. #define ST0_IEP 0x00000004
  384. #define ST0_KUP 0x00000008
  385. #define ST0_IEO 0x00000010
  386. #define ST0_KUO 0x00000020
  387. /* bits 6 & 7 are reserved on R[23]000 */
  388. #define ST0_ISC 0x00010000
  389. #define ST0_SWC 0x00020000
  390. #define ST0_CM 0x00080000
  391. /*
  392. * Bits specific to the R4640/R4650
  393. */
  394. #define ST0_UM (_ULCAST_(1) << 4)
  395. #define ST0_IL (_ULCAST_(1) << 23)
  396. #define ST0_DL (_ULCAST_(1) << 24)
  397. /*
  398. * Bitfields in the TX39 family CP0 Configuration Register 3
  399. */
  400. #define TX39_CONF_ICS_SHIFT 19
  401. #define TX39_CONF_ICS_MASK 0x00380000
  402. #define TX39_CONF_ICS_1KB 0x00000000
  403. #define TX39_CONF_ICS_2KB 0x00080000
  404. #define TX39_CONF_ICS_4KB 0x00100000
  405. #define TX39_CONF_ICS_8KB 0x00180000
  406. #define TX39_CONF_ICS_16KB 0x00200000
  407. #define TX39_CONF_DCS_SHIFT 16
  408. #define TX39_CONF_DCS_MASK 0x00070000
  409. #define TX39_CONF_DCS_1KB 0x00000000
  410. #define TX39_CONF_DCS_2KB 0x00010000
  411. #define TX39_CONF_DCS_4KB 0x00020000
  412. #define TX39_CONF_DCS_8KB 0x00030000
  413. #define TX39_CONF_DCS_16KB 0x00040000
  414. #define TX39_CONF_CWFON 0x00004000
  415. #define TX39_CONF_WBON 0x00002000
  416. #define TX39_CONF_RF_SHIFT 10
  417. #define TX39_CONF_RF_MASK 0x00000c00
  418. #define TX39_CONF_DOZE 0x00000200
  419. #define TX39_CONF_HALT 0x00000100
  420. #define TX39_CONF_LOCK 0x00000080
  421. #define TX39_CONF_ICE 0x00000020
  422. #define TX39_CONF_DCE 0x00000010
  423. #define TX39_CONF_IRSIZE_SHIFT 2
  424. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  425. #define TX39_CONF_DRSIZE_SHIFT 0
  426. #define TX39_CONF_DRSIZE_MASK 0x00000003
  427. /*
  428. * Status register bits available in all MIPS CPUs.
  429. */
  430. #define ST0_IM 0x0000ff00
  431. #define STATUSB_IP0 8
  432. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  433. #define STATUSB_IP1 9
  434. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  435. #define STATUSB_IP2 10
  436. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  437. #define STATUSB_IP3 11
  438. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  439. #define STATUSB_IP4 12
  440. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  441. #define STATUSB_IP5 13
  442. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  443. #define STATUSB_IP6 14
  444. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  445. #define STATUSB_IP7 15
  446. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  447. #define STATUSB_IP8 0
  448. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  449. #define STATUSB_IP9 1
  450. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  451. #define STATUSB_IP10 2
  452. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  453. #define STATUSB_IP11 3
  454. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  455. #define STATUSB_IP12 4
  456. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  457. #define STATUSB_IP13 5
  458. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  459. #define STATUSB_IP14 6
  460. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  461. #define STATUSB_IP15 7
  462. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  463. #define ST0_CH 0x00040000
  464. #define ST0_SR 0x00100000
  465. #define ST0_TS 0x00200000
  466. #define ST0_BEV 0x00400000
  467. #define ST0_RE 0x02000000
  468. #define ST0_FR 0x04000000
  469. #define ST0_CU 0xf0000000
  470. #define ST0_CU0 0x10000000
  471. #define ST0_CU1 0x20000000
  472. #define ST0_CU1_SHIFT 29
  473. #define ST0_CU2 0x40000000
  474. #define ST0_CU3 0x80000000
  475. #define ST0_XX 0x80000000 /* MIPS IV naming */
  476. /*
  477. * Bitfields and bit numbers in the coprocessor 0 cause register.
  478. *
  479. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  480. */
  481. #define CAUSEB_EXCCODE 2
  482. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  483. #define CAUSEB_IP 8
  484. #define CAUSEF_IP (_ULCAST_(255) << 8)
  485. #define CAUSEB_IP0 8
  486. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  487. #define CAUSEB_IP1 9
  488. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  489. #define CAUSEB_IP2 10
  490. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  491. #define CAUSEB_IP3 11
  492. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  493. #define CAUSEB_IP4 12
  494. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  495. #define CAUSEB_IP5 13
  496. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  497. #define CAUSEB_IP6 14
  498. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  499. #define CAUSEB_IP7 15
  500. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  501. #define CAUSEB_IV 23
  502. #define CAUSEF_IV (_ULCAST_(1) << 23)
  503. #define CAUSEB_CE 28
  504. #define CAUSEF_CE (_ULCAST_(3) << 28)
  505. #define CAUSEB_BD 31
  506. #define CAUSEF_BD (_ULCAST_(1) << 31)
  507. /*
  508. * Bits in the coprocessor 0 config register.
  509. */
  510. /* Generic bits. */
  511. #define CONF_CM_CACHABLE_NO_WA 0
  512. #define CONF_CM_CACHABLE_WA 1
  513. #define CONF_CM_UNCACHED 2
  514. #define CONF_CM_CACHABLE_NONCOHERENT 3
  515. #define CONF_CM_CACHABLE_CE 4
  516. #define CONF_CM_CACHABLE_COW 5
  517. #define CONF_CM_CACHABLE_CUW 6
  518. #define CONF_CM_CACHABLE_ACCELERATED 7
  519. #define CONF_CM_CMASK 7
  520. #define CONF_BE (_ULCAST_(1) << 15)
  521. /* Bits common to various processors. */
  522. #define CONF_CU (_ULCAST_(1) << 3)
  523. #define CONF_DB (_ULCAST_(1) << 4)
  524. #define CONF_IB (_ULCAST_(1) << 5)
  525. #define CONF_DC (_ULCAST_(7) << 6)
  526. #define CONF_IC (_ULCAST_(7) << 9)
  527. #define CONF_EB (_ULCAST_(1) << 13)
  528. #define CONF_EM (_ULCAST_(1) << 14)
  529. #define CONF_SM (_ULCAST_(1) << 16)
  530. #define CONF_SC (_ULCAST_(1) << 17)
  531. #define CONF_EW (_ULCAST_(3) << 18)
  532. #define CONF_EP (_ULCAST_(15)<< 24)
  533. #define CONF_EC (_ULCAST_(7) << 28)
  534. #define CONF_CM (_ULCAST_(1) << 31)
  535. /* Bits specific to the R4xx0. */
  536. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  537. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  538. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  539. /* Bits specific to the R5000. */
  540. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  541. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  542. /* Bits specific to the R10000. */
  543. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  544. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  545. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  546. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  547. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  548. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  549. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  550. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  551. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  552. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  553. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  554. /* Bits specific to the VR41xx. */
  555. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  556. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  557. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  558. /* Bits specific to the R30xx. */
  559. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  560. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  561. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  562. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  563. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  564. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  565. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  566. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  567. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  568. /* Bits specific to the TX49. */
  569. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  570. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  571. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  572. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  573. /* Bits specific to the MIPS32/64 PRA. */
  574. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  575. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  576. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  577. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  578. /*
  579. * R10000 performance counter definitions.
  580. *
  581. * FIXME: The R10000 performance counter opens a nice way to implement CPU
  582. * time accounting with a precission of one cycle. I don't have
  583. * R10000 silicon but just a manual, so ...
  584. */
  585. /*
  586. * Events counted by counter #0
  587. */
  588. #define CE0_CYCLES 0
  589. #define CE0_INSN_ISSUED 1
  590. #define CE0_LPSC_ISSUED 2
  591. #define CE0_S_ISSUED 3
  592. #define CE0_SC_ISSUED 4
  593. #define CE0_SC_FAILED 5
  594. #define CE0_BRANCH_DECODED 6
  595. #define CE0_QW_WB_SECONDARY 7
  596. #define CE0_CORRECTED_ECC_ERRORS 8
  597. #define CE0_ICACHE_MISSES 9
  598. #define CE0_SCACHE_I_MISSES 10
  599. #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
  600. #define CE0_EXT_INTERVENTIONS_REQ 12
  601. #define CE0_EXT_INVALIDATE_REQ 13
  602. #define CE0_VIRTUAL_COHERENCY_COND 14
  603. #define CE0_INSN_GRADUATED 15
  604. /*
  605. * Events counted by counter #1
  606. */
  607. #define CE1_CYCLES 0
  608. #define CE1_INSN_GRADUATED 1
  609. #define CE1_LPSC_GRADUATED 2
  610. #define CE1_S_GRADUATED 3
  611. #define CE1_SC_GRADUATED 4
  612. #define CE1_FP_INSN_GRADUATED 5
  613. #define CE1_QW_WB_PRIMARY 6
  614. #define CE1_TLB_REFILL 7
  615. #define CE1_BRANCH_MISSPREDICTED 8
  616. #define CE1_DCACHE_MISS 9
  617. #define CE1_SCACHE_D_MISSES 10
  618. #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
  619. #define CE1_EXT_INTERVENTION_HITS 12
  620. #define CE1_EXT_INVALIDATE_REQ 13
  621. #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
  622. #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
  623. /*
  624. * These flags define in which priviledge mode the counters count events
  625. */
  626. #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
  627. #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
  628. #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
  629. #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
  630. #ifndef __ASSEMBLY__
  631. #define CAUSE_EXCCODE(x) ((CAUSEF_EXCCODE & (x->cp0_cause)) >> CAUSEB_EXCCODE)
  632. #define CAUSE_EPC(x) (x->cp0_epc + (((x->cp0_cause & CAUSEF_BD) >> CAUSEB_BD) << 2))
  633. /*
  634. * Functions to access the r10k performance counter and control registers
  635. */
  636. #define read_r10k_perf_cntr(counter) \
  637. ({ unsigned int __res; \
  638. __asm__ __volatile__( \
  639. "mfpc\t%0, "STR(counter) \
  640. : "=r" (__res)); \
  641. __res;})
  642. #define write_r10k_perf_cntr(counter,val) \
  643. __asm__ __volatile__( \
  644. "mtpc\t%0, "STR(counter) \
  645. : : "r" (val));
  646. #define read_r10k_perf_cntl(counter) \
  647. ({ unsigned int __res; \
  648. __asm__ __volatile__( \
  649. "mfps\t%0, "STR(counter) \
  650. : "=r" (__res)); \
  651. __res;})
  652. #define write_r10k_perf_cntl(counter,val) \
  653. __asm__ __volatile__( \
  654. "mtps\t%0, "STR(counter) \
  655. : : "r" (val));
  656. /*
  657. * Macros to access the system control coprocessor
  658. */
  659. #define __read_32bit_c0_register(source, sel) \
  660. ({ int __res; \
  661. if (sel == 0) \
  662. __asm__ __volatile__( \
  663. "mfc0\t%0, " #source "\n\t" \
  664. : "=r" (__res)); \
  665. else \
  666. __asm__ __volatile__( \
  667. ".set\tmips32\n\t" \
  668. "mfc0\t%0, " #source ", " #sel "\n\t" \
  669. ".set\tmips0\n\t" \
  670. : "=r" (__res)); \
  671. __res; \
  672. })
  673. #define __read_64bit_c0_register(source, sel) \
  674. ({ unsigned long __res; \
  675. if (sel == 0) \
  676. __asm__ __volatile__( \
  677. ".set\tmips3\n\t" \
  678. "dmfc0\t%0, " #source "\n\t" \
  679. ".set\tmips0" \
  680. : "=r" (__res)); \
  681. else \
  682. __asm__ __volatile__( \
  683. ".set\tmips64\n\t" \
  684. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  685. ".set\tmips0" \
  686. : "=r" (__res)); \
  687. __res; \
  688. })
  689. #define __write_32bit_c0_register(register, sel, value) \
  690. do { \
  691. if (sel == 0) \
  692. __asm__ __volatile__( \
  693. "mtc0\t%z0, " #register "\n\t" \
  694. : : "Jr" (value)); \
  695. else \
  696. __asm__ __volatile__( \
  697. ".set\tmips32\n\t" \
  698. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  699. ".set\tmips0" \
  700. : : "Jr" (value)); \
  701. } while (0)
  702. #define __write_64bit_c0_register(register, sel, value) \
  703. do { \
  704. if (sel == 0) \
  705. __asm__ __volatile__( \
  706. ".set\tmips3\n\t" \
  707. "dmtc0\t%z0, " #register "\n\t" \
  708. ".set\tmips0" \
  709. : : "Jr" (value)); \
  710. else \
  711. __asm__ __volatile__( \
  712. ".set\tmips64\n\t" \
  713. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  714. ".set\tmips0" \
  715. : : "Jr" (value)); \
  716. } while (0)
  717. #define __read_ulong_c0_register(reg, sel) \
  718. ((sizeof(unsigned long) == 4) ? \
  719. __read_32bit_c0_register(reg, sel) : \
  720. __read_64bit_c0_register(reg, sel))
  721. #define __write_ulong_c0_register(reg, sel, val) \
  722. do { \
  723. if (sizeof(unsigned long) == 4) \
  724. __write_32bit_c0_register(reg, sel, val); \
  725. else \
  726. __write_64bit_c0_register(reg, sel, val); \
  727. } while (0)
  728. /*
  729. * These versions are only needed for systems with more than 38 bits of
  730. * physical address space running the 32-bit kernel. That's none atm :-)
  731. */
  732. #define __read_64bit_c0_split(source, sel) \
  733. ({ \
  734. unsigned long long val; \
  735. unsigned long flags; \
  736. \
  737. local_irq_save(flags); \
  738. if (sel == 0) \
  739. __asm__ __volatile__( \
  740. ".set\tmips64\n\t" \
  741. "dmfc0\t%M0, " #source "\n\t" \
  742. "dsll\t%L0, %M0, 32\n\t" \
  743. "dsrl\t%M0, %M0, 32\n\t" \
  744. "dsrl\t%L0, %L0, 32\n\t" \
  745. ".set\tmips0" \
  746. : "=r" (val)); \
  747. else \
  748. __asm__ __volatile__( \
  749. ".set\tmips64\n\t" \
  750. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  751. "dsll\t%L0, %M0, 32\n\t" \
  752. "dsrl\t%M0, %M0, 32\n\t" \
  753. "dsrl\t%L0, %L0, 32\n\t" \
  754. ".set\tmips0" \
  755. : "=r" (val)); \
  756. local_irq_restore(flags); \
  757. \
  758. val; \
  759. })
  760. #define __write_64bit_c0_split(source, sel, val) \
  761. do { \
  762. unsigned long flags; \
  763. \
  764. local_irq_save(flags); \
  765. if (sel == 0) \
  766. __asm__ __volatile__( \
  767. ".set\tmips64\n\t" \
  768. "dsll\t%L0, %L0, 32\n\t" \
  769. "dsrl\t%L0, %L0, 32\n\t" \
  770. "dsll\t%M0, %M0, 32\n\t" \
  771. "or\t%L0, %L0, %M0\n\t" \
  772. "dmtc0\t%L0, " #source "\n\t" \
  773. ".set\tmips0" \
  774. : : "r" (val)); \
  775. else \
  776. __asm__ __volatile__( \
  777. ".set\tmips64\n\t" \
  778. "dsll\t%L0, %L0, 32\n\t" \
  779. "dsrl\t%L0, %L0, 32\n\t" \
  780. "dsll\t%M0, %M0, 32\n\t" \
  781. "or\t%L0, %L0, %M0\n\t" \
  782. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  783. ".set\tmips0" \
  784. : : "r" (val)); \
  785. local_irq_restore(flags); \
  786. } while (0)
  787. #define read_c0_index() __read_32bit_c0_register($0, 0)
  788. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  789. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  790. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  791. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  792. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  793. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  794. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  795. #define read_c0_context() __read_ulong_c0_register($4, 0)
  796. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  797. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  798. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  799. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  800. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  801. #define read_c0_info() __read_32bit_c0_register($7, 0)
  802. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  803. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  804. #define read_c0_count() __read_32bit_c0_register($9, 0)
  805. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  806. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  807. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  808. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  809. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  810. #define read_c0_status() __read_32bit_c0_register($12, 0)
  811. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  812. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  813. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  814. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  815. #define read_c0_config() __read_32bit_c0_register($16, 0)
  816. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  817. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  818. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  819. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  820. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  821. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  822. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  823. /*
  824. * The WatchLo register. There may be upto 8 of them.
  825. */
  826. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  827. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  828. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  829. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  830. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  831. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  832. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  833. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  834. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  835. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  836. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  837. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  838. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  839. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  840. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  841. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  842. /*
  843. * The WatchHi register. There may be upto 8 of them.
  844. */
  845. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  846. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  847. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  848. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  849. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  850. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  851. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  852. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  853. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  854. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  855. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  856. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  857. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  858. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  859. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  860. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  861. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  862. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  863. #define read_c0_intcontrol() __read_32bit_c0_register($20, 1)
  864. #define write_c0_intcontrol(val) __write_32bit_c0_register($20, 1, val)
  865. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  866. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  867. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  868. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  869. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  870. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  871. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  872. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  873. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  874. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  875. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  876. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  877. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  878. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  879. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  880. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  881. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  882. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  883. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  884. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  885. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  886. #if 1
  887. /*
  888. * Macros to access the system control coprocessor
  889. */
  890. #define read_32bit_cp0_register(source) \
  891. ({ int __res; \
  892. __asm__ __volatile__( \
  893. ".set\tpush\n\t" \
  894. ".set\treorder\n\t" \
  895. "mfc0\t%0,"STR(source)"\n\t" \
  896. ".set\tpop" \
  897. : "=r" (__res)); \
  898. __res;})
  899. #define read_32bit_cp0_set1_register(source) \
  900. ({ int __res; \
  901. __asm__ __volatile__( \
  902. ".set\tpush\n\t" \
  903. ".set\treorder\n\t" \
  904. "cfc0\t%0,"STR(source)"\n\t" \
  905. ".set\tpop" \
  906. : "=r" (__res)); \
  907. __res;})
  908. /*
  909. * For now use this only with interrupts disabled!
  910. */
  911. #define read_64bit_cp0_register(source) \
  912. ({ int __res; \
  913. __asm__ __volatile__( \
  914. ".set\tmips3\n\t" \
  915. "dmfc0\t%0,"STR(source)"\n\t" \
  916. ".set\tmips0" \
  917. : "=r" (__res)); \
  918. __res;})
  919. #define write_32bit_cp0_register(register,value) \
  920. __asm__ __volatile__( \
  921. "mtc0\t%0,"STR(register)"\n\t" \
  922. "nop" \
  923. : : "r" (value));
  924. #define write_32bit_cp0_set1_register(register,value) \
  925. __asm__ __volatile__( \
  926. "ctc0\t%0,"STR(register)"\n\t" \
  927. "nop" \
  928. : : "r" (value));
  929. #define write_64bit_cp0_register(register,value) \
  930. __asm__ __volatile__( \
  931. ".set\tmips3\n\t" \
  932. "dmtc0\t%0,"STR(register)"\n\t" \
  933. ".set\tmips0" \
  934. : : "r" (value))
  935. /*
  936. * This should be changed when we get a compiler that support the MIPS32 ISA.
  937. */
  938. #define read_mips32_cp0_config1() \
  939. ({ int __res; \
  940. __asm__ __volatile__( \
  941. ".set\tnoreorder\n\t" \
  942. ".set\tnoat\n\t" \
  943. "#.set\tmips64\n\t" \
  944. "#mfc0\t$1, $16, 1\n\t" \
  945. "#.set\tmips0\n\t" \
  946. ".word\t0x40018001\n\t" \
  947. "move\t%0,$1\n\t" \
  948. ".set\tat\n\t" \
  949. ".set\treorder" \
  950. :"=r" (__res)); \
  951. __res;})
  952. #endif
  953. /*
  954. * Macros to access the floating point coprocessor control registers
  955. */
  956. #define read_32bit_cp1_register(source) \
  957. ({ int __res; \
  958. __asm__ __volatile__( \
  959. ".set\tpush\n\t" \
  960. ".set\treorder\n\t" \
  961. "cfc1\t%0,"STR(source)"\n\t" \
  962. ".set\tpop" \
  963. : "=r" (__res)); \
  964. __res;})
  965. /* TLB operations. */
  966. static inline void tlb_probe(void)
  967. {
  968. __asm__ __volatile__(
  969. ".set noreorder\n\t"
  970. "tlbp\n\t"
  971. ".set reorder");
  972. }
  973. static inline void tlb_read(void)
  974. {
  975. __asm__ __volatile__(
  976. ".set noreorder\n\t"
  977. "tlbr\n\t"
  978. ".set reorder");
  979. }
  980. static inline void tlb_write_indexed(void)
  981. {
  982. __asm__ __volatile__(
  983. ".set noreorder\n\t"
  984. "tlbwi\n\t"
  985. ".set reorder");
  986. }
  987. static inline void tlb_write_random(void)
  988. {
  989. __asm__ __volatile__(
  990. ".set noreorder\n\t"
  991. "tlbwr\n\t"
  992. ".set reorder");
  993. }
  994. /*
  995. * Manipulate bits in a c0 register.
  996. */
  997. #define __BUILD_SET_C0(name,register) \
  998. static inline unsigned int \
  999. set_c0_##name(unsigned int set) \
  1000. { \
  1001. unsigned int res; \
  1002. \
  1003. res = read_c0_##name(); \
  1004. res |= set; \
  1005. write_c0_##name(res); \
  1006. \
  1007. return res; \
  1008. } \
  1009. \
  1010. static inline unsigned int \
  1011. clear_c0_##name(unsigned int clear) \
  1012. { \
  1013. unsigned int res; \
  1014. \
  1015. res = read_c0_##name(); \
  1016. res &= ~clear; \
  1017. write_c0_##name(res); \
  1018. \
  1019. return res; \
  1020. } \
  1021. \
  1022. static inline unsigned int \
  1023. change_c0_##name(unsigned int change, unsigned int new) \
  1024. { \
  1025. unsigned int res; \
  1026. \
  1027. res = read_c0_##name(); \
  1028. res &= ~change; \
  1029. res |= (new & change); \
  1030. write_c0_##name(res); \
  1031. \
  1032. return res; \
  1033. }
  1034. __BUILD_SET_C0(status,CP0_STATUS)
  1035. __BUILD_SET_C0(cause,CP0_CAUSE)
  1036. __BUILD_SET_C0(config,CP0_CONFIG)
  1037. #define set_cp0_status(x) set_c0_status(x)
  1038. #define set_cp0_cause(x) set_c0_cause(x)
  1039. #define set_cp0_config(x) set_c0_config(x)
  1040. #endif /* !__ASSEMBLY__ */
  1041. #endif /* _MIPS_REGS_H_ */