mipsregs.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2000 Silicon Graphics, Inc.
  8. * Modified for further R[236]000 support by Paul M. Antoine, 1996.
  9. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  11. * Copyright (C) 2003 Maciej W. Rozycki
  12. */
  13. #ifndef _ASM_MIPSREGS_H
  14. #define _ASM_MIPSREGS_H
  15. #if 0
  16. #include <linux/linkage.h>
  17. #endif
  18. /*
  19. * The following macros are especially useful for __asm__
  20. * inline assembler.
  21. */
  22. #ifndef __STR
  23. #define __STR(x) #x
  24. #endif
  25. #ifndef STR
  26. #define STR(x) __STR(x)
  27. #endif
  28. /*
  29. * Coprocessor 0 register names
  30. */
  31. #define CP0_INDEX $0
  32. #define CP0_RANDOM $1
  33. #define CP0_ENTRYLO0 $2
  34. #define CP0_ENTRYLO1 $3
  35. #define CP0_CONF $3
  36. #define CP0_CONTEXT $4
  37. #define CP0_PAGEMASK $5
  38. #define CP0_WIRED $6
  39. #define CP0_INFO $7
  40. #define CP0_BADVADDR $8
  41. #define CP0_COUNT $9
  42. #define CP0_ENTRYHI $10
  43. #define CP0_COMPARE $11
  44. #define CP0_STATUS $12
  45. #define CP0_CAUSE $13
  46. #define CP0_EPC $14
  47. #define CP0_PRID $15
  48. #define CP0_CONFIG $16
  49. #define CP0_LLADDR $17
  50. #define CP0_WATCHLO $18
  51. #define CP0_WATCHHI $19
  52. #define CP0_XCONTEXT $20
  53. #define CP0_FRAMEMASK $21
  54. #define CP0_DIAGNOSTIC $22
  55. #define CP0_PERFORMANCE $25
  56. #define CP0_ECC $26
  57. #define CP0_CACHEERR $27
  58. #define CP0_TAGLO $28
  59. #define CP0_TAGHI $29
  60. #define CP0_ERROREPC $30
  61. /*
  62. * R4640/R4650 cp0 register names. These registers are listed
  63. * here only for completeness; without MMU these CPUs are not useable
  64. * by Linux. A future ELKS port might take make Linux run on them
  65. * though ...
  66. */
  67. #define CP0_IBASE $0
  68. #define CP0_IBOUND $1
  69. #define CP0_DBASE $2
  70. #define CP0_DBOUND $3
  71. #define CP0_CALG $17
  72. #define CP0_IWATCH $18
  73. #define CP0_DWATCH $19
  74. /*
  75. * Coprocessor 0 Set 1 register names
  76. */
  77. #define CP0_S1_DERRADDR0 $26
  78. #define CP0_S1_DERRADDR1 $27
  79. #define CP0_S1_INTCONTROL $20
  80. /*
  81. * Coprocessor 1 (FPU) register names
  82. */
  83. #define CP1_REVISION $0
  84. #define CP1_STATUS $31
  85. /*
  86. * FPU Status Register Values
  87. */
  88. /*
  89. * Status Register Values
  90. */
  91. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  92. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  93. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  94. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  95. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  96. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  97. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  98. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  99. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  100. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  101. /*
  102. * X the exception cause indicator
  103. * E the exception enable
  104. * S the sticky/flag bit
  105. */
  106. #define FPU_CSR_ALL_X 0x0003f000
  107. #define FPU_CSR_UNI_X 0x00020000
  108. #define FPU_CSR_INV_X 0x00010000
  109. #define FPU_CSR_DIV_X 0x00008000
  110. #define FPU_CSR_OVF_X 0x00004000
  111. #define FPU_CSR_UDF_X 0x00002000
  112. #define FPU_CSR_INE_X 0x00001000
  113. #define FPU_CSR_ALL_E 0x00000f80
  114. #define FPU_CSR_INV_E 0x00000800
  115. #define FPU_CSR_DIV_E 0x00000400
  116. #define FPU_CSR_OVF_E 0x00000200
  117. #define FPU_CSR_UDF_E 0x00000100
  118. #define FPU_CSR_INE_E 0x00000080
  119. #define FPU_CSR_ALL_S 0x0000007c
  120. #define FPU_CSR_INV_S 0x00000040
  121. #define FPU_CSR_DIV_S 0x00000020
  122. #define FPU_CSR_OVF_S 0x00000010
  123. #define FPU_CSR_UDF_S 0x00000008
  124. #define FPU_CSR_INE_S 0x00000004
  125. /* rounding mode */
  126. #define FPU_CSR_RN 0x0 /* nearest */
  127. #define FPU_CSR_RZ 0x1 /* towards zero */
  128. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  129. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  130. /*
  131. * Values for PageMask register
  132. */
  133. #include <linux/config.h>
  134. #ifdef CONFIG_CPU_VR41XX
  135. #define PM_1K 0x00000000
  136. #define PM_4K 0x00001800
  137. #define PM_16K 0x00007800
  138. #define PM_64K 0x0001f800
  139. #define PM_256K 0x0007f800
  140. #else
  141. #define PM_4K 0x00000000
  142. #define PM_16K 0x00006000
  143. #define PM_64K 0x0001e000
  144. #define PM_256K 0x0007e000
  145. #define PM_1M 0x001fe000
  146. #define PM_4M 0x007fe000
  147. #define PM_16M 0x01ffe000
  148. #endif
  149. /*
  150. * Values used for computation of new tlb entries
  151. */
  152. #define PL_4K 12
  153. #define PL_16K 14
  154. #define PL_64K 16
  155. #define PL_256K 18
  156. #define PL_1M 20
  157. #define PL_4M 22
  158. #define PL_16M 24
  159. /*
  160. * Macros to access the system control coprocessor
  161. */
  162. #define read_32bit_cp0_register(source) \
  163. ({ int __res; \
  164. __asm__ __volatile__( \
  165. ".set\tpush\n\t" \
  166. ".set\treorder\n\t" \
  167. "mfc0\t%0,"STR(source)"\n\t" \
  168. ".set\tpop" \
  169. : "=r" (__res)); \
  170. __res;})
  171. #define read_32bit_cp0_set1_register(source) \
  172. ({ int __res; \
  173. __asm__ __volatile__( \
  174. ".set\tpush\n\t" \
  175. ".set\treorder\n\t" \
  176. "cfc0\t%0,"STR(source)"\n\t" \
  177. ".set\tpop" \
  178. : "=r" (__res)); \
  179. __res;})
  180. /*
  181. * For now use this only with interrupts disabled!
  182. */
  183. #define read_64bit_cp0_register(source) \
  184. ({ int __res; \
  185. __asm__ __volatile__( \
  186. ".set\tmips3\n\t" \
  187. "dmfc0\t%0,"STR(source)"\n\t" \
  188. ".set\tmips0" \
  189. : "=r" (__res)); \
  190. __res;})
  191. #define write_32bit_cp0_register(register,value) \
  192. __asm__ __volatile__( \
  193. "mtc0\t%0,"STR(register)"\n\t" \
  194. "nop" \
  195. : : "r" (value));
  196. #define write_32bit_cp0_set1_register(register,value) \
  197. __asm__ __volatile__( \
  198. "ctc0\t%0,"STR(register)"\n\t" \
  199. "nop" \
  200. : : "r" (value));
  201. #define write_64bit_cp0_register(register,value) \
  202. __asm__ __volatile__( \
  203. ".set\tmips3\n\t" \
  204. "dmtc0\t%0,"STR(register)"\n\t" \
  205. ".set\tmips0" \
  206. : : "r" (value))
  207. /*
  208. * This should be changed when we get a compiler that support the MIPS32 ISA.
  209. */
  210. #define read_mips32_cp0_config1() \
  211. ({ int __res; \
  212. __asm__ __volatile__( \
  213. ".set\tnoreorder\n\t" \
  214. ".set\tnoat\n\t" \
  215. ".word\t0x40018001\n\t" \
  216. "move\t%0,$1\n\t" \
  217. ".set\tat\n\t" \
  218. ".set\treorder" \
  219. :"=r" (__res)); \
  220. __res;})
  221. #define tlb_write_indexed() \
  222. __asm__ __volatile__( \
  223. ".set noreorder\n\t" \
  224. "tlbwi\n\t" \
  225. ".set reorder")
  226. /*
  227. * R4x00 interrupt enable / cause bits
  228. */
  229. #define IE_SW0 (1<< 8)
  230. #define IE_SW1 (1<< 9)
  231. #define IE_IRQ0 (1<<10)
  232. #define IE_IRQ1 (1<<11)
  233. #define IE_IRQ2 (1<<12)
  234. #define IE_IRQ3 (1<<13)
  235. #define IE_IRQ4 (1<<14)
  236. #define IE_IRQ5 (1<<15)
  237. /*
  238. * R4x00 interrupt cause bits
  239. */
  240. #define C_SW0 (1<< 8)
  241. #define C_SW1 (1<< 9)
  242. #define C_IRQ0 (1<<10)
  243. #define C_IRQ1 (1<<11)
  244. #define C_IRQ2 (1<<12)
  245. #define C_IRQ3 (1<<13)
  246. #define C_IRQ4 (1<<14)
  247. #define C_IRQ5 (1<<15)
  248. #ifndef _LANGUAGE_ASSEMBLY
  249. /*
  250. * Manipulate the status register.
  251. * Mostly used to access the interrupt bits.
  252. */
  253. #define __BUILD_SET_CP0(name,register) \
  254. extern __inline__ unsigned int \
  255. set_cp0_##name(unsigned int set) \
  256. { \
  257. unsigned int res; \
  258. \
  259. res = read_32bit_cp0_register(register); \
  260. res |= set; \
  261. write_32bit_cp0_register(register, res); \
  262. \
  263. return res; \
  264. } \
  265. \
  266. extern __inline__ unsigned int \
  267. clear_cp0_##name(unsigned int clear) \
  268. { \
  269. unsigned int res; \
  270. \
  271. res = read_32bit_cp0_register(register); \
  272. res &= ~clear; \
  273. write_32bit_cp0_register(register, res); \
  274. \
  275. return res; \
  276. } \
  277. \
  278. extern __inline__ unsigned int \
  279. change_cp0_##name(unsigned int change, unsigned int new) \
  280. { \
  281. unsigned int res; \
  282. \
  283. res = read_32bit_cp0_register(register); \
  284. res &= ~change; \
  285. res |= (new & change); \
  286. if(change) \
  287. write_32bit_cp0_register(register, res); \
  288. \
  289. return res; \
  290. }
  291. __BUILD_SET_CP0(status,CP0_STATUS)
  292. __BUILD_SET_CP0(cause,CP0_CAUSE)
  293. __BUILD_SET_CP0(config,CP0_CONFIG)
  294. #endif /* defined (_LANGUAGE_ASSEMBLY) */
  295. /*
  296. * Bitfields in the R4xx0 cp0 status register
  297. */
  298. #define ST0_IE 0x00000001
  299. #define ST0_EXL 0x00000002
  300. #define ST0_ERL 0x00000004
  301. #define ST0_KSU 0x00000018
  302. # define KSU_USER 0x00000010
  303. # define KSU_SUPERVISOR 0x00000008
  304. # define KSU_KERNEL 0x00000000
  305. #define ST0_UX 0x00000020
  306. #define ST0_SX 0x00000040
  307. #define ST0_KX 0x00000080
  308. #define ST0_DE 0x00010000
  309. #define ST0_CE 0x00020000
  310. /*
  311. * Bitfields in the R[23]000 cp0 status register.
  312. */
  313. #define ST0_IEC 0x00000001
  314. #define ST0_KUC 0x00000002
  315. #define ST0_IEP 0x00000004
  316. #define ST0_KUP 0x00000008
  317. #define ST0_IEO 0x00000010
  318. #define ST0_KUO 0x00000020
  319. /* bits 6 & 7 are reserved on R[23]000 */
  320. #define ST0_ISC 0x00010000
  321. #define ST0_SWC 0x00020000
  322. #define ST0_CM 0x00080000
  323. /*
  324. * Bits specific to the R4640/R4650
  325. */
  326. #define ST0_UM (1 << 4)
  327. #define ST0_IL (1 << 23)
  328. #define ST0_DL (1 << 24)
  329. /*
  330. * Bitfields in the TX39 family CP0 Configuration Register 3
  331. */
  332. #define TX39_CONF_ICS_SHIFT 19
  333. #define TX39_CONF_ICS_MASK 0x00380000
  334. #define TX39_CONF_ICS_1KB 0x00000000
  335. #define TX39_CONF_ICS_2KB 0x00080000
  336. #define TX39_CONF_ICS_4KB 0x00100000
  337. #define TX39_CONF_ICS_8KB 0x00180000
  338. #define TX39_CONF_ICS_16KB 0x00200000
  339. #define TX39_CONF_DCS_SHIFT 16
  340. #define TX39_CONF_DCS_MASK 0x00070000
  341. #define TX39_CONF_DCS_1KB 0x00000000
  342. #define TX39_CONF_DCS_2KB 0x00010000
  343. #define TX39_CONF_DCS_4KB 0x00020000
  344. #define TX39_CONF_DCS_8KB 0x00030000
  345. #define TX39_CONF_DCS_16KB 0x00040000
  346. #define TX39_CONF_CWFON 0x00004000
  347. #define TX39_CONF_WBON 0x00002000
  348. #define TX39_CONF_RF_SHIFT 10
  349. #define TX39_CONF_RF_MASK 0x00000c00
  350. #define TX39_CONF_DOZE 0x00000200
  351. #define TX39_CONF_HALT 0x00000100
  352. #define TX39_CONF_LOCK 0x00000080
  353. #define TX39_CONF_ICE 0x00000020
  354. #define TX39_CONF_DCE 0x00000010
  355. #define TX39_CONF_IRSIZE_SHIFT 2
  356. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  357. #define TX39_CONF_DRSIZE_SHIFT 0
  358. #define TX39_CONF_DRSIZE_MASK 0x00000003
  359. /*
  360. * Status register bits available in all MIPS CPUs.
  361. */
  362. #define ST0_IM 0x0000ff00
  363. #define STATUSB_IP0 8
  364. #define STATUSF_IP0 (1 << 8)
  365. #define STATUSB_IP1 9
  366. #define STATUSF_IP1 (1 << 9)
  367. #define STATUSB_IP2 10
  368. #define STATUSF_IP2 (1 << 10)
  369. #define STATUSB_IP3 11
  370. #define STATUSF_IP3 (1 << 11)
  371. #define STATUSB_IP4 12
  372. #define STATUSF_IP4 (1 << 12)
  373. #define STATUSB_IP5 13
  374. #define STATUSF_IP5 (1 << 13)
  375. #define STATUSB_IP6 14
  376. #define STATUSF_IP6 (1 << 14)
  377. #define STATUSB_IP7 15
  378. #define STATUSF_IP7 (1 << 15)
  379. #define STATUSB_IP8 0
  380. #define STATUSF_IP8 (1 << 0)
  381. #define STATUSB_IP9 1
  382. #define STATUSF_IP9 (1 << 1)
  383. #define STATUSB_IP10 2
  384. #define STATUSF_IP10 (1 << 2)
  385. #define STATUSB_IP11 3
  386. #define STATUSF_IP11 (1 << 3)
  387. #define STATUSB_IP12 4
  388. #define STATUSF_IP12 (1 << 4)
  389. #define STATUSB_IP13 5
  390. #define STATUSF_IP13 (1 << 5)
  391. #define STATUSB_IP14 6
  392. #define STATUSF_IP14 (1 << 6)
  393. #define STATUSB_IP15 7
  394. #define STATUSF_IP15 (1 << 7)
  395. #define ST0_CH 0x00040000
  396. #define ST0_SR 0x00100000
  397. #define ST0_BEV 0x00400000
  398. #define ST0_RE 0x02000000
  399. #define ST0_FR 0x04000000
  400. #define ST0_CU 0xf0000000
  401. #define ST0_CU0 0x10000000
  402. #define ST0_CU1 0x20000000
  403. #define ST0_CU2 0x40000000
  404. #define ST0_CU3 0x80000000
  405. #define ST0_XX 0x80000000 /* MIPS IV naming */
  406. /*
  407. * Bitfields and bit numbers in the coprocessor 0 cause register.
  408. *
  409. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  410. */
  411. #define CAUSEB_EXCCODE 2
  412. #define CAUSEF_EXCCODE (31 << 2)
  413. #define CAUSEB_IP 8
  414. #define CAUSEF_IP (255 << 8)
  415. #define CAUSEB_IP0 8
  416. #define CAUSEF_IP0 (1 << 8)
  417. #define CAUSEB_IP1 9
  418. #define CAUSEF_IP1 (1 << 9)
  419. #define CAUSEB_IP2 10
  420. #define CAUSEF_IP2 (1 << 10)
  421. #define CAUSEB_IP3 11
  422. #define CAUSEF_IP3 (1 << 11)
  423. #define CAUSEB_IP4 12
  424. #define CAUSEF_IP4 (1 << 12)
  425. #define CAUSEB_IP5 13
  426. #define CAUSEF_IP5 (1 << 13)
  427. #define CAUSEB_IP6 14
  428. #define CAUSEF_IP6 (1 << 14)
  429. #define CAUSEB_IP7 15
  430. #define CAUSEF_IP7 (1 << 15)
  431. #define CAUSEB_IV 23
  432. #define CAUSEF_IV (1 << 23)
  433. #define CAUSEB_CE 28
  434. #define CAUSEF_CE (3 << 28)
  435. #define CAUSEB_BD 31
  436. #define CAUSEF_BD (1 << 31)
  437. /*
  438. * Bits in the coprozessor 0 config register.
  439. */
  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_DB (1 << 4)
  450. #define CONF_IB (1 << 5)
  451. #define CONF_SC (1 << 17)
  452. #define CONF_AC (1 << 23)
  453. #define CONF_HALT (1 << 25)
  454. /*
  455. * R10000 performance counter definitions.
  456. *
  457. * FIXME: The R10000 performance counter opens a nice way to implement CPU
  458. * time accounting with a precission of one cycle. I don't have
  459. * R10000 silicon but just a manual, so ...
  460. */
  461. /*
  462. * Events counted by counter #0
  463. */
  464. #define CE0_CYCLES 0
  465. #define CE0_INSN_ISSUED 1
  466. #define CE0_LPSC_ISSUED 2
  467. #define CE0_S_ISSUED 3
  468. #define CE0_SC_ISSUED 4
  469. #define CE0_SC_FAILED 5
  470. #define CE0_BRANCH_DECODED 6
  471. #define CE0_QW_WB_SECONDARY 7
  472. #define CE0_CORRECTED_ECC_ERRORS 8
  473. #define CE0_ICACHE_MISSES 9
  474. #define CE0_SCACHE_I_MISSES 10
  475. #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
  476. #define CE0_EXT_INTERVENTIONS_REQ 12
  477. #define CE0_EXT_INVALIDATE_REQ 13
  478. #define CE0_VIRTUAL_COHERENCY_COND 14
  479. #define CE0_INSN_GRADUATED 15
  480. /*
  481. * Events counted by counter #1
  482. */
  483. #define CE1_CYCLES 0
  484. #define CE1_INSN_GRADUATED 1
  485. #define CE1_LPSC_GRADUATED 2
  486. #define CE1_S_GRADUATED 3
  487. #define CE1_SC_GRADUATED 4
  488. #define CE1_FP_INSN_GRADUATED 5
  489. #define CE1_QW_WB_PRIMARY 6
  490. #define CE1_TLB_REFILL 7
  491. #define CE1_BRANCH_MISSPREDICTED 8
  492. #define CE1_DCACHE_MISS 9
  493. #define CE1_SCACHE_D_MISSES 10
  494. #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
  495. #define CE1_EXT_INTERVENTION_HITS 12
  496. #define CE1_EXT_INVALIDATE_REQ 13
  497. #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
  498. #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
  499. /*
  500. * These flags define in which priviledge mode the counters count events
  501. */
  502. #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
  503. #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
  504. #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
  505. #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
  506. #endif /* _ASM_MIPSREGS_H */