mipsregs.h 96 KB

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