mips_regs.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-12-04 Jiaxun Yang Initial version
  9. */
  10. #ifndef _MIPS_REGS_H_
  11. #define _MIPS_REGS_H_
  12. #define REG_A0 4
  13. #define REG_SP 29
  14. #define REG_GP 28
  15. #define REG_FP 30
  16. #define REG_RA 31
  17. #define zero $0 /* wired zero */
  18. #define AT $1 /* assembler temp - uppercase because of ".set at" */
  19. #define v0 $2 /* return value */
  20. #define v1 $3
  21. #define a0 $4 /* argument registers */
  22. #define a1 $5
  23. #define a2 $6
  24. #define a3 $7
  25. #define t0 $8 /* caller saved */
  26. #define t1 $9
  27. #define t2 $10
  28. #define t3 $11
  29. #define t4 $12
  30. #define ta0 $12
  31. #define t5 $13
  32. #define ta1 $13
  33. #define t6 $14
  34. #define ta2 $14
  35. #define t7 $15
  36. #define ta3 $15
  37. #define s0 $16 /* callee saved */
  38. #define s1 $17
  39. #define s2 $18
  40. #define s3 $19
  41. #define s4 $20
  42. #define s5 $21
  43. #define s6 $22
  44. #define s7 $23
  45. #define t8 $24 /* caller saved */
  46. #define t9 $25
  47. #define jp $25 /* PIC jump register */
  48. #define k0 $26 /* kernel scratch */
  49. #define k1 $27
  50. #define gp $28 /* global pointer */
  51. #define sp $29 /* stack pointer */
  52. #define fp $30 /* frame pointer */
  53. #define s8 $30 /* same like fp! */
  54. #define ra $31 /* return address */
  55. #define fv0 $f0 /* return value */
  56. #define fv0f $f1
  57. #define fv1 $f2
  58. #define fv1f $f3
  59. #define fa0 $f12 /* argument registers */
  60. #define fa0f $f13
  61. #define fa1 $f14
  62. #define fa1f $f15
  63. #define ft0 $f4 /* caller saved */
  64. #define ft0f $f5
  65. #define ft1 $f6
  66. #define ft1f $f7
  67. #define ft2 $f8
  68. #define ft2f $f9
  69. #define ft3 $f10
  70. #define ft3f $f11
  71. #define ft4 $f16
  72. #define ft4f $f17
  73. #define ft5 $f18
  74. #define ft5f $f19
  75. #define fs0 $f20 /* callee saved */
  76. #define fs0f $f21
  77. #define fs1 $f22
  78. #define fs1f $f23
  79. #define fs2 $f24
  80. #define fs2f $f25
  81. #define fs3 $f26
  82. #define fs3f $f27
  83. #define fs4 $f28
  84. #define fs4f $f29
  85. #define fs5 $f30
  86. #define fs5f $f31
  87. #define fcr31 $31 /* FPU status register */
  88. /*
  89. * The following macros are especially useful for __asm__
  90. * inline assembler.
  91. */
  92. #ifndef __STR
  93. #define __STR(x) #x
  94. #endif
  95. #ifndef STR
  96. #define STR(x) __STR(x)
  97. #endif
  98. /*
  99. * Configure language
  100. */
  101. #ifdef __ASSEMBLY__
  102. #define _ULCAST_
  103. #else
  104. #define _ULCAST_ (unsigned long)
  105. #endif
  106. /*
  107. * Coprocessor 0 register names
  108. */
  109. #define CP0_INDEX $0
  110. #define CP0_RANDOM $1
  111. #define CP0_ENTRYLO0 $2
  112. #define CP0_ENTRYLO1 $3
  113. #define CP0_CONF $3
  114. #define CP0_CONTEXT $4
  115. #define CP0_PAGEMASK $5
  116. #define CP0_WIRED $6
  117. #define CP0_INFO $7
  118. #define CP0_BADVADDR $8
  119. #define CP0_COUNT $9
  120. #define CP0_ENTRYHI $10
  121. #define CP0_COMPARE $11
  122. #define CP0_STATUS $12
  123. #define CP0_CAUSE $13
  124. #define CP0_EPC $14
  125. #define CP0_PRID $15
  126. #define CP0_CONFIG $16
  127. #define CP0_LLADDR $17
  128. #define CP0_WATCHLO $18
  129. #define CP0_WATCHHI $19
  130. #define CP0_XCONTEXT $20
  131. #define CP0_FRAMEMASK $21
  132. #define CP0_DIAGNOSTIC $22
  133. #define CP0_DEBUG $23
  134. #define CP0_DEPC $24
  135. #define CP0_PERFORMANCE $25
  136. #define CP0_ECC $26
  137. #define CP0_CACHEERR $27
  138. #define CP0_TAGLO $28
  139. #define CP0_TAGHI $29
  140. #define CP0_ERROREPC $30
  141. #define CP0_DESAVE $31
  142. /*
  143. * R4640/R4650 cp0 register names. These registers are listed
  144. * here only for completeness; without MMU these CPUs are not useable
  145. * by Linux. A future ELKS port might take make Linux run on them
  146. * though ...
  147. */
  148. #define CP0_IBASE $0
  149. #define CP0_IBOUND $1
  150. #define CP0_DBASE $2
  151. #define CP0_DBOUND $3
  152. #define CP0_CALG $17
  153. #define CP0_IWATCH $18
  154. #define CP0_DWATCH $19
  155. /*
  156. * Coprocessor 0 Set 1 register names
  157. */
  158. #define CP0_S1_DERRADDR0 $26
  159. #define CP0_S1_DERRADDR1 $27
  160. #define CP0_S1_INTCONTROL $20
  161. /*
  162. * TX39 Series
  163. */
  164. #define CP0_TX39_CACHE $7
  165. /*
  166. * Coprocessor 1 (FPU) register names
  167. */
  168. #define CP1_REVISION $0
  169. #define CP1_UFR $1
  170. #define CP1_UNFR $4
  171. #define CP1_FCCR $25
  172. #define CP1_FEXR $26
  173. #define CP1_FENR $28
  174. #define CP1_STATUS $31
  175. /*
  176. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  177. */
  178. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  179. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  180. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  181. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  182. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  183. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  184. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  185. #define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
  186. #define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
  187. #define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
  188. /*
  189. * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
  190. */
  191. #define MIPS_FCCR_CONDX_S 0
  192. #define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
  193. #define MIPS_FCCR_COND0_S 0
  194. #define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
  195. #define MIPS_FCCR_COND1_S 1
  196. #define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
  197. #define MIPS_FCCR_COND2_S 2
  198. #define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
  199. #define MIPS_FCCR_COND3_S 3
  200. #define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
  201. #define MIPS_FCCR_COND4_S 4
  202. #define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
  203. #define MIPS_FCCR_COND5_S 5
  204. #define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
  205. #define MIPS_FCCR_COND6_S 6
  206. #define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
  207. #define MIPS_FCCR_COND7_S 7
  208. #define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
  209. /*
  210. * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
  211. */
  212. #define MIPS_FENR_FS_S 2
  213. #define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
  214. /*
  215. * FPU Status Register Values
  216. */
  217. #define FPU_CSR_COND_S 23 /* $fcc0 */
  218. #define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
  219. #define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
  220. #define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
  221. #define FPU_CSR_FO 0x00400000
  222. #define FPU_CSR_FN 0x00200000
  223. #define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
  224. #define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
  225. #define FPU_CSR_COND1_S 25 /* $fcc1 */
  226. #define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
  227. #define FPU_CSR_COND2_S 26 /* $fcc2 */
  228. #define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
  229. #define FPU_CSR_COND3_S 27 /* $fcc3 */
  230. #define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
  231. #define FPU_CSR_COND4_S 28 /* $fcc4 */
  232. #define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
  233. #define FPU_CSR_COND5_S 29 /* $fcc5 */
  234. #define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
  235. #define FPU_CSR_COND6_S 30 /* $fcc6 */
  236. #define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
  237. #define FPU_CSR_COND7_S 31 /* $fcc7 */
  238. #define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
  239. /*
  240. * Bits 22:20 of the FPU Status Register will be read as 0,
  241. * and should be written as zero.
  242. */
  243. #define FPU_CSR_RSVD (_ULCAST_(7) << 20)
  244. #define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
  245. #define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
  246. /*
  247. * X the exception cause indicator
  248. * E the exception enable
  249. * S the sticky/flag bit
  250. */
  251. #define FPU_CSR_ALL_X 0x0003f000
  252. #define FPU_CSR_UNI_X 0x00020000
  253. #define FPU_CSR_INV_X 0x00010000
  254. #define FPU_CSR_DIV_X 0x00008000
  255. #define FPU_CSR_OVF_X 0x00004000
  256. #define FPU_CSR_UDF_X 0x00002000
  257. #define FPU_CSR_INE_X 0x00001000
  258. #define FPU_CSR_ALL_E 0x00000f80
  259. #define FPU_CSR_INV_E 0x00000800
  260. #define FPU_CSR_DIV_E 0x00000400
  261. #define FPU_CSR_OVF_E 0x00000200
  262. #define FPU_CSR_UDF_E 0x00000100
  263. #define FPU_CSR_INE_E 0x00000080
  264. #define FPU_CSR_ALL_S 0x0000007c
  265. #define FPU_CSR_INV_S 0x00000040
  266. #define FPU_CSR_DIV_S 0x00000020
  267. #define FPU_CSR_OVF_S 0x00000010
  268. #define FPU_CSR_UDF_S 0x00000008
  269. #define FPU_CSR_INE_S 0x00000004
  270. /* Bits 0 and 1 of FPU Status Register specify the rounding mode */
  271. #define FPU_CSR_RM 0x00000003
  272. #define FPU_CSR_RN 0x0 /* nearest */
  273. #define FPU_CSR_RZ 0x1 /* towards zero */
  274. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  275. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  276. #define PM_4K 0x00000000
  277. #define PM_16K 0x00006000
  278. #define PM_64K 0x0001e000
  279. #define PM_256K 0x0007e000
  280. #define PM_1M 0x001fe000
  281. #define PM_4M 0x007fe000
  282. #define PM_16M 0x01ffe000
  283. #define PM_64M 0x07ffe000
  284. #define PM_256M 0x1fffe000
  285. /*
  286. * Values used for computation of new tlb entries
  287. */
  288. #define PL_4K 12
  289. #define PL_16K 14
  290. #define PL_64K 16
  291. #define PL_256K 18
  292. #define PL_1M 20
  293. #define PL_4M 22
  294. #define PL_16M 24
  295. #define PL_64M 26
  296. #define PL_256M 28
  297. /*
  298. * R4x00 interrupt enable / cause bits
  299. */
  300. #define IE_SW0 (_ULCAST_(1) << 8)
  301. #define IE_SW1 (_ULCAST_(1) << 9)
  302. #define IE_IRQ0 (_ULCAST_(1) << 10)
  303. #define IE_IRQ1 (_ULCAST_(1) << 11)
  304. #define IE_IRQ2 (_ULCAST_(1) << 12)
  305. #define IE_IRQ3 (_ULCAST_(1) << 13)
  306. #define IE_IRQ4 (_ULCAST_(1) << 14)
  307. #define IE_IRQ5 (_ULCAST_(1) << 15)
  308. /*
  309. * R4x00 interrupt cause bits
  310. */
  311. #define C_SW0 (_ULCAST_(1) << 8)
  312. #define C_SW1 (_ULCAST_(1) << 9)
  313. #define C_IRQ0 (_ULCAST_(1) << 10)
  314. #define C_IRQ1 (_ULCAST_(1) << 11)
  315. #define C_IRQ2 (_ULCAST_(1) << 12)
  316. #define C_IRQ3 (_ULCAST_(1) << 13)
  317. #define C_IRQ4 (_ULCAST_(1) << 14)
  318. #define C_IRQ5 (_ULCAST_(1) << 15)
  319. /*
  320. * Bitfields in the R4xx0 cp0 status register
  321. */
  322. #define ST0_IE 0x00000001
  323. #define ST0_EXL 0x00000002
  324. #define ST0_ERL 0x00000004
  325. #define ST0_KSU 0x00000018
  326. # define KSU_USER 0x00000010
  327. # define KSU_SUPERVISOR 0x00000008
  328. # define KSU_KERNEL 0x00000000
  329. #define ST0_UX 0x00000020
  330. #define ST0_SX 0x00000040
  331. #define ST0_KX 0x00000080
  332. #define ST0_DE 0x00010000
  333. #define ST0_CE 0x00020000
  334. /*
  335. * Bitfields in the R[23]000 cp0 status register.
  336. */
  337. #define ST0_IEC 0x00000001
  338. #define ST0_KUC 0x00000002
  339. #define ST0_IEP 0x00000004
  340. #define ST0_KUP 0x00000008
  341. #define ST0_IEO 0x00000010
  342. #define ST0_KUO 0x00000020
  343. /* bits 6 & 7 are reserved on R[23]000 */
  344. #define ST0_ISC 0x00010000
  345. #define ST0_SWC 0x00020000
  346. #define ST0_CM 0x00080000
  347. /*
  348. * Bits specific to the R4640/R4650
  349. */
  350. #define ST0_UM (_ULCAST_(1) << 4)
  351. #define ST0_IL (_ULCAST_(1) << 23)
  352. #define ST0_DL (_ULCAST_(1) << 24)
  353. /*
  354. * Status register bits available in all MIPS CPUs.
  355. */
  356. #define ST0_IM 0x0000ff00
  357. #define STATUSB_IP0 8
  358. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  359. #define STATUSB_IP1 9
  360. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  361. #define STATUSB_IP2 10
  362. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  363. #define STATUSB_IP3 11
  364. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  365. #define STATUSB_IP4 12
  366. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  367. #define STATUSB_IP5 13
  368. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  369. #define STATUSB_IP6 14
  370. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  371. #define STATUSB_IP7 15
  372. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  373. #define STATUSB_IP8 0
  374. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  375. #define STATUSB_IP9 1
  376. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  377. #define STATUSB_IP10 2
  378. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  379. #define STATUSB_IP11 3
  380. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  381. #define STATUSB_IP12 4
  382. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  383. #define STATUSB_IP13 5
  384. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  385. #define STATUSB_IP14 6
  386. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  387. #define STATUSB_IP15 7
  388. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  389. #define ST0_CH 0x00040000
  390. #define ST0_SR 0x00100000
  391. #define ST0_TS 0x00200000
  392. #define ST0_BEV 0x00400000
  393. #define ST0_RE 0x02000000
  394. #define ST0_FR 0x04000000
  395. #define ST0_CU 0xf0000000
  396. #define ST0_CU0 0x10000000
  397. #define ST0_CU1 0x20000000
  398. #define ST0_CU1_SHIFT 29
  399. #define ST0_CU2 0x40000000
  400. #define ST0_CU3 0x80000000
  401. #define ST0_XX 0x80000000 /* MIPS IV naming */
  402. /*
  403. * Bitfields and bit numbers in the coprocessor 0 cause register.
  404. *
  405. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  406. */
  407. #define CAUSEB_EXCCODE 2
  408. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  409. #define CAUSEB_IP 8
  410. #define CAUSEF_IP (_ULCAST_(255) << 8)
  411. #define CAUSEB_IP0 8
  412. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  413. #define CAUSEB_IP1 9
  414. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  415. #define CAUSEB_IP2 10
  416. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  417. #define CAUSEB_IP3 11
  418. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  419. #define CAUSEB_IP4 12
  420. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  421. #define CAUSEB_IP5 13
  422. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  423. #define CAUSEB_IP6 14
  424. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  425. #define CAUSEB_IP7 15
  426. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  427. #define CAUSEB_IV 23
  428. #define CAUSEF_IV (_ULCAST_(1) << 23)
  429. #define CAUSEB_CE 28
  430. #define CAUSEF_CE (_ULCAST_(3) << 28)
  431. #define CAUSEB_BD 31
  432. #define CAUSEF_BD (_ULCAST_(1) << 31)
  433. /*
  434. * Bits in the coprocessor 0 config register.
  435. */
  436. /* Generic bits. */
  437. #define CONF_CM_CACHABLE_NO_WA 0
  438. #define CONF_CM_CACHABLE_WA 1
  439. #define CONF_CM_UNCACHED 2
  440. #define CONF_CM_CACHABLE_NONCOHERENT 3
  441. #define CONF_CM_CACHABLE_CE 4
  442. #define CONF_CM_CACHABLE_COW 5
  443. #define CONF_CM_CACHABLE_CUW 6
  444. #define CONF_CM_CACHABLE_ACCELERATED 7
  445. #define CONF_CM_CMASK 7
  446. #define CONF_BE (_ULCAST_(1) << 15)
  447. /* Bits common to various processors. */
  448. #define CONF_CU (_ULCAST_(1) << 3)
  449. #define CONF_DB (_ULCAST_(1) << 4)
  450. #define CONF_IB (_ULCAST_(1) << 5)
  451. #define CONF_DC (_ULCAST_(7) << 6)
  452. #define CONF_IC (_ULCAST_(7) << 9)
  453. #define CONF_EB (_ULCAST_(1) << 13)
  454. #define CONF_EM (_ULCAST_(1) << 14)
  455. #define CONF_SM (_ULCAST_(1) << 16)
  456. #define CONF_SC (_ULCAST_(1) << 17)
  457. #define CONF_EW (_ULCAST_(3) << 18)
  458. #define CONF_EP (_ULCAST_(15)<< 24)
  459. #define CONF_EC (_ULCAST_(7) << 28)
  460. #define CONF_CM (_ULCAST_(1) << 31)
  461. /* Bits specific to the R4xx0. */
  462. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  463. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  464. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  465. /* Bits specific to the R5000. */
  466. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  467. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  468. /* Bits specific to the R10000. */
  469. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  470. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  471. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  472. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  473. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  474. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  475. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  476. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  477. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  478. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  479. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  480. /* Bits specific to the VR41xx. */
  481. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  482. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  483. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  484. /* Bits specific to the R30xx. */
  485. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  486. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  487. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  488. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  489. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  490. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  491. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  492. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  493. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  494. /* Bits specific to the TX49. */
  495. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  496. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  497. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  498. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  499. /* Bits specific to the MIPS32/64 PRA. */
  500. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  501. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  502. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  503. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  504. /*
  505. * R10000 performance counter definitions.
  506. *
  507. * FIXME: The R10000 performance counter opens a nice way to implement CPU
  508. * time accounting with a precission of one cycle. I don't have
  509. * R10000 silicon but just a manual, so ...
  510. */
  511. /*
  512. * Events counted by counter #0
  513. */
  514. #define CE0_CYCLES 0
  515. #define CE0_INSN_ISSUED 1
  516. #define CE0_LPSC_ISSUED 2
  517. #define CE0_S_ISSUED 3
  518. #define CE0_SC_ISSUED 4
  519. #define CE0_SC_FAILED 5
  520. #define CE0_BRANCH_DECODED 6
  521. #define CE0_QW_WB_SECONDARY 7
  522. #define CE0_CORRECTED_ECC_ERRORS 8
  523. #define CE0_ICACHE_MISSES 9
  524. #define CE0_SCACHE_I_MISSES 10
  525. #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
  526. #define CE0_EXT_INTERVENTIONS_REQ 12
  527. #define CE0_EXT_INVALIDATE_REQ 13
  528. #define CE0_VIRTUAL_COHERENCY_COND 14
  529. #define CE0_INSN_GRADUATED 15
  530. /*
  531. * Events counted by counter #1
  532. */
  533. #define CE1_CYCLES 0
  534. #define CE1_INSN_GRADUATED 1
  535. #define CE1_LPSC_GRADUATED 2
  536. #define CE1_S_GRADUATED 3
  537. #define CE1_SC_GRADUATED 4
  538. #define CE1_FP_INSN_GRADUATED 5
  539. #define CE1_QW_WB_PRIMARY 6
  540. #define CE1_TLB_REFILL 7
  541. #define CE1_BRANCH_MISSPREDICTED 8
  542. #define CE1_DCACHE_MISS 9
  543. #define CE1_SCACHE_D_MISSES 10
  544. #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
  545. #define CE1_EXT_INTERVENTION_HITS 12
  546. #define CE1_EXT_INVALIDATE_REQ 13
  547. #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
  548. #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
  549. /*
  550. * These flags define in which priviledge mode the counters count events
  551. */
  552. #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
  553. #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
  554. #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
  555. #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
  556. #ifndef __ASSEMBLY__
  557. #define CAUSE_EXCCODE(x) ((CAUSEF_EXCCODE & (x->cp0_cause)) >> CAUSEB_EXCCODE)
  558. #define CAUSE_EPC(x) (x->cp0_epc + (((x->cp0_cause & CAUSEF_BD) >> CAUSEB_BD) << 2))
  559. /*
  560. * Functions to access the r10k performance counter and control registers
  561. */
  562. #define read_r10k_perf_cntr(counter) \
  563. ({ unsigned int __res; \
  564. __asm__ __volatile__( \
  565. "mfpc\t%0, "STR(counter) \
  566. : "=r" (__res)); \
  567. __res;})
  568. #define write_r10k_perf_cntr(counter,val) \
  569. __asm__ __volatile__( \
  570. "mtpc\t%0, "STR(counter) \
  571. : : "r" (val));
  572. #define read_r10k_perf_cntl(counter) \
  573. ({ unsigned int __res; \
  574. __asm__ __volatile__( \
  575. "mfps\t%0, "STR(counter) \
  576. : "=r" (__res)); \
  577. __res;})
  578. #define write_r10k_perf_cntl(counter,val) \
  579. __asm__ __volatile__( \
  580. "mtps\t%0, "STR(counter) \
  581. : : "r" (val));
  582. /*
  583. * Macros to access the system control coprocessor
  584. */
  585. #define __read_32bit_c0_register(source, sel) \
  586. ({ int __res; \
  587. if (sel == 0) \
  588. __asm__ __volatile__( \
  589. "mfc0\t%0, " #source "\n\t" \
  590. : "=r" (__res)); \
  591. else \
  592. __asm__ __volatile__( \
  593. ".set\tmips32\n\t" \
  594. "mfc0\t%0, " #source ", " #sel "\n\t" \
  595. ".set\tmips0\n\t" \
  596. : "=r" (__res)); \
  597. __res; \
  598. })
  599. #define __read_64bit_c0_register(source, sel) \
  600. ({ unsigned long __res; \
  601. if (sel == 0) \
  602. __asm__ __volatile__( \
  603. ".set\tmips3\n\t" \
  604. "dmfc0\t%0, " #source "\n\t" \
  605. ".set\tmips0" \
  606. : "=r" (__res)); \
  607. else \
  608. __asm__ __volatile__( \
  609. ".set\tmips64\n\t" \
  610. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  611. ".set\tmips0" \
  612. : "=r" (__res)); \
  613. __res; \
  614. })
  615. #define __write_32bit_c0_register(register, sel, value) \
  616. do { \
  617. if (sel == 0) \
  618. __asm__ __volatile__( \
  619. "mtc0\t%z0, " #register "\n\t" \
  620. : : "Jr" (value)); \
  621. else \
  622. __asm__ __volatile__( \
  623. ".set\tmips32\n\t" \
  624. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  625. ".set\tmips0" \
  626. : : "Jr" (value)); \
  627. } while (0)
  628. #define __write_64bit_c0_register(register, sel, value) \
  629. do { \
  630. if (sel == 0) \
  631. __asm__ __volatile__( \
  632. ".set\tmips3\n\t" \
  633. "dmtc0\t%z0, " #register "\n\t" \
  634. ".set\tmips0" \
  635. : : "Jr" (value)); \
  636. else \
  637. __asm__ __volatile__( \
  638. ".set\tmips64\n\t" \
  639. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  640. ".set\tmips0" \
  641. : : "Jr" (value)); \
  642. } while (0)
  643. #define __read_ulong_c0_register(reg, sel) \
  644. ((sizeof(unsigned long) == 4) ? \
  645. __read_32bit_c0_register(reg, sel) : \
  646. __read_64bit_c0_register(reg, sel))
  647. #define __write_ulong_c0_register(reg, sel, val) \
  648. do { \
  649. if (sizeof(unsigned long) == 4) \
  650. __write_32bit_c0_register(reg, sel, val); \
  651. else \
  652. __write_64bit_c0_register(reg, sel, val); \
  653. } while (0)
  654. /*
  655. * These versions are only needed for systems with more than 38 bits of
  656. * physical address space running the 32-bit kernel. That's none atm :-)
  657. */
  658. #define __read_64bit_c0_split(source, sel) \
  659. ({ \
  660. unsigned long long val; \
  661. unsigned long flags; \
  662. \
  663. local_irq_save(flags); \
  664. if (sel == 0) \
  665. __asm__ __volatile__( \
  666. ".set\tmips64\n\t" \
  667. "dmfc0\t%M0, " #source "\n\t" \
  668. "dsll\t%L0, %M0, 32\n\t" \
  669. "dsrl\t%M0, %M0, 32\n\t" \
  670. "dsrl\t%L0, %L0, 32\n\t" \
  671. ".set\tmips0" \
  672. : "=r" (val)); \
  673. else \
  674. __asm__ __volatile__( \
  675. ".set\tmips64\n\t" \
  676. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  677. "dsll\t%L0, %M0, 32\n\t" \
  678. "dsrl\t%M0, %M0, 32\n\t" \
  679. "dsrl\t%L0, %L0, 32\n\t" \
  680. ".set\tmips0" \
  681. : "=r" (val)); \
  682. local_irq_restore(flags); \
  683. \
  684. val; \
  685. })
  686. #define __write_64bit_c0_split(source, sel, val) \
  687. do { \
  688. unsigned long flags; \
  689. \
  690. local_irq_save(flags); \
  691. if (sel == 0) \
  692. __asm__ __volatile__( \
  693. ".set\tmips64\n\t" \
  694. "dsll\t%L0, %L0, 32\n\t" \
  695. "dsrl\t%L0, %L0, 32\n\t" \
  696. "dsll\t%M0, %M0, 32\n\t" \
  697. "or\t%L0, %L0, %M0\n\t" \
  698. "dmtc0\t%L0, " #source "\n\t" \
  699. ".set\tmips0" \
  700. : : "r" (val)); \
  701. else \
  702. __asm__ __volatile__( \
  703. ".set\tmips64\n\t" \
  704. "dsll\t%L0, %L0, 32\n\t" \
  705. "dsrl\t%L0, %L0, 32\n\t" \
  706. "dsll\t%M0, %M0, 32\n\t" \
  707. "or\t%L0, %L0, %M0\n\t" \
  708. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  709. ".set\tmips0" \
  710. : : "r" (val)); \
  711. local_irq_restore(flags); \
  712. } while (0)
  713. #define read_c0_index() __read_32bit_c0_register($0, 0)
  714. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  715. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  716. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  717. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  718. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  719. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  720. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  721. #define read_c0_context() __read_ulong_c0_register($4, 0)
  722. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  723. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  724. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  725. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  726. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  727. #define read_c0_info() __read_32bit_c0_register($7, 0)
  728. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  729. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  730. #define read_c0_count() __read_32bit_c0_register($9, 0)
  731. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  732. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  733. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  734. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  735. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  736. #define read_c0_status() __read_32bit_c0_register($12, 0)
  737. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  738. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  739. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  740. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  741. #define read_c0_ebase() __read_32bit_c0_register($15, 1)
  742. #define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
  743. #define read_c0_config() __read_32bit_c0_register($16, 0)
  744. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  745. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  746. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  747. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  748. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  749. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  750. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  751. /*
  752. * The WatchLo register. There may be upto 8 of them.
  753. */
  754. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  755. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  756. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  757. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  758. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  759. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  760. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  761. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  762. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  763. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  764. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  765. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  766. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  767. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  768. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  769. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  770. /*
  771. * The WatchHi register. There may be upto 8 of them.
  772. */
  773. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  774. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  775. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  776. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  777. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  778. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  779. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  780. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  781. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  782. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  783. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  784. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  785. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  786. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  787. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  788. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  789. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  790. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  791. #define read_c0_intcontrol() __read_32bit_c0_register($20, 1)
  792. #define write_c0_intcontrol(val) __write_32bit_c0_register($20, 1, val)
  793. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  794. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  795. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  796. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  797. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  798. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  799. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  800. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  801. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  802. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  803. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  804. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  805. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  806. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  807. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  808. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  809. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  810. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  811. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  812. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  813. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  814. #if 1
  815. /*
  816. * Macros to access the system control coprocessor
  817. */
  818. #define read_32bit_cp0_register(source) \
  819. ({ int __res; \
  820. __asm__ __volatile__( \
  821. ".set\tpush\n\t" \
  822. ".set\treorder\n\t" \
  823. "mfc0\t%0,"STR(source)"\n\t" \
  824. ".set\tpop" \
  825. : "=r" (__res)); \
  826. __res;})
  827. #define read_32bit_cp0_set1_register(source) \
  828. ({ int __res; \
  829. __asm__ __volatile__( \
  830. ".set\tpush\n\t" \
  831. ".set\treorder\n\t" \
  832. "cfc0\t%0,"STR(source)"\n\t" \
  833. ".set\tpop" \
  834. : "=r" (__res)); \
  835. __res;})
  836. /*
  837. * For now use this only with interrupts disabled!
  838. */
  839. #define read_64bit_cp0_register(source) \
  840. ({ int __res; \
  841. __asm__ __volatile__( \
  842. ".set\tmips3\n\t" \
  843. "dmfc0\t%0,"STR(source)"\n\t" \
  844. ".set\tmips0" \
  845. : "=r" (__res)); \
  846. __res;})
  847. #define write_32bit_cp0_register(register,value) \
  848. __asm__ __volatile__( \
  849. "mtc0\t%0,"STR(register)"\n\t" \
  850. "nop" \
  851. : : "r" (value));
  852. #define write_32bit_cp0_set1_register(register,value) \
  853. __asm__ __volatile__( \
  854. "ctc0\t%0,"STR(register)"\n\t" \
  855. "nop" \
  856. : : "r" (value));
  857. #define write_64bit_cp0_register(register,value) \
  858. __asm__ __volatile__( \
  859. ".set\tmips3\n\t" \
  860. "dmtc0\t%0,"STR(register)"\n\t" \
  861. ".set\tmips0" \
  862. : : "r" (value))
  863. /*
  864. * This should be changed when we get a compiler that support the MIPS32 ISA.
  865. */
  866. #define read_mips32_cp0_config1() \
  867. ({ int __res; \
  868. __asm__ __volatile__( \
  869. ".set\tnoreorder\n\t" \
  870. ".set\tnoat\n\t" \
  871. "#.set\tmips64\n\t" \
  872. "#mfc0\t$1, $16, 1\n\t" \
  873. "#.set\tmips0\n\t" \
  874. ".word\t0x40018001\n\t" \
  875. "move\t%0,$1\n\t" \
  876. ".set\tat\n\t" \
  877. ".set\treorder" \
  878. :"=r" (__res)); \
  879. __res;})
  880. #endif
  881. /*
  882. * Macros to access the floating point coprocessor control registers
  883. */
  884. #define read_32bit_cp1_register(source) \
  885. ({ int __res; \
  886. __asm__ __volatile__( \
  887. ".set\tpush\n\t" \
  888. ".set\treorder\n\t" \
  889. "cfc1\t%0,"STR(source)"\n\t" \
  890. ".set\tpop" \
  891. : "=r" (__res)); \
  892. __res;})
  893. #define write_32bit_cp1_register(register,value) \
  894. __asm__ __volatile__( \
  895. "ctc1\t%0,"STR(register)"\n\t" \
  896. "nop" \
  897. : : "r" (value));
  898. /* TLB operations. */
  899. static inline void tlb_probe(void)
  900. {
  901. __asm__ __volatile__(
  902. ".set noreorder\n\t"
  903. "tlbp\n\t"
  904. ".set reorder");
  905. }
  906. static inline void tlb_read(void)
  907. {
  908. __asm__ __volatile__(
  909. ".set noreorder\n\t"
  910. "tlbr\n\t"
  911. ".set reorder");
  912. }
  913. static inline void tlb_write_indexed(void)
  914. {
  915. __asm__ __volatile__(
  916. ".set noreorder\n\t"
  917. "tlbwi\n\t"
  918. ".set reorder");
  919. }
  920. static inline void tlb_write_random(void)
  921. {
  922. __asm__ __volatile__(
  923. ".set noreorder\n\t"
  924. "tlbwr\n\t"
  925. ".set reorder");
  926. }
  927. /*
  928. * Manipulate bits in a c0 register.
  929. */
  930. #define __BUILD_SET_C0(name,register) \
  931. static inline unsigned int \
  932. set_c0_##name(unsigned int set) \
  933. { \
  934. unsigned int res; \
  935. \
  936. res = read_c0_##name(); \
  937. res |= set; \
  938. write_c0_##name(res); \
  939. \
  940. return res; \
  941. } \
  942. \
  943. static inline unsigned int \
  944. clear_c0_##name(unsigned int clear) \
  945. { \
  946. unsigned int res; \
  947. \
  948. res = read_c0_##name(); \
  949. res &= ~clear; \
  950. write_c0_##name(res); \
  951. \
  952. return res; \
  953. } \
  954. \
  955. static inline unsigned int \
  956. change_c0_##name(unsigned int change, unsigned int new) \
  957. { \
  958. unsigned int res; \
  959. \
  960. res = read_c0_##name(); \
  961. res &= ~change; \
  962. res |= (new & change); \
  963. write_c0_##name(res); \
  964. \
  965. return res; \
  966. }
  967. __BUILD_SET_C0(status,CP0_STATUS)
  968. __BUILD_SET_C0(cause,CP0_CAUSE)
  969. __BUILD_SET_C0(config,CP0_CONFIG)
  970. #define set_cp0_status(x) set_c0_status(x)
  971. #define set_cp0_cause(x) set_c0_cause(x)
  972. #define set_cp0_config(x) set_c0_config(x)
  973. #define read_c1_status() read_32bit_cp1_register(31)
  974. #define write_c1_status(x) write_32bit_cp1_register(31, x)
  975. #define readb(reg) (*((volatile unsigned char *) (reg)))
  976. #define readw(reg) (*((volatile unsigned short *) (reg)))
  977. #define readl(reg) (*((volatile unsigned int *) (reg)))
  978. #define writeb(data, reg) ((*((volatile unsigned char *)(reg))) = (unsigned char)(data))
  979. #define writew(data, reg) ((*((volatile unsigned short *)(reg))) = (unsigned short)(data))
  980. #define writel(data, reg) ((*((volatile unsigned int *)(reg))) = (unsigned int)(data))
  981. #endif /* !__ASSEMBLY__ */
  982. #endif /* _MIPS_REGS_H_ */