mips_regs.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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. * 2016-9-7 Urey the first version
  9. */
  10. #ifndef _MIPS_REGS_H_
  11. #define _MIPS_REGS_H_
  12. #if !defined(__ASSEMBLY__) && !defined(ASSEMBLY)
  13. #include <rtdef.h>
  14. #define MIPS_REG_NR 32
  15. typedef struct {
  16. rt_uint32_t regs[MIPS_REG_NR]; /* 32 个通用目的寄存器 */
  17. rt_uint32_t CP0Status; /* CP0 协处理器状态寄存器 */
  18. rt_uint32_t CP0DataHI; /* 除数高位寄存器 */
  19. rt_uint32_t CP0DataLO; /* 除数低位寄存器 */
  20. rt_uint32_t CP0BadVAddr; /* 出错地址寄存器 */
  21. rt_uint32_t CP0Cause; /* 产生中断或者异常查看的寄存器*/
  22. rt_uint32_t CP0EPC; /* 程序计数器寄存器 */
  23. } mips_reg_ctx;
  24. #define MIPS_ARG_REG_NR 4
  25. typedef struct
  26. {
  27. rt_uint32_t args[MIPS_ARG_REG_NR]; /* 4 个参数寄存器 */
  28. } mips_arg_ctx;
  29. struct linkctx
  30. {
  31. rt_uint32_t id;
  32. struct linkctx *next;
  33. };
  34. struct fpctx
  35. {
  36. struct linkctx link;
  37. rt_uint32_t fcsr;
  38. rt_uint32_t reserved;
  39. };
  40. struct fp32ctx
  41. {
  42. struct fpctx fp;
  43. union
  44. {
  45. double d[16]; /* even doubles */
  46. float s[32]; /* even singles, padded */
  47. };
  48. };
  49. struct fp64ctx
  50. {
  51. struct fpctx fp;
  52. union
  53. {
  54. double d[32]; /* even doubles, followed by odd doubles */
  55. float s[64]; /* even singles, followed by odd singles, padded */
  56. };
  57. };
  58. #endif /* !defined(__ASSEMBLY__) && !defined(ASSEMBLY) */
  59. #define MIPS_STK_CTX_WORD_SIZE 38
  60. #define SZREG 4
  61. /*********************************************************************************************************
  62. MIPS 的寄存器索引
  63. *********************************************************************************************************/
  64. #define REG_ZERO 0 /* wired zero */
  65. #define REG_AT 1 /* assembler temp */
  66. #define REG_V0 2 /* return reg 0 */
  67. #define REG_V1 3 /* return reg 1 */
  68. #define REG_A0 4 /* arg reg 0 */
  69. #define REG_A1 5 /* arg reg 1 */
  70. #define REG_A2 6 /* arg reg 2 */
  71. #define REG_A3 7 /* arg reg 3 */
  72. #define REG_T0 8 /* caller saved 0 */
  73. #define REG_T1 9 /* caller saved 1 */
  74. #define REG_T2 10 /* caller saved 2 */
  75. #define REG_T3 11 /* caller saved 3 */
  76. #define REG_T4 12 /* caller saved 4 */
  77. #define REG_T5 13 /* caller saved 5 */
  78. #define REG_T6 14 /* caller saved 6 */
  79. #define REG_T7 15 /* caller saved 7 */
  80. #define REG_S0 16 /* callee saved 0 */
  81. #define REG_S1 17 /* callee saved 1 */
  82. #define REG_S2 18 /* callee saved 2 */
  83. #define REG_S3 19 /* callee saved 3 */
  84. #define REG_S4 20 /* callee saved 4 */
  85. #define REG_S5 21 /* callee saved 5 */
  86. #define REG_S6 22 /* callee saved 6 */
  87. #define REG_S7 23 /* callee saved 7 */
  88. #define REG_T8 24 /* caller saved 8 */
  89. #define REG_T9 25 /* caller saved 9 */
  90. #define REG_K0 26 /* kernel temp 0 */
  91. #define REG_K1 27 /* kernel temp 1 */
  92. #define REG_GP 28 /* global pointer */
  93. #define REG_SP 29 /* stack pointer */
  94. #define REG_S8 30 /* callee saved 8 */
  95. #define REG_FP REG_S8 /* callee saved 8 */
  96. #define REG_RA 31 /* return address */
  97. #define STK_CTX_SIZE (MIPS_STK_CTX_WORD_SIZE * SZREG)
  98. #define STK_OFFSET_SR ((32 + 0) * SZREG)
  99. #define STK_OFFSET_HI ((32 + 1) * SZREG)
  100. #define STK_OFFSET_LO ((32 + 2) * SZREG)
  101. #define STK_OFFSET_BADVADDR ((32 + 3) * SZREG)
  102. #define STK_OFFSET_CAUSE ((32 + 4) * SZREG)
  103. #define STK_OFFSET_EPC ((32 + 5) * SZREG)
  104. #define STK_OFFSET_LAST ((MIPS_STK_CTX_WORD_SIZE - 1) * SZREG)
  105. #define FP32CTX_CSR ((SZREG)*2)
  106. #define FP64CTX_CSR ((SZREG)*2)
  107. #define LINKCTX_ID ((SZREG)*0)
  108. #define LINKCTX_NEXT ((SZREG)*1)
  109. #define LINKCTX_TYPE_MSA 0x004D5341
  110. #define LINKCTX_TYPE_FP32 0x46503332
  111. #define LINKCTX_TYPE_FP64 0x46503634
  112. #define LINKCTX_TYPE_FMSA 0x463D5341
  113. #define LINKCTX_TYPE_DSP 0x00445350
  114. #define LINKCTX_TYPE_STKSWP 0x53574150
  115. #define LINKCTX_TYPE_XPA 0x00585041
  116. #define FP32CTX_0 ((SZREG)*4)
  117. #define FP32CTX_2 (FP32CTX_0 + (1 * 8))
  118. #define FP32CTX_4 (FP32CTX_0 + (2 * 8))
  119. #define FP32CTX_6 (FP32CTX_0 + (3 * 8))
  120. #define FP32CTX_8 (FP32CTX_0 + (4 * 8))
  121. #define FP32CTX_10 (FP32CTX_0 + (5 * 8))
  122. #define FP32CTX_12 (FP32CTX_0 + (6 * 8))
  123. #define FP32CTX_14 (FP32CTX_0 + (7 * 8))
  124. #define FP32CTX_16 (FP32CTX_0 + (8 * 8))
  125. #define FP32CTX_18 (FP32CTX_0 + (9 * 8))
  126. #define FP32CTX_20 (FP32CTX_0 + (10 * 8))
  127. #define FP32CTX_22 (FP32CTX_0 + (11 * 8))
  128. #define FP32CTX_24 (FP32CTX_0 + (12 * 8))
  129. #define FP32CTX_26 (FP32CTX_0 + (13 * 8))
  130. #define FP32CTX_28 (FP32CTX_0 + (14 * 8))
  131. #define FP32CTX_30 (FP32CTX_0 + (15 * 8))
  132. #define FP32CTX_SIZE (FP32CTX_30 + (17 * 8))
  133. #define FP64CTX_0 ((SZREG)*4)
  134. #define FP64CTX_2 (FP64CTX_0 + (1 * 8))
  135. #define FP64CTX_4 (FP64CTX_0 + (2 * 8))
  136. #define FP64CTX_6 (FP64CTX_0 + (3 * 8))
  137. #define FP64CTX_8 (FP64CTX_0 + (4 * 8))
  138. #define FP64CTX_10 (FP64CTX_0 + (5 * 8))
  139. #define FP64CTX_12 (FP64CTX_0 + (6 * 8))
  140. #define FP64CTX_14 (FP64CTX_0 + (7 * 8))
  141. #define FP64CTX_16 (FP64CTX_0 + (8 * 8))
  142. #define FP64CTX_18 (FP64CTX_0 + (9 * 8))
  143. #define FP64CTX_20 (FP64CTX_0 + (10 * 8))
  144. #define FP64CTX_22 (FP64CTX_0 + (11 * 8))
  145. #define FP64CTX_24 (FP64CTX_0 + (12 * 8))
  146. #define FP64CTX_26 (FP64CTX_0 + (13 * 8))
  147. #define FP64CTX_28 (FP64CTX_0 + (14 * 8))
  148. #define FP64CTX_30 (FP64CTX_0 + (15 * 8))
  149. #define FP64CTX_1 (FP64CTX_30 + (1 * 8))
  150. #define FP64CTX_3 (FP64CTX_30 + (2 * 8))
  151. #define FP64CTX_5 (FP64CTX_30 + (3 * 8))
  152. #define FP64CTX_7 (FP64CTX_30 + (4 * 8))
  153. #define FP64CTX_9 (FP64CTX_30 + (5 * 8))
  154. #define FP64CTX_11 (FP64CTX_30 + (6 * 8))
  155. #define FP64CTX_13 (FP64CTX_30 + (7 * 8))
  156. #define FP64CTX_15 (FP64CTX_30 + (8 * 8))
  157. #define FP64CTX_17 (FP64CTX_30 + (9 * 8))
  158. #define FP64CTX_19 (FP64CTX_30 + (10 * 8))
  159. #define FP64CTX_21 (FP64CTX_30 + (11 * 8))
  160. #define FP64CTX_23 (FP64CTX_30 + (12 * 8))
  161. #define FP64CTX_25 (FP64CTX_30 + (13 * 8))
  162. #define FP64CTX_27 (FP64CTX_30 + (14 * 8))
  163. #define FP64CTX_29 (FP64CTX_30 + (15 * 8))
  164. #define FP64CTX_31 (FP64CTX_30 + (16 * 8))
  165. #define FP64CTX_SIZE (FP64CTX_31 + (17 * 8))
  166. #define FPCTX_SIZE() (mips_getsr() & ST0_FR ? FP64CTX_SIZE : FP32CTX_SIZE)
  167. /*
  168. * The following macros are especially useful for __asm__
  169. * inline assembler.
  170. */
  171. #ifndef __STR
  172. #define __STR(x) #x
  173. #endif
  174. #ifndef STR
  175. #define STR(x) __STR(x)
  176. #endif
  177. /*
  178. * Configure language
  179. */
  180. #ifdef __ASSEMBLY__
  181. #define _ULCAST_
  182. #else
  183. #define _ULCAST_ (unsigned long)
  184. #endif
  185. /*
  186. * Coprocessor 0 register names
  187. */
  188. #define CP0_INDEX $0
  189. #define CP0_RANDOM $1
  190. #define CP0_ENTRYLO0 $2
  191. #define CP0_ENTRYLO1 $3
  192. #define CP0_CONF $3
  193. #define CP0_CONTEXT $4
  194. #define CP0_PAGEMASK $5
  195. #define CP0_WIRED $6
  196. #define CP0_INFO $7
  197. #define CP0_BADVADDR $8
  198. #define CP0_COUNT $9
  199. #define CP0_ENTRYHI $10
  200. #define CP0_COMPARE $11
  201. #define CP0_STATUS $12
  202. #define CP0_CAUSE $13
  203. #define CP0_EPC $14
  204. #define CP0_PRID $15
  205. #define CP0_CONFIG $16
  206. #define CP0_LLADDR $17
  207. #define CP0_WATCHLO $18
  208. #define CP0_WATCHHI $19
  209. #define CP0_XCONTEXT $20
  210. #define CP0_FRAMEMASK $21
  211. #define CP0_DIAGNOSTIC $22
  212. #define CP0_DEBUG $23
  213. #define CP0_DEPC $24
  214. #define CP0_PERFORMANCE $25
  215. #define CP0_ECC $26
  216. #define CP0_CACHEERR $27
  217. #define CP0_TAGLO $28
  218. #define CP0_TAGHI $29
  219. #define CP0_ERROREPC $30
  220. #define CP0_DESAVE $31
  221. /*
  222. * R4640/R4650 cp0 register names. These registers are listed
  223. * here only for completeness; without MMU these CPUs are not useable
  224. * by Linux. A future ELKS port might take make Linux run on them
  225. * though ...
  226. */
  227. #define CP0_IBASE $0
  228. #define CP0_IBOUND $1
  229. #define CP0_DBASE $2
  230. #define CP0_DBOUND $3
  231. #define CP0_CALG $17
  232. #define CP0_IWATCH $18
  233. #define CP0_DWATCH $19
  234. /*
  235. * Coprocessor 0 Set 1 register names
  236. */
  237. #define CP0_S1_DERRADDR0 $26
  238. #define CP0_S1_DERRADDR1 $27
  239. #define CP0_S1_INTCONTROL $20
  240. /*
  241. * TX39 Series
  242. */
  243. #define CP0_TX39_CACHE $7
  244. /*
  245. * Coprocessor 1 (FPU) register names
  246. */
  247. #define CP1_REVISION $0
  248. #define CP1_STATUS $31
  249. /*
  250. * FPU Status Register Values
  251. */
  252. /*
  253. * Status Register Values
  254. */
  255. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  256. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  257. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  258. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  259. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  260. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  261. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  262. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  263. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  264. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  265. /*
  266. * X the exception cause indicator
  267. * E the exception enable
  268. * S the sticky/flag bit
  269. */
  270. #define FPU_CSR_ALL_X 0x0003f000
  271. #define FPU_CSR_UNI_X 0x00020000
  272. #define FPU_CSR_INV_X 0x00010000
  273. #define FPU_CSR_DIV_X 0x00008000
  274. #define FPU_CSR_OVF_X 0x00004000
  275. #define FPU_CSR_UDF_X 0x00002000
  276. #define FPU_CSR_INE_X 0x00001000
  277. #define FPU_CSR_ALL_E 0x00000f80
  278. #define FPU_CSR_INV_E 0x00000800
  279. #define FPU_CSR_DIV_E 0x00000400
  280. #define FPU_CSR_OVF_E 0x00000200
  281. #define FPU_CSR_UDF_E 0x00000100
  282. #define FPU_CSR_INE_E 0x00000080
  283. #define FPU_CSR_ALL_S 0x0000007c
  284. #define FPU_CSR_INV_S 0x00000040
  285. #define FPU_CSR_DIV_S 0x00000020
  286. #define FPU_CSR_OVF_S 0x00000010
  287. #define FPU_CSR_UDF_S 0x00000008
  288. #define FPU_CSR_INE_S 0x00000004
  289. /* rounding mode */
  290. #define FPU_CSR_RN 0x0 /* nearest */
  291. #define FPU_CSR_RZ 0x1 /* towards zero */
  292. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  293. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  294. /*
  295. * Values for PageMask register
  296. */
  297. #ifdef CONFIG_CPU_VR41XX
  298. /* Why doesn't stupidity hurt ... */
  299. #define PM_1K 0x00000000
  300. #define PM_4K 0x00001800
  301. #define PM_16K 0x00007800
  302. #define PM_64K 0x0001f800
  303. #define PM_256K 0x0007f800
  304. #else
  305. #define PM_4K 0x00000000
  306. #define PM_16K 0x00006000
  307. #define PM_64K 0x0001e000
  308. #define PM_256K 0x0007e000
  309. #define PM_1M 0x001fe000
  310. #define PM_4M 0x007fe000
  311. #define PM_16M 0x01ffe000
  312. #define PM_64M 0x07ffe000
  313. #define PM_256M 0x1fffe000
  314. #endif
  315. /*
  316. * Values used for computation of new tlb entries
  317. */
  318. #define PL_4K 12
  319. #define PL_16K 14
  320. #define PL_64K 16
  321. #define PL_256K 18
  322. #define PL_1M 20
  323. #define PL_4M 22
  324. #define PL_16M 24
  325. #define PL_64M 26
  326. #define PL_256M 28
  327. /*
  328. * R4x00 interrupt enable / cause bits
  329. */
  330. #define IE_SW0 (_ULCAST_(1) << 8)
  331. #define IE_SW1 (_ULCAST_(1) << 9)
  332. #define IE_IRQ0 (_ULCAST_(1) << 10)
  333. #define IE_IRQ1 (_ULCAST_(1) << 11)
  334. #define IE_IRQ2 (_ULCAST_(1) << 12)
  335. #define IE_IRQ3 (_ULCAST_(1) << 13)
  336. #define IE_IRQ4 (_ULCAST_(1) << 14)
  337. #define IE_IRQ5 (_ULCAST_(1) << 15)
  338. /*
  339. * R4x00 interrupt cause bits
  340. */
  341. #define C_SW0 (_ULCAST_(1) << 8)
  342. #define C_SW1 (_ULCAST_(1) << 9)
  343. #define C_IRQ0 (_ULCAST_(1) << 10)
  344. #define C_IRQ1 (_ULCAST_(1) << 11)
  345. #define C_IRQ2 (_ULCAST_(1) << 12)
  346. #define C_IRQ3 (_ULCAST_(1) << 13)
  347. #define C_IRQ4 (_ULCAST_(1) << 14)
  348. #define C_IRQ5 (_ULCAST_(1) << 15)
  349. /*
  350. * Bitfields in the R4xx0 cp0 status register
  351. */
  352. #define ST0_IE 0x00000001
  353. #define ST0_EXL 0x00000002
  354. #define ST0_ERL 0x00000004
  355. #define ST0_KSU 0x00000018
  356. # define KSU_USER 0x00000010
  357. # define KSU_SUPERVISOR 0x00000008
  358. # define KSU_KERNEL 0x00000000
  359. #define ST0_UX 0x00000020
  360. #define ST0_SX 0x00000040
  361. #define ST0_KX 0x00000080
  362. #define ST0_DE 0x00010000
  363. #define ST0_CE 0x00020000
  364. /*
  365. * Bitfields in the R[23]000 cp0 status register.
  366. */
  367. #define ST0_IEC 0x00000001
  368. #define ST0_KUC 0x00000002
  369. #define ST0_IEP 0x00000004
  370. #define ST0_KUP 0x00000008
  371. #define ST0_IEO 0x00000010
  372. #define ST0_KUO 0x00000020
  373. /* bits 6 & 7 are reserved on R[23]000 */
  374. #define ST0_ISC 0x00010000
  375. #define ST0_SWC 0x00020000
  376. #define ST0_CM 0x00080000
  377. /*
  378. * Bits specific to the R4640/R4650
  379. */
  380. #define ST0_UM (_ULCAST_(1) << 4)
  381. #define ST0_IL (_ULCAST_(1) << 23)
  382. #define ST0_DL (_ULCAST_(1) << 24)
  383. /*
  384. * Bitfields in the TX39 family CP0 Configuration Register 3
  385. */
  386. #define TX39_CONF_ICS_SHIFT 19
  387. #define TX39_CONF_ICS_MASK 0x00380000
  388. #define TX39_CONF_ICS_1KB 0x00000000
  389. #define TX39_CONF_ICS_2KB 0x00080000
  390. #define TX39_CONF_ICS_4KB 0x00100000
  391. #define TX39_CONF_ICS_8KB 0x00180000
  392. #define TX39_CONF_ICS_16KB 0x00200000
  393. #define TX39_CONF_DCS_SHIFT 16
  394. #define TX39_CONF_DCS_MASK 0x00070000
  395. #define TX39_CONF_DCS_1KB 0x00000000
  396. #define TX39_CONF_DCS_2KB 0x00010000
  397. #define TX39_CONF_DCS_4KB 0x00020000
  398. #define TX39_CONF_DCS_8KB 0x00030000
  399. #define TX39_CONF_DCS_16KB 0x00040000
  400. #define TX39_CONF_CWFON 0x00004000
  401. #define TX39_CONF_WBON 0x00002000
  402. #define TX39_CONF_RF_SHIFT 10
  403. #define TX39_CONF_RF_MASK 0x00000c00
  404. #define TX39_CONF_DOZE 0x00000200
  405. #define TX39_CONF_HALT 0x00000100
  406. #define TX39_CONF_LOCK 0x00000080
  407. #define TX39_CONF_ICE 0x00000020
  408. #define TX39_CONF_DCE 0x00000010
  409. #define TX39_CONF_IRSIZE_SHIFT 2
  410. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  411. #define TX39_CONF_DRSIZE_SHIFT 0
  412. #define TX39_CONF_DRSIZE_MASK 0x00000003
  413. /*
  414. * Status register bits available in all MIPS CPUs.
  415. */
  416. #define ST0_IM 0x0000ff00
  417. #define STATUSB_IP0 8
  418. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  419. #define STATUSB_IP1 9
  420. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  421. #define STATUSB_IP2 10
  422. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  423. #define STATUSB_IP3 11
  424. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  425. #define STATUSB_IP4 12
  426. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  427. #define STATUSB_IP5 13
  428. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  429. #define STATUSB_IP6 14
  430. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  431. #define STATUSB_IP7 15
  432. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  433. #define STATUSB_IP8 0
  434. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  435. #define STATUSB_IP9 1
  436. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  437. #define STATUSB_IP10 2
  438. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  439. #define STATUSB_IP11 3
  440. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  441. #define STATUSB_IP12 4
  442. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  443. #define STATUSB_IP13 5
  444. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  445. #define STATUSB_IP14 6
  446. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  447. #define STATUSB_IP15 7
  448. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  449. #define ST0_CH 0x00040000
  450. #define ST0_SR 0x00100000
  451. #define ST0_TS 0x00200000
  452. #define ST0_BEV 0x00400000
  453. #define ST0_RE 0x02000000
  454. #define ST0_FR 0x04000000
  455. #define ST0_CU 0xf0000000
  456. #define ST0_CU0 0x10000000
  457. #define ST0_CU1 0x20000000
  458. #define ST0_CU1_SHIFT 29
  459. #define ST0_CU2 0x40000000
  460. #define ST0_CU3 0x80000000
  461. #define ST0_XX 0x80000000 /* MIPS IV naming */
  462. /*
  463. * Bitfields and bit numbers in the coprocessor 0 cause register.
  464. *
  465. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  466. */
  467. #define CAUSEB_EXCCODE 2
  468. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  469. #define CAUSEB_IP 8
  470. #define CAUSEF_IP (_ULCAST_(255) << 8)
  471. #define CAUSEB_IP0 8
  472. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  473. #define CAUSEB_IP1 9
  474. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  475. #define CAUSEB_IP2 10
  476. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  477. #define CAUSEB_IP3 11
  478. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  479. #define CAUSEB_IP4 12
  480. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  481. #define CAUSEB_IP5 13
  482. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  483. #define CAUSEB_IP6 14
  484. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  485. #define CAUSEB_IP7 15
  486. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  487. #define CAUSEB_IV 23
  488. #define CAUSEF_IV (_ULCAST_(1) << 23)
  489. #define CAUSEB_CE 28
  490. #define CAUSEF_CE (_ULCAST_(3) << 28)
  491. #define CAUSEB_BD 31
  492. #define CAUSEF_BD (_ULCAST_(1) << 31)
  493. /*
  494. * Bits in the coprocessor 0 config register.
  495. */
  496. /* Generic bits. */
  497. #define CONF_CM_CACHABLE_NO_WA 0
  498. #define CONF_CM_CACHABLE_WA 1
  499. #define CONF_CM_UNCACHED 2
  500. #define CONF_CM_CACHABLE_NONCOHERENT 3
  501. #define CONF_CM_CACHABLE_CE 4
  502. #define CONF_CM_CACHABLE_COW 5
  503. #define CONF_CM_CACHABLE_CUW 6
  504. #define CONF_CM_CACHABLE_ACCELERATED 7
  505. #define CONF_CM_CMASK 7
  506. #define CONF_BE (_ULCAST_(1) << 15)
  507. /* Bits common to various processors. */
  508. #define CONF_CU (_ULCAST_(1) << 3)
  509. #define CONF_DB (_ULCAST_(1) << 4)
  510. #define CONF_IB (_ULCAST_(1) << 5)
  511. #define CONF_DC (_ULCAST_(7) << 6)
  512. #define CONF_IC (_ULCAST_(7) << 9)
  513. #define CONF_EB (_ULCAST_(1) << 13)
  514. #define CONF_EM (_ULCAST_(1) << 14)
  515. #define CONF_SM (_ULCAST_(1) << 16)
  516. #define CONF_SC (_ULCAST_(1) << 17)
  517. #define CONF_EW (_ULCAST_(3) << 18)
  518. #define CONF_EP (_ULCAST_(15)<< 24)
  519. #define CONF_EC (_ULCAST_(7) << 28)
  520. #define CONF_CM (_ULCAST_(1) << 31)
  521. /* Bits specific to the R4xx0. */
  522. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  523. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  524. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  525. /* Bits specific to the R5000. */
  526. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  527. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  528. /* Bits specific to the R10000. */
  529. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  530. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  531. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  532. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  533. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  534. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  535. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  536. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  537. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  538. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  539. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  540. /* Bits specific to the VR41xx. */
  541. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  542. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  543. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  544. /* Bits specific to the R30xx. */
  545. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  546. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  547. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  548. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  549. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  550. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  551. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  552. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  553. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  554. /* Bits specific to the TX49. */
  555. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  556. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  557. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  558. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  559. /* Bits specific to the MIPS32/64 PRA. */
  560. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  561. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  562. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  563. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  564. /*
  565. * R10000 performance counter definitions.
  566. *
  567. * FIXME: The R10000 performance counter opens a nice way to implement CPU
  568. * time accounting with a precission of one cycle. I don't have
  569. * R10000 silicon but just a manual, so ...
  570. */
  571. /*
  572. * Events counted by counter #0
  573. */
  574. #define CE0_CYCLES 0
  575. #define CE0_INSN_ISSUED 1
  576. #define CE0_LPSC_ISSUED 2
  577. #define CE0_S_ISSUED 3
  578. #define CE0_SC_ISSUED 4
  579. #define CE0_SC_FAILED 5
  580. #define CE0_BRANCH_DECODED 6
  581. #define CE0_QW_WB_SECONDARY 7
  582. #define CE0_CORRECTED_ECC_ERRORS 8
  583. #define CE0_ICACHE_MISSES 9
  584. #define CE0_SCACHE_I_MISSES 10
  585. #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
  586. #define CE0_EXT_INTERVENTIONS_REQ 12
  587. #define CE0_EXT_INVALIDATE_REQ 13
  588. #define CE0_VIRTUAL_COHERENCY_COND 14
  589. #define CE0_INSN_GRADUATED 15
  590. /*
  591. * Events counted by counter #1
  592. */
  593. #define CE1_CYCLES 0
  594. #define CE1_INSN_GRADUATED 1
  595. #define CE1_LPSC_GRADUATED 2
  596. #define CE1_S_GRADUATED 3
  597. #define CE1_SC_GRADUATED 4
  598. #define CE1_FP_INSN_GRADUATED 5
  599. #define CE1_QW_WB_PRIMARY 6
  600. #define CE1_TLB_REFILL 7
  601. #define CE1_BRANCH_MISSPREDICTED 8
  602. #define CE1_DCACHE_MISS 9
  603. #define CE1_SCACHE_D_MISSES 10
  604. #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
  605. #define CE1_EXT_INTERVENTION_HITS 12
  606. #define CE1_EXT_INVALIDATE_REQ 13
  607. #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
  608. #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
  609. /*
  610. * These flags define in which priviledge mode the counters count events
  611. */
  612. #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
  613. #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
  614. #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
  615. #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
  616. #ifndef __ASSEMBLY__
  617. #define CAUSE_EXCCODE(x) ((CAUSEF_EXCCODE & (x->cp0_cause)) >> CAUSEB_EXCCODE)
  618. #define CAUSE_EPC(x) (x->cp0_epc + (((x->cp0_cause & CAUSEF_BD) >> CAUSEB_BD) << 2))
  619. /*
  620. * Functions to access the r10k performance counter and control registers
  621. */
  622. #define read_r10k_perf_cntr(counter) \
  623. ({ unsigned int __res; \
  624. __asm__ __volatile__( \
  625. "mfpc\t%0, "STR(counter) \
  626. : "=r" (__res)); \
  627. __res;})
  628. #define write_r10k_perf_cntr(counter,val) \
  629. __asm__ __volatile__( \
  630. "mtpc\t%0, "STR(counter) \
  631. : : "r" (val));
  632. #define read_r10k_perf_cntl(counter) \
  633. ({ unsigned int __res; \
  634. __asm__ __volatile__( \
  635. "mfps\t%0, "STR(counter) \
  636. : "=r" (__res)); \
  637. __res;})
  638. #define write_r10k_perf_cntl(counter,val) \
  639. __asm__ __volatile__( \
  640. "mtps\t%0, "STR(counter) \
  641. : : "r" (val));
  642. /*
  643. * Macros to access the system control coprocessor
  644. */
  645. #define __read_32bit_c0_register(source, sel) \
  646. ({ int __res; \
  647. if (sel == 0) \
  648. __asm__ __volatile__( \
  649. "mfc0\t%0, " #source "\n\t" \
  650. : "=r" (__res)); \
  651. else \
  652. __asm__ __volatile__( \
  653. ".set\tmips32\n\t" \
  654. "mfc0\t%0, " #source ", " #sel "\n\t" \
  655. ".set\tmips0\n\t" \
  656. : "=r" (__res)); \
  657. __res; \
  658. })
  659. #define __read_64bit_c0_register(source, sel) \
  660. ({ unsigned long __res; \
  661. if (sel == 0) \
  662. __asm__ __volatile__( \
  663. ".set\tmips3\n\t" \
  664. "dmfc0\t%0, " #source "\n\t" \
  665. ".set\tmips0" \
  666. : "=r" (__res)); \
  667. else \
  668. __asm__ __volatile__( \
  669. ".set\tmips64\n\t" \
  670. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  671. ".set\tmips0" \
  672. : "=r" (__res)); \
  673. __res; \
  674. })
  675. #define __write_32bit_c0_register(register, sel, value) \
  676. do { \
  677. if (sel == 0) \
  678. __asm__ __volatile__( \
  679. "mtc0\t%z0, " #register "\n\t" \
  680. : : "Jr" (value)); \
  681. else \
  682. __asm__ __volatile__( \
  683. ".set\tmips32\n\t" \
  684. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  685. ".set\tmips0" \
  686. : : "Jr" (value)); \
  687. } while (0)
  688. #define __write_64bit_c0_register(register, sel, value) \
  689. do { \
  690. if (sel == 0) \
  691. __asm__ __volatile__( \
  692. ".set\tmips3\n\t" \
  693. "dmtc0\t%z0, " #register "\n\t" \
  694. ".set\tmips0" \
  695. : : "Jr" (value)); \
  696. else \
  697. __asm__ __volatile__( \
  698. ".set\tmips64\n\t" \
  699. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  700. ".set\tmips0" \
  701. : : "Jr" (value)); \
  702. } while (0)
  703. #define __read_ulong_c0_register(reg, sel) \
  704. ((sizeof(unsigned long) == 4) ? \
  705. __read_32bit_c0_register(reg, sel) : \
  706. __read_64bit_c0_register(reg, sel))
  707. #define __write_ulong_c0_register(reg, sel, val) \
  708. do { \
  709. if (sizeof(unsigned long) == 4) \
  710. __write_32bit_c0_register(reg, sel, val); \
  711. else \
  712. __write_64bit_c0_register(reg, sel, val); \
  713. } while (0)
  714. /*
  715. * These versions are only needed for systems with more than 38 bits of
  716. * physical address space running the 32-bit kernel. That's none atm :-)
  717. */
  718. #define __read_64bit_c0_split(source, sel) \
  719. ({ \
  720. unsigned long long val; \
  721. unsigned long flags; \
  722. \
  723. local_irq_save(flags); \
  724. if (sel == 0) \
  725. __asm__ __volatile__( \
  726. ".set\tmips64\n\t" \
  727. "dmfc0\t%M0, " #source "\n\t" \
  728. "dsll\t%L0, %M0, 32\n\t" \
  729. "dsrl\t%M0, %M0, 32\n\t" \
  730. "dsrl\t%L0, %L0, 32\n\t" \
  731. ".set\tmips0" \
  732. : "=r" (val)); \
  733. else \
  734. __asm__ __volatile__( \
  735. ".set\tmips64\n\t" \
  736. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  737. "dsll\t%L0, %M0, 32\n\t" \
  738. "dsrl\t%M0, %M0, 32\n\t" \
  739. "dsrl\t%L0, %L0, 32\n\t" \
  740. ".set\tmips0" \
  741. : "=r" (val)); \
  742. local_irq_restore(flags); \
  743. \
  744. val; \
  745. })
  746. #define __write_64bit_c0_split(source, sel, val) \
  747. do { \
  748. unsigned long flags; \
  749. \
  750. local_irq_save(flags); \
  751. if (sel == 0) \
  752. __asm__ __volatile__( \
  753. ".set\tmips64\n\t" \
  754. "dsll\t%L0, %L0, 32\n\t" \
  755. "dsrl\t%L0, %L0, 32\n\t" \
  756. "dsll\t%M0, %M0, 32\n\t" \
  757. "or\t%L0, %L0, %M0\n\t" \
  758. "dmtc0\t%L0, " #source "\n\t" \
  759. ".set\tmips0" \
  760. : : "r" (val)); \
  761. else \
  762. __asm__ __volatile__( \
  763. ".set\tmips64\n\t" \
  764. "dsll\t%L0, %L0, 32\n\t" \
  765. "dsrl\t%L0, %L0, 32\n\t" \
  766. "dsll\t%M0, %M0, 32\n\t" \
  767. "or\t%L0, %L0, %M0\n\t" \
  768. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  769. ".set\tmips0" \
  770. : : "r" (val)); \
  771. local_irq_restore(flags); \
  772. } while (0)
  773. #define read_c0_index() __read_32bit_c0_register($0, 0)
  774. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  775. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  776. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  777. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  778. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  779. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  780. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  781. #define read_c0_context() __read_ulong_c0_register($4, 0)
  782. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  783. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  784. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  785. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  786. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  787. #define read_c0_info() __read_32bit_c0_register($7, 0)
  788. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  789. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  790. #define read_c0_count() __read_32bit_c0_register($9, 0)
  791. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  792. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  793. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  794. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  795. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  796. #define read_c0_status() __read_32bit_c0_register($12, 0)
  797. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  798. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  799. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  800. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  801. #define read_c0_config() __read_32bit_c0_register($16, 0)
  802. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  803. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  804. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  805. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  806. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  807. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  808. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  809. /*
  810. * The WatchLo register. There may be upto 8 of them.
  811. */
  812. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  813. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  814. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  815. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  816. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  817. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  818. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  819. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  820. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  821. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  822. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  823. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  824. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  825. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  826. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  827. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  828. /*
  829. * The WatchHi register. There may be upto 8 of them.
  830. */
  831. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  832. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  833. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  834. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  835. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  836. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  837. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  838. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  839. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  840. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  841. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  842. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  843. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  844. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  845. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  846. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  847. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  848. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  849. #define read_c0_intcontrol() __read_32bit_c0_register($20, 1)
  850. #define write_c0_intcontrol(val) __write_32bit_c0_register($20, 1, val)
  851. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  852. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  853. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  854. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  855. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  856. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  857. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  858. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  859. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  860. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  861. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  862. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  863. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  864. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  865. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  866. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  867. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  868. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  869. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  870. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  871. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  872. #if 1
  873. /*
  874. * Macros to access the system control coprocessor
  875. */
  876. #define read_32bit_cp0_register(source) \
  877. ({ int __res; \
  878. __asm__ __volatile__( \
  879. ".set\tpush\n\t" \
  880. ".set\treorder\n\t" \
  881. "mfc0\t%0,"STR(source)"\n\t" \
  882. ".set\tpop" \
  883. : "=r" (__res)); \
  884. __res;})
  885. #define read_32bit_cp0_set1_register(source) \
  886. ({ int __res; \
  887. __asm__ __volatile__( \
  888. ".set\tpush\n\t" \
  889. ".set\treorder\n\t" \
  890. "cfc0\t%0,"STR(source)"\n\t" \
  891. ".set\tpop" \
  892. : "=r" (__res)); \
  893. __res;})
  894. /*
  895. * For now use this only with interrupts disabled!
  896. */
  897. #define read_64bit_cp0_register(source) \
  898. ({ int __res; \
  899. __asm__ __volatile__( \
  900. ".set\tmips3\n\t" \
  901. "dmfc0\t%0,"STR(source)"\n\t" \
  902. ".set\tmips0" \
  903. : "=r" (__res)); \
  904. __res;})
  905. #define write_32bit_cp0_register(register,value) \
  906. __asm__ __volatile__( \
  907. "mtc0\t%0,"STR(register)"\n\t" \
  908. "nop" \
  909. : : "r" (value));
  910. #define write_32bit_cp0_set1_register(register,value) \
  911. __asm__ __volatile__( \
  912. "ctc0\t%0,"STR(register)"\n\t" \
  913. "nop" \
  914. : : "r" (value));
  915. #define write_64bit_cp0_register(register,value) \
  916. __asm__ __volatile__( \
  917. ".set\tmips3\n\t" \
  918. "dmtc0\t%0,"STR(register)"\n\t" \
  919. ".set\tmips0" \
  920. : : "r" (value))
  921. /*
  922. * This should be changed when we get a compiler that support the MIPS32 ISA.
  923. */
  924. #define read_mips32_cp0_config1() \
  925. ({ int __res; \
  926. __asm__ __volatile__( \
  927. ".set\tnoreorder\n\t" \
  928. ".set\tnoat\n\t" \
  929. "#.set\tmips64\n\t" \
  930. "#mfc0\t$1, $16, 1\n\t" \
  931. "#.set\tmips0\n\t" \
  932. ".word\t0x40018001\n\t" \
  933. "move\t%0,$1\n\t" \
  934. ".set\tat\n\t" \
  935. ".set\treorder" \
  936. :"=r" (__res)); \
  937. __res;})
  938. #endif
  939. /*
  940. * Macros to access the floating point coprocessor control registers
  941. */
  942. #define read_32bit_cp1_register(source) \
  943. ({ int __res; \
  944. __asm__ __volatile__( \
  945. ".set\tpush\n\t" \
  946. ".set\treorder\n\t" \
  947. "cfc1\t%0,"STR(source)"\n\t" \
  948. ".set\tpop" \
  949. : "=r" (__res)); \
  950. __res;})
  951. /* TLB operations. */
  952. static inline void tlb_probe(void)
  953. {
  954. __asm__ __volatile__(
  955. ".set noreorder\n\t"
  956. "tlbp\n\t"
  957. ".set reorder");
  958. }
  959. static inline void tlb_read(void)
  960. {
  961. __asm__ __volatile__(
  962. ".set noreorder\n\t"
  963. "tlbr\n\t"
  964. ".set reorder");
  965. }
  966. static inline void tlb_write_indexed(void)
  967. {
  968. __asm__ __volatile__(
  969. ".set noreorder\n\t"
  970. "tlbwi\n\t"
  971. ".set reorder");
  972. }
  973. static inline void tlb_write_random(void)
  974. {
  975. __asm__ __volatile__(
  976. ".set noreorder\n\t"
  977. "tlbwr\n\t"
  978. ".set reorder");
  979. }
  980. /*
  981. * Manipulate bits in a c0 register.
  982. */
  983. #define __BUILD_SET_C0(name,register) \
  984. static inline unsigned int \
  985. set_c0_##name(unsigned int set) \
  986. { \
  987. unsigned int res; \
  988. \
  989. res = read_c0_##name(); \
  990. res |= set; \
  991. write_c0_##name(res); \
  992. \
  993. return res; \
  994. } \
  995. \
  996. static inline unsigned int \
  997. clear_c0_##name(unsigned int clear) \
  998. { \
  999. unsigned int res; \
  1000. \
  1001. res = read_c0_##name(); \
  1002. res &= ~clear; \
  1003. write_c0_##name(res); \
  1004. \
  1005. return res; \
  1006. } \
  1007. \
  1008. static inline unsigned int \
  1009. change_c0_##name(unsigned int change, unsigned int new) \
  1010. { \
  1011. unsigned int res; \
  1012. \
  1013. res = read_c0_##name(); \
  1014. res &= ~change; \
  1015. res |= (new & change); \
  1016. write_c0_##name(res); \
  1017. \
  1018. return res; \
  1019. }
  1020. __BUILD_SET_C0(status,CP0_STATUS)
  1021. __BUILD_SET_C0(cause,CP0_CAUSE)
  1022. __BUILD_SET_C0(config,CP0_CONFIG)
  1023. #define set_cp0_status(x) set_c0_status(x)
  1024. #define set_cp0_cause(x) set_c0_cause(x)
  1025. #define set_cp0_config(x) set_c0_config(x)
  1026. #endif /* !__ASSEMBLY__ */
  1027. #endif /* _MIPS_REGS_H_ */