mipsregs.h 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677
  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_SEGCTL0 $5, 2
  48. #define CP0_SEGCTL1 $5, 3
  49. #define CP0_SEGCTL2 $5, 4
  50. #define CP0_WIRED $6
  51. #define CP0_INFO $7
  52. #define CP0_HWRENA $7
  53. #define CP0_BADVADDR $8
  54. #define CP0_BADINSTR $8, 1
  55. #define CP0_COUNT $9
  56. #define CP0_ENTRYHI $10
  57. #define CP0_GUESTCTL1 $10, 4
  58. #define CP0_GUESTCTL2 $10, 5
  59. #define CP0_GUESTCTL3 $10, 6
  60. #define CP0_COMPARE $11
  61. #define CP0_GUESTCTL0EXT $11, 4
  62. #define CP0_STATUS $12
  63. #define CP0_GUESTCTL0 $12, 6
  64. #define CP0_GTOFFSET $12, 7
  65. #define CP0_CAUSE $13
  66. #define CP0_EPC $14
  67. #define CP0_PRID $15
  68. #define CP0_EBASE $15, 1
  69. #define CP0_CMGCRBASE $15, 3
  70. #define CP0_CONFIG $16
  71. #define CP0_CONFIG3 $16, 3
  72. #define CP0_CONFIG5 $16, 5
  73. #define CP0_LLADDR $17
  74. #define CP0_WATCHLO $18
  75. #define CP0_WATCHHI $19
  76. #define CP0_XCONTEXT $20
  77. #define CP0_FRAMEMASK $21
  78. #define CP0_DIAGNOSTIC $22
  79. #define CP0_DEBUG $23
  80. #define CP0_DEPC $24
  81. #define CP0_PERFORMANCE $25
  82. #define CP0_ECC $26
  83. #define CP0_CACHEERR $27
  84. #define CP0_TAGLO $28
  85. #define CP0_TAGHI $29
  86. #define CP0_ERROREPC $30
  87. #define CP0_DESAVE $31
  88. /*
  89. * R4640/R4650 cp0 register names. These registers are listed
  90. * here only for completeness; without MMU these CPUs are not useable
  91. * by Linux. A future ELKS port might take make Linux run on them
  92. * though ...
  93. */
  94. #define CP0_IBASE $0
  95. #define CP0_IBOUND $1
  96. #define CP0_DBASE $2
  97. #define CP0_DBOUND $3
  98. #define CP0_CALG $17
  99. #define CP0_IWATCH $18
  100. #define CP0_DWATCH $19
  101. /*
  102. * Coprocessor 0 Set 1 register names
  103. */
  104. #define CP0_S1_DERRADDR0 $26
  105. #define CP0_S1_DERRADDR1 $27
  106. #define CP0_S1_INTCONTROL $20
  107. /*
  108. * Coprocessor 0 Set 2 register names
  109. */
  110. #define CP0_S2_SRSCTL $12 /* MIPSR2 */
  111. /*
  112. * Coprocessor 0 Set 3 register names
  113. */
  114. #define CP0_S3_SRSMAP $12 /* MIPSR2 */
  115. /*
  116. * TX39 Series
  117. */
  118. #define CP0_TX39_CACHE $7
  119. /* Generic EntryLo bit definitions */
  120. #define ENTRYLO_G (_ULCAST_(1) << 0)
  121. #define ENTRYLO_V (_ULCAST_(1) << 1)
  122. #define ENTRYLO_D (_ULCAST_(1) << 2)
  123. #define ENTRYLO_C_SHIFT 3
  124. #define ENTRYLO_C (_ULCAST_(7) << ENTRYLO_C_SHIFT)
  125. /* R3000 EntryLo bit definitions */
  126. #define R3K_ENTRYLO_G (_ULCAST_(1) << 8)
  127. #define R3K_ENTRYLO_V (_ULCAST_(1) << 9)
  128. #define R3K_ENTRYLO_D (_ULCAST_(1) << 10)
  129. #define R3K_ENTRYLO_N (_ULCAST_(1) << 11)
  130. /* MIPS32/64 EntryLo bit definitions */
  131. #define MIPS_ENTRYLO_PFN_SHIFT 6
  132. #define MIPS_ENTRYLO_XI (_ULCAST_(1) << (BITS_PER_LONG - 2))
  133. #define MIPS_ENTRYLO_RI (_ULCAST_(1) << (BITS_PER_LONG - 1))
  134. /*
  135. * Values for PageMask register
  136. */
  137. #ifdef CONFIG_CPU_VR41XX
  138. /* Why doesn't stupidity hurt ... */
  139. #define PM_1K 0x00000000
  140. #define PM_4K 0x00001800
  141. #define PM_16K 0x00007800
  142. #define PM_64K 0x0001f800
  143. #define PM_256K 0x0007f800
  144. #else
  145. #define PM_4K 0x00000000
  146. #define PM_8K 0x00002000
  147. #define PM_16K 0x00006000
  148. #define PM_32K 0x0000e000
  149. #define PM_64K 0x0001e000
  150. #define PM_128K 0x0003e000
  151. #define PM_256K 0x0007e000
  152. #define PM_512K 0x000fe000
  153. #define PM_1M 0x001fe000
  154. #define PM_2M 0x003fe000
  155. #define PM_4M 0x007fe000
  156. #define PM_8M 0x00ffe000
  157. #define PM_16M 0x01ffe000
  158. #define PM_32M 0x03ffe000
  159. #define PM_64M 0x07ffe000
  160. #define PM_256M 0x1fffe000
  161. #define PM_1G 0x7fffe000
  162. #endif
  163. /*
  164. * Default page size for a given kernel configuration
  165. */
  166. #ifdef CONFIG_PAGE_SIZE_4KB
  167. #define PM_DEFAULT_MASK PM_4K
  168. #elif defined(CONFIG_PAGE_SIZE_8KB)
  169. #define PM_DEFAULT_MASK PM_8K
  170. #elif defined(CONFIG_PAGE_SIZE_16KB)
  171. #define PM_DEFAULT_MASK PM_16K
  172. #elif defined(CONFIG_PAGE_SIZE_32KB)
  173. #define PM_DEFAULT_MASK PM_32K
  174. #elif defined(CONFIG_PAGE_SIZE_64KB)
  175. #define PM_DEFAULT_MASK PM_64K
  176. #else
  177. #error Bad page size configuration!
  178. #endif
  179. /*
  180. * Default huge tlb size for a given kernel configuration
  181. */
  182. #ifdef CONFIG_PAGE_SIZE_4KB
  183. #define PM_HUGE_MASK PM_1M
  184. #elif defined(CONFIG_PAGE_SIZE_8KB)
  185. #define PM_HUGE_MASK PM_4M
  186. #elif defined(CONFIG_PAGE_SIZE_16KB)
  187. #define PM_HUGE_MASK PM_16M
  188. #elif defined(CONFIG_PAGE_SIZE_32KB)
  189. #define PM_HUGE_MASK PM_64M
  190. #elif defined(CONFIG_PAGE_SIZE_64KB)
  191. #define PM_HUGE_MASK PM_256M
  192. #elif defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
  193. #error Bad page size configuration for hugetlbfs!
  194. #endif
  195. /*
  196. * Values used for computation of new tlb entries
  197. */
  198. #define PL_4K 12
  199. #define PL_16K 14
  200. #define PL_64K 16
  201. #define PL_256K 18
  202. #define PL_1M 20
  203. #define PL_4M 22
  204. #define PL_16M 24
  205. #define PL_64M 26
  206. #define PL_256M 28
  207. /*
  208. * PageGrain bits
  209. */
  210. #define PG_RIE (_ULCAST_(1) << 31)
  211. #define PG_XIE (_ULCAST_(1) << 30)
  212. #define PG_ELPA (_ULCAST_(1) << 29)
  213. #define PG_ESP (_ULCAST_(1) << 28)
  214. #define PG_IEC (_ULCAST_(1) << 27)
  215. /* MIPS32/64 EntryHI bit definitions */
  216. #define MIPS_ENTRYHI_EHINV (_ULCAST_(1) << 10)
  217. #define MIPS_ENTRYHI_ASIDX (_ULCAST_(0x3) << 8)
  218. #define MIPS_ENTRYHI_ASID (_ULCAST_(0xff) << 0)
  219. /*
  220. * R4x00 interrupt enable / cause bits
  221. */
  222. #define IE_SW0 (_ULCAST_(1) << 8)
  223. #define IE_SW1 (_ULCAST_(1) << 9)
  224. #define IE_IRQ0 (_ULCAST_(1) << 10)
  225. #define IE_IRQ1 (_ULCAST_(1) << 11)
  226. #define IE_IRQ2 (_ULCAST_(1) << 12)
  227. #define IE_IRQ3 (_ULCAST_(1) << 13)
  228. #define IE_IRQ4 (_ULCAST_(1) << 14)
  229. #define IE_IRQ5 (_ULCAST_(1) << 15)
  230. /*
  231. * R4x00 interrupt cause bits
  232. */
  233. #define C_SW0 (_ULCAST_(1) << 8)
  234. #define C_SW1 (_ULCAST_(1) << 9)
  235. #define C_IRQ0 (_ULCAST_(1) << 10)
  236. #define C_IRQ1 (_ULCAST_(1) << 11)
  237. #define C_IRQ2 (_ULCAST_(1) << 12)
  238. #define C_IRQ3 (_ULCAST_(1) << 13)
  239. #define C_IRQ4 (_ULCAST_(1) << 14)
  240. #define C_IRQ5 (_ULCAST_(1) << 15)
  241. /*
  242. * Bitfields in the R4xx0 cp0 status register
  243. */
  244. #define ST0_IE 0x00000001
  245. #define ST0_EXL 0x00000002
  246. #define ST0_ERL 0x00000004
  247. #define ST0_KSU 0x00000018
  248. # define KSU_USER 0x00000010
  249. # define KSU_SUPERVISOR 0x00000008
  250. # define KSU_KERNEL 0x00000000
  251. #define ST0_UX 0x00000020
  252. #define ST0_SX 0x00000040
  253. #define ST0_KX 0x00000080
  254. #define ST0_DE 0x00010000
  255. #define ST0_CE 0x00020000
  256. /*
  257. * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
  258. * cacheops in userspace. This bit exists only on RM7000 and RM9000
  259. * processors.
  260. */
  261. #define ST0_CO 0x08000000
  262. /*
  263. * Bitfields in the R[23]000 cp0 status register.
  264. */
  265. #define ST0_IEC 0x00000001
  266. #define ST0_KUC 0x00000002
  267. #define ST0_IEP 0x00000004
  268. #define ST0_KUP 0x00000008
  269. #define ST0_IEO 0x00000010
  270. #define ST0_KUO 0x00000020
  271. /* bits 6 & 7 are reserved on R[23]000 */
  272. #define ST0_ISC 0x00010000
  273. #define ST0_SWC 0x00020000
  274. #define ST0_CM 0x00080000
  275. /*
  276. * Bits specific to the R4640/R4650
  277. */
  278. #define ST0_UM (_ULCAST_(1) << 4)
  279. #define ST0_IL (_ULCAST_(1) << 23)
  280. #define ST0_DL (_ULCAST_(1) << 24)
  281. /*
  282. * Enable the MIPS MDMX and DSP ASEs
  283. */
  284. #define ST0_MX 0x01000000
  285. /*
  286. * Status register bits available in all MIPS CPUs.
  287. */
  288. #define ST0_IM 0x0000ff00
  289. #define STATUSB_IP0 8
  290. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  291. #define STATUSB_IP1 9
  292. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  293. #define STATUSB_IP2 10
  294. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  295. #define STATUSB_IP3 11
  296. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  297. #define STATUSB_IP4 12
  298. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  299. #define STATUSB_IP5 13
  300. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  301. #define STATUSB_IP6 14
  302. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  303. #define STATUSB_IP7 15
  304. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  305. #define STATUSB_IP8 0
  306. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  307. #define STATUSB_IP9 1
  308. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  309. #define STATUSB_IP10 2
  310. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  311. #define STATUSB_IP11 3
  312. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  313. #define STATUSB_IP12 4
  314. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  315. #define STATUSB_IP13 5
  316. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  317. #define STATUSB_IP14 6
  318. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  319. #define STATUSB_IP15 7
  320. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  321. #define ST0_CH 0x00040000
  322. #define ST0_NMI 0x00080000
  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 IntCtl register. (MIPSR2)
  336. */
  337. #define INTCTLB_IPFDC 23
  338. #define INTCTLF_IPFDC (_ULCAST_(7) << INTCTLB_IPFDC)
  339. #define INTCTLB_IPPCI 26
  340. #define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
  341. #define INTCTLB_IPTI 29
  342. #define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
  343. /*
  344. * Bitfields and bit numbers in the coprocessor 0 cause register.
  345. *
  346. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  347. */
  348. #define CAUSEB_EXCCODE 2
  349. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  350. #define CAUSEB_IP 8
  351. #define CAUSEF_IP (_ULCAST_(255) << 8)
  352. #define CAUSEB_IP0 8
  353. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  354. #define CAUSEB_IP1 9
  355. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  356. #define CAUSEB_IP2 10
  357. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  358. #define CAUSEB_IP3 11
  359. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  360. #define CAUSEB_IP4 12
  361. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  362. #define CAUSEB_IP5 13
  363. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  364. #define CAUSEB_IP6 14
  365. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  366. #define CAUSEB_IP7 15
  367. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  368. #define CAUSEB_FDCI 21
  369. #define CAUSEF_FDCI (_ULCAST_(1) << 21)
  370. #define CAUSEB_WP 22
  371. #define CAUSEF_WP (_ULCAST_(1) << 22)
  372. #define CAUSEB_IV 23
  373. #define CAUSEF_IV (_ULCAST_(1) << 23)
  374. #define CAUSEB_PCI 26
  375. #define CAUSEF_PCI (_ULCAST_(1) << 26)
  376. #define CAUSEB_DC 27
  377. #define CAUSEF_DC (_ULCAST_(1) << 27)
  378. #define CAUSEB_CE 28
  379. #define CAUSEF_CE (_ULCAST_(3) << 28)
  380. #define CAUSEB_TI 30
  381. #define CAUSEF_TI (_ULCAST_(1) << 30)
  382. #define CAUSEB_BD 31
  383. #define CAUSEF_BD (_ULCAST_(1) << 31)
  384. /*
  385. * Cause.ExcCode trap codes.
  386. */
  387. #define EXCCODE_INT 0 /* Interrupt pending */
  388. #define EXCCODE_MOD 1 /* TLB modified fault */
  389. #define EXCCODE_TLBL 2 /* TLB miss on load or ifetch */
  390. #define EXCCODE_TLBS 3 /* TLB miss on a store */
  391. #define EXCCODE_ADEL 4 /* Address error on a load or ifetch */
  392. #define EXCCODE_ADES 5 /* Address error on a store */
  393. #define EXCCODE_IBE 6 /* Bus error on an ifetch */
  394. #define EXCCODE_DBE 7 /* Bus error on a load or store */
  395. #define EXCCODE_SYS 8 /* System call */
  396. #define EXCCODE_BP 9 /* Breakpoint */
  397. #define EXCCODE_RI 10 /* Reserved instruction exception */
  398. #define EXCCODE_CPU 11 /* Coprocessor unusable */
  399. #define EXCCODE_OV 12 /* Arithmetic overflow */
  400. #define EXCCODE_TR 13 /* Trap instruction */
  401. #define EXCCODE_MSAFPE 14 /* MSA floating point exception */
  402. #define EXCCODE_FPE 15 /* Floating point exception */
  403. #define EXCCODE_TLBRI 19 /* TLB Read-Inhibit exception */
  404. #define EXCCODE_TLBXI 20 /* TLB Execution-Inhibit exception */
  405. #define EXCCODE_MSADIS 21 /* MSA disabled exception */
  406. #define EXCCODE_MDMX 22 /* MDMX unusable exception */
  407. #define EXCCODE_WATCH 23 /* Watch address reference */
  408. #define EXCCODE_MCHECK 24 /* Machine check */
  409. #define EXCCODE_THREAD 25 /* Thread exceptions (MT) */
  410. #define EXCCODE_DSPDIS 26 /* DSP disabled exception */
  411. #define EXCCODE_GE 27 /* Virtualized guest exception (VZ) */
  412. /* Implementation specific trap codes used by MIPS cores */
  413. #define MIPS_EXCCODE_TLBPAR 16 /* TLB parity error exception */
  414. /*
  415. * Bits in the coprocessor 0 config register.
  416. */
  417. /* Generic bits. */
  418. #define CONF_CM_CACHABLE_NO_WA 0
  419. #define CONF_CM_CACHABLE_WA 1
  420. #define CONF_CM_UNCACHED 2
  421. #define CONF_CM_CACHABLE_NONCOHERENT 3
  422. #define CONF_CM_CACHABLE_CE 4
  423. #define CONF_CM_CACHABLE_COW 5
  424. #define CONF_CM_CACHABLE_CUW 6
  425. #define CONF_CM_CACHABLE_ACCELERATED 7
  426. #define CONF_CM_CMASK 7
  427. #define CONF_BE (_ULCAST_(1) << 15)
  428. /* Bits common to various processors. */
  429. #define CONF_CU (_ULCAST_(1) << 3)
  430. #define CONF_DB (_ULCAST_(1) << 4)
  431. #define CONF_IB (_ULCAST_(1) << 5)
  432. #define CONF_DC (_ULCAST_(7) << 6)
  433. #define CONF_IC (_ULCAST_(7) << 9)
  434. #define CONF_EB (_ULCAST_(1) << 13)
  435. #define CONF_EM (_ULCAST_(1) << 14)
  436. #define CONF_SM (_ULCAST_(1) << 16)
  437. #define CONF_SC (_ULCAST_(1) << 17)
  438. #define CONF_EW (_ULCAST_(3) << 18)
  439. #define CONF_EP (_ULCAST_(15)<< 24)
  440. #define CONF_EC (_ULCAST_(7) << 28)
  441. #define CONF_CM (_ULCAST_(1) << 31)
  442. /* Bits specific to the R4xx0. */
  443. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  444. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  445. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  446. /* Bits specific to the R5000. */
  447. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  448. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  449. /* Bits specific to the RM7000. */
  450. #define RM7K_CONF_SE (_ULCAST_(1) << 3)
  451. #define RM7K_CONF_TE (_ULCAST_(1) << 12)
  452. #define RM7K_CONF_CLK (_ULCAST_(1) << 16)
  453. #define RM7K_CONF_TC (_ULCAST_(1) << 17)
  454. #define RM7K_CONF_SI (_ULCAST_(3) << 20)
  455. #define RM7K_CONF_SC (_ULCAST_(1) << 31)
  456. /* Bits specific to the R10000. */
  457. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  458. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  459. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  460. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  461. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  462. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  463. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  464. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  465. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  466. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  467. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  468. /* Bits specific to the VR41xx. */
  469. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  470. #define VR41_CONF_P4K (_ULCAST_(1) << 13)
  471. #define VR41_CONF_BP (_ULCAST_(1) << 16)
  472. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  473. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  474. /* Bits specific to the R30xx. */
  475. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  476. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  477. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  478. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  479. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  480. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  481. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  482. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  483. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  484. /* Bits specific to the TX49. */
  485. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  486. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  487. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  488. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  489. /* Bits specific to the MIPS32/64 PRA. */
  490. #define MIPS_CONF_VI (_ULCAST_(1) << 3)
  491. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  492. #define MIPS_CONF_MT_TLB (_ULCAST_(1) << 7)
  493. #define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)
  494. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  495. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  496. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  497. /*
  498. * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
  499. */
  500. #define MIPS_CONF1_FP (_ULCAST_(1) << 0)
  501. #define MIPS_CONF1_EP (_ULCAST_(1) << 1)
  502. #define MIPS_CONF1_CA (_ULCAST_(1) << 2)
  503. #define MIPS_CONF1_WR (_ULCAST_(1) << 3)
  504. #define MIPS_CONF1_PC (_ULCAST_(1) << 4)
  505. #define MIPS_CONF1_MD (_ULCAST_(1) << 5)
  506. #define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
  507. #define MIPS_CONF1_DA_SHF 7
  508. #define MIPS_CONF1_DA_SZ 3
  509. #define MIPS_CONF1_DA (_ULCAST_(7) << 7)
  510. #define MIPS_CONF1_DL_SHF 10
  511. #define MIPS_CONF1_DL_SZ 3
  512. #define MIPS_CONF1_DL (_ULCAST_(7) << 10)
  513. #define MIPS_CONF1_DS_SHF 13
  514. #define MIPS_CONF1_DS_SZ 3
  515. #define MIPS_CONF1_DS (_ULCAST_(7) << 13)
  516. #define MIPS_CONF1_IA_SHF 16
  517. #define MIPS_CONF1_IA_SZ 3
  518. #define MIPS_CONF1_IA (_ULCAST_(7) << 16)
  519. #define MIPS_CONF1_IL_SHF 19
  520. #define MIPS_CONF1_IL_SZ 3
  521. #define MIPS_CONF1_IL (_ULCAST_(7) << 19)
  522. #define MIPS_CONF1_IS_SHF 22
  523. #define MIPS_CONF1_IS_SZ 3
  524. #define MIPS_CONF1_IS (_ULCAST_(7) << 22)
  525. #define MIPS_CONF1_TLBS_SHIFT (25)
  526. #define MIPS_CONF1_TLBS_SIZE (6)
  527. #define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
  528. #define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
  529. #define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
  530. #define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
  531. #define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
  532. #define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
  533. #define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
  534. #define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
  535. #define MIPS_CONF2_TU (_ULCAST_(7) << 28)
  536. #define MIPS_CONF3_TL (_ULCAST_(1) << 0)
  537. #define MIPS_CONF3_SM (_ULCAST_(1) << 1)
  538. #define MIPS_CONF3_MT (_ULCAST_(1) << 2)
  539. #define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
  540. #define MIPS_CONF3_SP (_ULCAST_(1) << 4)
  541. #define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
  542. #define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
  543. #define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
  544. #define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
  545. #define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
  546. #define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
  547. #define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
  548. #define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
  549. #define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
  550. #define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
  551. #define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
  552. #define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
  553. #define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
  554. #define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
  555. #define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
  556. #define MIPS_CONF3_PW (_ULCAST_(1) << 24)
  557. #define MIPS_CONF3_SC (_ULCAST_(1) << 25)
  558. #define MIPS_CONF3_BI (_ULCAST_(1) << 26)
  559. #define MIPS_CONF3_BP (_ULCAST_(1) << 27)
  560. #define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
  561. #define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
  562. #define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
  563. #define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
  564. #define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
  565. #define MIPS_CONF4_FTLBSETS_SHIFT (0)
  566. #define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
  567. #define MIPS_CONF4_FTLBWAYS_SHIFT (4)
  568. #define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
  569. #define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
  570. /* bits 10:8 in FTLB-only configurations */
  571. #define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
  572. /* bits 12:8 in VTLB-FTLB only configurations */
  573. #define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
  574. #define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
  575. #define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
  576. #define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
  577. #define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
  578. #define MIPS_CONF4_KSCREXIST_SHIFT (16)
  579. #define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << MIPS_CONF4_KSCREXIST_SHIFT)
  580. #define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
  581. #define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
  582. #define MIPS_CONF4_AE (_ULCAST_(1) << 28)
  583. #define MIPS_CONF4_IE (_ULCAST_(3) << 29)
  584. #define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
  585. #define MIPS_CONF5_NF (_ULCAST_(1) << 0)
  586. #define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
  587. #define MIPS_CONF5_MRP (_ULCAST_(1) << 3)
  588. #define MIPS_CONF5_LLB (_ULCAST_(1) << 4)
  589. #define MIPS_CONF5_MVH (_ULCAST_(1) << 5)
  590. #define MIPS_CONF5_VP (_ULCAST_(1) << 7)
  591. #define MIPS_CONF5_FRE (_ULCAST_(1) << 8)
  592. #define MIPS_CONF5_UFE (_ULCAST_(1) << 9)
  593. #define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
  594. #define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
  595. #define MIPS_CONF5_CV (_ULCAST_(1) << 29)
  596. #define MIPS_CONF5_K (_ULCAST_(1) << 30)
  597. #define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
  598. /* proAptiv FTLB on/off bit */
  599. #define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
  600. /* Loongson-3 FTLB on/off bit */
  601. #define MIPS_CONF6_FTLBDIS (_ULCAST_(1) << 22)
  602. /* FTLB probability bits */
  603. #define MIPS_CONF6_FTLBP_SHIFT (16)
  604. #define MIPS_CONF7_WII (_ULCAST_(1) << 31)
  605. #define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
  606. #define MIPS_CONF7_IAR (_ULCAST_(1) << 10)
  607. #define MIPS_CONF7_AR (_ULCAST_(1) << 16)
  608. /* FTLB probability bits for R6 */
  609. #define MIPS_CONF7_FTLBP_SHIFT (18)
  610. /* WatchLo* register definitions */
  611. #define MIPS_WATCHLO_IRW (_ULCAST_(0x7) << 0)
  612. /* WatchHi* register definitions */
  613. #define MIPS_WATCHHI_M (_ULCAST_(1) << 31)
  614. #define MIPS_WATCHHI_G (_ULCAST_(1) << 30)
  615. #define MIPS_WATCHHI_WM (_ULCAST_(0x3) << 28)
  616. #define MIPS_WATCHHI_WM_R_RVA (_ULCAST_(0) << 28)
  617. #define MIPS_WATCHHI_WM_R_GPA (_ULCAST_(1) << 28)
  618. #define MIPS_WATCHHI_WM_G_GVA (_ULCAST_(2) << 28)
  619. #define MIPS_WATCHHI_EAS (_ULCAST_(0x3) << 24)
  620. #define MIPS_WATCHHI_ASID (_ULCAST_(0xff) << 16)
  621. #define MIPS_WATCHHI_MASK (_ULCAST_(0x1ff) << 3)
  622. #define MIPS_WATCHHI_I (_ULCAST_(1) << 2)
  623. #define MIPS_WATCHHI_R (_ULCAST_(1) << 1)
  624. #define MIPS_WATCHHI_W (_ULCAST_(1) << 0)
  625. #define MIPS_WATCHHI_IRW (_ULCAST_(0x7) << 0)
  626. /* MAAR bit definitions */
  627. #define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12)
  628. #define MIPS_MAAR_ADDR_SHIFT 12
  629. #define MIPS_MAAR_S (_ULCAST_(1) << 1)
  630. #define MIPS_MAAR_V (_ULCAST_(1) << 0)
  631. /* EBase bit definitions */
  632. #define MIPS_EBASE_CPUNUM_SHIFT 0
  633. #define MIPS_EBASE_CPUNUM (_ULCAST_(0x3ff) << 0)
  634. #define MIPS_EBASE_WG_SHIFT 11
  635. #define MIPS_EBASE_WG (_ULCAST_(1) << 11)
  636. #define MIPS_EBASE_BASE_SHIFT 12
  637. #define MIPS_EBASE_BASE (~_ULCAST_((1 << MIPS_EBASE_BASE_SHIFT) - 1))
  638. /* CMGCRBase bit definitions */
  639. #define MIPS_CMGCRB_BASE 11
  640. #define MIPS_CMGCRF_BASE (~_ULCAST_((1 << MIPS_CMGCRB_BASE) - 1))
  641. /*
  642. * Bits in the MIPS32 Memory Segmentation registers.
  643. */
  644. #define MIPS_SEGCFG_PA_SHIFT 9
  645. #define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
  646. #define MIPS_SEGCFG_AM_SHIFT 4
  647. #define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
  648. #define MIPS_SEGCFG_EU_SHIFT 3
  649. #define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
  650. #define MIPS_SEGCFG_C_SHIFT 0
  651. #define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
  652. #define MIPS_SEGCFG_UUSK _ULCAST_(7)
  653. #define MIPS_SEGCFG_USK _ULCAST_(5)
  654. #define MIPS_SEGCFG_MUSUK _ULCAST_(4)
  655. #define MIPS_SEGCFG_MUSK _ULCAST_(3)
  656. #define MIPS_SEGCFG_MSK _ULCAST_(2)
  657. #define MIPS_SEGCFG_MK _ULCAST_(1)
  658. #define MIPS_SEGCFG_UK _ULCAST_(0)
  659. #define MIPS_PWFIELD_GDI_SHIFT 24
  660. #define MIPS_PWFIELD_GDI_MASK 0x3f000000
  661. #define MIPS_PWFIELD_UDI_SHIFT 18
  662. #define MIPS_PWFIELD_UDI_MASK 0x00fc0000
  663. #define MIPS_PWFIELD_MDI_SHIFT 12
  664. #define MIPS_PWFIELD_MDI_MASK 0x0003f000
  665. #define MIPS_PWFIELD_PTI_SHIFT 6
  666. #define MIPS_PWFIELD_PTI_MASK 0x00000fc0
  667. #define MIPS_PWFIELD_PTEI_SHIFT 0
  668. #define MIPS_PWFIELD_PTEI_MASK 0x0000003f
  669. #define MIPS_PWSIZE_PS_SHIFT 30
  670. #define MIPS_PWSIZE_PS_MASK 0x40000000
  671. #define MIPS_PWSIZE_GDW_SHIFT 24
  672. #define MIPS_PWSIZE_GDW_MASK 0x3f000000
  673. #define MIPS_PWSIZE_UDW_SHIFT 18
  674. #define MIPS_PWSIZE_UDW_MASK 0x00fc0000
  675. #define MIPS_PWSIZE_MDW_SHIFT 12
  676. #define MIPS_PWSIZE_MDW_MASK 0x0003f000
  677. #define MIPS_PWSIZE_PTW_SHIFT 6
  678. #define MIPS_PWSIZE_PTW_MASK 0x00000fc0
  679. #define MIPS_PWSIZE_PTEW_SHIFT 0
  680. #define MIPS_PWSIZE_PTEW_MASK 0x0000003f
  681. #define MIPS_PWCTL_PWEN_SHIFT 31
  682. #define MIPS_PWCTL_PWEN_MASK 0x80000000
  683. #define MIPS_PWCTL_XK_SHIFT 28
  684. #define MIPS_PWCTL_XK_MASK 0x10000000
  685. #define MIPS_PWCTL_XS_SHIFT 27
  686. #define MIPS_PWCTL_XS_MASK 0x08000000
  687. #define MIPS_PWCTL_XU_SHIFT 26
  688. #define MIPS_PWCTL_XU_MASK 0x04000000
  689. #define MIPS_PWCTL_DPH_SHIFT 7
  690. #define MIPS_PWCTL_DPH_MASK 0x00000080
  691. #define MIPS_PWCTL_HUGEPG_SHIFT 6
  692. #define MIPS_PWCTL_HUGEPG_MASK 0x00000060
  693. #define MIPS_PWCTL_PSN_SHIFT 0
  694. #define MIPS_PWCTL_PSN_MASK 0x0000003f
  695. /* GuestCtl0 fields */
  696. #define MIPS_GCTL0_GM_SHIFT 31
  697. #define MIPS_GCTL0_GM (_ULCAST_(1) << MIPS_GCTL0_GM_SHIFT)
  698. #define MIPS_GCTL0_RI_SHIFT 30
  699. #define MIPS_GCTL0_RI (_ULCAST_(1) << MIPS_GCTL0_RI_SHIFT)
  700. #define MIPS_GCTL0_MC_SHIFT 29
  701. #define MIPS_GCTL0_MC (_ULCAST_(1) << MIPS_GCTL0_MC_SHIFT)
  702. #define MIPS_GCTL0_CP0_SHIFT 28
  703. #define MIPS_GCTL0_CP0 (_ULCAST_(1) << MIPS_GCTL0_CP0_SHIFT)
  704. #define MIPS_GCTL0_AT_SHIFT 26
  705. #define MIPS_GCTL0_AT (_ULCAST_(0x3) << MIPS_GCTL0_AT_SHIFT)
  706. #define MIPS_GCTL0_GT_SHIFT 25
  707. #define MIPS_GCTL0_GT (_ULCAST_(1) << MIPS_GCTL0_GT_SHIFT)
  708. #define MIPS_GCTL0_CG_SHIFT 24
  709. #define MIPS_GCTL0_CG (_ULCAST_(1) << MIPS_GCTL0_CG_SHIFT)
  710. #define MIPS_GCTL0_CF_SHIFT 23
  711. #define MIPS_GCTL0_CF (_ULCAST_(1) << MIPS_GCTL0_CF_SHIFT)
  712. #define MIPS_GCTL0_G1_SHIFT 22
  713. #define MIPS_GCTL0_G1 (_ULCAST_(1) << MIPS_GCTL0_G1_SHIFT)
  714. #define MIPS_GCTL0_G0E_SHIFT 19
  715. #define MIPS_GCTL0_G0E (_ULCAST_(1) << MIPS_GCTL0_G0E_SHIFT)
  716. #define MIPS_GCTL0_PT_SHIFT 18
  717. #define MIPS_GCTL0_PT (_ULCAST_(1) << MIPS_GCTL0_PT_SHIFT)
  718. #define MIPS_GCTL0_RAD_SHIFT 9
  719. #define MIPS_GCTL0_RAD (_ULCAST_(1) << MIPS_GCTL0_RAD_SHIFT)
  720. #define MIPS_GCTL0_DRG_SHIFT 8
  721. #define MIPS_GCTL0_DRG (_ULCAST_(1) << MIPS_GCTL0_DRG_SHIFT)
  722. #define MIPS_GCTL0_G2_SHIFT 7
  723. #define MIPS_GCTL0_G2 (_ULCAST_(1) << MIPS_GCTL0_G2_SHIFT)
  724. #define MIPS_GCTL0_GEXC_SHIFT 2
  725. #define MIPS_GCTL0_GEXC (_ULCAST_(0x1f) << MIPS_GCTL0_GEXC_SHIFT)
  726. #define MIPS_GCTL0_SFC2_SHIFT 1
  727. #define MIPS_GCTL0_SFC2 (_ULCAST_(1) << MIPS_GCTL0_SFC2_SHIFT)
  728. #define MIPS_GCTL0_SFC1_SHIFT 0
  729. #define MIPS_GCTL0_SFC1 (_ULCAST_(1) << MIPS_GCTL0_SFC1_SHIFT)
  730. /* GuestCtl0.AT Guest address translation control */
  731. #define MIPS_GCTL0_AT_ROOT 1 /* Guest MMU under Root control */
  732. #define MIPS_GCTL0_AT_GUEST 3 /* Guest MMU under Guest control */
  733. /* GuestCtl0.GExcCode Hypervisor exception cause codes */
  734. #define MIPS_GCTL0_GEXC_GPSI 0 /* Guest Privileged Sensitive Instruction */
  735. #define MIPS_GCTL0_GEXC_GSFC 1 /* Guest Software Field Change */
  736. #define MIPS_GCTL0_GEXC_HC 2 /* Hypercall */
  737. #define MIPS_GCTL0_GEXC_GRR 3 /* Guest Reserved Instruction Redirect */
  738. #define MIPS_GCTL0_GEXC_GVA 8 /* Guest Virtual Address available */
  739. #define MIPS_GCTL0_GEXC_GHFC 9 /* Guest Hardware Field Change */
  740. #define MIPS_GCTL0_GEXC_GPA 10 /* Guest Physical Address available */
  741. /* GuestCtl0Ext fields */
  742. #define MIPS_GCTL0EXT_RPW_SHIFT 8
  743. #define MIPS_GCTL0EXT_RPW (_ULCAST_(0x3) << MIPS_GCTL0EXT_RPW_SHIFT)
  744. #define MIPS_GCTL0EXT_NCC_SHIFT 6
  745. #define MIPS_GCTL0EXT_NCC (_ULCAST_(0x3) << MIPS_GCTL0EXT_NCC_SHIFT)
  746. #define MIPS_GCTL0EXT_CGI_SHIFT 4
  747. #define MIPS_GCTL0EXT_CGI (_ULCAST_(1) << MIPS_GCTL0EXT_CGI_SHIFT)
  748. #define MIPS_GCTL0EXT_FCD_SHIFT 3
  749. #define MIPS_GCTL0EXT_FCD (_ULCAST_(1) << MIPS_GCTL0EXT_FCD_SHIFT)
  750. #define MIPS_GCTL0EXT_OG_SHIFT 2
  751. #define MIPS_GCTL0EXT_OG (_ULCAST_(1) << MIPS_GCTL0EXT_OG_SHIFT)
  752. #define MIPS_GCTL0EXT_BG_SHIFT 1
  753. #define MIPS_GCTL0EXT_BG (_ULCAST_(1) << MIPS_GCTL0EXT_BG_SHIFT)
  754. #define MIPS_GCTL0EXT_MG_SHIFT 0
  755. #define MIPS_GCTL0EXT_MG (_ULCAST_(1) << MIPS_GCTL0EXT_MG_SHIFT)
  756. /* GuestCtl0Ext.RPW Root page walk configuration */
  757. #define MIPS_GCTL0EXT_RPW_BOTH 0 /* Root PW for GPA->RPA and RVA->RPA */
  758. #define MIPS_GCTL0EXT_RPW_GPA 2 /* Root PW for GPA->RPA */
  759. #define MIPS_GCTL0EXT_RPW_RVA 3 /* Root PW for RVA->RPA */
  760. /* GuestCtl0Ext.NCC Nested cache coherency attributes */
  761. #define MIPS_GCTL0EXT_NCC_IND 0 /* Guest CCA independent of Root CCA */
  762. #define MIPS_GCTL0EXT_NCC_MOD 1 /* Guest CCA modified by Root CCA */
  763. /* GuestCtl1 fields */
  764. #define MIPS_GCTL1_ID_SHIFT 0
  765. #define MIPS_GCTL1_ID_WIDTH 8
  766. #define MIPS_GCTL1_ID (_ULCAST_(0xff) << MIPS_GCTL1_ID_SHIFT)
  767. #define MIPS_GCTL1_RID_SHIFT 16
  768. #define MIPS_GCTL1_RID_WIDTH 8
  769. #define MIPS_GCTL1_RID (_ULCAST_(0xff) << MIPS_GCTL1_RID_SHIFT)
  770. #define MIPS_GCTL1_EID_SHIFT 24
  771. #define MIPS_GCTL1_EID_WIDTH 8
  772. #define MIPS_GCTL1_EID (_ULCAST_(0xff) << MIPS_GCTL1_EID_SHIFT)
  773. /* GuestID reserved for root context */
  774. #define MIPS_GCTL1_ROOT_GUESTID 0
  775. /* CDMMBase register bit definitions */
  776. #define MIPS_CDMMBASE_SIZE_SHIFT 0
  777. #define MIPS_CDMMBASE_SIZE (_ULCAST_(511) << MIPS_CDMMBASE_SIZE_SHIFT)
  778. #define MIPS_CDMMBASE_CI (_ULCAST_(1) << 9)
  779. #define MIPS_CDMMBASE_EN (_ULCAST_(1) << 10)
  780. #define MIPS_CDMMBASE_ADDR_SHIFT 11
  781. #define MIPS_CDMMBASE_ADDR_START 15
  782. /* RDHWR register numbers */
  783. #define MIPS_HWR_CPUNUM 0 /* CPU number */
  784. #define MIPS_HWR_SYNCISTEP 1 /* SYNCI step size */
  785. #define MIPS_HWR_CC 2 /* Cycle counter */
  786. #define MIPS_HWR_CCRES 3 /* Cycle counter resolution */
  787. #define MIPS_HWR_ULR 29 /* UserLocal */
  788. #define MIPS_HWR_IMPL1 30 /* Implementation dependent */
  789. #define MIPS_HWR_IMPL2 31 /* Implementation dependent */
  790. /* Bits in HWREna register */
  791. #define MIPS_HWRENA_CPUNUM (_ULCAST_(1) << MIPS_HWR_CPUNUM)
  792. #define MIPS_HWRENA_SYNCISTEP (_ULCAST_(1) << MIPS_HWR_SYNCISTEP)
  793. #define MIPS_HWRENA_CC (_ULCAST_(1) << MIPS_HWR_CC)
  794. #define MIPS_HWRENA_CCRES (_ULCAST_(1) << MIPS_HWR_CCRES)
  795. #define MIPS_HWRENA_ULR (_ULCAST_(1) << MIPS_HWR_ULR)
  796. #define MIPS_HWRENA_IMPL1 (_ULCAST_(1) << MIPS_HWR_IMPL1)
  797. #define MIPS_HWRENA_IMPL2 (_ULCAST_(1) << MIPS_HWR_IMPL2)
  798. /*
  799. * Bitfields in the TX39 family CP0 Configuration Register 3
  800. */
  801. #define TX39_CONF_ICS_SHIFT 19
  802. #define TX39_CONF_ICS_MASK 0x00380000
  803. #define TX39_CONF_ICS_1KB 0x00000000
  804. #define TX39_CONF_ICS_2KB 0x00080000
  805. #define TX39_CONF_ICS_4KB 0x00100000
  806. #define TX39_CONF_ICS_8KB 0x00180000
  807. #define TX39_CONF_ICS_16KB 0x00200000
  808. #define TX39_CONF_DCS_SHIFT 16
  809. #define TX39_CONF_DCS_MASK 0x00070000
  810. #define TX39_CONF_DCS_1KB 0x00000000
  811. #define TX39_CONF_DCS_2KB 0x00010000
  812. #define TX39_CONF_DCS_4KB 0x00020000
  813. #define TX39_CONF_DCS_8KB 0x00030000
  814. #define TX39_CONF_DCS_16KB 0x00040000
  815. #define TX39_CONF_CWFON 0x00004000
  816. #define TX39_CONF_WBON 0x00002000
  817. #define TX39_CONF_RF_SHIFT 10
  818. #define TX39_CONF_RF_MASK 0x00000c00
  819. #define TX39_CONF_DOZE 0x00000200
  820. #define TX39_CONF_HALT 0x00000100
  821. #define TX39_CONF_LOCK 0x00000080
  822. #define TX39_CONF_ICE 0x00000020
  823. #define TX39_CONF_DCE 0x00000010
  824. #define TX39_CONF_IRSIZE_SHIFT 2
  825. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  826. #define TX39_CONF_DRSIZE_SHIFT 0
  827. #define TX39_CONF_DRSIZE_MASK 0x00000003
  828. /*
  829. * Interesting Bits in the R10K CP0 Branch Diagnostic Register
  830. */
  831. /* Disable Branch Target Address Cache */
  832. #define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27)
  833. /* Enable Branch Prediction Global History */
  834. #define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26)
  835. /* Disable Branch Return Cache */
  836. #define R10K_DIAG_D_BRC (_ULCAST_(1) << 22)
  837. /* Flush ITLB */
  838. #define LOONGSON_DIAG_ITLB (_ULCAST_(1) << 2)
  839. /* Flush DTLB */
  840. #define LOONGSON_DIAG_DTLB (_ULCAST_(1) << 3)
  841. /* Flush VTLB */
  842. #define LOONGSON_DIAG_VTLB (_ULCAST_(1) << 12)
  843. /* Flush FTLB */
  844. #define LOONGSON_DIAG_FTLB (_ULCAST_(1) << 13)
  845. /*
  846. * Coprocessor 1 (FPU) register names
  847. */
  848. #define CP1_REVISION $0
  849. #define CP1_UFR $1
  850. #define CP1_UNFR $4
  851. #define CP1_FCCR $25
  852. #define CP1_FEXR $26
  853. #define CP1_FENR $28
  854. #define CP1_STATUS $31
  855. /*
  856. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  857. */
  858. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  859. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  860. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  861. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  862. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  863. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  864. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  865. #define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
  866. #define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
  867. #define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
  868. /*
  869. * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
  870. */
  871. #define MIPS_FCCR_CONDX_S 0
  872. #define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
  873. #define MIPS_FCCR_COND0_S 0
  874. #define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
  875. #define MIPS_FCCR_COND1_S 1
  876. #define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
  877. #define MIPS_FCCR_COND2_S 2
  878. #define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
  879. #define MIPS_FCCR_COND3_S 3
  880. #define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
  881. #define MIPS_FCCR_COND4_S 4
  882. #define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
  883. #define MIPS_FCCR_COND5_S 5
  884. #define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
  885. #define MIPS_FCCR_COND6_S 6
  886. #define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
  887. #define MIPS_FCCR_COND7_S 7
  888. #define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
  889. /*
  890. * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
  891. */
  892. #define MIPS_FENR_FS_S 2
  893. #define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
  894. /*
  895. * FPU Status Register Values
  896. */
  897. #define FPU_CSR_COND_S 23 /* $fcc0 */
  898. #define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
  899. #define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
  900. #define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
  901. #define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
  902. #define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
  903. #define FPU_CSR_COND1_S 25 /* $fcc1 */
  904. #define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
  905. #define FPU_CSR_COND2_S 26 /* $fcc2 */
  906. #define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
  907. #define FPU_CSR_COND3_S 27 /* $fcc3 */
  908. #define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
  909. #define FPU_CSR_COND4_S 28 /* $fcc4 */
  910. #define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
  911. #define FPU_CSR_COND5_S 29 /* $fcc5 */
  912. #define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
  913. #define FPU_CSR_COND6_S 30 /* $fcc6 */
  914. #define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
  915. #define FPU_CSR_COND7_S 31 /* $fcc7 */
  916. #define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
  917. /*
  918. * Bits 22:20 of the FPU Status Register will be read as 0,
  919. * and should be written as zero.
  920. */
  921. #define FPU_CSR_RSVD (_ULCAST_(7) << 20)
  922. #define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
  923. #define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
  924. /*
  925. * X the exception cause indicator
  926. * E the exception enable
  927. * S the sticky/flag bit
  928. */
  929. #define FPU_CSR_ALL_X 0x0003f000
  930. #define FPU_CSR_UNI_X 0x00020000
  931. #define FPU_CSR_INV_X 0x00010000
  932. #define FPU_CSR_DIV_X 0x00008000
  933. #define FPU_CSR_OVF_X 0x00004000
  934. #define FPU_CSR_UDF_X 0x00002000
  935. #define FPU_CSR_INE_X 0x00001000
  936. #define FPU_CSR_ALL_E 0x00000f80
  937. #define FPU_CSR_INV_E 0x00000800
  938. #define FPU_CSR_DIV_E 0x00000400
  939. #define FPU_CSR_OVF_E 0x00000200
  940. #define FPU_CSR_UDF_E 0x00000100
  941. #define FPU_CSR_INE_E 0x00000080
  942. #define FPU_CSR_ALL_S 0x0000007c
  943. #define FPU_CSR_INV_S 0x00000040
  944. #define FPU_CSR_DIV_S 0x00000020
  945. #define FPU_CSR_OVF_S 0x00000010
  946. #define FPU_CSR_UDF_S 0x00000008
  947. #define FPU_CSR_INE_S 0x00000004
  948. /* Bits 0 and 1 of FPU Status Register specify the rounding mode */
  949. #define FPU_CSR_RM 0x00000003
  950. #define FPU_CSR_RN 0x0 /* nearest */
  951. #define FPU_CSR_RZ 0x1 /* towards zero */
  952. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  953. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  954. #ifndef __ASSEMBLY__
  955. /*
  956. * Macros for handling the ISA mode bit for MIPS16 and microMIPS.
  957. */
  958. #if defined(CONFIG_SYS_SUPPORTS_MIPS16) || \
  959. defined(CONFIG_SYS_SUPPORTS_MICROMIPS)
  960. #define get_isa16_mode(x) ((x) & 0x1)
  961. #define msk_isa16_mode(x) ((x) & ~0x1)
  962. #define set_isa16_mode(x) do { (x) |= 0x1; } while(0)
  963. #else
  964. #define get_isa16_mode(x) 0
  965. #define msk_isa16_mode(x) (x)
  966. #define set_isa16_mode(x) do { } while(0)
  967. #endif
  968. /*
  969. * microMIPS instructions can be 16-bit or 32-bit in length. This
  970. * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
  971. */
  972. static inline int mm_insn_16bit(u16 insn)
  973. {
  974. u16 opcode = (insn >> 10) & 0x7;
  975. return (opcode >= 1 && opcode <= 3) ? 1 : 0;
  976. }
  977. /*
  978. * Helper macros for generating raw instruction encodings in inline asm.
  979. */
  980. #ifdef CONFIG_CPU_MICROMIPS
  981. #define _ASM_INSN16_IF_MM(_enc) \
  982. ".insn\n\t" \
  983. ".hword (" #_enc ")\n\t"
  984. #define _ASM_INSN32_IF_MM(_enc) \
  985. ".insn\n\t" \
  986. ".hword ((" #_enc ") >> 16)\n\t" \
  987. ".hword ((" #_enc ") & 0xffff)\n\t"
  988. #else
  989. #define _ASM_INSN_IF_MIPS(_enc) \
  990. ".insn\n\t" \
  991. ".word (" #_enc ")\n\t"
  992. #endif
  993. #ifndef _ASM_INSN16_IF_MM
  994. #define _ASM_INSN16_IF_MM(_enc)
  995. #endif
  996. #ifndef _ASM_INSN32_IF_MM
  997. #define _ASM_INSN32_IF_MM(_enc)
  998. #endif
  999. #ifndef _ASM_INSN_IF_MIPS
  1000. #define _ASM_INSN_IF_MIPS(_enc)
  1001. #endif
  1002. /*
  1003. * TLB Invalidate Flush
  1004. */
  1005. static inline void tlbinvf(void)
  1006. {
  1007. __asm__ __volatile__(
  1008. ".set push\n\t"
  1009. ".set noreorder\n\t"
  1010. "# tlbinvf\n\t"
  1011. _ASM_INSN_IF_MIPS(0x42000004)
  1012. _ASM_INSN32_IF_MM(0x0000537c)
  1013. ".set pop");
  1014. }
  1015. /*
  1016. * Functions to access the R10000 performance counters. These are basically
  1017. * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
  1018. * performance counter number encoded into bits 1 ... 5 of the instruction.
  1019. * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
  1020. * disassembler these will look like an access to sel 0 or 1.
  1021. */
  1022. #define read_r10k_perf_cntr(counter) \
  1023. ({ \
  1024. unsigned int __res; \
  1025. __asm__ __volatile__( \
  1026. "mfpc\t%0, %1" \
  1027. : "=r" (__res) \
  1028. : "i" (counter)); \
  1029. \
  1030. __res; \
  1031. })
  1032. #define write_r10k_perf_cntr(counter,val) \
  1033. do { \
  1034. __asm__ __volatile__( \
  1035. "mtpc\t%0, %1" \
  1036. : \
  1037. : "r" (val), "i" (counter)); \
  1038. } while (0)
  1039. #define read_r10k_perf_event(counter) \
  1040. ({ \
  1041. unsigned int __res; \
  1042. __asm__ __volatile__( \
  1043. "mfps\t%0, %1" \
  1044. : "=r" (__res) \
  1045. : "i" (counter)); \
  1046. \
  1047. __res; \
  1048. })
  1049. #define write_r10k_perf_cntl(counter,val) \
  1050. do { \
  1051. __asm__ __volatile__( \
  1052. "mtps\t%0, %1" \
  1053. : \
  1054. : "r" (val), "i" (counter)); \
  1055. } while (0)
  1056. /*
  1057. * Macros to access the system control coprocessor
  1058. */
  1059. #define __read_32bit_c0_register(source, sel) \
  1060. ({ unsigned int __res; \
  1061. if (sel == 0) \
  1062. __asm__ __volatile__( \
  1063. "mfc0\t%0, " #source "\n\t" \
  1064. : "=r" (__res)); \
  1065. else \
  1066. __asm__ __volatile__( \
  1067. ".set\tmips32\n\t" \
  1068. "mfc0\t%0, " #source ", " #sel "\n\t" \
  1069. ".set\tmips0\n\t" \
  1070. : "=r" (__res)); \
  1071. __res; \
  1072. })
  1073. #define __read_64bit_c0_register(source, sel) \
  1074. ({ unsigned long long __res; \
  1075. if (sizeof(unsigned long) == 4) \
  1076. __res = __read_64bit_c0_split(source, sel); \
  1077. else if (sel == 0) \
  1078. __asm__ __volatile__( \
  1079. ".set\tmips3\n\t" \
  1080. "dmfc0\t%0, " #source "\n\t" \
  1081. ".set\tmips0" \
  1082. : "=r" (__res)); \
  1083. else \
  1084. __asm__ __volatile__( \
  1085. ".set\tmips64\n\t" \
  1086. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  1087. ".set\tmips0" \
  1088. : "=r" (__res)); \
  1089. __res; \
  1090. })
  1091. #define __write_32bit_c0_register(register, sel, value) \
  1092. do { \
  1093. if (sel == 0) \
  1094. __asm__ __volatile__( \
  1095. "mtc0\t%z0, " #register "\n\t" \
  1096. : : "Jr" ((unsigned int)(value))); \
  1097. else \
  1098. __asm__ __volatile__( \
  1099. ".set\tmips32\n\t" \
  1100. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  1101. ".set\tmips0" \
  1102. : : "Jr" ((unsigned int)(value))); \
  1103. } while (0)
  1104. #define __write_64bit_c0_register(register, sel, value) \
  1105. do { \
  1106. if (sizeof(unsigned long) == 4) \
  1107. __write_64bit_c0_split(register, sel, value); \
  1108. else if (sel == 0) \
  1109. __asm__ __volatile__( \
  1110. ".set\tmips3\n\t" \
  1111. "dmtc0\t%z0, " #register "\n\t" \
  1112. ".set\tmips0" \
  1113. : : "Jr" (value)); \
  1114. else \
  1115. __asm__ __volatile__( \
  1116. ".set\tmips64\n\t" \
  1117. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  1118. ".set\tmips0" \
  1119. : : "Jr" (value)); \
  1120. } while (0)
  1121. #define __read_ulong_c0_register(reg, sel) \
  1122. ((sizeof(unsigned long) == 4) ? \
  1123. (unsigned long) __read_32bit_c0_register(reg, sel) : \
  1124. (unsigned long) __read_64bit_c0_register(reg, sel))
  1125. #define __write_ulong_c0_register(reg, sel, val) \
  1126. do { \
  1127. if (sizeof(unsigned long) == 4) \
  1128. __write_32bit_c0_register(reg, sel, val); \
  1129. else \
  1130. __write_64bit_c0_register(reg, sel, val); \
  1131. } while (0)
  1132. /*
  1133. * On RM7000/RM9000 these are uses to access cop0 set 1 registers
  1134. */
  1135. #define __read_32bit_c0_ctrl_register(source) \
  1136. ({ unsigned int __res; \
  1137. __asm__ __volatile__( \
  1138. "cfc0\t%0, " #source "\n\t" \
  1139. : "=r" (__res)); \
  1140. __res; \
  1141. })
  1142. #define __write_32bit_c0_ctrl_register(register, value) \
  1143. do { \
  1144. __asm__ __volatile__( \
  1145. "ctc0\t%z0, " #register "\n\t" \
  1146. : : "Jr" ((unsigned int)(value))); \
  1147. } while (0)
  1148. /*
  1149. * These versions are only needed for systems with more than 38 bits of
  1150. * physical address space running the 32-bit kernel. That's none atm :-)
  1151. */
  1152. #define __read_64bit_c0_split(source, sel) \
  1153. ({ \
  1154. unsigned long long __val; \
  1155. unsigned long __flags; \
  1156. \
  1157. local_irq_save(__flags); \
  1158. if (sel == 0) \
  1159. __asm__ __volatile__( \
  1160. ".set\tmips64\n\t" \
  1161. "dmfc0\t%M0, " #source "\n\t" \
  1162. "dsll\t%L0, %M0, 32\n\t" \
  1163. "dsra\t%M0, %M0, 32\n\t" \
  1164. "dsra\t%L0, %L0, 32\n\t" \
  1165. ".set\tmips0" \
  1166. : "=r" (__val)); \
  1167. else \
  1168. __asm__ __volatile__( \
  1169. ".set\tmips64\n\t" \
  1170. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  1171. "dsll\t%L0, %M0, 32\n\t" \
  1172. "dsra\t%M0, %M0, 32\n\t" \
  1173. "dsra\t%L0, %L0, 32\n\t" \
  1174. ".set\tmips0" \
  1175. : "=r" (__val)); \
  1176. local_irq_restore(__flags); \
  1177. \
  1178. __val; \
  1179. })
  1180. #define __write_64bit_c0_split(source, sel, val) \
  1181. do { \
  1182. unsigned long __flags; \
  1183. \
  1184. local_irq_save(__flags); \
  1185. if (sel == 0) \
  1186. __asm__ __volatile__( \
  1187. ".set\tmips64\n\t" \
  1188. "dsll\t%L0, %L0, 32\n\t" \
  1189. "dsrl\t%L0, %L0, 32\n\t" \
  1190. "dsll\t%M0, %M0, 32\n\t" \
  1191. "or\t%L0, %L0, %M0\n\t" \
  1192. "dmtc0\t%L0, " #source "\n\t" \
  1193. ".set\tmips0" \
  1194. : : "r" (val)); \
  1195. else \
  1196. __asm__ __volatile__( \
  1197. ".set\tmips64\n\t" \
  1198. "dsll\t%L0, %L0, 32\n\t" \
  1199. "dsrl\t%L0, %L0, 32\n\t" \
  1200. "dsll\t%M0, %M0, 32\n\t" \
  1201. "or\t%L0, %L0, %M0\n\t" \
  1202. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  1203. ".set\tmips0" \
  1204. : : "r" (val)); \
  1205. local_irq_restore(__flags); \
  1206. } while (0)
  1207. #define __readx_32bit_c0_register(source) \
  1208. ({ \
  1209. unsigned int __res; \
  1210. \
  1211. __asm__ __volatile__( \
  1212. " .set push \n" \
  1213. " .set noat \n" \
  1214. " .set mips32r2 \n" \
  1215. " # mfhc0 $1, %1 \n" \
  1216. _ASM_INSN_IF_MIPS(0x40410000 | ((%1 & 0x1f) << 11)) \
  1217. _ASM_INSN32_IF_MM(0x002000f4 | ((%1 & 0x1f) << 16)) \
  1218. " move %0, $1 \n" \
  1219. " .set pop \n" \
  1220. : "=r" (__res) \
  1221. : "i" (source)); \
  1222. __res; \
  1223. })
  1224. #define __writex_32bit_c0_register(register, value) \
  1225. do { \
  1226. __asm__ __volatile__( \
  1227. " .set push \n" \
  1228. " .set noat \n" \
  1229. " .set mips32r2 \n" \
  1230. " move $1, %0 \n" \
  1231. " # mthc0 $1, %1 \n" \
  1232. _ASM_INSN_IF_MIPS(0x40c10000 | ((%1 & 0x1f) << 11)) \
  1233. _ASM_INSN32_IF_MM(0x002002f4 | ((%1 & 0x1f) << 16)) \
  1234. " .set pop \n" \
  1235. : \
  1236. : "r" (value), "i" (register)); \
  1237. } while (0)
  1238. #define read_c0_index() __read_32bit_c0_register($0, 0)
  1239. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  1240. #define read_c0_random() __read_32bit_c0_register($1, 0)
  1241. #define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
  1242. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  1243. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  1244. #define readx_c0_entrylo0() __readx_32bit_c0_register(2)
  1245. #define writex_c0_entrylo0(val) __writex_32bit_c0_register(2, val)
  1246. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  1247. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  1248. #define readx_c0_entrylo1() __readx_32bit_c0_register(3)
  1249. #define writex_c0_entrylo1(val) __writex_32bit_c0_register(3, val)
  1250. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  1251. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  1252. #define read_c0_context() __read_ulong_c0_register($4, 0)
  1253. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  1254. #define read_c0_contextconfig() __read_32bit_c0_register($4, 1)
  1255. #define write_c0_contextconfig(val) __write_32bit_c0_register($4, 1, val)
  1256. #define read_c0_userlocal() __read_ulong_c0_register($4, 2)
  1257. #define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
  1258. #define read_c0_xcontextconfig() __read_ulong_c0_register($4, 3)
  1259. #define write_c0_xcontextconfig(val) __write_ulong_c0_register($4, 3, val)
  1260. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  1261. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  1262. #define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
  1263. #define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
  1264. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  1265. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  1266. #define read_c0_info() __read_32bit_c0_register($7, 0)
  1267. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  1268. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  1269. #define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
  1270. #define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
  1271. #define read_c0_badinstr() __read_32bit_c0_register($8, 1)
  1272. #define read_c0_badinstrp() __read_32bit_c0_register($8, 2)
  1273. #define read_c0_count() __read_32bit_c0_register($9, 0)
  1274. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  1275. #define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
  1276. #define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
  1277. #define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
  1278. #define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
  1279. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  1280. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  1281. #define read_c0_guestctl1() __read_32bit_c0_register($10, 4)
  1282. #define write_c0_guestctl1(val) __write_32bit_c0_register($10, 4, val)
  1283. #define read_c0_guestctl2() __read_32bit_c0_register($10, 5)
  1284. #define write_c0_guestctl2(val) __write_32bit_c0_register($10, 5, val)
  1285. #define read_c0_guestctl3() __read_32bit_c0_register($10, 6)
  1286. #define write_c0_guestctl3(val) __write_32bit_c0_register($10, 6, val)
  1287. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  1288. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  1289. #define read_c0_guestctl0ext() __read_32bit_c0_register($11, 4)
  1290. #define write_c0_guestctl0ext(val) __write_32bit_c0_register($11, 4, val)
  1291. #define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
  1292. #define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
  1293. #define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
  1294. #define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
  1295. #define read_c0_status() __read_32bit_c0_register($12, 0)
  1296. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  1297. #define read_c0_guestctl0() __read_32bit_c0_register($12, 6)
  1298. #define write_c0_guestctl0(val) __write_32bit_c0_register($12, 6, val)
  1299. #define read_c0_gtoffset() __read_32bit_c0_register($12, 7)
  1300. #define write_c0_gtoffset(val) __write_32bit_c0_register($12, 7, val)
  1301. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  1302. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  1303. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  1304. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  1305. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  1306. #define read_c0_cmgcrbase() __read_ulong_c0_register($15, 3)
  1307. #define read_c0_config() __read_32bit_c0_register($16, 0)
  1308. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  1309. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  1310. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  1311. #define read_c0_config4() __read_32bit_c0_register($16, 4)
  1312. #define read_c0_config5() __read_32bit_c0_register($16, 5)
  1313. #define read_c0_config6() __read_32bit_c0_register($16, 6)
  1314. #define read_c0_config7() __read_32bit_c0_register($16, 7)
  1315. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  1316. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  1317. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  1318. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  1319. #define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
  1320. #define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
  1321. #define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
  1322. #define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
  1323. #define read_c0_lladdr() __read_ulong_c0_register($17, 0)
  1324. #define write_c0_lladdr(val) __write_ulong_c0_register($17, 0, val)
  1325. #define read_c0_maar() __read_ulong_c0_register($17, 1)
  1326. #define write_c0_maar(val) __write_ulong_c0_register($17, 1, val)
  1327. #define read_c0_maari() __read_32bit_c0_register($17, 2)
  1328. #define write_c0_maari(val) __write_32bit_c0_register($17, 2, val)
  1329. /*
  1330. * The WatchLo register. There may be up to 8 of them.
  1331. */
  1332. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  1333. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  1334. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  1335. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  1336. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  1337. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  1338. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  1339. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  1340. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  1341. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  1342. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  1343. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  1344. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  1345. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  1346. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  1347. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  1348. /*
  1349. * The WatchHi register. There may be up to 8 of them.
  1350. */
  1351. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  1352. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  1353. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  1354. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  1355. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  1356. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  1357. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  1358. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  1359. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  1360. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  1361. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  1362. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  1363. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  1364. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  1365. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  1366. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  1367. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  1368. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  1369. #define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
  1370. #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
  1371. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  1372. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  1373. #define read_c0_diag() __read_32bit_c0_register($22, 0)
  1374. #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
  1375. /* R10K CP0 Branch Diagnostic register is 64bits wide */
  1376. #define read_c0_r10k_diag() __read_64bit_c0_register($22, 0)
  1377. #define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val)
  1378. #define read_c0_diag1() __read_32bit_c0_register($22, 1)
  1379. #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
  1380. #define read_c0_diag2() __read_32bit_c0_register($22, 2)
  1381. #define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
  1382. #define read_c0_diag3() __read_32bit_c0_register($22, 3)
  1383. #define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
  1384. #define read_c0_diag4() __read_32bit_c0_register($22, 4)
  1385. #define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
  1386. #define read_c0_diag5() __read_32bit_c0_register($22, 5)
  1387. #define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
  1388. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  1389. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  1390. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  1391. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  1392. /*
  1393. * MIPS32 / MIPS64 performance counters
  1394. */
  1395. #define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
  1396. #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
  1397. #define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
  1398. #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
  1399. #define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
  1400. #define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
  1401. #define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
  1402. #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
  1403. #define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
  1404. #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
  1405. #define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
  1406. #define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
  1407. #define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
  1408. #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
  1409. #define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
  1410. #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
  1411. #define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
  1412. #define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
  1413. #define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
  1414. #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
  1415. #define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
  1416. #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
  1417. #define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
  1418. #define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
  1419. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  1420. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  1421. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  1422. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  1423. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  1424. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  1425. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  1426. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  1427. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  1428. #define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
  1429. #define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
  1430. #define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
  1431. #define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
  1432. #define read_c0_staglo() __read_32bit_c0_register($28, 4)
  1433. #define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
  1434. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  1435. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  1436. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  1437. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  1438. /* MIPSR2 */
  1439. #define read_c0_hwrena() __read_32bit_c0_register($7, 0)
  1440. #define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
  1441. #define read_c0_intctl() __read_32bit_c0_register($12, 1)
  1442. #define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
  1443. #define read_c0_srsctl() __read_32bit_c0_register($12, 2)
  1444. #define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
  1445. #define read_c0_srsmap() __read_32bit_c0_register($12, 3)
  1446. #define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
  1447. #define read_c0_ebase() __read_32bit_c0_register($15, 1)
  1448. #define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
  1449. #define read_c0_ebase_64() __read_64bit_c0_register($15, 1)
  1450. #define write_c0_ebase_64(val) __write_64bit_c0_register($15, 1, val)
  1451. #define read_c0_cdmmbase() __read_ulong_c0_register($15, 2)
  1452. #define write_c0_cdmmbase(val) __write_ulong_c0_register($15, 2, val)
  1453. /* MIPSR3 */
  1454. #define read_c0_segctl0() __read_32bit_c0_register($5, 2)
  1455. #define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
  1456. #define read_c0_segctl1() __read_32bit_c0_register($5, 3)
  1457. #define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
  1458. #define read_c0_segctl2() __read_32bit_c0_register($5, 4)
  1459. #define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
  1460. /* Hardware Page Table Walker */
  1461. #define read_c0_pwbase() __read_ulong_c0_register($5, 5)
  1462. #define write_c0_pwbase(val) __write_ulong_c0_register($5, 5, val)
  1463. #define read_c0_pwfield() __read_ulong_c0_register($5, 6)
  1464. #define write_c0_pwfield(val) __write_ulong_c0_register($5, 6, val)
  1465. #define read_c0_pwsize() __read_ulong_c0_register($5, 7)
  1466. #define write_c0_pwsize(val) __write_ulong_c0_register($5, 7, val)
  1467. #define read_c0_pwctl() __read_32bit_c0_register($6, 6)
  1468. #define write_c0_pwctl(val) __write_32bit_c0_register($6, 6, val)
  1469. #define read_c0_pgd() __read_64bit_c0_register($9, 7)
  1470. #define write_c0_pgd(val) __write_64bit_c0_register($9, 7, val)
  1471. #define read_c0_kpgd() __read_64bit_c0_register($31, 7)
  1472. #define write_c0_kpgd(val) __write_64bit_c0_register($31, 7, val)
  1473. /* Cavium OCTEON (cnMIPS) */
  1474. #define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
  1475. #define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
  1476. #define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
  1477. #define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
  1478. #define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
  1479. #define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
  1480. /*
  1481. * The cacheerr registers are not standardized. On OCTEON, they are
  1482. * 64 bits wide.
  1483. */
  1484. #define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
  1485. #define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
  1486. #define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
  1487. #define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
  1488. /* BMIPS3300 */
  1489. #define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
  1490. #define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
  1491. #define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
  1492. #define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
  1493. #define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
  1494. #define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
  1495. /* BMIPS43xx */
  1496. #define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
  1497. #define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
  1498. #define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
  1499. #define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
  1500. #define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
  1501. #define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
  1502. #define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
  1503. #define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
  1504. #define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
  1505. #define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
  1506. /* BMIPS5000 */
  1507. #define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
  1508. #define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
  1509. #define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
  1510. #define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
  1511. #define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
  1512. #define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
  1513. #define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
  1514. #define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
  1515. #define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
  1516. #define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
  1517. #define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
  1518. #define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
  1519. /*
  1520. * Macros to access the guest system control coprocessor
  1521. */
  1522. #ifdef TOOLCHAIN_SUPPORTS_VIRT
  1523. #define __read_32bit_gc0_register(source, sel) \
  1524. ({ int __res; \
  1525. __asm__ __volatile__( \
  1526. ".set\tpush\n\t" \
  1527. ".set\tmips32r2\n\t" \
  1528. ".set\tvirt\n\t" \
  1529. "mfgc0\t%0, $%1, %2\n\t" \
  1530. ".set\tpop" \
  1531. : "=r" (__res) \
  1532. : "i" (source), "i" (sel)); \
  1533. __res; \
  1534. })
  1535. #define __read_64bit_gc0_register(source, sel) \
  1536. ({ unsigned long long __res; \
  1537. __asm__ __volatile__( \
  1538. ".set\tpush\n\t" \
  1539. ".set\tmips64r2\n\t" \
  1540. ".set\tvirt\n\t" \
  1541. "dmfgc0\t%0, $%1, %2\n\t" \
  1542. ".set\tpop" \
  1543. : "=r" (__res) \
  1544. : "i" (source), "i" (sel)); \
  1545. __res; \
  1546. })
  1547. #define __write_32bit_gc0_register(register, sel, value) \
  1548. do { \
  1549. __asm__ __volatile__( \
  1550. ".set\tpush\n\t" \
  1551. ".set\tmips32r2\n\t" \
  1552. ".set\tvirt\n\t" \
  1553. "mtgc0\t%z0, $%1, %2\n\t" \
  1554. ".set\tpop" \
  1555. : : "Jr" ((unsigned int)(value)), \
  1556. "i" (register), "i" (sel)); \
  1557. } while (0)
  1558. #define __write_64bit_gc0_register(register, sel, value) \
  1559. do { \
  1560. __asm__ __volatile__( \
  1561. ".set\tpush\n\t" \
  1562. ".set\tmips64r2\n\t" \
  1563. ".set\tvirt\n\t" \
  1564. "dmtgc0\t%z0, $%1, %2\n\t" \
  1565. ".set\tpop" \
  1566. : : "Jr" (value), \
  1567. "i" (register), "i" (sel)); \
  1568. } while (0)
  1569. #else /* TOOLCHAIN_SUPPORTS_VIRT */
  1570. #define __read_32bit_gc0_register(source, sel) \
  1571. ({ int __res; \
  1572. __asm__ __volatile__( \
  1573. ".set\tpush\n\t" \
  1574. ".set\tnoat\n\t" \
  1575. "# mfgc0\t$1, $%1, %2\n\t" \
  1576. _ASM_INSN_IF_MIPS(0x40610000 | %1 << 11 | %2) \
  1577. _ASM_INSN32_IF_MM(0x002004fc | %1 << 16 | %2 << 11) \
  1578. "move\t%0, $1\n\t" \
  1579. ".set\tpop" \
  1580. : "=r" (__res) \
  1581. : "i" (source), "i" (sel)); \
  1582. __res; \
  1583. })
  1584. #define __read_64bit_gc0_register(source, sel) \
  1585. ({ unsigned long long __res; \
  1586. __asm__ __volatile__( \
  1587. ".set\tpush\n\t" \
  1588. ".set\tnoat\n\t" \
  1589. "# dmfgc0\t$1, $%1, %2\n\t" \
  1590. _ASM_INSN_IF_MIPS(0x40610100 | %1 << 11 | %2) \
  1591. _ASM_INSN32_IF_MM(0x582004fc | %1 << 16 | %2 << 11) \
  1592. "move\t%0, $1\n\t" \
  1593. ".set\tpop" \
  1594. : "=r" (__res) \
  1595. : "i" (source), "i" (sel)); \
  1596. __res; \
  1597. })
  1598. #define __write_32bit_gc0_register(register, sel, value) \
  1599. do { \
  1600. __asm__ __volatile__( \
  1601. ".set\tpush\n\t" \
  1602. ".set\tnoat\n\t" \
  1603. "move\t$1, %z0\n\t" \
  1604. "# mtgc0\t$1, $%1, %2\n\t" \
  1605. _ASM_INSN_IF_MIPS(0x40610200 | %1 << 11 | %2) \
  1606. _ASM_INSN32_IF_MM(0x002006fc | %1 << 16 | %2 << 11) \
  1607. ".set\tpop" \
  1608. : : "Jr" ((unsigned int)(value)), \
  1609. "i" (register), "i" (sel)); \
  1610. } while (0)
  1611. #define __write_64bit_gc0_register(register, sel, value) \
  1612. do { \
  1613. __asm__ __volatile__( \
  1614. ".set\tpush\n\t" \
  1615. ".set\tnoat\n\t" \
  1616. "move\t$1, %z0\n\t" \
  1617. "# dmtgc0\t$1, $%1, %2\n\t" \
  1618. _ASM_INSN_IF_MIPS(0x40610300 | %1 << 11 | %2) \
  1619. _ASM_INSN32_IF_MM(0x582006fc | %1 << 16 | %2 << 11) \
  1620. ".set\tpop" \
  1621. : : "Jr" (value), \
  1622. "i" (register), "i" (sel)); \
  1623. } while (0)
  1624. #endif /* !TOOLCHAIN_SUPPORTS_VIRT */
  1625. #define __read_ulong_gc0_register(reg, sel) \
  1626. ((sizeof(unsigned long) == 4) ? \
  1627. (unsigned long) __read_32bit_gc0_register(reg, sel) : \
  1628. (unsigned long) __read_64bit_gc0_register(reg, sel))
  1629. #define __write_ulong_gc0_register(reg, sel, val) \
  1630. do { \
  1631. if (sizeof(unsigned long) == 4) \
  1632. __write_32bit_gc0_register(reg, sel, val); \
  1633. else \
  1634. __write_64bit_gc0_register(reg, sel, val); \
  1635. } while (0)
  1636. #define read_gc0_index() __read_32bit_gc0_register(0, 0)
  1637. #define write_gc0_index(val) __write_32bit_gc0_register(0, 0, val)
  1638. #define read_gc0_entrylo0() __read_ulong_gc0_register(2, 0)
  1639. #define write_gc0_entrylo0(val) __write_ulong_gc0_register(2, 0, val)
  1640. #define read_gc0_entrylo1() __read_ulong_gc0_register(3, 0)
  1641. #define write_gc0_entrylo1(val) __write_ulong_gc0_register(3, 0, val)
  1642. #define read_gc0_context() __read_ulong_gc0_register(4, 0)
  1643. #define write_gc0_context(val) __write_ulong_gc0_register(4, 0, val)
  1644. #define read_gc0_contextconfig() __read_32bit_gc0_register(4, 1)
  1645. #define write_gc0_contextconfig(val) __write_32bit_gc0_register(4, 1, val)
  1646. #define read_gc0_userlocal() __read_ulong_gc0_register(4, 2)
  1647. #define write_gc0_userlocal(val) __write_ulong_gc0_register(4, 2, val)
  1648. #define read_gc0_xcontextconfig() __read_ulong_gc0_register(4, 3)
  1649. #define write_gc0_xcontextconfig(val) __write_ulong_gc0_register(4, 3, val)
  1650. #define read_gc0_pagemask() __read_32bit_gc0_register(5, 0)
  1651. #define write_gc0_pagemask(val) __write_32bit_gc0_register(5, 0, val)
  1652. #define read_gc0_pagegrain() __read_32bit_gc0_register(5, 1)
  1653. #define write_gc0_pagegrain(val) __write_32bit_gc0_register(5, 1, val)
  1654. #define read_gc0_segctl0() __read_ulong_gc0_register(5, 2)
  1655. #define write_gc0_segctl0(val) __write_ulong_gc0_register(5, 2, val)
  1656. #define read_gc0_segctl1() __read_ulong_gc0_register(5, 3)
  1657. #define write_gc0_segctl1(val) __write_ulong_gc0_register(5, 3, val)
  1658. #define read_gc0_segctl2() __read_ulong_gc0_register(5, 4)
  1659. #define write_gc0_segctl2(val) __write_ulong_gc0_register(5, 4, val)
  1660. #define read_gc0_pwbase() __read_ulong_gc0_register(5, 5)
  1661. #define write_gc0_pwbase(val) __write_ulong_gc0_register(5, 5, val)
  1662. #define read_gc0_pwfield() __read_ulong_gc0_register(5, 6)
  1663. #define write_gc0_pwfield(val) __write_ulong_gc0_register(5, 6, val)
  1664. #define read_gc0_pwsize() __read_ulong_gc0_register(5, 7)
  1665. #define write_gc0_pwsize(val) __write_ulong_gc0_register(5, 7, val)
  1666. #define read_gc0_wired() __read_32bit_gc0_register(6, 0)
  1667. #define write_gc0_wired(val) __write_32bit_gc0_register(6, 0, val)
  1668. #define read_gc0_pwctl() __read_32bit_gc0_register(6, 6)
  1669. #define write_gc0_pwctl(val) __write_32bit_gc0_register(6, 6, val)
  1670. #define read_gc0_hwrena() __read_32bit_gc0_register(7, 0)
  1671. #define write_gc0_hwrena(val) __write_32bit_gc0_register(7, 0, val)
  1672. #define read_gc0_badvaddr() __read_ulong_gc0_register(8, 0)
  1673. #define write_gc0_badvaddr(val) __write_ulong_gc0_register(8, 0, val)
  1674. #define read_gc0_badinstr() __read_32bit_gc0_register(8, 1)
  1675. #define write_gc0_badinstr(val) __write_32bit_gc0_register(8, 1, val)
  1676. #define read_gc0_badinstrp() __read_32bit_gc0_register(8, 2)
  1677. #define write_gc0_badinstrp(val) __write_32bit_gc0_register(8, 2, val)
  1678. #define read_gc0_count() __read_32bit_gc0_register(9, 0)
  1679. #define read_gc0_entryhi() __read_ulong_gc0_register(10, 0)
  1680. #define write_gc0_entryhi(val) __write_ulong_gc0_register(10, 0, val)
  1681. #define read_gc0_compare() __read_32bit_gc0_register(11, 0)
  1682. #define write_gc0_compare(val) __write_32bit_gc0_register(11, 0, val)
  1683. #define read_gc0_status() __read_32bit_gc0_register(12, 0)
  1684. #define write_gc0_status(val) __write_32bit_gc0_register(12, 0, val)
  1685. #define read_gc0_intctl() __read_32bit_gc0_register(12, 1)
  1686. #define write_gc0_intctl(val) __write_32bit_gc0_register(12, 1, val)
  1687. #define read_gc0_cause() __read_32bit_gc0_register(13, 0)
  1688. #define write_gc0_cause(val) __write_32bit_gc0_register(13, 0, val)
  1689. #define read_gc0_epc() __read_ulong_gc0_register(14, 0)
  1690. #define write_gc0_epc(val) __write_ulong_gc0_register(14, 0, val)
  1691. #define read_gc0_ebase() __read_32bit_gc0_register(15, 1)
  1692. #define write_gc0_ebase(val) __write_32bit_gc0_register(15, 1, val)
  1693. #define read_gc0_ebase_64() __read_64bit_gc0_register(15, 1)
  1694. #define write_gc0_ebase_64(val) __write_64bit_gc0_register(15, 1, val)
  1695. #define read_gc0_config() __read_32bit_gc0_register(16, 0)
  1696. #define read_gc0_config1() __read_32bit_gc0_register(16, 1)
  1697. #define read_gc0_config2() __read_32bit_gc0_register(16, 2)
  1698. #define read_gc0_config3() __read_32bit_gc0_register(16, 3)
  1699. #define read_gc0_config4() __read_32bit_gc0_register(16, 4)
  1700. #define read_gc0_config5() __read_32bit_gc0_register(16, 5)
  1701. #define read_gc0_config6() __read_32bit_gc0_register(16, 6)
  1702. #define read_gc0_config7() __read_32bit_gc0_register(16, 7)
  1703. #define write_gc0_config(val) __write_32bit_gc0_register(16, 0, val)
  1704. #define write_gc0_config1(val) __write_32bit_gc0_register(16, 1, val)
  1705. #define write_gc0_config2(val) __write_32bit_gc0_register(16, 2, val)
  1706. #define write_gc0_config3(val) __write_32bit_gc0_register(16, 3, val)
  1707. #define write_gc0_config4(val) __write_32bit_gc0_register(16, 4, val)
  1708. #define write_gc0_config5(val) __write_32bit_gc0_register(16, 5, val)
  1709. #define write_gc0_config6(val) __write_32bit_gc0_register(16, 6, val)
  1710. #define write_gc0_config7(val) __write_32bit_gc0_register(16, 7, val)
  1711. #define read_gc0_watchlo0() __read_ulong_gc0_register(18, 0)
  1712. #define read_gc0_watchlo1() __read_ulong_gc0_register(18, 1)
  1713. #define read_gc0_watchlo2() __read_ulong_gc0_register(18, 2)
  1714. #define read_gc0_watchlo3() __read_ulong_gc0_register(18, 3)
  1715. #define read_gc0_watchlo4() __read_ulong_gc0_register(18, 4)
  1716. #define read_gc0_watchlo5() __read_ulong_gc0_register(18, 5)
  1717. #define read_gc0_watchlo6() __read_ulong_gc0_register(18, 6)
  1718. #define read_gc0_watchlo7() __read_ulong_gc0_register(18, 7)
  1719. #define write_gc0_watchlo0(val) __write_ulong_gc0_register(18, 0, val)
  1720. #define write_gc0_watchlo1(val) __write_ulong_gc0_register(18, 1, val)
  1721. #define write_gc0_watchlo2(val) __write_ulong_gc0_register(18, 2, val)
  1722. #define write_gc0_watchlo3(val) __write_ulong_gc0_register(18, 3, val)
  1723. #define write_gc0_watchlo4(val) __write_ulong_gc0_register(18, 4, val)
  1724. #define write_gc0_watchlo5(val) __write_ulong_gc0_register(18, 5, val)
  1725. #define write_gc0_watchlo6(val) __write_ulong_gc0_register(18, 6, val)
  1726. #define write_gc0_watchlo7(val) __write_ulong_gc0_register(18, 7, val)
  1727. #define read_gc0_watchhi0() __read_32bit_gc0_register(19, 0)
  1728. #define read_gc0_watchhi1() __read_32bit_gc0_register(19, 1)
  1729. #define read_gc0_watchhi2() __read_32bit_gc0_register(19, 2)
  1730. #define read_gc0_watchhi3() __read_32bit_gc0_register(19, 3)
  1731. #define read_gc0_watchhi4() __read_32bit_gc0_register(19, 4)
  1732. #define read_gc0_watchhi5() __read_32bit_gc0_register(19, 5)
  1733. #define read_gc0_watchhi6() __read_32bit_gc0_register(19, 6)
  1734. #define read_gc0_watchhi7() __read_32bit_gc0_register(19, 7)
  1735. #define write_gc0_watchhi0(val) __write_32bit_gc0_register(19, 0, val)
  1736. #define write_gc0_watchhi1(val) __write_32bit_gc0_register(19, 1, val)
  1737. #define write_gc0_watchhi2(val) __write_32bit_gc0_register(19, 2, val)
  1738. #define write_gc0_watchhi3(val) __write_32bit_gc0_register(19, 3, val)
  1739. #define write_gc0_watchhi4(val) __write_32bit_gc0_register(19, 4, val)
  1740. #define write_gc0_watchhi5(val) __write_32bit_gc0_register(19, 5, val)
  1741. #define write_gc0_watchhi6(val) __write_32bit_gc0_register(19, 6, val)
  1742. #define write_gc0_watchhi7(val) __write_32bit_gc0_register(19, 7, val)
  1743. #define read_gc0_xcontext() __read_ulong_gc0_register(20, 0)
  1744. #define write_gc0_xcontext(val) __write_ulong_gc0_register(20, 0, val)
  1745. #define read_gc0_perfctrl0() __read_32bit_gc0_register(25, 0)
  1746. #define write_gc0_perfctrl0(val) __write_32bit_gc0_register(25, 0, val)
  1747. #define read_gc0_perfcntr0() __read_32bit_gc0_register(25, 1)
  1748. #define write_gc0_perfcntr0(val) __write_32bit_gc0_register(25, 1, val)
  1749. #define read_gc0_perfcntr0_64() __read_64bit_gc0_register(25, 1)
  1750. #define write_gc0_perfcntr0_64(val) __write_64bit_gc0_register(25, 1, val)
  1751. #define read_gc0_perfctrl1() __read_32bit_gc0_register(25, 2)
  1752. #define write_gc0_perfctrl1(val) __write_32bit_gc0_register(25, 2, val)
  1753. #define read_gc0_perfcntr1() __read_32bit_gc0_register(25, 3)
  1754. #define write_gc0_perfcntr1(val) __write_32bit_gc0_register(25, 3, val)
  1755. #define read_gc0_perfcntr1_64() __read_64bit_gc0_register(25, 3)
  1756. #define write_gc0_perfcntr1_64(val) __write_64bit_gc0_register(25, 3, val)
  1757. #define read_gc0_perfctrl2() __read_32bit_gc0_register(25, 4)
  1758. #define write_gc0_perfctrl2(val) __write_32bit_gc0_register(25, 4, val)
  1759. #define read_gc0_perfcntr2() __read_32bit_gc0_register(25, 5)
  1760. #define write_gc0_perfcntr2(val) __write_32bit_gc0_register(25, 5, val)
  1761. #define read_gc0_perfcntr2_64() __read_64bit_gc0_register(25, 5)
  1762. #define write_gc0_perfcntr2_64(val) __write_64bit_gc0_register(25, 5, val)
  1763. #define read_gc0_perfctrl3() __read_32bit_gc0_register(25, 6)
  1764. #define write_gc0_perfctrl3(val) __write_32bit_gc0_register(25, 6, val)
  1765. #define read_gc0_perfcntr3() __read_32bit_gc0_register(25, 7)
  1766. #define write_gc0_perfcntr3(val) __write_32bit_gc0_register(25, 7, val)
  1767. #define read_gc0_perfcntr3_64() __read_64bit_gc0_register(25, 7)
  1768. #define write_gc0_perfcntr3_64(val) __write_64bit_gc0_register(25, 7, val)
  1769. #define read_gc0_errorepc() __read_ulong_gc0_register(30, 0)
  1770. #define write_gc0_errorepc(val) __write_ulong_gc0_register(30, 0, val)
  1771. #define read_gc0_kscratch1() __read_ulong_gc0_register(31, 2)
  1772. #define read_gc0_kscratch2() __read_ulong_gc0_register(31, 3)
  1773. #define read_gc0_kscratch3() __read_ulong_gc0_register(31, 4)
  1774. #define read_gc0_kscratch4() __read_ulong_gc0_register(31, 5)
  1775. #define read_gc0_kscratch5() __read_ulong_gc0_register(31, 6)
  1776. #define read_gc0_kscratch6() __read_ulong_gc0_register(31, 7)
  1777. #define write_gc0_kscratch1(val) __write_ulong_gc0_register(31, 2, val)
  1778. #define write_gc0_kscratch2(val) __write_ulong_gc0_register(31, 3, val)
  1779. #define write_gc0_kscratch3(val) __write_ulong_gc0_register(31, 4, val)
  1780. #define write_gc0_kscratch4(val) __write_ulong_gc0_register(31, 5, val)
  1781. #define write_gc0_kscratch5(val) __write_ulong_gc0_register(31, 6, val)
  1782. #define write_gc0_kscratch6(val) __write_ulong_gc0_register(31, 7, val)
  1783. /*
  1784. * Macros to access the floating point coprocessor control registers
  1785. */
  1786. #define _read_32bit_cp1_register(source, gas_hardfloat) \
  1787. ({ \
  1788. unsigned int __res; \
  1789. \
  1790. __asm__ __volatile__( \
  1791. " .set push \n" \
  1792. " .set reorder \n" \
  1793. " # gas fails to assemble cfc1 for some archs, \n" \
  1794. " # like Octeon. \n" \
  1795. " .set mips1 \n" \
  1796. " "STR(gas_hardfloat)" \n" \
  1797. " cfc1 %0,"STR(source)" \n" \
  1798. " .set pop \n" \
  1799. : "=r" (__res)); \
  1800. __res; \
  1801. })
  1802. #define _write_32bit_cp1_register(dest, val, gas_hardfloat) \
  1803. do { \
  1804. __asm__ __volatile__( \
  1805. " .set push \n" \
  1806. " .set reorder \n" \
  1807. " "STR(gas_hardfloat)" \n" \
  1808. " ctc1 %0,"STR(dest)" \n" \
  1809. " .set pop \n" \
  1810. : : "r" (val)); \
  1811. } while (0)
  1812. #ifdef GAS_HAS_SET_HARDFLOAT
  1813. #define read_32bit_cp1_register(source) \
  1814. _read_32bit_cp1_register(source, .set hardfloat)
  1815. #define write_32bit_cp1_register(dest, val) \
  1816. _write_32bit_cp1_register(dest, val, .set hardfloat)
  1817. #else
  1818. #define read_32bit_cp1_register(source) \
  1819. _read_32bit_cp1_register(source, )
  1820. #define write_32bit_cp1_register(dest, val) \
  1821. _write_32bit_cp1_register(dest, val, )
  1822. #endif
  1823. #ifdef HAVE_AS_DSP
  1824. #define rddsp(mask) \
  1825. ({ \
  1826. unsigned int __dspctl; \
  1827. \
  1828. __asm__ __volatile__( \
  1829. " .set push \n" \
  1830. " .set dsp \n" \
  1831. " rddsp %0, %x1 \n" \
  1832. " .set pop \n" \
  1833. : "=r" (__dspctl) \
  1834. : "i" (mask)); \
  1835. __dspctl; \
  1836. })
  1837. #define wrdsp(val, mask) \
  1838. do { \
  1839. __asm__ __volatile__( \
  1840. " .set push \n" \
  1841. " .set dsp \n" \
  1842. " wrdsp %0, %x1 \n" \
  1843. " .set pop \n" \
  1844. : \
  1845. : "r" (val), "i" (mask)); \
  1846. } while (0)
  1847. #define mflo0() \
  1848. ({ \
  1849. long mflo0; \
  1850. __asm__( \
  1851. " .set push \n" \
  1852. " .set dsp \n" \
  1853. " mflo %0, $ac0 \n" \
  1854. " .set pop \n" \
  1855. : "=r" (mflo0)); \
  1856. mflo0; \
  1857. })
  1858. #define mflo1() \
  1859. ({ \
  1860. long mflo1; \
  1861. __asm__( \
  1862. " .set push \n" \
  1863. " .set dsp \n" \
  1864. " mflo %0, $ac1 \n" \
  1865. " .set pop \n" \
  1866. : "=r" (mflo1)); \
  1867. mflo1; \
  1868. })
  1869. #define mflo2() \
  1870. ({ \
  1871. long mflo2; \
  1872. __asm__( \
  1873. " .set push \n" \
  1874. " .set dsp \n" \
  1875. " mflo %0, $ac2 \n" \
  1876. " .set pop \n" \
  1877. : "=r" (mflo2)); \
  1878. mflo2; \
  1879. })
  1880. #define mflo3() \
  1881. ({ \
  1882. long mflo3; \
  1883. __asm__( \
  1884. " .set push \n" \
  1885. " .set dsp \n" \
  1886. " mflo %0, $ac3 \n" \
  1887. " .set pop \n" \
  1888. : "=r" (mflo3)); \
  1889. mflo3; \
  1890. })
  1891. #define mfhi0() \
  1892. ({ \
  1893. long mfhi0; \
  1894. __asm__( \
  1895. " .set push \n" \
  1896. " .set dsp \n" \
  1897. " mfhi %0, $ac0 \n" \
  1898. " .set pop \n" \
  1899. : "=r" (mfhi0)); \
  1900. mfhi0; \
  1901. })
  1902. #define mfhi1() \
  1903. ({ \
  1904. long mfhi1; \
  1905. __asm__( \
  1906. " .set push \n" \
  1907. " .set dsp \n" \
  1908. " mfhi %0, $ac1 \n" \
  1909. " .set pop \n" \
  1910. : "=r" (mfhi1)); \
  1911. mfhi1; \
  1912. })
  1913. #define mfhi2() \
  1914. ({ \
  1915. long mfhi2; \
  1916. __asm__( \
  1917. " .set push \n" \
  1918. " .set dsp \n" \
  1919. " mfhi %0, $ac2 \n" \
  1920. " .set pop \n" \
  1921. : "=r" (mfhi2)); \
  1922. mfhi2; \
  1923. })
  1924. #define mfhi3() \
  1925. ({ \
  1926. long mfhi3; \
  1927. __asm__( \
  1928. " .set push \n" \
  1929. " .set dsp \n" \
  1930. " mfhi %0, $ac3 \n" \
  1931. " .set pop \n" \
  1932. : "=r" (mfhi3)); \
  1933. mfhi3; \
  1934. })
  1935. #define mtlo0(x) \
  1936. ({ \
  1937. __asm__( \
  1938. " .set push \n" \
  1939. " .set dsp \n" \
  1940. " mtlo %0, $ac0 \n" \
  1941. " .set pop \n" \
  1942. : \
  1943. : "r" (x)); \
  1944. })
  1945. #define mtlo1(x) \
  1946. ({ \
  1947. __asm__( \
  1948. " .set push \n" \
  1949. " .set dsp \n" \
  1950. " mtlo %0, $ac1 \n" \
  1951. " .set pop \n" \
  1952. : \
  1953. : "r" (x)); \
  1954. })
  1955. #define mtlo2(x) \
  1956. ({ \
  1957. __asm__( \
  1958. " .set push \n" \
  1959. " .set dsp \n" \
  1960. " mtlo %0, $ac2 \n" \
  1961. " .set pop \n" \
  1962. : \
  1963. : "r" (x)); \
  1964. })
  1965. #define mtlo3(x) \
  1966. ({ \
  1967. __asm__( \
  1968. " .set push \n" \
  1969. " .set dsp \n" \
  1970. " mtlo %0, $ac3 \n" \
  1971. " .set pop \n" \
  1972. : \
  1973. : "r" (x)); \
  1974. })
  1975. #define mthi0(x) \
  1976. ({ \
  1977. __asm__( \
  1978. " .set push \n" \
  1979. " .set dsp \n" \
  1980. " mthi %0, $ac0 \n" \
  1981. " .set pop \n" \
  1982. : \
  1983. : "r" (x)); \
  1984. })
  1985. #define mthi1(x) \
  1986. ({ \
  1987. __asm__( \
  1988. " .set push \n" \
  1989. " .set dsp \n" \
  1990. " mthi %0, $ac1 \n" \
  1991. " .set pop \n" \
  1992. : \
  1993. : "r" (x)); \
  1994. })
  1995. #define mthi2(x) \
  1996. ({ \
  1997. __asm__( \
  1998. " .set push \n" \
  1999. " .set dsp \n" \
  2000. " mthi %0, $ac2 \n" \
  2001. " .set pop \n" \
  2002. : \
  2003. : "r" (x)); \
  2004. })
  2005. #define mthi3(x) \
  2006. ({ \
  2007. __asm__( \
  2008. " .set push \n" \
  2009. " .set dsp \n" \
  2010. " mthi %0, $ac3 \n" \
  2011. " .set pop \n" \
  2012. : \
  2013. : "r" (x)); \
  2014. })
  2015. #else
  2016. #define rddsp(mask) \
  2017. ({ \
  2018. unsigned int __res; \
  2019. \
  2020. __asm__ __volatile__( \
  2021. " .set push \n" \
  2022. " .set noat \n" \
  2023. " # rddsp $1, %x1 \n" \
  2024. _ASM_INSN_IF_MIPS(0x7c000cb8 | (%x1 << 16)) \
  2025. _ASM_INSN32_IF_MM(0x0020067c | (%x1 << 14)) \
  2026. " move %0, $1 \n" \
  2027. " .set pop \n" \
  2028. : "=r" (__res) \
  2029. : "i" (mask)); \
  2030. __res; \
  2031. })
  2032. #define wrdsp(val, mask) \
  2033. do { \
  2034. __asm__ __volatile__( \
  2035. " .set push \n" \
  2036. " .set noat \n" \
  2037. " move $1, %0 \n" \
  2038. " # wrdsp $1, %x1 \n" \
  2039. _ASM_INSN_IF_MIPS(0x7c2004f8 | (%x1 << 11)) \
  2040. _ASM_INSN32_IF_MM(0x0020167c | (%x1 << 14)) \
  2041. " .set pop \n" \
  2042. : \
  2043. : "r" (val), "i" (mask)); \
  2044. } while (0)
  2045. #define _dsp_mfxxx(ins) \
  2046. ({ \
  2047. unsigned long __treg; \
  2048. \
  2049. __asm__ __volatile__( \
  2050. " .set push \n" \
  2051. " .set noat \n" \
  2052. _ASM_INSN_IF_MIPS(0x00000810 | %X1) \
  2053. _ASM_INSN32_IF_MM(0x0001007c | %x1) \
  2054. " move %0, $1 \n" \
  2055. " .set pop \n" \
  2056. : "=r" (__treg) \
  2057. : "i" (ins)); \
  2058. __treg; \
  2059. })
  2060. #define _dsp_mtxxx(val, ins) \
  2061. do { \
  2062. __asm__ __volatile__( \
  2063. " .set push \n" \
  2064. " .set noat \n" \
  2065. " move $1, %0 \n" \
  2066. _ASM_INSN_IF_MIPS(0x00200011 | %X1) \
  2067. _ASM_INSN32_IF_MM(0x0001207c | %x1) \
  2068. " .set pop \n" \
  2069. : \
  2070. : "r" (val), "i" (ins)); \
  2071. } while (0)
  2072. #ifdef CONFIG_CPU_MICROMIPS
  2073. #define _dsp_mflo(reg) _dsp_mfxxx((reg << 14) | 0x1000)
  2074. #define _dsp_mfhi(reg) _dsp_mfxxx((reg << 14) | 0x0000)
  2075. #define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 14) | 0x1000))
  2076. #define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 14) | 0x0000))
  2077. #else /* !CONFIG_CPU_MICROMIPS */
  2078. #define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
  2079. #define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
  2080. #define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
  2081. #define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
  2082. #endif /* CONFIG_CPU_MICROMIPS */
  2083. #define mflo0() _dsp_mflo(0)
  2084. #define mflo1() _dsp_mflo(1)
  2085. #define mflo2() _dsp_mflo(2)
  2086. #define mflo3() _dsp_mflo(3)
  2087. #define mfhi0() _dsp_mfhi(0)
  2088. #define mfhi1() _dsp_mfhi(1)
  2089. #define mfhi2() _dsp_mfhi(2)
  2090. #define mfhi3() _dsp_mfhi(3)
  2091. #define mtlo0(x) _dsp_mtlo(x, 0)
  2092. #define mtlo1(x) _dsp_mtlo(x, 1)
  2093. #define mtlo2(x) _dsp_mtlo(x, 2)
  2094. #define mtlo3(x) _dsp_mtlo(x, 3)
  2095. #define mthi0(x) _dsp_mthi(x, 0)
  2096. #define mthi1(x) _dsp_mthi(x, 1)
  2097. #define mthi2(x) _dsp_mthi(x, 2)
  2098. #define mthi3(x) _dsp_mthi(x, 3)
  2099. #endif
  2100. /*
  2101. * TLB operations.
  2102. *
  2103. * It is responsibility of the caller to take care of any TLB hazards.
  2104. */
  2105. static inline void tlb_probe(void)
  2106. {
  2107. __asm__ __volatile__(
  2108. ".set noreorder\n\t"
  2109. "tlbp\n\t"
  2110. ".set reorder");
  2111. }
  2112. static inline void tlb_read(void)
  2113. {
  2114. #if MIPS34K_MISSED_ITLB_WAR
  2115. int res = 0;
  2116. __asm__ __volatile__(
  2117. " .set push \n"
  2118. " .set noreorder \n"
  2119. " .set noat \n"
  2120. " .set mips32r2 \n"
  2121. " .word 0x41610001 # dvpe $1 \n"
  2122. " move %0, $1 \n"
  2123. " ehb \n"
  2124. " .set pop \n"
  2125. : "=r" (res));
  2126. instruction_hazard();
  2127. #endif
  2128. __asm__ __volatile__(
  2129. ".set noreorder\n\t"
  2130. "tlbr\n\t"
  2131. ".set reorder");
  2132. #if MIPS34K_MISSED_ITLB_WAR
  2133. if ((res & _ULCAST_(1)))
  2134. __asm__ __volatile__(
  2135. " .set push \n"
  2136. " .set noreorder \n"
  2137. " .set noat \n"
  2138. " .set mips32r2 \n"
  2139. " .word 0x41600021 # evpe \n"
  2140. " ehb \n"
  2141. " .set pop \n");
  2142. #endif
  2143. }
  2144. static inline void tlb_write_indexed(void)
  2145. {
  2146. __asm__ __volatile__(
  2147. ".set noreorder\n\t"
  2148. "tlbwi\n\t"
  2149. ".set reorder");
  2150. }
  2151. static inline void tlb_write_random(void)
  2152. {
  2153. __asm__ __volatile__(
  2154. ".set noreorder\n\t"
  2155. "tlbwr\n\t"
  2156. ".set reorder");
  2157. }
  2158. #ifdef TOOLCHAIN_SUPPORTS_VIRT
  2159. /*
  2160. * Guest TLB operations.
  2161. *
  2162. * It is responsibility of the caller to take care of any TLB hazards.
  2163. */
  2164. static inline void guest_tlb_probe(void)
  2165. {
  2166. __asm__ __volatile__(
  2167. ".set push\n\t"
  2168. ".set noreorder\n\t"
  2169. ".set virt\n\t"
  2170. "tlbgp\n\t"
  2171. ".set pop");
  2172. }
  2173. static inline void guest_tlb_read(void)
  2174. {
  2175. __asm__ __volatile__(
  2176. ".set push\n\t"
  2177. ".set noreorder\n\t"
  2178. ".set virt\n\t"
  2179. "tlbgr\n\t"
  2180. ".set pop");
  2181. }
  2182. static inline void guest_tlb_write_indexed(void)
  2183. {
  2184. __asm__ __volatile__(
  2185. ".set push\n\t"
  2186. ".set noreorder\n\t"
  2187. ".set virt\n\t"
  2188. "tlbgwi\n\t"
  2189. ".set pop");
  2190. }
  2191. static inline void guest_tlb_write_random(void)
  2192. {
  2193. __asm__ __volatile__(
  2194. ".set push\n\t"
  2195. ".set noreorder\n\t"
  2196. ".set virt\n\t"
  2197. "tlbgwr\n\t"
  2198. ".set pop");
  2199. }
  2200. /*
  2201. * Guest TLB Invalidate Flush
  2202. */
  2203. static inline void guest_tlbinvf(void)
  2204. {
  2205. __asm__ __volatile__(
  2206. ".set push\n\t"
  2207. ".set noreorder\n\t"
  2208. ".set virt\n\t"
  2209. "tlbginvf\n\t"
  2210. ".set pop");
  2211. }
  2212. #else /* TOOLCHAIN_SUPPORTS_VIRT */
  2213. /*
  2214. * Guest TLB operations.
  2215. *
  2216. * It is responsibility of the caller to take care of any TLB hazards.
  2217. */
  2218. static inline void guest_tlb_probe(void)
  2219. {
  2220. __asm__ __volatile__(
  2221. "# tlbgp\n\t"
  2222. _ASM_INSN_IF_MIPS(0x42000010)
  2223. _ASM_INSN32_IF_MM(0x0000017c));
  2224. }
  2225. static inline void guest_tlb_read(void)
  2226. {
  2227. __asm__ __volatile__(
  2228. "# tlbgr\n\t"
  2229. _ASM_INSN_IF_MIPS(0x42000009)
  2230. _ASM_INSN32_IF_MM(0x0000117c));
  2231. }
  2232. static inline void guest_tlb_write_indexed(void)
  2233. {
  2234. __asm__ __volatile__(
  2235. "# tlbgwi\n\t"
  2236. _ASM_INSN_IF_MIPS(0x4200000a)
  2237. _ASM_INSN32_IF_MM(0x0000217c));
  2238. }
  2239. static inline void guest_tlb_write_random(void)
  2240. {
  2241. __asm__ __volatile__(
  2242. "# tlbgwr\n\t"
  2243. _ASM_INSN_IF_MIPS(0x4200000e)
  2244. _ASM_INSN32_IF_MM(0x0000317c));
  2245. }
  2246. /*
  2247. * Guest TLB Invalidate Flush
  2248. */
  2249. static inline void guest_tlbinvf(void)
  2250. {
  2251. __asm__ __volatile__(
  2252. "# tlbginvf\n\t"
  2253. _ASM_INSN_IF_MIPS(0x4200000c)
  2254. _ASM_INSN32_IF_MM(0x0000517c));
  2255. }
  2256. #endif /* !TOOLCHAIN_SUPPORTS_VIRT */
  2257. /*
  2258. * Manipulate bits in a register.
  2259. */
  2260. #define __BUILD_SET_COMMON(name) \
  2261. static inline unsigned int \
  2262. set_##name(unsigned int set) \
  2263. { \
  2264. unsigned int res, new; \
  2265. \
  2266. res = read_##name(); \
  2267. new = res | set; \
  2268. write_##name(new); \
  2269. \
  2270. return res; \
  2271. } \
  2272. \
  2273. static inline unsigned int \
  2274. clear_##name(unsigned int clear) \
  2275. { \
  2276. unsigned int res, new; \
  2277. \
  2278. res = read_##name(); \
  2279. new = res & ~clear; \
  2280. write_##name(new); \
  2281. \
  2282. return res; \
  2283. } \
  2284. \
  2285. static inline unsigned int \
  2286. change_##name(unsigned int change, unsigned int val) \
  2287. { \
  2288. unsigned int res, new; \
  2289. \
  2290. res = read_##name(); \
  2291. new = res & ~change; \
  2292. new |= (val & change); \
  2293. write_##name(new); \
  2294. \
  2295. return res; \
  2296. }
  2297. /*
  2298. * Manipulate bits in a c0 register.
  2299. */
  2300. #define __BUILD_SET_C0(name) __BUILD_SET_COMMON(c0_##name)
  2301. __BUILD_SET_C0(status)
  2302. __BUILD_SET_C0(cause)
  2303. __BUILD_SET_C0(config)
  2304. __BUILD_SET_C0(config5)
  2305. __BUILD_SET_C0(intcontrol)
  2306. __BUILD_SET_C0(intctl)
  2307. __BUILD_SET_C0(srsmap)
  2308. __BUILD_SET_C0(pagegrain)
  2309. __BUILD_SET_C0(guestctl0)
  2310. __BUILD_SET_C0(guestctl0ext)
  2311. __BUILD_SET_C0(guestctl1)
  2312. __BUILD_SET_C0(guestctl2)
  2313. __BUILD_SET_C0(guestctl3)
  2314. __BUILD_SET_C0(brcm_config_0)
  2315. __BUILD_SET_C0(brcm_bus_pll)
  2316. __BUILD_SET_C0(brcm_reset)
  2317. __BUILD_SET_C0(brcm_cmt_intr)
  2318. __BUILD_SET_C0(brcm_cmt_ctrl)
  2319. __BUILD_SET_C0(brcm_config)
  2320. __BUILD_SET_C0(brcm_mode)
  2321. /*
  2322. * Manipulate bits in a guest c0 register.
  2323. */
  2324. #define __BUILD_SET_GC0(name) __BUILD_SET_COMMON(gc0_##name)
  2325. __BUILD_SET_GC0(status)
  2326. __BUILD_SET_GC0(cause)
  2327. __BUILD_SET_GC0(ebase)
  2328. /*
  2329. * Return low 10 bits of ebase.
  2330. * Note that under KVM (MIPSVZ) this returns vcpu id.
  2331. */
  2332. static inline unsigned int get_ebase_cpunum(void)
  2333. {
  2334. return read_c0_ebase() & MIPS_EBASE_CPUNUM;
  2335. }
  2336. #endif /* !__ASSEMBLY__ */
  2337. #endif /* _ASM_MIPSREGS_H */