mipsregs.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  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, 07 MIPS Technologies, Inc.
  11. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  12. */
  13. #ifndef _ASM_MIPSREGS_H
  14. #define _ASM_MIPSREGS_H
  15. #include <linux/linkage.h>
  16. #include <linux/types.h>
  17. #include <asm/hazards.h>
  18. #include <asm/war.h>
  19. /*
  20. * The following macros are especially useful for __asm__
  21. * inline assembler.
  22. */
  23. #ifndef __STR
  24. #define __STR(x) #x
  25. #endif
  26. #ifndef STR
  27. #define STR(x) __STR(x)
  28. #endif
  29. /*
  30. * Configure language
  31. */
  32. #ifdef __ASSEMBLY__
  33. #define _ULCAST_
  34. #else
  35. #define _ULCAST_ (unsigned long)
  36. #endif
  37. /*
  38. * Coprocessor 0 register names
  39. */
  40. #define CP0_INDEX $0
  41. #define CP0_RANDOM $1
  42. #define CP0_ENTRYLO0 $2
  43. #define CP0_ENTRYLO1 $3
  44. #define CP0_CONF $3
  45. #define CP0_CONTEXT $4
  46. #define CP0_PAGEMASK $5
  47. #define CP0_WIRED $6
  48. #define CP0_INFO $7
  49. #define CP0_HWRENA $7, 0
  50. #define CP0_BADVADDR $8
  51. #define CP0_BADINSTR $8, 1
  52. #define CP0_COUNT $9
  53. #define CP0_ENTRYHI $10
  54. #define CP0_COMPARE $11
  55. #define CP0_STATUS $12
  56. #define CP0_CAUSE $13
  57. #define CP0_EPC $14
  58. #define CP0_PRID $15
  59. #define CP0_EBASE $15, 1
  60. #define CP0_CMGCRBASE $15, 3
  61. #define CP0_CONFIG $16
  62. #define CP0_CONFIG3 $16, 3
  63. #define CP0_CONFIG5 $16, 5
  64. #define CP0_LLADDR $17
  65. #define CP0_WATCHLO $18
  66. #define CP0_WATCHHI $19
  67. #define CP0_XCONTEXT $20
  68. #define CP0_FRAMEMASK $21
  69. #define CP0_DIAGNOSTIC $22
  70. #define CP0_DEBUG $23
  71. #define CP0_DEPC $24
  72. #define CP0_PERFORMANCE $25
  73. #define CP0_ECC $26
  74. #define CP0_CACHEERR $27
  75. #define CP0_TAGLO $28
  76. #define CP0_TAGHI $29
  77. #define CP0_ERROREPC $30
  78. #define CP0_DESAVE $31
  79. /*
  80. * R4640/R4650 cp0 register names. These registers are listed
  81. * here only for completeness; without MMU these CPUs are not useable
  82. * by Linux. A future ELKS port might take make Linux run on them
  83. * though ...
  84. */
  85. #define CP0_IBASE $0
  86. #define CP0_IBOUND $1
  87. #define CP0_DBASE $2
  88. #define CP0_DBOUND $3
  89. #define CP0_CALG $17
  90. #define CP0_IWATCH $18
  91. #define CP0_DWATCH $19
  92. /*
  93. * Coprocessor 0 Set 1 register names
  94. */
  95. #define CP0_S1_DERRADDR0 $26
  96. #define CP0_S1_DERRADDR1 $27
  97. #define CP0_S1_INTCONTROL $20
  98. /*
  99. * Coprocessor 0 Set 2 register names
  100. */
  101. #define CP0_S2_SRSCTL $12 /* MIPSR2 */
  102. /*
  103. * Coprocessor 0 Set 3 register names
  104. */
  105. #define CP0_S3_SRSMAP $12 /* MIPSR2 */
  106. /*
  107. * TX39 Series
  108. */
  109. #define CP0_TX39_CACHE $7
  110. /* Generic EntryLo bit definitions */
  111. #define ENTRYLO_G (_ULCAST_(1) << 0)
  112. #define ENTRYLO_V (_ULCAST_(1) << 1)
  113. #define ENTRYLO_D (_ULCAST_(1) << 2)
  114. #define ENTRYLO_C_SHIFT 3
  115. #define ENTRYLO_C (_ULCAST_(7) << ENTRYLO_C_SHIFT)
  116. /* R3000 EntryLo bit definitions */
  117. #define R3K_ENTRYLO_G (_ULCAST_(1) << 8)
  118. #define R3K_ENTRYLO_V (_ULCAST_(1) << 9)
  119. #define R3K_ENTRYLO_D (_ULCAST_(1) << 10)
  120. #define R3K_ENTRYLO_N (_ULCAST_(1) << 11)
  121. /* MIPS32/64 EntryLo bit definitions */
  122. #define MIPS_ENTRYLO_PFN_SHIFT 6
  123. #define MIPS_ENTRYLO_XI (_ULCAST_(1) << (BITS_PER_LONG - 2))
  124. #define MIPS_ENTRYLO_RI (_ULCAST_(1) << (BITS_PER_LONG - 1))
  125. /*
  126. * Values for PageMask register
  127. */
  128. #ifdef CONFIG_CPU_VR41XX
  129. /* Why doesn't stupidity hurt ... */
  130. #define PM_1K 0x00000000
  131. #define PM_4K 0x00001800
  132. #define PM_16K 0x00007800
  133. #define PM_64K 0x0001f800
  134. #define PM_256K 0x0007f800
  135. #else
  136. #define PM_4K 0x00000000
  137. #define PM_8K 0x00002000
  138. #define PM_16K 0x00006000
  139. #define PM_32K 0x0000e000
  140. #define PM_64K 0x0001e000
  141. #define PM_128K 0x0003e000
  142. #define PM_256K 0x0007e000
  143. #define PM_512K 0x000fe000
  144. #define PM_1M 0x001fe000
  145. #define PM_2M 0x003fe000
  146. #define PM_4M 0x007fe000
  147. #define PM_8M 0x00ffe000
  148. #define PM_16M 0x01ffe000
  149. #define PM_32M 0x03ffe000
  150. #define PM_64M 0x07ffe000
  151. #define PM_256M 0x1fffe000
  152. #define PM_1G 0x7fffe000
  153. #endif
  154. /*
  155. * Default page size for a given kernel configuration
  156. */
  157. #ifdef CONFIG_PAGE_SIZE_4KB
  158. #define PM_DEFAULT_MASK PM_4K
  159. #elif defined(CONFIG_PAGE_SIZE_8KB)
  160. #define PM_DEFAULT_MASK PM_8K
  161. #elif defined(CONFIG_PAGE_SIZE_16KB)
  162. #define PM_DEFAULT_MASK PM_16K
  163. #elif defined(CONFIG_PAGE_SIZE_32KB)
  164. #define PM_DEFAULT_MASK PM_32K
  165. #elif defined(CONFIG_PAGE_SIZE_64KB)
  166. #define PM_DEFAULT_MASK PM_64K
  167. #else
  168. #error Bad page size configuration!
  169. #endif
  170. /*
  171. * Default huge tlb size for a given kernel configuration
  172. */
  173. #ifdef CONFIG_PAGE_SIZE_4KB
  174. #define PM_HUGE_MASK PM_1M
  175. #elif defined(CONFIG_PAGE_SIZE_8KB)
  176. #define PM_HUGE_MASK PM_4M
  177. #elif defined(CONFIG_PAGE_SIZE_16KB)
  178. #define PM_HUGE_MASK PM_16M
  179. #elif defined(CONFIG_PAGE_SIZE_32KB)
  180. #define PM_HUGE_MASK PM_64M
  181. #elif defined(CONFIG_PAGE_SIZE_64KB)
  182. #define PM_HUGE_MASK PM_256M
  183. #elif defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
  184. #error Bad page size configuration for hugetlbfs!
  185. #endif
  186. /*
  187. * Values used for computation of new tlb entries
  188. */
  189. #define PL_4K 12
  190. #define PL_16K 14
  191. #define PL_64K 16
  192. #define PL_256K 18
  193. #define PL_1M 20
  194. #define PL_4M 22
  195. #define PL_16M 24
  196. #define PL_64M 26
  197. #define PL_256M 28
  198. /*
  199. * PageGrain bits
  200. */
  201. #define PG_RIE (_ULCAST_(1) << 31)
  202. #define PG_XIE (_ULCAST_(1) << 30)
  203. #define PG_ELPA (_ULCAST_(1) << 29)
  204. #define PG_ESP (_ULCAST_(1) << 28)
  205. #define PG_IEC (_ULCAST_(1) << 27)
  206. /* MIPS32/64 EntryHI bit definitions */
  207. #define MIPS_ENTRYHI_EHINV (_ULCAST_(1) << 10)
  208. #define MIPS_ENTRYHI_ASIDX (_ULCAST_(0x3) << 8)
  209. #define MIPS_ENTRYHI_ASID (_ULCAST_(0xff) << 0)
  210. /*
  211. * R4x00 interrupt enable / cause bits
  212. */
  213. #define IE_SW0 (_ULCAST_(1) << 8)
  214. #define IE_SW1 (_ULCAST_(1) << 9)
  215. #define IE_IRQ0 (_ULCAST_(1) << 10)
  216. #define IE_IRQ1 (_ULCAST_(1) << 11)
  217. #define IE_IRQ2 (_ULCAST_(1) << 12)
  218. #define IE_IRQ3 (_ULCAST_(1) << 13)
  219. #define IE_IRQ4 (_ULCAST_(1) << 14)
  220. #define IE_IRQ5 (_ULCAST_(1) << 15)
  221. /*
  222. * R4x00 interrupt cause bits
  223. */
  224. #define C_SW0 (_ULCAST_(1) << 8)
  225. #define C_SW1 (_ULCAST_(1) << 9)
  226. #define C_IRQ0 (_ULCAST_(1) << 10)
  227. #define C_IRQ1 (_ULCAST_(1) << 11)
  228. #define C_IRQ2 (_ULCAST_(1) << 12)
  229. #define C_IRQ3 (_ULCAST_(1) << 13)
  230. #define C_IRQ4 (_ULCAST_(1) << 14)
  231. #define C_IRQ5 (_ULCAST_(1) << 15)
  232. /*
  233. * Bitfields in the R4xx0 cp0 status register
  234. */
  235. #define ST0_IE 0x00000001
  236. #define ST0_EXL 0x00000002
  237. #define ST0_ERL 0x00000004
  238. #define ST0_KSU 0x00000018
  239. # define KSU_USER 0x00000010
  240. # define KSU_SUPERVISOR 0x00000008
  241. # define KSU_KERNEL 0x00000000
  242. #define ST0_UX 0x00000020
  243. #define ST0_SX 0x00000040
  244. #define ST0_KX 0x00000080
  245. #define ST0_DE 0x00010000
  246. #define ST0_CE 0x00020000
  247. /*
  248. * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
  249. * cacheops in userspace. This bit exists only on RM7000 and RM9000
  250. * processors.
  251. */
  252. #define ST0_CO 0x08000000
  253. /*
  254. * Bitfields in the R[23]000 cp0 status register.
  255. */
  256. #define ST0_IEC 0x00000001
  257. #define ST0_KUC 0x00000002
  258. #define ST0_IEP 0x00000004
  259. #define ST0_KUP 0x00000008
  260. #define ST0_IEO 0x00000010
  261. #define ST0_KUO 0x00000020
  262. /* bits 6 & 7 are reserved on R[23]000 */
  263. #define ST0_ISC 0x00010000
  264. #define ST0_SWC 0x00020000
  265. #define ST0_CM 0x00080000
  266. /*
  267. * Bits specific to the R4640/R4650
  268. */
  269. #define ST0_UM (_ULCAST_(1) << 4)
  270. #define ST0_IL (_ULCAST_(1) << 23)
  271. #define ST0_DL (_ULCAST_(1) << 24)
  272. /*
  273. * Enable the MIPS MDMX and DSP ASEs
  274. */
  275. #define ST0_MX 0x01000000
  276. /*
  277. * Status register bits available in all MIPS CPUs.
  278. */
  279. #define ST0_IM 0x0000ff00
  280. #define STATUSB_IP0 8
  281. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  282. #define STATUSB_IP1 9
  283. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  284. #define STATUSB_IP2 10
  285. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  286. #define STATUSB_IP3 11
  287. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  288. #define STATUSB_IP4 12
  289. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  290. #define STATUSB_IP5 13
  291. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  292. #define STATUSB_IP6 14
  293. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  294. #define STATUSB_IP7 15
  295. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  296. #define STATUSB_IP8 0
  297. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  298. #define STATUSB_IP9 1
  299. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  300. #define STATUSB_IP10 2
  301. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  302. #define STATUSB_IP11 3
  303. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  304. #define STATUSB_IP12 4
  305. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  306. #define STATUSB_IP13 5
  307. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  308. #define STATUSB_IP14 6
  309. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  310. #define STATUSB_IP15 7
  311. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  312. #define ST0_CH 0x00040000
  313. #define ST0_NMI 0x00080000
  314. #define ST0_SR 0x00100000
  315. #define ST0_TS 0x00200000
  316. #define ST0_BEV 0x00400000
  317. #define ST0_RE 0x02000000
  318. #define ST0_FR 0x04000000
  319. #define ST0_CU 0xf0000000
  320. #define ST0_CU0 0x10000000
  321. #define ST0_CU1 0x20000000
  322. #define ST0_CU2 0x40000000
  323. #define ST0_CU3 0x80000000
  324. #define ST0_XX 0x80000000 /* MIPS IV naming */
  325. /*
  326. * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
  327. */
  328. #define INTCTLB_IPFDC 23
  329. #define INTCTLF_IPFDC (_ULCAST_(7) << INTCTLB_IPFDC)
  330. #define INTCTLB_IPPCI 26
  331. #define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
  332. #define INTCTLB_IPTI 29
  333. #define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
  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_FDCI 21
  360. #define CAUSEF_FDCI (_ULCAST_(1) << 21)
  361. #define CAUSEB_WP 22
  362. #define CAUSEF_WP (_ULCAST_(1) << 22)
  363. #define CAUSEB_IV 23
  364. #define CAUSEF_IV (_ULCAST_(1) << 23)
  365. #define CAUSEB_PCI 26
  366. #define CAUSEF_PCI (_ULCAST_(1) << 26)
  367. #define CAUSEB_DC 27
  368. #define CAUSEF_DC (_ULCAST_(1) << 27)
  369. #define CAUSEB_CE 28
  370. #define CAUSEF_CE (_ULCAST_(3) << 28)
  371. #define CAUSEB_TI 30
  372. #define CAUSEF_TI (_ULCAST_(1) << 30)
  373. #define CAUSEB_BD 31
  374. #define CAUSEF_BD (_ULCAST_(1) << 31)
  375. /*
  376. * Cause.ExcCode trap codes.
  377. */
  378. #define EXCCODE_INT 0 /* Interrupt pending */
  379. #define EXCCODE_MOD 1 /* TLB modified fault */
  380. #define EXCCODE_TLBL 2 /* TLB miss on load or ifetch */
  381. #define EXCCODE_TLBS 3 /* TLB miss on a store */
  382. #define EXCCODE_ADEL 4 /* Address error on a load or ifetch */
  383. #define EXCCODE_ADES 5 /* Address error on a store */
  384. #define EXCCODE_IBE 6 /* Bus error on an ifetch */
  385. #define EXCCODE_DBE 7 /* Bus error on a load or store */
  386. #define EXCCODE_SYS 8 /* System call */
  387. #define EXCCODE_BP 9 /* Breakpoint */
  388. #define EXCCODE_RI 10 /* Reserved instruction exception */
  389. #define EXCCODE_CPU 11 /* Coprocessor unusable */
  390. #define EXCCODE_OV 12 /* Arithmetic overflow */
  391. #define EXCCODE_TR 13 /* Trap instruction */
  392. #define EXCCODE_MSAFPE 14 /* MSA floating point exception */
  393. #define EXCCODE_FPE 15 /* Floating point exception */
  394. #define EXCCODE_TLBRI 19 /* TLB Read-Inhibit exception */
  395. #define EXCCODE_TLBXI 20 /* TLB Execution-Inhibit exception */
  396. #define EXCCODE_MSADIS 21 /* MSA disabled exception */
  397. #define EXCCODE_MDMX 22 /* MDMX unusable exception */
  398. #define EXCCODE_WATCH 23 /* Watch address reference */
  399. #define EXCCODE_MCHECK 24 /* Machine check */
  400. #define EXCCODE_THREAD 25 /* Thread exceptions (MT) */
  401. #define EXCCODE_DSPDIS 26 /* DSP disabled exception */
  402. #define EXCCODE_GE 27 /* Virtualized guest exception (VZ) */
  403. /* Implementation specific trap codes used by MIPS cores */
  404. #define MIPS_EXCCODE_TLBPAR 16 /* TLB parity error exception */
  405. /*
  406. * Bits in the coprocessor 0 config register.
  407. */
  408. /* Generic bits. */
  409. #define CONF_CM_CACHABLE_NO_WA 0
  410. #define CONF_CM_CACHABLE_WA 1
  411. #define CONF_CM_UNCACHED 2
  412. #define CONF_CM_CACHABLE_NONCOHERENT 3
  413. #define CONF_CM_CACHABLE_CE 4
  414. #define CONF_CM_CACHABLE_COW 5
  415. #define CONF_CM_CACHABLE_CUW 6
  416. #define CONF_CM_CACHABLE_ACCELERATED 7
  417. #define CONF_CM_CMASK 7
  418. #define CONF_BE (_ULCAST_(1) << 15)
  419. /* Bits common to various processors. */
  420. #define CONF_CU (_ULCAST_(1) << 3)
  421. #define CONF_DB (_ULCAST_(1) << 4)
  422. #define CONF_IB (_ULCAST_(1) << 5)
  423. #define CONF_DC (_ULCAST_(7) << 6)
  424. #define CONF_IC (_ULCAST_(7) << 9)
  425. #define CONF_EB (_ULCAST_(1) << 13)
  426. #define CONF_EM (_ULCAST_(1) << 14)
  427. #define CONF_SM (_ULCAST_(1) << 16)
  428. #define CONF_SC (_ULCAST_(1) << 17)
  429. #define CONF_EW (_ULCAST_(3) << 18)
  430. #define CONF_EP (_ULCAST_(15)<< 24)
  431. #define CONF_EC (_ULCAST_(7) << 28)
  432. #define CONF_CM (_ULCAST_(1) << 31)
  433. /* Bits specific to the R4xx0. */
  434. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  435. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  436. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  437. /* Bits specific to the R5000. */
  438. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  439. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  440. /* Bits specific to the RM7000. */
  441. #define RM7K_CONF_SE (_ULCAST_(1) << 3)
  442. #define RM7K_CONF_TE (_ULCAST_(1) << 12)
  443. #define RM7K_CONF_CLK (_ULCAST_(1) << 16)
  444. #define RM7K_CONF_TC (_ULCAST_(1) << 17)
  445. #define RM7K_CONF_SI (_ULCAST_(3) << 20)
  446. #define RM7K_CONF_SC (_ULCAST_(1) << 31)
  447. /* Bits specific to the R10000. */
  448. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  449. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  450. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  451. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  452. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  453. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  454. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  455. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  456. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  457. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  458. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  459. /* Bits specific to the VR41xx. */
  460. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  461. #define VR41_CONF_P4K (_ULCAST_(1) << 13)
  462. #define VR41_CONF_BP (_ULCAST_(1) << 16)
  463. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  464. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  465. /* Bits specific to the R30xx. */
  466. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  467. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  468. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  469. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  470. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  471. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  472. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  473. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  474. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  475. /* Bits specific to the TX49. */
  476. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  477. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  478. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  479. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  480. /* Bits specific to the MIPS32/64 PRA. */
  481. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  482. #define MIPS_CONF_MT_TLB (_ULCAST_(1) << 7)
  483. #define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)
  484. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  485. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  486. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  487. /*
  488. * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
  489. */
  490. #define MIPS_CONF1_FP (_ULCAST_(1) << 0)
  491. #define MIPS_CONF1_EP (_ULCAST_(1) << 1)
  492. #define MIPS_CONF1_CA (_ULCAST_(1) << 2)
  493. #define MIPS_CONF1_WR (_ULCAST_(1) << 3)
  494. #define MIPS_CONF1_PC (_ULCAST_(1) << 4)
  495. #define MIPS_CONF1_MD (_ULCAST_(1) << 5)
  496. #define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
  497. #define MIPS_CONF1_DA_SHF 7
  498. #define MIPS_CONF1_DA_SZ 3
  499. #define MIPS_CONF1_DA (_ULCAST_(7) << 7)
  500. #define MIPS_CONF1_DL_SHF 10
  501. #define MIPS_CONF1_DL_SZ 3
  502. #define MIPS_CONF1_DL (_ULCAST_(7) << 10)
  503. #define MIPS_CONF1_DS_SHF 13
  504. #define MIPS_CONF1_DS_SZ 3
  505. #define MIPS_CONF1_DS (_ULCAST_(7) << 13)
  506. #define MIPS_CONF1_IA_SHF 16
  507. #define MIPS_CONF1_IA_SZ 3
  508. #define MIPS_CONF1_IA (_ULCAST_(7) << 16)
  509. #define MIPS_CONF1_IL_SHF 19
  510. #define MIPS_CONF1_IL_SZ 3
  511. #define MIPS_CONF1_IL (_ULCAST_(7) << 19)
  512. #define MIPS_CONF1_IS_SHF 22
  513. #define MIPS_CONF1_IS_SZ 3
  514. #define MIPS_CONF1_IS (_ULCAST_(7) << 22)
  515. #define MIPS_CONF1_TLBS_SHIFT (25)
  516. #define MIPS_CONF1_TLBS_SIZE (6)
  517. #define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
  518. #define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
  519. #define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
  520. #define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
  521. #define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
  522. #define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
  523. #define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
  524. #define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
  525. #define MIPS_CONF2_TU (_ULCAST_(7) << 28)
  526. #define MIPS_CONF3_TL (_ULCAST_(1) << 0)
  527. #define MIPS_CONF3_SM (_ULCAST_(1) << 1)
  528. #define MIPS_CONF3_MT (_ULCAST_(1) << 2)
  529. #define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
  530. #define MIPS_CONF3_SP (_ULCAST_(1) << 4)
  531. #define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
  532. #define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
  533. #define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
  534. #define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
  535. #define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
  536. #define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
  537. #define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
  538. #define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
  539. #define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
  540. #define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
  541. #define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
  542. #define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
  543. #define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
  544. #define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
  545. #define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
  546. #define MIPS_CONF3_PW (_ULCAST_(1) << 24)
  547. #define MIPS_CONF3_SC (_ULCAST_(1) << 25)
  548. #define MIPS_CONF3_BI (_ULCAST_(1) << 26)
  549. #define MIPS_CONF3_BP (_ULCAST_(1) << 27)
  550. #define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
  551. #define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
  552. #define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
  553. #define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
  554. #define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
  555. #define MIPS_CONF4_FTLBSETS_SHIFT (0)
  556. #define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
  557. #define MIPS_CONF4_FTLBWAYS_SHIFT (4)
  558. #define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
  559. #define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
  560. /* bits 10:8 in FTLB-only configurations */
  561. #define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
  562. /* bits 12:8 in VTLB-FTLB only configurations */
  563. #define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
  564. #define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
  565. #define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
  566. #define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
  567. #define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
  568. #define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << 16)
  569. #define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
  570. #define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
  571. #define MIPS_CONF4_AE (_ULCAST_(1) << 28)
  572. #define MIPS_CONF4_IE (_ULCAST_(3) << 29)
  573. #define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
  574. #define MIPS_CONF5_NF (_ULCAST_(1) << 0)
  575. #define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
  576. #define MIPS_CONF5_MRP (_ULCAST_(1) << 3)
  577. #define MIPS_CONF5_LLB (_ULCAST_(1) << 4)
  578. #define MIPS_CONF5_MVH (_ULCAST_(1) << 5)
  579. #define MIPS_CONF5_VP (_ULCAST_(1) << 7)
  580. #define MIPS_CONF5_FRE (_ULCAST_(1) << 8)
  581. #define MIPS_CONF5_UFE (_ULCAST_(1) << 9)
  582. #define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
  583. #define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
  584. #define MIPS_CONF5_CV (_ULCAST_(1) << 29)
  585. #define MIPS_CONF5_K (_ULCAST_(1) << 30)
  586. #define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
  587. /* proAptiv FTLB on/off bit */
  588. #define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
  589. /* Loongson-3 FTLB on/off bit */
  590. #define MIPS_CONF6_FTLBDIS (_ULCAST_(1) << 22)
  591. /* FTLB probability bits */
  592. #define MIPS_CONF6_FTLBP_SHIFT (16)
  593. #define MIPS_CONF7_WII (_ULCAST_(1) << 31)
  594. #define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
  595. #define MIPS_CONF7_IAR (_ULCAST_(1) << 10)
  596. #define MIPS_CONF7_AR (_ULCAST_(1) << 16)
  597. /* FTLB probability bits for R6 */
  598. #define MIPS_CONF7_FTLBP_SHIFT (18)
  599. /* WatchLo* register definitions */
  600. #define MIPS_WATCHLO_IRW (_ULCAST_(0x7) << 0)
  601. /* WatchHi* register definitions */
  602. #define MIPS_WATCHHI_M (_ULCAST_(1) << 31)
  603. #define MIPS_WATCHHI_G (_ULCAST_(1) << 30)
  604. #define MIPS_WATCHHI_WM (_ULCAST_(0x3) << 28)
  605. #define MIPS_WATCHHI_WM_R_RVA (_ULCAST_(0) << 28)
  606. #define MIPS_WATCHHI_WM_R_GPA (_ULCAST_(1) << 28)
  607. #define MIPS_WATCHHI_WM_G_GVA (_ULCAST_(2) << 28)
  608. #define MIPS_WATCHHI_EAS (_ULCAST_(0x3) << 24)
  609. #define MIPS_WATCHHI_ASID (_ULCAST_(0xff) << 16)
  610. #define MIPS_WATCHHI_MASK (_ULCAST_(0x1ff) << 3)
  611. #define MIPS_WATCHHI_I (_ULCAST_(1) << 2)
  612. #define MIPS_WATCHHI_R (_ULCAST_(1) << 1)
  613. #define MIPS_WATCHHI_W (_ULCAST_(1) << 0)
  614. #define MIPS_WATCHHI_IRW (_ULCAST_(0x7) << 0)
  615. /* MAAR bit definitions */
  616. #define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12)
  617. #define MIPS_MAAR_ADDR_SHIFT 12
  618. #define MIPS_MAAR_S (_ULCAST_(1) << 1)
  619. #define MIPS_MAAR_V (_ULCAST_(1) << 0)
  620. /* EBase bit definitions */
  621. #define MIPS_EBASE_CPUNUM_SHIFT 0
  622. #define MIPS_EBASE_CPUNUM (_ULCAST_(0x3ff) << 0)
  623. #define MIPS_EBASE_WG_SHIFT 11
  624. #define MIPS_EBASE_WG (_ULCAST_(1) << 11)
  625. #define MIPS_EBASE_BASE_SHIFT 12
  626. #define MIPS_EBASE_BASE (~_ULCAST_((1 << MIPS_EBASE_BASE_SHIFT) - 1))
  627. /* CMGCRBase bit definitions */
  628. #define MIPS_CMGCRB_BASE 11
  629. #define MIPS_CMGCRF_BASE (~_ULCAST_((1 << MIPS_CMGCRB_BASE) - 1))
  630. /*
  631. * Bits in the MIPS32 Memory Segmentation registers.
  632. */
  633. #define MIPS_SEGCFG_PA_SHIFT 9
  634. #define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
  635. #define MIPS_SEGCFG_AM_SHIFT 4
  636. #define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
  637. #define MIPS_SEGCFG_EU_SHIFT 3
  638. #define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
  639. #define MIPS_SEGCFG_C_SHIFT 0
  640. #define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
  641. #define MIPS_SEGCFG_UUSK _ULCAST_(7)
  642. #define MIPS_SEGCFG_USK _ULCAST_(5)
  643. #define MIPS_SEGCFG_MUSUK _ULCAST_(4)
  644. #define MIPS_SEGCFG_MUSK _ULCAST_(3)
  645. #define MIPS_SEGCFG_MSK _ULCAST_(2)
  646. #define MIPS_SEGCFG_MK _ULCAST_(1)
  647. #define MIPS_SEGCFG_UK _ULCAST_(0)
  648. #define MIPS_PWFIELD_GDI_SHIFT 24
  649. #define MIPS_PWFIELD_GDI_MASK 0x3f000000
  650. #define MIPS_PWFIELD_UDI_SHIFT 18
  651. #define MIPS_PWFIELD_UDI_MASK 0x00fc0000
  652. #define MIPS_PWFIELD_MDI_SHIFT 12
  653. #define MIPS_PWFIELD_MDI_MASK 0x0003f000
  654. #define MIPS_PWFIELD_PTI_SHIFT 6
  655. #define MIPS_PWFIELD_PTI_MASK 0x00000fc0
  656. #define MIPS_PWFIELD_PTEI_SHIFT 0
  657. #define MIPS_PWFIELD_PTEI_MASK 0x0000003f
  658. #define MIPS_PWSIZE_GDW_SHIFT 24
  659. #define MIPS_PWSIZE_GDW_MASK 0x3f000000
  660. #define MIPS_PWSIZE_UDW_SHIFT 18
  661. #define MIPS_PWSIZE_UDW_MASK 0x00fc0000
  662. #define MIPS_PWSIZE_MDW_SHIFT 12
  663. #define MIPS_PWSIZE_MDW_MASK 0x0003f000
  664. #define MIPS_PWSIZE_PTW_SHIFT 6
  665. #define MIPS_PWSIZE_PTW_MASK 0x00000fc0
  666. #define MIPS_PWSIZE_PTEW_SHIFT 0
  667. #define MIPS_PWSIZE_PTEW_MASK 0x0000003f
  668. #define MIPS_PWCTL_PWEN_SHIFT 31
  669. #define MIPS_PWCTL_PWEN_MASK 0x80000000
  670. #define MIPS_PWCTL_DPH_SHIFT 7
  671. #define MIPS_PWCTL_DPH_MASK 0x00000080
  672. #define MIPS_PWCTL_HUGEPG_SHIFT 6
  673. #define MIPS_PWCTL_HUGEPG_MASK 0x00000060
  674. #define MIPS_PWCTL_PSN_SHIFT 0
  675. #define MIPS_PWCTL_PSN_MASK 0x0000003f
  676. /* CDMMBase register bit definitions */
  677. #define MIPS_CDMMBASE_SIZE_SHIFT 0
  678. #define MIPS_CDMMBASE_SIZE (_ULCAST_(511) << MIPS_CDMMBASE_SIZE_SHIFT)
  679. #define MIPS_CDMMBASE_CI (_ULCAST_(1) << 9)
  680. #define MIPS_CDMMBASE_EN (_ULCAST_(1) << 10)
  681. #define MIPS_CDMMBASE_ADDR_SHIFT 11
  682. #define MIPS_CDMMBASE_ADDR_START 15
  683. /*
  684. * Bitfields in the TX39 family CP0 Configuration Register 3
  685. */
  686. #define TX39_CONF_ICS_SHIFT 19
  687. #define TX39_CONF_ICS_MASK 0x00380000
  688. #define TX39_CONF_ICS_1KB 0x00000000
  689. #define TX39_CONF_ICS_2KB 0x00080000
  690. #define TX39_CONF_ICS_4KB 0x00100000
  691. #define TX39_CONF_ICS_8KB 0x00180000
  692. #define TX39_CONF_ICS_16KB 0x00200000
  693. #define TX39_CONF_DCS_SHIFT 16
  694. #define TX39_CONF_DCS_MASK 0x00070000
  695. #define TX39_CONF_DCS_1KB 0x00000000
  696. #define TX39_CONF_DCS_2KB 0x00010000
  697. #define TX39_CONF_DCS_4KB 0x00020000
  698. #define TX39_CONF_DCS_8KB 0x00030000
  699. #define TX39_CONF_DCS_16KB 0x00040000
  700. #define TX39_CONF_CWFON 0x00004000
  701. #define TX39_CONF_WBON 0x00002000
  702. #define TX39_CONF_RF_SHIFT 10
  703. #define TX39_CONF_RF_MASK 0x00000c00
  704. #define TX39_CONF_DOZE 0x00000200
  705. #define TX39_CONF_HALT 0x00000100
  706. #define TX39_CONF_LOCK 0x00000080
  707. #define TX39_CONF_ICE 0x00000020
  708. #define TX39_CONF_DCE 0x00000010
  709. #define TX39_CONF_IRSIZE_SHIFT 2
  710. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  711. #define TX39_CONF_DRSIZE_SHIFT 0
  712. #define TX39_CONF_DRSIZE_MASK 0x00000003
  713. /*
  714. * Interesting Bits in the R10K CP0 Branch Diagnostic Register
  715. */
  716. /* Disable Branch Target Address Cache */
  717. #define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27)
  718. /* Enable Branch Prediction Global History */
  719. #define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26)
  720. /* Disable Branch Return Cache */
  721. #define R10K_DIAG_D_BRC (_ULCAST_(1) << 22)
  722. /* Flush ITLB */
  723. #define LOONGSON_DIAG_ITLB (_ULCAST_(1) << 2)
  724. /* Flush DTLB */
  725. #define LOONGSON_DIAG_DTLB (_ULCAST_(1) << 3)
  726. /* Flush VTLB */
  727. #define LOONGSON_DIAG_VTLB (_ULCAST_(1) << 12)
  728. /* Flush FTLB */
  729. #define LOONGSON_DIAG_FTLB (_ULCAST_(1) << 13)
  730. /*
  731. * Coprocessor 1 (FPU) register names
  732. */
  733. #define CP1_REVISION $0
  734. #define CP1_UFR $1
  735. #define CP1_UNFR $4
  736. #define CP1_FCCR $25
  737. #define CP1_FEXR $26
  738. #define CP1_FENR $28
  739. #define CP1_STATUS $31
  740. /*
  741. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  742. */
  743. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  744. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  745. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  746. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  747. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  748. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  749. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  750. #define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
  751. #define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
  752. #define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
  753. /*
  754. * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
  755. */
  756. #define MIPS_FCCR_CONDX_S 0
  757. #define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
  758. #define MIPS_FCCR_COND0_S 0
  759. #define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
  760. #define MIPS_FCCR_COND1_S 1
  761. #define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
  762. #define MIPS_FCCR_COND2_S 2
  763. #define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
  764. #define MIPS_FCCR_COND3_S 3
  765. #define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
  766. #define MIPS_FCCR_COND4_S 4
  767. #define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
  768. #define MIPS_FCCR_COND5_S 5
  769. #define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
  770. #define MIPS_FCCR_COND6_S 6
  771. #define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
  772. #define MIPS_FCCR_COND7_S 7
  773. #define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
  774. /*
  775. * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
  776. */
  777. #define MIPS_FENR_FS_S 2
  778. #define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
  779. /*
  780. * FPU Status Register Values
  781. */
  782. #define FPU_CSR_COND_S 23 /* $fcc0 */
  783. #define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
  784. #define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
  785. #define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
  786. #define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
  787. #define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
  788. #define FPU_CSR_COND1_S 25 /* $fcc1 */
  789. #define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
  790. #define FPU_CSR_COND2_S 26 /* $fcc2 */
  791. #define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
  792. #define FPU_CSR_COND3_S 27 /* $fcc3 */
  793. #define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
  794. #define FPU_CSR_COND4_S 28 /* $fcc4 */
  795. #define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
  796. #define FPU_CSR_COND5_S 29 /* $fcc5 */
  797. #define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
  798. #define FPU_CSR_COND6_S 30 /* $fcc6 */
  799. #define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
  800. #define FPU_CSR_COND7_S 31 /* $fcc7 */
  801. #define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
  802. /*
  803. * Bits 22:20 of the FPU Status Register will be read as 0,
  804. * and should be written as zero.
  805. */
  806. #define FPU_CSR_RSVD (_ULCAST_(7) << 20)
  807. #define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
  808. #define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
  809. /*
  810. * X the exception cause indicator
  811. * E the exception enable
  812. * S the sticky/flag bit
  813. */
  814. #define FPU_CSR_ALL_X 0x0003f000
  815. #define FPU_CSR_UNI_X 0x00020000
  816. #define FPU_CSR_INV_X 0x00010000
  817. #define FPU_CSR_DIV_X 0x00008000
  818. #define FPU_CSR_OVF_X 0x00004000
  819. #define FPU_CSR_UDF_X 0x00002000
  820. #define FPU_CSR_INE_X 0x00001000
  821. #define FPU_CSR_ALL_E 0x00000f80
  822. #define FPU_CSR_INV_E 0x00000800
  823. #define FPU_CSR_DIV_E 0x00000400
  824. #define FPU_CSR_OVF_E 0x00000200
  825. #define FPU_CSR_UDF_E 0x00000100
  826. #define FPU_CSR_INE_E 0x00000080
  827. #define FPU_CSR_ALL_S 0x0000007c
  828. #define FPU_CSR_INV_S 0x00000040
  829. #define FPU_CSR_DIV_S 0x00000020
  830. #define FPU_CSR_OVF_S 0x00000010
  831. #define FPU_CSR_UDF_S 0x00000008
  832. #define FPU_CSR_INE_S 0x00000004
  833. /* Bits 0 and 1 of FPU Status Register specify the rounding mode */
  834. #define FPU_CSR_RM 0x00000003
  835. #define FPU_CSR_RN 0x0 /* nearest */
  836. #define FPU_CSR_RZ 0x1 /* towards zero */
  837. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  838. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  839. #ifndef __ASSEMBLY__
  840. /*
  841. * Macros for handling the ISA mode bit for MIPS16 and microMIPS.
  842. */
  843. #if defined(CONFIG_SYS_SUPPORTS_MIPS16) || \
  844. defined(CONFIG_SYS_SUPPORTS_MICROMIPS)
  845. #define get_isa16_mode(x) ((x) & 0x1)
  846. #define msk_isa16_mode(x) ((x) & ~0x1)
  847. #define set_isa16_mode(x) do { (x) |= 0x1; } while(0)
  848. #else
  849. #define get_isa16_mode(x) 0
  850. #define msk_isa16_mode(x) (x)
  851. #define set_isa16_mode(x) do { } while(0)
  852. #endif
  853. /*
  854. * microMIPS instructions can be 16-bit or 32-bit in length. This
  855. * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
  856. */
  857. static inline int mm_insn_16bit(u16 insn)
  858. {
  859. u16 opcode = (insn >> 10) & 0x7;
  860. return (opcode >= 1 && opcode <= 3) ? 1 : 0;
  861. }
  862. /*
  863. * TLB Invalidate Flush
  864. */
  865. static inline void tlbinvf(void)
  866. {
  867. __asm__ __volatile__(
  868. ".set push\n\t"
  869. ".set noreorder\n\t"
  870. ".word 0x42000004\n\t" /* tlbinvf */
  871. ".set pop");
  872. }
  873. /*
  874. * Functions to access the R10000 performance counters. These are basically
  875. * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
  876. * performance counter number encoded into bits 1 ... 5 of the instruction.
  877. * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
  878. * disassembler these will look like an access to sel 0 or 1.
  879. */
  880. #define read_r10k_perf_cntr(counter) \
  881. ({ \
  882. unsigned int __res; \
  883. __asm__ __volatile__( \
  884. "mfpc\t%0, %1" \
  885. : "=r" (__res) \
  886. : "i" (counter)); \
  887. \
  888. __res; \
  889. })
  890. #define write_r10k_perf_cntr(counter,val) \
  891. do { \
  892. __asm__ __volatile__( \
  893. "mtpc\t%0, %1" \
  894. : \
  895. : "r" (val), "i" (counter)); \
  896. } while (0)
  897. #define read_r10k_perf_event(counter) \
  898. ({ \
  899. unsigned int __res; \
  900. __asm__ __volatile__( \
  901. "mfps\t%0, %1" \
  902. : "=r" (__res) \
  903. : "i" (counter)); \
  904. \
  905. __res; \
  906. })
  907. #define write_r10k_perf_cntl(counter,val) \
  908. do { \
  909. __asm__ __volatile__( \
  910. "mtps\t%0, %1" \
  911. : \
  912. : "r" (val), "i" (counter)); \
  913. } while (0)
  914. /*
  915. * Macros to access the system control coprocessor
  916. */
  917. #define __read_32bit_c0_register(source, sel) \
  918. ({ unsigned int __res; \
  919. if (sel == 0) \
  920. __asm__ __volatile__( \
  921. "mfc0\t%0, " #source "\n\t" \
  922. : "=r" (__res)); \
  923. else \
  924. __asm__ __volatile__( \
  925. ".set\tmips32\n\t" \
  926. "mfc0\t%0, " #source ", " #sel "\n\t" \
  927. ".set\tmips0\n\t" \
  928. : "=r" (__res)); \
  929. __res; \
  930. })
  931. #define __read_64bit_c0_register(source, sel) \
  932. ({ unsigned long long __res; \
  933. if (sizeof(unsigned long) == 4) \
  934. __res = __read_64bit_c0_split(source, sel); \
  935. else if (sel == 0) \
  936. __asm__ __volatile__( \
  937. ".set\tmips3\n\t" \
  938. "dmfc0\t%0, " #source "\n\t" \
  939. ".set\tmips0" \
  940. : "=r" (__res)); \
  941. else \
  942. __asm__ __volatile__( \
  943. ".set\tmips64\n\t" \
  944. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  945. ".set\tmips0" \
  946. : "=r" (__res)); \
  947. __res; \
  948. })
  949. #define __write_32bit_c0_register(register, sel, value) \
  950. do { \
  951. if (sel == 0) \
  952. __asm__ __volatile__( \
  953. "mtc0\t%z0, " #register "\n\t" \
  954. : : "Jr" ((unsigned int)(value))); \
  955. else \
  956. __asm__ __volatile__( \
  957. ".set\tmips32\n\t" \
  958. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  959. ".set\tmips0" \
  960. : : "Jr" ((unsigned int)(value))); \
  961. } while (0)
  962. #define __write_64bit_c0_register(register, sel, value) \
  963. do { \
  964. if (sizeof(unsigned long) == 4) \
  965. __write_64bit_c0_split(register, sel, value); \
  966. else if (sel == 0) \
  967. __asm__ __volatile__( \
  968. ".set\tmips3\n\t" \
  969. "dmtc0\t%z0, " #register "\n\t" \
  970. ".set\tmips0" \
  971. : : "Jr" (value)); \
  972. else \
  973. __asm__ __volatile__( \
  974. ".set\tmips64\n\t" \
  975. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  976. ".set\tmips0" \
  977. : : "Jr" (value)); \
  978. } while (0)
  979. #define __read_ulong_c0_register(reg, sel) \
  980. ((sizeof(unsigned long) == 4) ? \
  981. (unsigned long) __read_32bit_c0_register(reg, sel) : \
  982. (unsigned long) __read_64bit_c0_register(reg, sel))
  983. #define __write_ulong_c0_register(reg, sel, val) \
  984. do { \
  985. if (sizeof(unsigned long) == 4) \
  986. __write_32bit_c0_register(reg, sel, val); \
  987. else \
  988. __write_64bit_c0_register(reg, sel, val); \
  989. } while (0)
  990. /*
  991. * On RM7000/RM9000 these are uses to access cop0 set 1 registers
  992. */
  993. #define __read_32bit_c0_ctrl_register(source) \
  994. ({ unsigned int __res; \
  995. __asm__ __volatile__( \
  996. "cfc0\t%0, " #source "\n\t" \
  997. : "=r" (__res)); \
  998. __res; \
  999. })
  1000. #define __write_32bit_c0_ctrl_register(register, value) \
  1001. do { \
  1002. __asm__ __volatile__( \
  1003. "ctc0\t%z0, " #register "\n\t" \
  1004. : : "Jr" ((unsigned int)(value))); \
  1005. } while (0)
  1006. /*
  1007. * These versions are only needed for systems with more than 38 bits of
  1008. * physical address space running the 32-bit kernel. That's none atm :-)
  1009. */
  1010. #define __read_64bit_c0_split(source, sel) \
  1011. ({ \
  1012. unsigned long long __val; \
  1013. unsigned long __flags; \
  1014. \
  1015. local_irq_save(__flags); \
  1016. if (sel == 0) \
  1017. __asm__ __volatile__( \
  1018. ".set\tmips64\n\t" \
  1019. "dmfc0\t%M0, " #source "\n\t" \
  1020. "dsll\t%L0, %M0, 32\n\t" \
  1021. "dsra\t%M0, %M0, 32\n\t" \
  1022. "dsra\t%L0, %L0, 32\n\t" \
  1023. ".set\tmips0" \
  1024. : "=r" (__val)); \
  1025. else \
  1026. __asm__ __volatile__( \
  1027. ".set\tmips64\n\t" \
  1028. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  1029. "dsll\t%L0, %M0, 32\n\t" \
  1030. "dsra\t%M0, %M0, 32\n\t" \
  1031. "dsra\t%L0, %L0, 32\n\t" \
  1032. ".set\tmips0" \
  1033. : "=r" (__val)); \
  1034. local_irq_restore(__flags); \
  1035. \
  1036. __val; \
  1037. })
  1038. #define __write_64bit_c0_split(source, sel, val) \
  1039. do { \
  1040. unsigned long __flags; \
  1041. \
  1042. local_irq_save(__flags); \
  1043. if (sel == 0) \
  1044. __asm__ __volatile__( \
  1045. ".set\tmips64\n\t" \
  1046. "dsll\t%L0, %L0, 32\n\t" \
  1047. "dsrl\t%L0, %L0, 32\n\t" \
  1048. "dsll\t%M0, %M0, 32\n\t" \
  1049. "or\t%L0, %L0, %M0\n\t" \
  1050. "dmtc0\t%L0, " #source "\n\t" \
  1051. ".set\tmips0" \
  1052. : : "r" (val)); \
  1053. else \
  1054. __asm__ __volatile__( \
  1055. ".set\tmips64\n\t" \
  1056. "dsll\t%L0, %L0, 32\n\t" \
  1057. "dsrl\t%L0, %L0, 32\n\t" \
  1058. "dsll\t%M0, %M0, 32\n\t" \
  1059. "or\t%L0, %L0, %M0\n\t" \
  1060. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  1061. ".set\tmips0" \
  1062. : : "r" (val)); \
  1063. local_irq_restore(__flags); \
  1064. } while (0)
  1065. #define __readx_32bit_c0_register(source) \
  1066. ({ \
  1067. unsigned int __res; \
  1068. \
  1069. __asm__ __volatile__( \
  1070. " .set push \n" \
  1071. " .set noat \n" \
  1072. " .set mips32r2 \n" \
  1073. " .insn \n" \
  1074. " # mfhc0 $1, %1 \n" \
  1075. " .word (0x40410000 | ((%1 & 0x1f) << 11)) \n" \
  1076. " move %0, $1 \n" \
  1077. " .set pop \n" \
  1078. : "=r" (__res) \
  1079. : "i" (source)); \
  1080. __res; \
  1081. })
  1082. #define __writex_32bit_c0_register(register, value) \
  1083. do { \
  1084. __asm__ __volatile__( \
  1085. " .set push \n" \
  1086. " .set noat \n" \
  1087. " .set mips32r2 \n" \
  1088. " move $1, %0 \n" \
  1089. " # mthc0 $1, %1 \n" \
  1090. " .insn \n" \
  1091. " .word (0x40c10000 | ((%1 & 0x1f) << 11)) \n" \
  1092. " .set pop \n" \
  1093. : \
  1094. : "r" (value), "i" (register)); \
  1095. } while (0)
  1096. #define read_c0_index() __read_32bit_c0_register($0, 0)
  1097. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  1098. #define read_c0_random() __read_32bit_c0_register($1, 0)
  1099. #define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
  1100. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  1101. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  1102. #define readx_c0_entrylo0() __readx_32bit_c0_register(2)
  1103. #define writex_c0_entrylo0(val) __writex_32bit_c0_register(2, val)
  1104. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  1105. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  1106. #define readx_c0_entrylo1() __readx_32bit_c0_register(3)
  1107. #define writex_c0_entrylo1(val) __writex_32bit_c0_register(3, val)
  1108. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  1109. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  1110. #define read_c0_context() __read_ulong_c0_register($4, 0)
  1111. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  1112. #define read_c0_userlocal() __read_ulong_c0_register($4, 2)
  1113. #define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
  1114. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  1115. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  1116. #define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
  1117. #define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
  1118. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  1119. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  1120. #define read_c0_info() __read_32bit_c0_register($7, 0)
  1121. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  1122. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  1123. #define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
  1124. #define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
  1125. #define read_c0_count() __read_32bit_c0_register($9, 0)
  1126. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  1127. #define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
  1128. #define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
  1129. #define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
  1130. #define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
  1131. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  1132. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  1133. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  1134. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  1135. #define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
  1136. #define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
  1137. #define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
  1138. #define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
  1139. #define read_c0_status() __read_32bit_c0_register($12, 0)
  1140. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  1141. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  1142. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  1143. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  1144. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  1145. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  1146. #define read_c0_cmgcrbase() __read_ulong_c0_register($15, 3)
  1147. #define read_c0_config() __read_32bit_c0_register($16, 0)
  1148. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  1149. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  1150. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  1151. #define read_c0_config4() __read_32bit_c0_register($16, 4)
  1152. #define read_c0_config5() __read_32bit_c0_register($16, 5)
  1153. #define read_c0_config6() __read_32bit_c0_register($16, 6)
  1154. #define read_c0_config7() __read_32bit_c0_register($16, 7)
  1155. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  1156. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  1157. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  1158. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  1159. #define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
  1160. #define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
  1161. #define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
  1162. #define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
  1163. #define read_c0_lladdr() __read_ulong_c0_register($17, 0)
  1164. #define write_c0_lladdr(val) __write_ulong_c0_register($17, 0, val)
  1165. #define read_c0_maar() __read_ulong_c0_register($17, 1)
  1166. #define write_c0_maar(val) __write_ulong_c0_register($17, 1, val)
  1167. #define read_c0_maari() __read_32bit_c0_register($17, 2)
  1168. #define write_c0_maari(val) __write_32bit_c0_register($17, 2, val)
  1169. /*
  1170. * The WatchLo register. There may be up to 8 of them.
  1171. */
  1172. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  1173. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  1174. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  1175. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  1176. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  1177. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  1178. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  1179. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  1180. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  1181. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  1182. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  1183. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  1184. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  1185. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  1186. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  1187. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  1188. /*
  1189. * The WatchHi register. There may be up to 8 of them.
  1190. */
  1191. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  1192. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  1193. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  1194. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  1195. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  1196. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  1197. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  1198. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  1199. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  1200. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  1201. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  1202. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  1203. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  1204. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  1205. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  1206. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  1207. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  1208. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  1209. #define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
  1210. #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
  1211. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  1212. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  1213. #define read_c0_diag() __read_32bit_c0_register($22, 0)
  1214. #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
  1215. /* R10K CP0 Branch Diagnostic register is 64bits wide */
  1216. #define read_c0_r10k_diag() __read_64bit_c0_register($22, 0)
  1217. #define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val)
  1218. #define read_c0_diag1() __read_32bit_c0_register($22, 1)
  1219. #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
  1220. #define read_c0_diag2() __read_32bit_c0_register($22, 2)
  1221. #define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
  1222. #define read_c0_diag3() __read_32bit_c0_register($22, 3)
  1223. #define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
  1224. #define read_c0_diag4() __read_32bit_c0_register($22, 4)
  1225. #define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
  1226. #define read_c0_diag5() __read_32bit_c0_register($22, 5)
  1227. #define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
  1228. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  1229. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  1230. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  1231. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  1232. /*
  1233. * MIPS32 / MIPS64 performance counters
  1234. */
  1235. #define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
  1236. #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
  1237. #define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
  1238. #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
  1239. #define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
  1240. #define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
  1241. #define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
  1242. #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
  1243. #define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
  1244. #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
  1245. #define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
  1246. #define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
  1247. #define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
  1248. #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
  1249. #define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
  1250. #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
  1251. #define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
  1252. #define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
  1253. #define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
  1254. #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
  1255. #define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
  1256. #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
  1257. #define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
  1258. #define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
  1259. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  1260. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  1261. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  1262. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  1263. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  1264. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  1265. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  1266. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  1267. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  1268. #define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
  1269. #define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
  1270. #define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
  1271. #define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
  1272. #define read_c0_staglo() __read_32bit_c0_register($28, 4)
  1273. #define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
  1274. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  1275. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  1276. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  1277. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  1278. /* MIPSR2 */
  1279. #define read_c0_hwrena() __read_32bit_c0_register($7, 0)
  1280. #define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
  1281. #define read_c0_intctl() __read_32bit_c0_register($12, 1)
  1282. #define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
  1283. #define read_c0_srsctl() __read_32bit_c0_register($12, 2)
  1284. #define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
  1285. #define read_c0_srsmap() __read_32bit_c0_register($12, 3)
  1286. #define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
  1287. #define read_c0_ebase() __read_32bit_c0_register($15, 1)
  1288. #define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
  1289. #define read_c0_ebase_64() __read_64bit_c0_register($15, 1)
  1290. #define write_c0_ebase_64(val) __write_64bit_c0_register($15, 1, val)
  1291. #define read_c0_cdmmbase() __read_ulong_c0_register($15, 2)
  1292. #define write_c0_cdmmbase(val) __write_ulong_c0_register($15, 2, val)
  1293. /* MIPSR3 */
  1294. #define read_c0_segctl0() __read_32bit_c0_register($5, 2)
  1295. #define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
  1296. #define read_c0_segctl1() __read_32bit_c0_register($5, 3)
  1297. #define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
  1298. #define read_c0_segctl2() __read_32bit_c0_register($5, 4)
  1299. #define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
  1300. /* Hardware Page Table Walker */
  1301. #define read_c0_pwbase() __read_ulong_c0_register($5, 5)
  1302. #define write_c0_pwbase(val) __write_ulong_c0_register($5, 5, val)
  1303. #define read_c0_pwfield() __read_ulong_c0_register($5, 6)
  1304. #define write_c0_pwfield(val) __write_ulong_c0_register($5, 6, val)
  1305. #define read_c0_pwsize() __read_ulong_c0_register($5, 7)
  1306. #define write_c0_pwsize(val) __write_ulong_c0_register($5, 7, val)
  1307. #define read_c0_pwctl() __read_32bit_c0_register($6, 6)
  1308. #define write_c0_pwctl(val) __write_32bit_c0_register($6, 6, val)
  1309. #define read_c0_pgd() __read_64bit_c0_register($9, 7)
  1310. #define write_c0_pgd(val) __write_64bit_c0_register($9, 7, val)
  1311. #define read_c0_kpgd() __read_64bit_c0_register($31, 7)
  1312. #define write_c0_kpgd(val) __write_64bit_c0_register($31, 7, val)
  1313. /* Cavium OCTEON (cnMIPS) */
  1314. #define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
  1315. #define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
  1316. #define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
  1317. #define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
  1318. #define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
  1319. #define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
  1320. /*
  1321. * The cacheerr registers are not standardized. On OCTEON, they are
  1322. * 64 bits wide.
  1323. */
  1324. #define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
  1325. #define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
  1326. #define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
  1327. #define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
  1328. /* BMIPS3300 */
  1329. #define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
  1330. #define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
  1331. #define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
  1332. #define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
  1333. #define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
  1334. #define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
  1335. /* BMIPS43xx */
  1336. #define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
  1337. #define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
  1338. #define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
  1339. #define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
  1340. #define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
  1341. #define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
  1342. #define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
  1343. #define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
  1344. #define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
  1345. #define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
  1346. /* BMIPS5000 */
  1347. #define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
  1348. #define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
  1349. #define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
  1350. #define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
  1351. #define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
  1352. #define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
  1353. #define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
  1354. #define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
  1355. #define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
  1356. #define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
  1357. #define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
  1358. #define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
  1359. /*
  1360. * Macros to access the floating point coprocessor control registers
  1361. */
  1362. #define _read_32bit_cp1_register(source, gas_hardfloat) \
  1363. ({ \
  1364. unsigned int __res; \
  1365. \
  1366. __asm__ __volatile__( \
  1367. " .set push \n" \
  1368. " .set reorder \n" \
  1369. " # gas fails to assemble cfc1 for some archs, \n" \
  1370. " # like Octeon. \n" \
  1371. " .set mips1 \n" \
  1372. " "STR(gas_hardfloat)" \n" \
  1373. " cfc1 %0,"STR(source)" \n" \
  1374. " .set pop \n" \
  1375. : "=r" (__res)); \
  1376. __res; \
  1377. })
  1378. #define _write_32bit_cp1_register(dest, val, gas_hardfloat) \
  1379. do { \
  1380. __asm__ __volatile__( \
  1381. " .set push \n" \
  1382. " .set reorder \n" \
  1383. " "STR(gas_hardfloat)" \n" \
  1384. " ctc1 %0,"STR(dest)" \n" \
  1385. " .set pop \n" \
  1386. : : "r" (val)); \
  1387. } while (0)
  1388. #ifdef GAS_HAS_SET_HARDFLOAT
  1389. #define read_32bit_cp1_register(source) \
  1390. _read_32bit_cp1_register(source, .set hardfloat)
  1391. #define write_32bit_cp1_register(dest, val) \
  1392. _write_32bit_cp1_register(dest, val, .set hardfloat)
  1393. #else
  1394. #define read_32bit_cp1_register(source) \
  1395. _read_32bit_cp1_register(source, )
  1396. #define write_32bit_cp1_register(dest, val) \
  1397. _write_32bit_cp1_register(dest, val, )
  1398. #endif
  1399. #ifdef HAVE_AS_DSP
  1400. #define rddsp(mask) \
  1401. ({ \
  1402. unsigned int __dspctl; \
  1403. \
  1404. __asm__ __volatile__( \
  1405. " .set push \n" \
  1406. " .set dsp \n" \
  1407. " rddsp %0, %x1 \n" \
  1408. " .set pop \n" \
  1409. : "=r" (__dspctl) \
  1410. : "i" (mask)); \
  1411. __dspctl; \
  1412. })
  1413. #define wrdsp(val, mask) \
  1414. do { \
  1415. __asm__ __volatile__( \
  1416. " .set push \n" \
  1417. " .set dsp \n" \
  1418. " wrdsp %0, %x1 \n" \
  1419. " .set pop \n" \
  1420. : \
  1421. : "r" (val), "i" (mask)); \
  1422. } while (0)
  1423. #define mflo0() \
  1424. ({ \
  1425. long mflo0; \
  1426. __asm__( \
  1427. " .set push \n" \
  1428. " .set dsp \n" \
  1429. " mflo %0, $ac0 \n" \
  1430. " .set pop \n" \
  1431. : "=r" (mflo0)); \
  1432. mflo0; \
  1433. })
  1434. #define mflo1() \
  1435. ({ \
  1436. long mflo1; \
  1437. __asm__( \
  1438. " .set push \n" \
  1439. " .set dsp \n" \
  1440. " mflo %0, $ac1 \n" \
  1441. " .set pop \n" \
  1442. : "=r" (mflo1)); \
  1443. mflo1; \
  1444. })
  1445. #define mflo2() \
  1446. ({ \
  1447. long mflo2; \
  1448. __asm__( \
  1449. " .set push \n" \
  1450. " .set dsp \n" \
  1451. " mflo %0, $ac2 \n" \
  1452. " .set pop \n" \
  1453. : "=r" (mflo2)); \
  1454. mflo2; \
  1455. })
  1456. #define mflo3() \
  1457. ({ \
  1458. long mflo3; \
  1459. __asm__( \
  1460. " .set push \n" \
  1461. " .set dsp \n" \
  1462. " mflo %0, $ac3 \n" \
  1463. " .set pop \n" \
  1464. : "=r" (mflo3)); \
  1465. mflo3; \
  1466. })
  1467. #define mfhi0() \
  1468. ({ \
  1469. long mfhi0; \
  1470. __asm__( \
  1471. " .set push \n" \
  1472. " .set dsp \n" \
  1473. " mfhi %0, $ac0 \n" \
  1474. " .set pop \n" \
  1475. : "=r" (mfhi0)); \
  1476. mfhi0; \
  1477. })
  1478. #define mfhi1() \
  1479. ({ \
  1480. long mfhi1; \
  1481. __asm__( \
  1482. " .set push \n" \
  1483. " .set dsp \n" \
  1484. " mfhi %0, $ac1 \n" \
  1485. " .set pop \n" \
  1486. : "=r" (mfhi1)); \
  1487. mfhi1; \
  1488. })
  1489. #define mfhi2() \
  1490. ({ \
  1491. long mfhi2; \
  1492. __asm__( \
  1493. " .set push \n" \
  1494. " .set dsp \n" \
  1495. " mfhi %0, $ac2 \n" \
  1496. " .set pop \n" \
  1497. : "=r" (mfhi2)); \
  1498. mfhi2; \
  1499. })
  1500. #define mfhi3() \
  1501. ({ \
  1502. long mfhi3; \
  1503. __asm__( \
  1504. " .set push \n" \
  1505. " .set dsp \n" \
  1506. " mfhi %0, $ac3 \n" \
  1507. " .set pop \n" \
  1508. : "=r" (mfhi3)); \
  1509. mfhi3; \
  1510. })
  1511. #define mtlo0(x) \
  1512. ({ \
  1513. __asm__( \
  1514. " .set push \n" \
  1515. " .set dsp \n" \
  1516. " mtlo %0, $ac0 \n" \
  1517. " .set pop \n" \
  1518. : \
  1519. : "r" (x)); \
  1520. })
  1521. #define mtlo1(x) \
  1522. ({ \
  1523. __asm__( \
  1524. " .set push \n" \
  1525. " .set dsp \n" \
  1526. " mtlo %0, $ac1 \n" \
  1527. " .set pop \n" \
  1528. : \
  1529. : "r" (x)); \
  1530. })
  1531. #define mtlo2(x) \
  1532. ({ \
  1533. __asm__( \
  1534. " .set push \n" \
  1535. " .set dsp \n" \
  1536. " mtlo %0, $ac2 \n" \
  1537. " .set pop \n" \
  1538. : \
  1539. : "r" (x)); \
  1540. })
  1541. #define mtlo3(x) \
  1542. ({ \
  1543. __asm__( \
  1544. " .set push \n" \
  1545. " .set dsp \n" \
  1546. " mtlo %0, $ac3 \n" \
  1547. " .set pop \n" \
  1548. : \
  1549. : "r" (x)); \
  1550. })
  1551. #define mthi0(x) \
  1552. ({ \
  1553. __asm__( \
  1554. " .set push \n" \
  1555. " .set dsp \n" \
  1556. " mthi %0, $ac0 \n" \
  1557. " .set pop \n" \
  1558. : \
  1559. : "r" (x)); \
  1560. })
  1561. #define mthi1(x) \
  1562. ({ \
  1563. __asm__( \
  1564. " .set push \n" \
  1565. " .set dsp \n" \
  1566. " mthi %0, $ac1 \n" \
  1567. " .set pop \n" \
  1568. : \
  1569. : "r" (x)); \
  1570. })
  1571. #define mthi2(x) \
  1572. ({ \
  1573. __asm__( \
  1574. " .set push \n" \
  1575. " .set dsp \n" \
  1576. " mthi %0, $ac2 \n" \
  1577. " .set pop \n" \
  1578. : \
  1579. : "r" (x)); \
  1580. })
  1581. #define mthi3(x) \
  1582. ({ \
  1583. __asm__( \
  1584. " .set push \n" \
  1585. " .set dsp \n" \
  1586. " mthi %0, $ac3 \n" \
  1587. " .set pop \n" \
  1588. : \
  1589. : "r" (x)); \
  1590. })
  1591. #else
  1592. #ifdef CONFIG_CPU_MICROMIPS
  1593. #define rddsp(mask) \
  1594. ({ \
  1595. unsigned int __res; \
  1596. \
  1597. __asm__ __volatile__( \
  1598. " .set push \n" \
  1599. " .set noat \n" \
  1600. " # rddsp $1, %x1 \n" \
  1601. " .hword ((0x0020067c | (%x1 << 14)) >> 16) \n" \
  1602. " .hword ((0x0020067c | (%x1 << 14)) & 0xffff) \n" \
  1603. " move %0, $1 \n" \
  1604. " .set pop \n" \
  1605. : "=r" (__res) \
  1606. : "i" (mask)); \
  1607. __res; \
  1608. })
  1609. #define wrdsp(val, mask) \
  1610. do { \
  1611. __asm__ __volatile__( \
  1612. " .set push \n" \
  1613. " .set noat \n" \
  1614. " move $1, %0 \n" \
  1615. " # wrdsp $1, %x1 \n" \
  1616. " .hword ((0x0020167c | (%x1 << 14)) >> 16) \n" \
  1617. " .hword ((0x0020167c | (%x1 << 14)) & 0xffff) \n" \
  1618. " .set pop \n" \
  1619. : \
  1620. : "r" (val), "i" (mask)); \
  1621. } while (0)
  1622. #define _umips_dsp_mfxxx(ins) \
  1623. ({ \
  1624. unsigned long __treg; \
  1625. \
  1626. __asm__ __volatile__( \
  1627. " .set push \n" \
  1628. " .set noat \n" \
  1629. " .hword 0x0001 \n" \
  1630. " .hword %x1 \n" \
  1631. " move %0, $1 \n" \
  1632. " .set pop \n" \
  1633. : "=r" (__treg) \
  1634. : "i" (ins)); \
  1635. __treg; \
  1636. })
  1637. #define _umips_dsp_mtxxx(val, ins) \
  1638. do { \
  1639. __asm__ __volatile__( \
  1640. " .set push \n" \
  1641. " .set noat \n" \
  1642. " move $1, %0 \n" \
  1643. " .hword 0x0001 \n" \
  1644. " .hword %x1 \n" \
  1645. " .set pop \n" \
  1646. : \
  1647. : "r" (val), "i" (ins)); \
  1648. } while (0)
  1649. #define _umips_dsp_mflo(reg) _umips_dsp_mfxxx((reg << 14) | 0x107c)
  1650. #define _umips_dsp_mfhi(reg) _umips_dsp_mfxxx((reg << 14) | 0x007c)
  1651. #define _umips_dsp_mtlo(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x307c))
  1652. #define _umips_dsp_mthi(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x207c))
  1653. #define mflo0() _umips_dsp_mflo(0)
  1654. #define mflo1() _umips_dsp_mflo(1)
  1655. #define mflo2() _umips_dsp_mflo(2)
  1656. #define mflo3() _umips_dsp_mflo(3)
  1657. #define mfhi0() _umips_dsp_mfhi(0)
  1658. #define mfhi1() _umips_dsp_mfhi(1)
  1659. #define mfhi2() _umips_dsp_mfhi(2)
  1660. #define mfhi3() _umips_dsp_mfhi(3)
  1661. #define mtlo0(x) _umips_dsp_mtlo(x, 0)
  1662. #define mtlo1(x) _umips_dsp_mtlo(x, 1)
  1663. #define mtlo2(x) _umips_dsp_mtlo(x, 2)
  1664. #define mtlo3(x) _umips_dsp_mtlo(x, 3)
  1665. #define mthi0(x) _umips_dsp_mthi(x, 0)
  1666. #define mthi1(x) _umips_dsp_mthi(x, 1)
  1667. #define mthi2(x) _umips_dsp_mthi(x, 2)
  1668. #define mthi3(x) _umips_dsp_mthi(x, 3)
  1669. #else /* !CONFIG_CPU_MICROMIPS */
  1670. #define rddsp(mask) \
  1671. ({ \
  1672. unsigned int __res; \
  1673. \
  1674. __asm__ __volatile__( \
  1675. " .set push \n" \
  1676. " .set noat \n" \
  1677. " # rddsp $1, %x1 \n" \
  1678. " .word 0x7c000cb8 | (%x1 << 16) \n" \
  1679. " move %0, $1 \n" \
  1680. " .set pop \n" \
  1681. : "=r" (__res) \
  1682. : "i" (mask)); \
  1683. __res; \
  1684. })
  1685. #define wrdsp(val, mask) \
  1686. do { \
  1687. __asm__ __volatile__( \
  1688. " .set push \n" \
  1689. " .set noat \n" \
  1690. " move $1, %0 \n" \
  1691. " # wrdsp $1, %x1 \n" \
  1692. " .word 0x7c2004f8 | (%x1 << 11) \n" \
  1693. " .set pop \n" \
  1694. : \
  1695. : "r" (val), "i" (mask)); \
  1696. } while (0)
  1697. #define _dsp_mfxxx(ins) \
  1698. ({ \
  1699. unsigned long __treg; \
  1700. \
  1701. __asm__ __volatile__( \
  1702. " .set push \n" \
  1703. " .set noat \n" \
  1704. " .word (0x00000810 | %1) \n" \
  1705. " move %0, $1 \n" \
  1706. " .set pop \n" \
  1707. : "=r" (__treg) \
  1708. : "i" (ins)); \
  1709. __treg; \
  1710. })
  1711. #define _dsp_mtxxx(val, ins) \
  1712. do { \
  1713. __asm__ __volatile__( \
  1714. " .set push \n" \
  1715. " .set noat \n" \
  1716. " move $1, %0 \n" \
  1717. " .word (0x00200011 | %1) \n" \
  1718. " .set pop \n" \
  1719. : \
  1720. : "r" (val), "i" (ins)); \
  1721. } while (0)
  1722. #define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
  1723. #define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
  1724. #define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
  1725. #define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
  1726. #define mflo0() _dsp_mflo(0)
  1727. #define mflo1() _dsp_mflo(1)
  1728. #define mflo2() _dsp_mflo(2)
  1729. #define mflo3() _dsp_mflo(3)
  1730. #define mfhi0() _dsp_mfhi(0)
  1731. #define mfhi1() _dsp_mfhi(1)
  1732. #define mfhi2() _dsp_mfhi(2)
  1733. #define mfhi3() _dsp_mfhi(3)
  1734. #define mtlo0(x) _dsp_mtlo(x, 0)
  1735. #define mtlo1(x) _dsp_mtlo(x, 1)
  1736. #define mtlo2(x) _dsp_mtlo(x, 2)
  1737. #define mtlo3(x) _dsp_mtlo(x, 3)
  1738. #define mthi0(x) _dsp_mthi(x, 0)
  1739. #define mthi1(x) _dsp_mthi(x, 1)
  1740. #define mthi2(x) _dsp_mthi(x, 2)
  1741. #define mthi3(x) _dsp_mthi(x, 3)
  1742. #endif /* CONFIG_CPU_MICROMIPS */
  1743. #endif
  1744. /*
  1745. * TLB operations.
  1746. *
  1747. * It is responsibility of the caller to take care of any TLB hazards.
  1748. */
  1749. static inline void tlb_probe(void)
  1750. {
  1751. __asm__ __volatile__(
  1752. ".set noreorder\n\t"
  1753. "tlbp\n\t"
  1754. ".set reorder");
  1755. }
  1756. static inline void tlb_read(void)
  1757. {
  1758. #if MIPS34K_MISSED_ITLB_WAR
  1759. int res = 0;
  1760. __asm__ __volatile__(
  1761. " .set push \n"
  1762. " .set noreorder \n"
  1763. " .set noat \n"
  1764. " .set mips32r2 \n"
  1765. " .word 0x41610001 # dvpe $1 \n"
  1766. " move %0, $1 \n"
  1767. " ehb \n"
  1768. " .set pop \n"
  1769. : "=r" (res));
  1770. instruction_hazard();
  1771. #endif
  1772. __asm__ __volatile__(
  1773. ".set noreorder\n\t"
  1774. "tlbr\n\t"
  1775. ".set reorder");
  1776. #if MIPS34K_MISSED_ITLB_WAR
  1777. if ((res & _ULCAST_(1)))
  1778. __asm__ __volatile__(
  1779. " .set push \n"
  1780. " .set noreorder \n"
  1781. " .set noat \n"
  1782. " .set mips32r2 \n"
  1783. " .word 0x41600021 # evpe \n"
  1784. " ehb \n"
  1785. " .set pop \n");
  1786. #endif
  1787. }
  1788. static inline void tlb_write_indexed(void)
  1789. {
  1790. __asm__ __volatile__(
  1791. ".set noreorder\n\t"
  1792. "tlbwi\n\t"
  1793. ".set reorder");
  1794. }
  1795. static inline void tlb_write_random(void)
  1796. {
  1797. __asm__ __volatile__(
  1798. ".set noreorder\n\t"
  1799. "tlbwr\n\t"
  1800. ".set reorder");
  1801. }
  1802. /*
  1803. * Manipulate bits in a c0 register.
  1804. */
  1805. #define __BUILD_SET_C0(name) \
  1806. static inline unsigned int \
  1807. set_c0_##name(unsigned int set) \
  1808. { \
  1809. unsigned int res, new; \
  1810. \
  1811. res = read_c0_##name(); \
  1812. new = res | set; \
  1813. write_c0_##name(new); \
  1814. \
  1815. return res; \
  1816. } \
  1817. \
  1818. static inline unsigned int \
  1819. clear_c0_##name(unsigned int clear) \
  1820. { \
  1821. unsigned int res, new; \
  1822. \
  1823. res = read_c0_##name(); \
  1824. new = res & ~clear; \
  1825. write_c0_##name(new); \
  1826. \
  1827. return res; \
  1828. } \
  1829. \
  1830. static inline unsigned int \
  1831. change_c0_##name(unsigned int change, unsigned int val) \
  1832. { \
  1833. unsigned int res, new; \
  1834. \
  1835. res = read_c0_##name(); \
  1836. new = res & ~change; \
  1837. new |= (val & change); \
  1838. write_c0_##name(new); \
  1839. \
  1840. return res; \
  1841. }
  1842. __BUILD_SET_C0(status)
  1843. __BUILD_SET_C0(cause)
  1844. __BUILD_SET_C0(config)
  1845. __BUILD_SET_C0(config5)
  1846. __BUILD_SET_C0(intcontrol)
  1847. __BUILD_SET_C0(intctl)
  1848. __BUILD_SET_C0(srsmap)
  1849. __BUILD_SET_C0(pagegrain)
  1850. __BUILD_SET_C0(brcm_config_0)
  1851. __BUILD_SET_C0(brcm_bus_pll)
  1852. __BUILD_SET_C0(brcm_reset)
  1853. __BUILD_SET_C0(brcm_cmt_intr)
  1854. __BUILD_SET_C0(brcm_cmt_ctrl)
  1855. __BUILD_SET_C0(brcm_config)
  1856. __BUILD_SET_C0(brcm_mode)
  1857. /*
  1858. * Return low 10 bits of ebase.
  1859. * Note that under KVM (MIPSVZ) this returns vcpu id.
  1860. */
  1861. static inline unsigned int get_ebase_cpunum(void)
  1862. {
  1863. return read_c0_ebase() & MIPS_EBASE_CPUNUM;
  1864. }
  1865. #endif /* !__ASSEMBLY__ */
  1866. #endif /* _ASM_MIPSREGS_H */