mipsregs.h 16 KB

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