mips_regs.h 39 KB

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