mipsregs.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2000 Silicon Graphics, Inc.
  8. * Modified for further R[236]000 support by Paul M. Antoine, 1996.
  9. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  11. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  12. */
  13. #ifndef _ASM_MIPSREGS_H
  14. #define _ASM_MIPSREGS_H
  15. #include <linux/config.h>
  16. #include <linux/linkage.h>
  17. #include <asm/hazards.h>
  18. /*
  19. * The following macros are especially useful for __asm__
  20. * inline assembler.
  21. */
  22. #ifndef __STR
  23. #define __STR(x) #x
  24. #endif
  25. #ifndef STR
  26. #define STR(x) __STR(x)
  27. #endif
  28. /*
  29. * Configure language
  30. */
  31. #ifdef __ASSEMBLY__
  32. #define _ULCAST_
  33. #else
  34. #define _ULCAST_ (unsigned long)
  35. #endif
  36. /*
  37. * Coprocessor 0 register names
  38. */
  39. #define CP0_INDEX $0
  40. #define CP0_RANDOM $1
  41. #define CP0_ENTRYLO0 $2
  42. #define CP0_ENTRYLO1 $3
  43. #define CP0_CONF $3
  44. #define CP0_CONTEXT $4
  45. #define CP0_PAGEMASK $5
  46. #define CP0_WIRED $6
  47. #define CP0_INFO $7
  48. #define CP0_BADVADDR $8
  49. #define CP0_COUNT $9
  50. #define CP0_ENTRYHI $10
  51. #define CP0_COMPARE $11
  52. #define CP0_STATUS $12
  53. #define CP0_CAUSE $13
  54. #define CP0_EPC $14
  55. #define CP0_PRID $15
  56. #define CP0_CONFIG $16
  57. #define CP0_LLADDR $17
  58. #define CP0_WATCHLO $18
  59. #define CP0_WATCHHI $19
  60. #define CP0_XCONTEXT $20
  61. #define CP0_FRAMEMASK $21
  62. #define CP0_DIAGNOSTIC $22
  63. #define CP0_DEBUG $23
  64. #define CP0_DEPC $24
  65. #define CP0_PERFORMANCE $25
  66. #define CP0_ECC $26
  67. #define CP0_CACHEERR $27
  68. #define CP0_TAGLO $28
  69. #define CP0_TAGHI $29
  70. #define CP0_ERROREPC $30
  71. #define CP0_DESAVE $31
  72. /*
  73. * R4640/R4650 cp0 register names. These registers are listed
  74. * here only for completeness; without MMU these CPUs are not useable
  75. * by Linux. A future ELKS port might take make Linux run on them
  76. * though ...
  77. */
  78. #define CP0_IBASE $0
  79. #define CP0_IBOUND $1
  80. #define CP0_DBASE $2
  81. #define CP0_DBOUND $3
  82. #define CP0_CALG $17
  83. #define CP0_IWATCH $18
  84. #define CP0_DWATCH $19
  85. /*
  86. * Coprocessor 0 Set 1 register names
  87. */
  88. #define CP0_S1_DERRADDR0 $26
  89. #define CP0_S1_DERRADDR1 $27
  90. #define CP0_S1_INTCONTROL $20
  91. /*
  92. * TX39 Series
  93. */
  94. #define CP0_TX39_CACHE $7
  95. /*
  96. * Coprocessor 1 (FPU) register names
  97. */
  98. #define CP1_REVISION $0
  99. #define CP1_STATUS $31
  100. /*
  101. * FPU Status Register Values
  102. */
  103. /*
  104. * Status Register Values
  105. */
  106. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  107. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  108. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  109. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  110. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  111. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  112. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  113. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  114. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  115. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  116. /*
  117. * X the exception cause indicator
  118. * E the exception enable
  119. * S the sticky/flag bit
  120. */
  121. #define FPU_CSR_ALL_X 0x0003f000
  122. #define FPU_CSR_UNI_X 0x00020000
  123. #define FPU_CSR_INV_X 0x00010000
  124. #define FPU_CSR_DIV_X 0x00008000
  125. #define FPU_CSR_OVF_X 0x00004000
  126. #define FPU_CSR_UDF_X 0x00002000
  127. #define FPU_CSR_INE_X 0x00001000
  128. #define FPU_CSR_ALL_E 0x00000f80
  129. #define FPU_CSR_INV_E 0x00000800
  130. #define FPU_CSR_DIV_E 0x00000400
  131. #define FPU_CSR_OVF_E 0x00000200
  132. #define FPU_CSR_UDF_E 0x00000100
  133. #define FPU_CSR_INE_E 0x00000080
  134. #define FPU_CSR_ALL_S 0x0000007c
  135. #define FPU_CSR_INV_S 0x00000040
  136. #define FPU_CSR_DIV_S 0x00000020
  137. #define FPU_CSR_OVF_S 0x00000010
  138. #define FPU_CSR_UDF_S 0x00000008
  139. #define FPU_CSR_INE_S 0x00000004
  140. /* rounding mode */
  141. #define FPU_CSR_RN 0x0 /* nearest */
  142. #define FPU_CSR_RZ 0x1 /* towards zero */
  143. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  144. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  145. /*
  146. * Values for PageMask register
  147. */
  148. #ifdef CONFIG_CPU_VR41XX
  149. /* Why doesn't stupidity hurt ... */
  150. #define PM_1K 0x00000000
  151. #define PM_4K 0x00001800
  152. #define PM_16K 0x00007800
  153. #define PM_64K 0x0001f800
  154. #define PM_256K 0x0007f800
  155. #else
  156. #define PM_4K 0x00000000
  157. #define PM_16K 0x00006000
  158. #define PM_64K 0x0001e000
  159. #define PM_256K 0x0007e000
  160. #define PM_1M 0x001fe000
  161. #define PM_4M 0x007fe000
  162. #define PM_16M 0x01ffe000
  163. #define PM_64M 0x07ffe000
  164. #define PM_256M 0x1fffe000
  165. #endif
  166. /*
  167. * Default page size for a given kernel configuration
  168. */
  169. #ifdef CONFIG_PAGE_SIZE_4KB
  170. #define PM_DEFAULT_MASK PM_4K
  171. #elif defined(CONFIG_PAGE_SIZE_16KB)
  172. #define PM_DEFAULT_MASK PM_16K
  173. #elif defined(CONFIG_PAGE_SIZE_64KB)
  174. #define PM_DEFAULT_MASK PM_64K
  175. #else
  176. #error Bad page size configuration!
  177. #endif
  178. /*
  179. * Values used for computation of new tlb entries
  180. */
  181. #define PL_4K 12
  182. #define PL_16K 14
  183. #define PL_64K 16
  184. #define PL_256K 18
  185. #define PL_1M 20
  186. #define PL_4M 22
  187. #define PL_16M 24
  188. #define PL_64M 26
  189. #define PL_256M 28
  190. /*
  191. * R4x00 interrupt enable / cause bits
  192. */
  193. #define IE_SW0 (_ULCAST_(1) << 8)
  194. #define IE_SW1 (_ULCAST_(1) << 9)
  195. #define IE_IRQ0 (_ULCAST_(1) << 10)
  196. #define IE_IRQ1 (_ULCAST_(1) << 11)
  197. #define IE_IRQ2 (_ULCAST_(1) << 12)
  198. #define IE_IRQ3 (_ULCAST_(1) << 13)
  199. #define IE_IRQ4 (_ULCAST_(1) << 14)
  200. #define IE_IRQ5 (_ULCAST_(1) << 15)
  201. /*
  202. * R4x00 interrupt cause bits
  203. */
  204. #define C_SW0 (_ULCAST_(1) << 8)
  205. #define C_SW1 (_ULCAST_(1) << 9)
  206. #define C_IRQ0 (_ULCAST_(1) << 10)
  207. #define C_IRQ1 (_ULCAST_(1) << 11)
  208. #define C_IRQ2 (_ULCAST_(1) << 12)
  209. #define C_IRQ3 (_ULCAST_(1) << 13)
  210. #define C_IRQ4 (_ULCAST_(1) << 14)
  211. #define C_IRQ5 (_ULCAST_(1) << 15)
  212. /*
  213. * Bitfields in the R4xx0 cp0 status register
  214. */
  215. #define ST0_IE 0x00000001
  216. #define ST0_EXL 0x00000002
  217. #define ST0_ERL 0x00000004
  218. #define ST0_KSU 0x00000018
  219. # define KSU_USER 0x00000010
  220. # define KSU_SUPERVISOR 0x00000008
  221. # define KSU_KERNEL 0x00000000
  222. #define ST0_UX 0x00000020
  223. #define ST0_SX 0x00000040
  224. #define ST0_KX 0x00000080
  225. #define ST0_DE 0x00010000
  226. #define ST0_CE 0x00020000
  227. /*
  228. * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
  229. * cacheops in userspace. This bit exists only on RM7000 and RM9000
  230. * processors.
  231. */
  232. #define ST0_CO 0x08000000
  233. /*
  234. * Bitfields in the R[23]000 cp0 status register.
  235. */
  236. #define ST0_IEC 0x00000001
  237. #define ST0_KUC 0x00000002
  238. #define ST0_IEP 0x00000004
  239. #define ST0_KUP 0x00000008
  240. #define ST0_IEO 0x00000010
  241. #define ST0_KUO 0x00000020
  242. /* bits 6 & 7 are reserved on R[23]000 */
  243. #define ST0_ISC 0x00010000
  244. #define ST0_SWC 0x00020000
  245. #define ST0_CM 0x00080000
  246. /*
  247. * Bits specific to the R4640/R4650
  248. */
  249. #define ST0_UM (_ULCAST_(1) << 4)
  250. #define ST0_IL (_ULCAST_(1) << 23)
  251. #define ST0_DL (_ULCAST_(1) << 24)
  252. /*
  253. * Enable the MIPS DSP ASE
  254. */
  255. #define ST0_MX 0x01000000
  256. /*
  257. * Bitfields in the TX39 family CP0 Configuration Register 3
  258. */
  259. #define TX39_CONF_ICS_SHIFT 19
  260. #define TX39_CONF_ICS_MASK 0x00380000
  261. #define TX39_CONF_ICS_1KB 0x00000000
  262. #define TX39_CONF_ICS_2KB 0x00080000
  263. #define TX39_CONF_ICS_4KB 0x00100000
  264. #define TX39_CONF_ICS_8KB 0x00180000
  265. #define TX39_CONF_ICS_16KB 0x00200000
  266. #define TX39_CONF_DCS_SHIFT 16
  267. #define TX39_CONF_DCS_MASK 0x00070000
  268. #define TX39_CONF_DCS_1KB 0x00000000
  269. #define TX39_CONF_DCS_2KB 0x00010000
  270. #define TX39_CONF_DCS_4KB 0x00020000
  271. #define TX39_CONF_DCS_8KB 0x00030000
  272. #define TX39_CONF_DCS_16KB 0x00040000
  273. #define TX39_CONF_CWFON 0x00004000
  274. #define TX39_CONF_WBON 0x00002000
  275. #define TX39_CONF_RF_SHIFT 10
  276. #define TX39_CONF_RF_MASK 0x00000c00
  277. #define TX39_CONF_DOZE 0x00000200
  278. #define TX39_CONF_HALT 0x00000100
  279. #define TX39_CONF_LOCK 0x00000080
  280. #define TX39_CONF_ICE 0x00000020
  281. #define TX39_CONF_DCE 0x00000010
  282. #define TX39_CONF_IRSIZE_SHIFT 2
  283. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  284. #define TX39_CONF_DRSIZE_SHIFT 0
  285. #define TX39_CONF_DRSIZE_MASK 0x00000003
  286. /*
  287. * Status register bits available in all MIPS CPUs.
  288. */
  289. #define ST0_IM 0x0000ff00
  290. #define STATUSB_IP0 8
  291. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  292. #define STATUSB_IP1 9
  293. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  294. #define STATUSB_IP2 10
  295. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  296. #define STATUSB_IP3 11
  297. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  298. #define STATUSB_IP4 12
  299. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  300. #define STATUSB_IP5 13
  301. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  302. #define STATUSB_IP6 14
  303. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  304. #define STATUSB_IP7 15
  305. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  306. #define STATUSB_IP8 0
  307. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  308. #define STATUSB_IP9 1
  309. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  310. #define STATUSB_IP10 2
  311. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  312. #define STATUSB_IP11 3
  313. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  314. #define STATUSB_IP12 4
  315. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  316. #define STATUSB_IP13 5
  317. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  318. #define STATUSB_IP14 6
  319. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  320. #define STATUSB_IP15 7
  321. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  322. #define ST0_CH 0x00040000
  323. #define ST0_SR 0x00100000
  324. #define ST0_TS 0x00200000
  325. #define ST0_BEV 0x00400000
  326. #define ST0_RE 0x02000000
  327. #define ST0_FR 0x04000000
  328. #define ST0_CU 0xf0000000
  329. #define ST0_CU0 0x10000000
  330. #define ST0_CU1 0x20000000
  331. #define ST0_CU2 0x40000000
  332. #define ST0_CU3 0x80000000
  333. #define ST0_XX 0x80000000 /* MIPS IV naming */
  334. /*
  335. * Bitfields and bit numbers in the coprocessor 0 cause register.
  336. *
  337. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  338. */
  339. #define CAUSEB_EXCCODE 2
  340. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  341. #define CAUSEB_IP 8
  342. #define CAUSEF_IP (_ULCAST_(255) << 8)
  343. #define CAUSEB_IP0 8
  344. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  345. #define CAUSEB_IP1 9
  346. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  347. #define CAUSEB_IP2 10
  348. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  349. #define CAUSEB_IP3 11
  350. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  351. #define CAUSEB_IP4 12
  352. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  353. #define CAUSEB_IP5 13
  354. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  355. #define CAUSEB_IP6 14
  356. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  357. #define CAUSEB_IP7 15
  358. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  359. #define CAUSEB_IV 23
  360. #define CAUSEF_IV (_ULCAST_(1) << 23)
  361. #define CAUSEB_CE 28
  362. #define CAUSEF_CE (_ULCAST_(3) << 28)
  363. #define CAUSEB_BD 31
  364. #define CAUSEF_BD (_ULCAST_(1) << 31)
  365. /*
  366. * Bits in the coprocessor 0 config register.
  367. */
  368. /* Generic bits. */
  369. #define CONF_CM_CACHABLE_NO_WA 0
  370. #define CONF_CM_CACHABLE_WA 1
  371. #define CONF_CM_UNCACHED 2
  372. #define CONF_CM_CACHABLE_NONCOHERENT 3
  373. #define CONF_CM_CACHABLE_CE 4
  374. #define CONF_CM_CACHABLE_COW 5
  375. #define CONF_CM_CACHABLE_CUW 6
  376. #define CONF_CM_CACHABLE_ACCELERATED 7
  377. #define CONF_CM_CMASK 7
  378. #define CONF_BE (_ULCAST_(1) << 15)
  379. /* Bits common to various processors. */
  380. #define CONF_CU (_ULCAST_(1) << 3)
  381. #define CONF_DB (_ULCAST_(1) << 4)
  382. #define CONF_IB (_ULCAST_(1) << 5)
  383. #define CONF_DC (_ULCAST_(7) << 6)
  384. #define CONF_IC (_ULCAST_(7) << 9)
  385. #define CONF_EB (_ULCAST_(1) << 13)
  386. #define CONF_EM (_ULCAST_(1) << 14)
  387. #define CONF_SM (_ULCAST_(1) << 16)
  388. #define CONF_SC (_ULCAST_(1) << 17)
  389. #define CONF_EW (_ULCAST_(3) << 18)
  390. #define CONF_EP (_ULCAST_(15)<< 24)
  391. #define CONF_EC (_ULCAST_(7) << 28)
  392. #define CONF_CM (_ULCAST_(1) << 31)
  393. /* Bits specific to the R4xx0. */
  394. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  395. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  396. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  397. /* Bits specific to the R5000. */
  398. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  399. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  400. /* Bits specific to the RM7000. */
  401. #define RM7K_CONF_SE (_ULCAST_(1) << 3)
  402. #define RM7K_CONF_TE (_ULCAST_(1) << 12)
  403. #define RM7K_CONF_CLK (_ULCAST_(1) << 16)
  404. #define RM7K_CONF_TC (_ULCAST_(1) << 17)
  405. #define RM7K_CONF_SI (_ULCAST_(3) << 20)
  406. #define RM7K_CONF_SC (_ULCAST_(1) << 31)
  407. /* Bits specific to the R10000. */
  408. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  409. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  410. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  411. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  412. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  413. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  414. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  415. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  416. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  417. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  418. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  419. /* Bits specific to the VR41xx. */
  420. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  421. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  422. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  423. /* Bits specific to the R30xx. */
  424. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  425. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  426. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  427. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  428. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  429. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  430. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  431. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  432. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  433. /* Bits specific to the TX49. */
  434. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  435. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  436. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  437. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  438. /* Bits specific to the MIPS32/64 PRA. */
  439. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  440. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  441. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  442. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  443. /*
  444. * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
  445. */
  446. #define MIPS_CONF1_FP (_ULCAST_(1) << 0)
  447. #define MIPS_CONF1_EP (_ULCAST_(1) << 1)
  448. #define MIPS_CONF1_CA (_ULCAST_(1) << 2)
  449. #define MIPS_CONF1_WR (_ULCAST_(1) << 3)
  450. #define MIPS_CONF1_PC (_ULCAST_(1) << 4)
  451. #define MIPS_CONF1_MD (_ULCAST_(1) << 5)
  452. #define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
  453. #define MIPS_CONF1_DA (_ULCAST_(7) << 7)
  454. #define MIPS_CONF1_DL (_ULCAST_(7) << 10)
  455. #define MIPS_CONF1_DS (_ULCAST_(7) << 13)
  456. #define MIPS_CONF1_IA (_ULCAST_(7) << 16)
  457. #define MIPS_CONF1_IL (_ULCAST_(7) << 19)
  458. #define MIPS_CONF1_IS (_ULCAST_(7) << 22)
  459. #define MIPS_CONF1_TLBS (_ULCAST_(63)<< 25)
  460. #define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
  461. #define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
  462. #define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
  463. #define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
  464. #define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
  465. #define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
  466. #define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
  467. #define MIPS_CONF2_TU (_ULCAST_(7) << 28)
  468. #define MIPS_CONF3_TL (_ULCAST_(1) << 0)
  469. #define MIPS_CONF3_SM (_ULCAST_(1) << 1)
  470. #define MIPS_CONF3_SP (_ULCAST_(1) << 4)
  471. #define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
  472. #define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
  473. #define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
  474. #define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
  475. /*
  476. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  477. */
  478. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  479. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  480. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  481. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  482. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  483. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  484. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  485. /*
  486. * R10000 performance counter definitions.
  487. *
  488. * FIXME: The R10000 performance counter opens a nice way to implement CPU
  489. * time accounting with a precission of one cycle. I don't have
  490. * R10000 silicon but just a manual, so ...
  491. */
  492. /*
  493. * Events counted by counter #0
  494. */
  495. #define CE0_CYCLES 0
  496. #define CE0_INSN_ISSUED 1
  497. #define CE0_LPSC_ISSUED 2
  498. #define CE0_S_ISSUED 3
  499. #define CE0_SC_ISSUED 4
  500. #define CE0_SC_FAILED 5
  501. #define CE0_BRANCH_DECODED 6
  502. #define CE0_QW_WB_SECONDARY 7
  503. #define CE0_CORRECTED_ECC_ERRORS 8
  504. #define CE0_ICACHE_MISSES 9
  505. #define CE0_SCACHE_I_MISSES 10
  506. #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
  507. #define CE0_EXT_INTERVENTIONS_REQ 12
  508. #define CE0_EXT_INVALIDATE_REQ 13
  509. #define CE0_VIRTUAL_COHERENCY_COND 14
  510. #define CE0_INSN_GRADUATED 15
  511. /*
  512. * Events counted by counter #1
  513. */
  514. #define CE1_CYCLES 0
  515. #define CE1_INSN_GRADUATED 1
  516. #define CE1_LPSC_GRADUATED 2
  517. #define CE1_S_GRADUATED 3
  518. #define CE1_SC_GRADUATED 4
  519. #define CE1_FP_INSN_GRADUATED 5
  520. #define CE1_QW_WB_PRIMARY 6
  521. #define CE1_TLB_REFILL 7
  522. #define CE1_BRANCH_MISSPREDICTED 8
  523. #define CE1_DCACHE_MISS 9
  524. #define CE1_SCACHE_D_MISSES 10
  525. #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
  526. #define CE1_EXT_INTERVENTION_HITS 12
  527. #define CE1_EXT_INVALIDATE_REQ 13
  528. #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
  529. #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
  530. /*
  531. * These flags define in which privilege mode the counters count events
  532. */
  533. #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
  534. #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
  535. #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
  536. #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
  537. #ifndef __ASSEMBLY__
  538. /*
  539. * Functions to access the R10000 performance counters. These are basically
  540. * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
  541. * performance counter number encoded into bits 1 ... 5 of the instruction.
  542. * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
  543. * disassembler these will look like an access to sel 0 or 1.
  544. */
  545. #define read_r10k_perf_cntr(counter) \
  546. ({ \
  547. unsigned int __res; \
  548. __asm__ __volatile__( \
  549. "mfpc\t%0, %1" \
  550. : "=r" (__res) \
  551. : "i" (counter)); \
  552. \
  553. __res; \
  554. })
  555. #define write_r10k_perf_cntr(counter,val) \
  556. do { \
  557. __asm__ __volatile__( \
  558. "mtpc\t%0, %1" \
  559. : \
  560. : "r" (val), "i" (counter)); \
  561. } while (0)
  562. #define read_r10k_perf_event(counter) \
  563. ({ \
  564. unsigned int __res; \
  565. __asm__ __volatile__( \
  566. "mfps\t%0, %1" \
  567. : "=r" (__res) \
  568. : "i" (counter)); \
  569. \
  570. __res; \
  571. })
  572. #define write_r10k_perf_cntl(counter,val) \
  573. do { \
  574. __asm__ __volatile__( \
  575. "mtps\t%0, %1" \
  576. : \
  577. : "r" (val), "i" (counter)); \
  578. } while (0)
  579. /*
  580. * Macros to access the system control coprocessor
  581. */
  582. #define __read_32bit_c0_register(source, sel) \
  583. ({ int __res; \
  584. if (sel == 0) \
  585. __asm__ __volatile__( \
  586. "mfc0\t%0, " #source "\n\t" \
  587. : "=r" (__res)); \
  588. else \
  589. __asm__ __volatile__( \
  590. ".set\tmips32\n\t" \
  591. "mfc0\t%0, " #source ", " #sel "\n\t" \
  592. ".set\tmips0\n\t" \
  593. : "=r" (__res)); \
  594. __res; \
  595. })
  596. #define __read_64bit_c0_register(source, sel) \
  597. ({ unsigned long long __res; \
  598. if (sizeof(unsigned long) == 4) \
  599. __res = __read_64bit_c0_split(source, sel); \
  600. else if (sel == 0) \
  601. __asm__ __volatile__( \
  602. ".set\tmips3\n\t" \
  603. "dmfc0\t%0, " #source "\n\t" \
  604. ".set\tmips0" \
  605. : "=r" (__res)); \
  606. else \
  607. __asm__ __volatile__( \
  608. ".set\tmips64\n\t" \
  609. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  610. ".set\tmips0" \
  611. : "=r" (__res)); \
  612. __res; \
  613. })
  614. #define __write_32bit_c0_register(register, sel, value) \
  615. do { \
  616. if (sel == 0) \
  617. __asm__ __volatile__( \
  618. "mtc0\t%z0, " #register "\n\t" \
  619. : : "Jr" ((unsigned int)value)); \
  620. else \
  621. __asm__ __volatile__( \
  622. ".set\tmips32\n\t" \
  623. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  624. ".set\tmips0" \
  625. : : "Jr" ((unsigned int)value)); \
  626. } while (0)
  627. #define __write_64bit_c0_register(register, sel, value) \
  628. do { \
  629. if (sizeof(unsigned long) == 4) \
  630. __write_64bit_c0_split(register, sel, value); \
  631. else if (sel == 0) \
  632. __asm__ __volatile__( \
  633. ".set\tmips3\n\t" \
  634. "dmtc0\t%z0, " #register "\n\t" \
  635. ".set\tmips0" \
  636. : : "Jr" (value)); \
  637. else \
  638. __asm__ __volatile__( \
  639. ".set\tmips64\n\t" \
  640. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  641. ".set\tmips0" \
  642. : : "Jr" (value)); \
  643. } while (0)
  644. #define __read_ulong_c0_register(reg, sel) \
  645. ((sizeof(unsigned long) == 4) ? \
  646. (unsigned long) __read_32bit_c0_register(reg, sel) : \
  647. (unsigned long) __read_64bit_c0_register(reg, sel))
  648. #define __write_ulong_c0_register(reg, sel, val) \
  649. do { \
  650. if (sizeof(unsigned long) == 4) \
  651. __write_32bit_c0_register(reg, sel, val); \
  652. else \
  653. __write_64bit_c0_register(reg, sel, val); \
  654. } while (0)
  655. /*
  656. * On RM7000/RM9000 these are uses to access cop0 set 1 registers
  657. */
  658. #define __read_32bit_c0_ctrl_register(source) \
  659. ({ int __res; \
  660. __asm__ __volatile__( \
  661. "cfc0\t%0, " #source "\n\t" \
  662. : "=r" (__res)); \
  663. __res; \
  664. })
  665. #define __write_32bit_c0_ctrl_register(register, value) \
  666. do { \
  667. __asm__ __volatile__( \
  668. "ctc0\t%z0, " #register "\n\t" \
  669. : : "Jr" ((unsigned int)value)); \
  670. } while (0)
  671. /*
  672. * These versions are only needed for systems with more than 38 bits of
  673. * physical address space running the 32-bit kernel. That's none atm :-)
  674. */
  675. #define __read_64bit_c0_split(source, sel) \
  676. ({ \
  677. unsigned long long val; \
  678. unsigned long flags; \
  679. \
  680. local_irq_save(flags); \
  681. if (sel == 0) \
  682. __asm__ __volatile__( \
  683. ".set\tmips64\n\t" \
  684. "dmfc0\t%M0, " #source "\n\t" \
  685. "dsll\t%L0, %M0, 32\n\t" \
  686. "dsrl\t%M0, %M0, 32\n\t" \
  687. "dsrl\t%L0, %L0, 32\n\t" \
  688. ".set\tmips0" \
  689. : "=r" (val)); \
  690. else \
  691. __asm__ __volatile__( \
  692. ".set\tmips64\n\t" \
  693. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  694. "dsll\t%L0, %M0, 32\n\t" \
  695. "dsrl\t%M0, %M0, 32\n\t" \
  696. "dsrl\t%L0, %L0, 32\n\t" \
  697. ".set\tmips0" \
  698. : "=r" (val)); \
  699. local_irq_restore(flags); \
  700. \
  701. val; \
  702. })
  703. #define __write_64bit_c0_split(source, sel, val) \
  704. do { \
  705. unsigned long flags; \
  706. \
  707. local_irq_save(flags); \
  708. if (sel == 0) \
  709. __asm__ __volatile__( \
  710. ".set\tmips64\n\t" \
  711. "dsll\t%L0, %L0, 32\n\t" \
  712. "dsrl\t%L0, %L0, 32\n\t" \
  713. "dsll\t%M0, %M0, 32\n\t" \
  714. "or\t%L0, %L0, %M0\n\t" \
  715. "dmtc0\t%L0, " #source "\n\t" \
  716. ".set\tmips0" \
  717. : : "r" (val)); \
  718. else \
  719. __asm__ __volatile__( \
  720. ".set\tmips64\n\t" \
  721. "dsll\t%L0, %L0, 32\n\t" \
  722. "dsrl\t%L0, %L0, 32\n\t" \
  723. "dsll\t%M0, %M0, 32\n\t" \
  724. "or\t%L0, %L0, %M0\n\t" \
  725. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  726. ".set\tmips0" \
  727. : : "r" (val)); \
  728. local_irq_restore(flags); \
  729. } while (0)
  730. #define read_c0_index() __read_32bit_c0_register($0, 0)
  731. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  732. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  733. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  734. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  735. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  736. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  737. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  738. #define read_c0_context() __read_ulong_c0_register($4, 0)
  739. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  740. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  741. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  742. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  743. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  744. #define read_c0_info() __read_32bit_c0_register($7, 0)
  745. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  746. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  747. #define read_c0_count() __read_32bit_c0_register($9, 0)
  748. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  749. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  750. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  751. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  752. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  753. #define read_c0_status() __read_32bit_c0_register($12, 0)
  754. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  755. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  756. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  757. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  758. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  759. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  760. #define read_c0_config() __read_32bit_c0_register($16, 0)
  761. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  762. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  763. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  764. #define read_c0_config4() __read_32bit_c0_register($16, 4)
  765. #define read_c0_config5() __read_32bit_c0_register($16, 5)
  766. #define read_c0_config6() __read_32bit_c0_register($16, 6)
  767. #define read_c0_config7() __read_32bit_c0_register($16, 7)
  768. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  769. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  770. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  771. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  772. #define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
  773. #define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
  774. #define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
  775. #define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
  776. /*
  777. * The WatchLo register. There may be upto 8 of them.
  778. */
  779. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  780. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  781. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  782. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  783. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  784. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  785. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  786. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  787. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  788. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  789. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  790. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  791. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  792. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  793. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  794. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  795. /*
  796. * The WatchHi register. There may be upto 8 of them.
  797. */
  798. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  799. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  800. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  801. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  802. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  803. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  804. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  805. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  806. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  807. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  808. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  809. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  810. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  811. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  812. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  813. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  814. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  815. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  816. #define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
  817. #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
  818. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  819. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  820. /* RM9000 PerfControl performance counter control register */
  821. #define read_c0_perfcontrol() __read_32bit_c0_register($22, 0)
  822. #define write_c0_perfcontrol(val) __write_32bit_c0_register($22, 0, val)
  823. #define read_c0_diag() __read_32bit_c0_register($22, 0)
  824. #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
  825. #define read_c0_diag1() __read_32bit_c0_register($22, 1)
  826. #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
  827. #define read_c0_diag2() __read_32bit_c0_register($22, 2)
  828. #define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
  829. #define read_c0_diag3() __read_32bit_c0_register($22, 3)
  830. #define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
  831. #define read_c0_diag4() __read_32bit_c0_register($22, 4)
  832. #define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
  833. #define read_c0_diag5() __read_32bit_c0_register($22, 5)
  834. #define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
  835. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  836. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  837. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  838. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  839. /*
  840. * MIPS32 / MIPS64 performance counters
  841. */
  842. #define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
  843. #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
  844. #define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
  845. #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
  846. #define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
  847. #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
  848. #define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
  849. #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
  850. #define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
  851. #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
  852. #define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
  853. #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
  854. #define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
  855. #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
  856. #define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
  857. #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
  858. /* RM9000 PerfCount performance counter register */
  859. #define read_c0_perfcount() __read_64bit_c0_register($25, 0)
  860. #define write_c0_perfcount(val) __write_64bit_c0_register($25, 0, val)
  861. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  862. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  863. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  864. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  865. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  866. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  867. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  868. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  869. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  870. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  871. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  872. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  873. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  874. /*
  875. * Macros to access the floating point coprocessor control registers
  876. */
  877. #define read_32bit_cp1_register(source) \
  878. ({ int __res; \
  879. __asm__ __volatile__( \
  880. ".set\tpush\n\t" \
  881. ".set\treorder\n\t" \
  882. "cfc1\t%0,"STR(source)"\n\t" \
  883. ".set\tpop" \
  884. : "=r" (__res)); \
  885. __res;})
  886. #define rddsp(mask) \
  887. ({ \
  888. unsigned int __res; \
  889. \
  890. __asm__ __volatile__( \
  891. " .set push \n" \
  892. " .set noat \n" \
  893. " # rddsp $1, %x1 \n" \
  894. " .word 0x7c000cb8 | (%x1 << 16) \n" \
  895. " move %0, $1 \n" \
  896. " .set pop \n" \
  897. : "=r" (__res) \
  898. : "i" (mask)); \
  899. __res; \
  900. })
  901. #define wrdsp(val, mask) \
  902. do { \
  903. __asm__ __volatile__( \
  904. " .set push \n" \
  905. " .set noat \n" \
  906. " move $1, %0 \n" \
  907. " # wrdsp $1, %x1 \n" \
  908. " .word 0x7c2004f8 | (%x1 << 15) \n" \
  909. " .set pop \n" \
  910. : \
  911. : "r" (val), "i" (mask)); \
  912. } while (0)
  913. #if 0 /* Need DSP ASE capable assembler ... */
  914. #define mflo0() ({ long mflo0; __asm__("mflo %0, $ac0" : "=r" (mflo0)); mflo0;})
  915. #define mflo1() ({ long mflo1; __asm__("mflo %0, $ac1" : "=r" (mflo1)); mflo1;})
  916. #define mflo2() ({ long mflo2; __asm__("mflo %0, $ac2" : "=r" (mflo2)); mflo2;})
  917. #define mflo3() ({ long mflo3; __asm__("mflo %0, $ac3" : "=r" (mflo3)); mflo3;})
  918. #define mfhi0() ({ long mfhi0; __asm__("mfhi %0, $ac0" : "=r" (mfhi0)); mfhi0;})
  919. #define mfhi1() ({ long mfhi1; __asm__("mfhi %0, $ac1" : "=r" (mfhi1)); mfhi1;})
  920. #define mfhi2() ({ long mfhi2; __asm__("mfhi %0, $ac2" : "=r" (mfhi2)); mfhi2;})
  921. #define mfhi3() ({ long mfhi3; __asm__("mfhi %0, $ac3" : "=r" (mfhi3)); mfhi3;})
  922. #define mtlo0(x) __asm__("mtlo %0, $ac0" ::"r" (x))
  923. #define mtlo1(x) __asm__("mtlo %0, $ac1" ::"r" (x))
  924. #define mtlo2(x) __asm__("mtlo %0, $ac2" ::"r" (x))
  925. #define mtlo3(x) __asm__("mtlo %0, $ac3" ::"r" (x))
  926. #define mthi0(x) __asm__("mthi %0, $ac0" ::"r" (x))
  927. #define mthi1(x) __asm__("mthi %0, $ac1" ::"r" (x))
  928. #define mthi2(x) __asm__("mthi %0, $ac2" ::"r" (x))
  929. #define mthi3(x) __asm__("mthi %0, $ac3" ::"r" (x))
  930. #else
  931. #define mfhi0() \
  932. ({ \
  933. unsigned long __treg; \
  934. \
  935. __asm__ __volatile__( \
  936. " .set push \n" \
  937. " .set noat \n" \
  938. " # mfhi %0, $ac0 \n" \
  939. " .word 0x00000810 \n" \
  940. " move %0, $1 \n" \
  941. " .set pop \n" \
  942. : "=r" (__treg)); \
  943. __treg; \
  944. })
  945. #define mfhi1() \
  946. ({ \
  947. unsigned long __treg; \
  948. \
  949. __asm__ __volatile__( \
  950. " .set push \n" \
  951. " .set noat \n" \
  952. " # mfhi %0, $ac1 \n" \
  953. " .word 0x00200810 \n" \
  954. " move %0, $1 \n" \
  955. " .set pop \n" \
  956. : "=r" (__treg)); \
  957. __treg; \
  958. })
  959. #define mfhi2() \
  960. ({ \
  961. unsigned long __treg; \
  962. \
  963. __asm__ __volatile__( \
  964. " .set push \n" \
  965. " .set noat \n" \
  966. " # mfhi %0, $ac2 \n" \
  967. " .word 0x00400810 \n" \
  968. " move %0, $1 \n" \
  969. " .set pop \n" \
  970. : "=r" (__treg)); \
  971. __treg; \
  972. })
  973. #define mfhi3() \
  974. ({ \
  975. unsigned long __treg; \
  976. \
  977. __asm__ __volatile__( \
  978. " .set push \n" \
  979. " .set noat \n" \
  980. " # mfhi %0, $ac3 \n" \
  981. " .word 0x00600810 \n" \
  982. " move %0, $1 \n" \
  983. " .set pop \n" \
  984. : "=r" (__treg)); \
  985. __treg; \
  986. })
  987. #define mflo0() \
  988. ({ \
  989. unsigned long __treg; \
  990. \
  991. __asm__ __volatile__( \
  992. " .set push \n" \
  993. " .set noat \n" \
  994. " # mflo %0, $ac0 \n" \
  995. " .word 0x00000812 \n" \
  996. " move %0, $1 \n" \
  997. " .set pop \n" \
  998. : "=r" (__treg)); \
  999. __treg; \
  1000. })
  1001. #define mflo1() \
  1002. ({ \
  1003. unsigned long __treg; \
  1004. \
  1005. __asm__ __volatile__( \
  1006. " .set push \n" \
  1007. " .set noat \n" \
  1008. " # mflo %0, $ac1 \n" \
  1009. " .word 0x00200812 \n" \
  1010. " move %0, $1 \n" \
  1011. " .set pop \n" \
  1012. : "=r" (__treg)); \
  1013. __treg; \
  1014. })
  1015. #define mflo2() \
  1016. ({ \
  1017. unsigned long __treg; \
  1018. \
  1019. __asm__ __volatile__( \
  1020. " .set push \n" \
  1021. " .set noat \n" \
  1022. " # mflo %0, $ac2 \n" \
  1023. " .word 0x00400812 \n" \
  1024. " move %0, $1 \n" \
  1025. " .set pop \n" \
  1026. : "=r" (__treg)); \
  1027. __treg; \
  1028. })
  1029. #define mflo3() \
  1030. ({ \
  1031. unsigned long __treg; \
  1032. \
  1033. __asm__ __volatile__( \
  1034. " .set push \n" \
  1035. " .set noat \n" \
  1036. " # mflo %0, $ac3 \n" \
  1037. " .word 0x00600812 \n" \
  1038. " move %0, $1 \n" \
  1039. " .set pop \n" \
  1040. : "=r" (__treg)); \
  1041. __treg; \
  1042. })
  1043. #define mthi0(x) \
  1044. do { \
  1045. __asm__ __volatile__( \
  1046. " .set push \n" \
  1047. " .set noat \n" \
  1048. " move $1, %0 \n" \
  1049. " # mthi $1, $ac0 \n" \
  1050. " .word 0x00200011 \n" \
  1051. " .set pop \n" \
  1052. : \
  1053. : "r" (x)); \
  1054. } while (0)
  1055. #define mthi1(x) \
  1056. do { \
  1057. __asm__ __volatile__( \
  1058. " .set push \n" \
  1059. " .set noat \n" \
  1060. " move $1, %0 \n" \
  1061. " # mthi $1, $ac1 \n" \
  1062. " .word 0x00200811 \n" \
  1063. " .set pop \n" \
  1064. : \
  1065. : "r" (x)); \
  1066. } while (0)
  1067. #define mthi2(x) \
  1068. do { \
  1069. __asm__ __volatile__( \
  1070. " .set push \n" \
  1071. " .set noat \n" \
  1072. " move $1, %0 \n" \
  1073. " # mthi $1, $ac2 \n" \
  1074. " .word 0x00201011 \n" \
  1075. " .set pop \n" \
  1076. : \
  1077. : "r" (x)); \
  1078. } while (0)
  1079. #define mthi3(x) \
  1080. do { \
  1081. __asm__ __volatile__( \
  1082. " .set push \n" \
  1083. " .set noat \n" \
  1084. " move $1, %0 \n" \
  1085. " # mthi $1, $ac3 \n" \
  1086. " .word 0x00201811 \n" \
  1087. " .set pop \n" \
  1088. : \
  1089. : "r" (x)); \
  1090. } while (0)
  1091. #define mtlo0(x) \
  1092. do { \
  1093. __asm__ __volatile__( \
  1094. " .set push \n" \
  1095. " .set noat \n" \
  1096. " move $1, %0 \n" \
  1097. " # mtlo $1, $ac0 \n" \
  1098. " .word 0x00200013 \n" \
  1099. " .set pop \n" \
  1100. : \
  1101. : "r" (x)); \
  1102. } while (0)
  1103. #define mtlo1(x) \
  1104. do { \
  1105. __asm__ __volatile__( \
  1106. " .set push \n" \
  1107. " .set noat \n" \
  1108. " move $1, %0 \n" \
  1109. " # mtlo $1, $ac1 \n" \
  1110. " .word 0x00200813 \n" \
  1111. " .set pop \n" \
  1112. : \
  1113. : "r" (x)); \
  1114. } while (0)
  1115. #define mtlo2(x) \
  1116. do { \
  1117. __asm__ __volatile__( \
  1118. " .set push \n" \
  1119. " .set noat \n" \
  1120. " move $1, %0 \n" \
  1121. " # mtlo $1, $ac2 \n" \
  1122. " .word 0x00201013 \n" \
  1123. " .set pop \n" \
  1124. : \
  1125. : "r" (x)); \
  1126. } while (0)
  1127. #define mtlo3(x) \
  1128. do { \
  1129. __asm__ __volatile__( \
  1130. " .set push \n" \
  1131. " .set noat \n" \
  1132. " move $1, %0 \n" \
  1133. " # mtlo $1, $ac3 \n" \
  1134. " .word 0x00201813 \n" \
  1135. " .set pop \n" \
  1136. : \
  1137. : "r" (x)); \
  1138. } while (0)
  1139. #endif
  1140. /*
  1141. * TLB operations.
  1142. *
  1143. * It is responsibility of the caller to take care of any TLB hazards.
  1144. */
  1145. static inline void tlb_probe(void)
  1146. {
  1147. __asm__ __volatile__(
  1148. ".set noreorder\n\t"
  1149. "tlbp\n\t"
  1150. ".set reorder");
  1151. }
  1152. static inline void tlb_read(void)
  1153. {
  1154. __asm__ __volatile__(
  1155. ".set noreorder\n\t"
  1156. "tlbr\n\t"
  1157. ".set reorder");
  1158. }
  1159. static inline void tlb_write_indexed(void)
  1160. {
  1161. __asm__ __volatile__(
  1162. ".set noreorder\n\t"
  1163. "tlbwi\n\t"
  1164. ".set reorder");
  1165. }
  1166. static inline void tlb_write_random(void)
  1167. {
  1168. __asm__ __volatile__(
  1169. ".set noreorder\n\t"
  1170. "tlbwr\n\t"
  1171. ".set reorder");
  1172. }
  1173. /*
  1174. * Manipulate bits in a c0 register.
  1175. */
  1176. #define __BUILD_SET_C0(name) \
  1177. static inline unsigned int \
  1178. set_c0_##name(unsigned int set) \
  1179. { \
  1180. unsigned int res; \
  1181. \
  1182. res = read_c0_##name(); \
  1183. res |= set; \
  1184. write_c0_##name(res); \
  1185. \
  1186. return res; \
  1187. } \
  1188. \
  1189. static inline unsigned int \
  1190. clear_c0_##name(unsigned int clear) \
  1191. { \
  1192. unsigned int res; \
  1193. \
  1194. res = read_c0_##name(); \
  1195. res &= ~clear; \
  1196. write_c0_##name(res); \
  1197. \
  1198. return res; \
  1199. } \
  1200. \
  1201. static inline unsigned int \
  1202. change_c0_##name(unsigned int change, unsigned int new) \
  1203. { \
  1204. unsigned int res; \
  1205. \
  1206. res = read_c0_##name(); \
  1207. res &= ~change; \
  1208. res |= (new & change); \
  1209. write_c0_##name(res); \
  1210. \
  1211. return res; \
  1212. }
  1213. __BUILD_SET_C0(status)
  1214. __BUILD_SET_C0(cause)
  1215. __BUILD_SET_C0(config)
  1216. __BUILD_SET_C0(intcontrol)
  1217. #endif /* !__ASSEMBLY__ */
  1218. #endif /* _ASM_MIPSREGS_H */