r4k_fpu.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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) 1996, 98, 99, 2000, 01 Ralf Baechle
  7. *
  8. * Multi-arch abstraction and asm macros for easier reading:
  9. * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  10. *
  11. * Carsten Langgaard, carstenl@mips.com
  12. * Copyright (C) 2000 MIPS Technologies, Inc.
  13. * Copyright (C) 1999, 2001 Silicon Graphics, Inc.
  14. */
  15. #include <asm/asm.h>
  16. #include <asm/asmmacro.h>
  17. #include <asm/errno.h>
  18. #include <asm/export.h>
  19. #include <asm/fpregdef.h>
  20. #include <asm/mipsregs.h>
  21. #include <asm/asm-offsets.h>
  22. #include <asm/regdef.h>
  23. /* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
  24. #undef fp
  25. .macro EX insn, reg, src
  26. .set push
  27. SET_HARDFLOAT
  28. .set nomacro
  29. .ex\@: \insn \reg, \src
  30. .set pop
  31. .section __ex_table,"a"
  32. PTR .ex\@, fault
  33. .previous
  34. .endm
  35. /*
  36. * Save a thread's fp context.
  37. */
  38. LEAF(_save_fp)
  39. EXPORT_SYMBOL(_save_fp)
  40. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \
  41. defined(CONFIG_CPU_MIPSR6)
  42. mfc0 t0, CP0_STATUS
  43. #endif
  44. fpu_save_double a0 t0 t1 # clobbers t1
  45. jr ra
  46. END(_save_fp)
  47. /*
  48. * Restore a thread's fp context.
  49. */
  50. LEAF(_restore_fp)
  51. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \
  52. defined(CONFIG_CPU_MIPSR6)
  53. mfc0 t0, CP0_STATUS
  54. #endif
  55. fpu_restore_double a0 t0 t1 # clobbers t1
  56. jr ra
  57. END(_restore_fp)
  58. #ifdef CONFIG_CPU_HAS_MSA
  59. /*
  60. * Save a thread's MSA vector context.
  61. */
  62. LEAF(_save_msa)
  63. EXPORT_SYMBOL(_save_msa)
  64. msa_save_all a0
  65. jr ra
  66. END(_save_msa)
  67. /*
  68. * Restore a thread's MSA vector context.
  69. */
  70. LEAF(_restore_msa)
  71. msa_restore_all a0
  72. jr ra
  73. END(_restore_msa)
  74. LEAF(_init_msa_upper)
  75. msa_init_all_upper
  76. jr ra
  77. END(_init_msa_upper)
  78. #endif
  79. /*
  80. * Load the FPU with signalling NANS. This bit pattern we're using has
  81. * the property that no matter whether considered as single or as double
  82. * precision represents signaling NANS.
  83. *
  84. * The value to initialize fcr31 to comes in $a0.
  85. */
  86. .set push
  87. SET_HARDFLOAT
  88. LEAF(_init_fpu)
  89. mfc0 t0, CP0_STATUS
  90. li t1, ST0_CU1
  91. or t0, t1
  92. mtc0 t0, CP0_STATUS
  93. enable_fpu_hazard
  94. ctc1 a0, fcr31
  95. li t1, -1 # SNaN
  96. #ifdef CONFIG_64BIT
  97. sll t0, t0, 5
  98. bgez t0, 1f # 16 / 32 register mode?
  99. dmtc1 t1, $f1
  100. dmtc1 t1, $f3
  101. dmtc1 t1, $f5
  102. dmtc1 t1, $f7
  103. dmtc1 t1, $f9
  104. dmtc1 t1, $f11
  105. dmtc1 t1, $f13
  106. dmtc1 t1, $f15
  107. dmtc1 t1, $f17
  108. dmtc1 t1, $f19
  109. dmtc1 t1, $f21
  110. dmtc1 t1, $f23
  111. dmtc1 t1, $f25
  112. dmtc1 t1, $f27
  113. dmtc1 t1, $f29
  114. dmtc1 t1, $f31
  115. 1:
  116. #endif
  117. #ifdef CONFIG_CPU_MIPS32
  118. mtc1 t1, $f0
  119. mtc1 t1, $f1
  120. mtc1 t1, $f2
  121. mtc1 t1, $f3
  122. mtc1 t1, $f4
  123. mtc1 t1, $f5
  124. mtc1 t1, $f6
  125. mtc1 t1, $f7
  126. mtc1 t1, $f8
  127. mtc1 t1, $f9
  128. mtc1 t1, $f10
  129. mtc1 t1, $f11
  130. mtc1 t1, $f12
  131. mtc1 t1, $f13
  132. mtc1 t1, $f14
  133. mtc1 t1, $f15
  134. mtc1 t1, $f16
  135. mtc1 t1, $f17
  136. mtc1 t1, $f18
  137. mtc1 t1, $f19
  138. mtc1 t1, $f20
  139. mtc1 t1, $f21
  140. mtc1 t1, $f22
  141. mtc1 t1, $f23
  142. mtc1 t1, $f24
  143. mtc1 t1, $f25
  144. mtc1 t1, $f26
  145. mtc1 t1, $f27
  146. mtc1 t1, $f28
  147. mtc1 t1, $f29
  148. mtc1 t1, $f30
  149. mtc1 t1, $f31
  150. #if defined(CONFIG_CPU_MIPS32_R2) || defined(CONFIG_CPU_MIPS32_R6)
  151. .set push
  152. .set MIPS_ISA_LEVEL_RAW
  153. .set fp=64
  154. sll t0, t0, 5 # is Status.FR set?
  155. bgez t0, 1f # no: skip setting upper 32b
  156. mthc1 t1, $f0
  157. mthc1 t1, $f1
  158. mthc1 t1, $f2
  159. mthc1 t1, $f3
  160. mthc1 t1, $f4
  161. mthc1 t1, $f5
  162. mthc1 t1, $f6
  163. mthc1 t1, $f7
  164. mthc1 t1, $f8
  165. mthc1 t1, $f9
  166. mthc1 t1, $f10
  167. mthc1 t1, $f11
  168. mthc1 t1, $f12
  169. mthc1 t1, $f13
  170. mthc1 t1, $f14
  171. mthc1 t1, $f15
  172. mthc1 t1, $f16
  173. mthc1 t1, $f17
  174. mthc1 t1, $f18
  175. mthc1 t1, $f19
  176. mthc1 t1, $f20
  177. mthc1 t1, $f21
  178. mthc1 t1, $f22
  179. mthc1 t1, $f23
  180. mthc1 t1, $f24
  181. mthc1 t1, $f25
  182. mthc1 t1, $f26
  183. mthc1 t1, $f27
  184. mthc1 t1, $f28
  185. mthc1 t1, $f29
  186. mthc1 t1, $f30
  187. mthc1 t1, $f31
  188. 1: .set pop
  189. #endif /* CONFIG_CPU_MIPS32_R2 || CONFIG_CPU_MIPS32_R6 */
  190. #else
  191. .set MIPS_ISA_ARCH_LEVEL_RAW
  192. dmtc1 t1, $f0
  193. dmtc1 t1, $f2
  194. dmtc1 t1, $f4
  195. dmtc1 t1, $f6
  196. dmtc1 t1, $f8
  197. dmtc1 t1, $f10
  198. dmtc1 t1, $f12
  199. dmtc1 t1, $f14
  200. dmtc1 t1, $f16
  201. dmtc1 t1, $f18
  202. dmtc1 t1, $f20
  203. dmtc1 t1, $f22
  204. dmtc1 t1, $f24
  205. dmtc1 t1, $f26
  206. dmtc1 t1, $f28
  207. dmtc1 t1, $f30
  208. #endif
  209. jr ra
  210. END(_init_fpu)
  211. .set pop /* SET_HARDFLOAT */
  212. .set noreorder
  213. /**
  214. * _save_fp_context() - save FP context from the FPU
  215. * @a0 - pointer to fpregs field of sigcontext
  216. * @a1 - pointer to fpc_csr field of sigcontext
  217. *
  218. * Save FP context, including the 32 FP data registers and the FP
  219. * control & status register, from the FPU to signal context.
  220. */
  221. LEAF(_save_fp_context)
  222. .set push
  223. SET_HARDFLOAT
  224. cfc1 t1, fcr31
  225. .set pop
  226. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \
  227. defined(CONFIG_CPU_MIPSR6)
  228. .set push
  229. SET_HARDFLOAT
  230. #ifdef CONFIG_CPU_MIPSR2
  231. .set mips32r2
  232. .set fp=64
  233. mfc0 t0, CP0_STATUS
  234. sll t0, t0, 5
  235. bgez t0, 1f # skip storing odd if FR=0
  236. nop
  237. #endif
  238. /* Store the 16 odd double precision registers */
  239. EX sdc1 $f1, 8(a0)
  240. EX sdc1 $f3, 24(a0)
  241. EX sdc1 $f5, 40(a0)
  242. EX sdc1 $f7, 56(a0)
  243. EX sdc1 $f9, 72(a0)
  244. EX sdc1 $f11, 88(a0)
  245. EX sdc1 $f13, 104(a0)
  246. EX sdc1 $f15, 120(a0)
  247. EX sdc1 $f17, 136(a0)
  248. EX sdc1 $f19, 152(a0)
  249. EX sdc1 $f21, 168(a0)
  250. EX sdc1 $f23, 184(a0)
  251. EX sdc1 $f25, 200(a0)
  252. EX sdc1 $f27, 216(a0)
  253. EX sdc1 $f29, 232(a0)
  254. EX sdc1 $f31, 248(a0)
  255. 1: .set pop
  256. #endif
  257. .set push
  258. SET_HARDFLOAT
  259. /* Store the 16 even double precision registers */
  260. EX sdc1 $f0, 0(a0)
  261. EX sdc1 $f2, 16(a0)
  262. EX sdc1 $f4, 32(a0)
  263. EX sdc1 $f6, 48(a0)
  264. EX sdc1 $f8, 64(a0)
  265. EX sdc1 $f10, 80(a0)
  266. EX sdc1 $f12, 96(a0)
  267. EX sdc1 $f14, 112(a0)
  268. EX sdc1 $f16, 128(a0)
  269. EX sdc1 $f18, 144(a0)
  270. EX sdc1 $f20, 160(a0)
  271. EX sdc1 $f22, 176(a0)
  272. EX sdc1 $f24, 192(a0)
  273. EX sdc1 $f26, 208(a0)
  274. EX sdc1 $f28, 224(a0)
  275. EX sdc1 $f30, 240(a0)
  276. EX sw t1, 0(a1)
  277. jr ra
  278. li v0, 0 # success
  279. .set pop
  280. END(_save_fp_context)
  281. /**
  282. * _restore_fp_context() - restore FP context to the FPU
  283. * @a0 - pointer to fpregs field of sigcontext
  284. * @a1 - pointer to fpc_csr field of sigcontext
  285. *
  286. * Restore FP context, including the 32 FP data registers and the FP
  287. * control & status register, from signal context to the FPU.
  288. */
  289. LEAF(_restore_fp_context)
  290. EX lw t1, 0(a1)
  291. #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPSR2) || \
  292. defined(CONFIG_CPU_MIPSR6)
  293. .set push
  294. SET_HARDFLOAT
  295. #ifdef CONFIG_CPU_MIPSR2
  296. .set mips32r2
  297. .set fp=64
  298. mfc0 t0, CP0_STATUS
  299. sll t0, t0, 5
  300. bgez t0, 1f # skip loading odd if FR=0
  301. nop
  302. #endif
  303. EX ldc1 $f1, 8(a0)
  304. EX ldc1 $f3, 24(a0)
  305. EX ldc1 $f5, 40(a0)
  306. EX ldc1 $f7, 56(a0)
  307. EX ldc1 $f9, 72(a0)
  308. EX ldc1 $f11, 88(a0)
  309. EX ldc1 $f13, 104(a0)
  310. EX ldc1 $f15, 120(a0)
  311. EX ldc1 $f17, 136(a0)
  312. EX ldc1 $f19, 152(a0)
  313. EX ldc1 $f21, 168(a0)
  314. EX ldc1 $f23, 184(a0)
  315. EX ldc1 $f25, 200(a0)
  316. EX ldc1 $f27, 216(a0)
  317. EX ldc1 $f29, 232(a0)
  318. EX ldc1 $f31, 248(a0)
  319. 1: .set pop
  320. #endif
  321. .set push
  322. SET_HARDFLOAT
  323. EX ldc1 $f0, 0(a0)
  324. EX ldc1 $f2, 16(a0)
  325. EX ldc1 $f4, 32(a0)
  326. EX ldc1 $f6, 48(a0)
  327. EX ldc1 $f8, 64(a0)
  328. EX ldc1 $f10, 80(a0)
  329. EX ldc1 $f12, 96(a0)
  330. EX ldc1 $f14, 112(a0)
  331. EX ldc1 $f16, 128(a0)
  332. EX ldc1 $f18, 144(a0)
  333. EX ldc1 $f20, 160(a0)
  334. EX ldc1 $f22, 176(a0)
  335. EX ldc1 $f24, 192(a0)
  336. EX ldc1 $f26, 208(a0)
  337. EX ldc1 $f28, 224(a0)
  338. EX ldc1 $f30, 240(a0)
  339. ctc1 t1, fcr31
  340. .set pop
  341. jr ra
  342. li v0, 0 # success
  343. END(_restore_fp_context)
  344. #ifdef CONFIG_CPU_HAS_MSA
  345. .macro op_one_wr op, idx, base
  346. .align 4
  347. \idx: \op \idx, 0, \base
  348. jr ra
  349. nop
  350. .endm
  351. .macro op_msa_wr name, op
  352. LEAF(\name)
  353. .set push
  354. .set noreorder
  355. sll t0, a0, 4
  356. PTR_LA t1, 0f
  357. PTR_ADDU t0, t0, t1
  358. jr t0
  359. nop
  360. op_one_wr \op, 0, a1
  361. op_one_wr \op, 1, a1
  362. op_one_wr \op, 2, a1
  363. op_one_wr \op, 3, a1
  364. op_one_wr \op, 4, a1
  365. op_one_wr \op, 5, a1
  366. op_one_wr \op, 6, a1
  367. op_one_wr \op, 7, a1
  368. op_one_wr \op, 8, a1
  369. op_one_wr \op, 9, a1
  370. op_one_wr \op, 10, a1
  371. op_one_wr \op, 11, a1
  372. op_one_wr \op, 12, a1
  373. op_one_wr \op, 13, a1
  374. op_one_wr \op, 14, a1
  375. op_one_wr \op, 15, a1
  376. op_one_wr \op, 16, a1
  377. op_one_wr \op, 17, a1
  378. op_one_wr \op, 18, a1
  379. op_one_wr \op, 19, a1
  380. op_one_wr \op, 20, a1
  381. op_one_wr \op, 21, a1
  382. op_one_wr \op, 22, a1
  383. op_one_wr \op, 23, a1
  384. op_one_wr \op, 24, a1
  385. op_one_wr \op, 25, a1
  386. op_one_wr \op, 26, a1
  387. op_one_wr \op, 27, a1
  388. op_one_wr \op, 28, a1
  389. op_one_wr \op, 29, a1
  390. op_one_wr \op, 30, a1
  391. op_one_wr \op, 31, a1
  392. .set pop
  393. END(\name)
  394. .endm
  395. op_msa_wr read_msa_wr_b, st_b
  396. op_msa_wr read_msa_wr_h, st_h
  397. op_msa_wr read_msa_wr_w, st_w
  398. op_msa_wr read_msa_wr_d, st_d
  399. op_msa_wr write_msa_wr_b, ld_b
  400. op_msa_wr write_msa_wr_h, ld_h
  401. op_msa_wr write_msa_wr_w, ld_w
  402. op_msa_wr write_msa_wr_d, ld_d
  403. #endif /* CONFIG_CPU_HAS_MSA */
  404. #ifdef CONFIG_CPU_HAS_MSA
  405. .macro save_msa_upper wr, off, base
  406. .set push
  407. .set noat
  408. #ifdef CONFIG_64BIT
  409. copy_s_d \wr, 1
  410. EX sd $1, \off(\base)
  411. #elif defined(CONFIG_CPU_LITTLE_ENDIAN)
  412. copy_s_w \wr, 2
  413. EX sw $1, \off(\base)
  414. copy_s_w \wr, 3
  415. EX sw $1, (\off+4)(\base)
  416. #else /* CONFIG_CPU_BIG_ENDIAN */
  417. copy_s_w \wr, 2
  418. EX sw $1, (\off+4)(\base)
  419. copy_s_w \wr, 3
  420. EX sw $1, \off(\base)
  421. #endif
  422. .set pop
  423. .endm
  424. LEAF(_save_msa_all_upper)
  425. save_msa_upper 0, 0x00, a0
  426. save_msa_upper 1, 0x08, a0
  427. save_msa_upper 2, 0x10, a0
  428. save_msa_upper 3, 0x18, a0
  429. save_msa_upper 4, 0x20, a0
  430. save_msa_upper 5, 0x28, a0
  431. save_msa_upper 6, 0x30, a0
  432. save_msa_upper 7, 0x38, a0
  433. save_msa_upper 8, 0x40, a0
  434. save_msa_upper 9, 0x48, a0
  435. save_msa_upper 10, 0x50, a0
  436. save_msa_upper 11, 0x58, a0
  437. save_msa_upper 12, 0x60, a0
  438. save_msa_upper 13, 0x68, a0
  439. save_msa_upper 14, 0x70, a0
  440. save_msa_upper 15, 0x78, a0
  441. save_msa_upper 16, 0x80, a0
  442. save_msa_upper 17, 0x88, a0
  443. save_msa_upper 18, 0x90, a0
  444. save_msa_upper 19, 0x98, a0
  445. save_msa_upper 20, 0xa0, a0
  446. save_msa_upper 21, 0xa8, a0
  447. save_msa_upper 22, 0xb0, a0
  448. save_msa_upper 23, 0xb8, a0
  449. save_msa_upper 24, 0xc0, a0
  450. save_msa_upper 25, 0xc8, a0
  451. save_msa_upper 26, 0xd0, a0
  452. save_msa_upper 27, 0xd8, a0
  453. save_msa_upper 28, 0xe0, a0
  454. save_msa_upper 29, 0xe8, a0
  455. save_msa_upper 30, 0xf0, a0
  456. save_msa_upper 31, 0xf8, a0
  457. jr ra
  458. li v0, 0
  459. END(_save_msa_all_upper)
  460. .macro restore_msa_upper wr, off, base
  461. .set push
  462. .set noat
  463. #ifdef CONFIG_64BIT
  464. EX ld $1, \off(\base)
  465. insert_d \wr, 1
  466. #elif defined(CONFIG_CPU_LITTLE_ENDIAN)
  467. EX lw $1, \off(\base)
  468. insert_w \wr, 2
  469. EX lw $1, (\off+4)(\base)
  470. insert_w \wr, 3
  471. #else /* CONFIG_CPU_BIG_ENDIAN */
  472. EX lw $1, (\off+4)(\base)
  473. insert_w \wr, 2
  474. EX lw $1, \off(\base)
  475. insert_w \wr, 3
  476. #endif
  477. .set pop
  478. .endm
  479. LEAF(_restore_msa_all_upper)
  480. restore_msa_upper 0, 0x00, a0
  481. restore_msa_upper 1, 0x08, a0
  482. restore_msa_upper 2, 0x10, a0
  483. restore_msa_upper 3, 0x18, a0
  484. restore_msa_upper 4, 0x20, a0
  485. restore_msa_upper 5, 0x28, a0
  486. restore_msa_upper 6, 0x30, a0
  487. restore_msa_upper 7, 0x38, a0
  488. restore_msa_upper 8, 0x40, a0
  489. restore_msa_upper 9, 0x48, a0
  490. restore_msa_upper 10, 0x50, a0
  491. restore_msa_upper 11, 0x58, a0
  492. restore_msa_upper 12, 0x60, a0
  493. restore_msa_upper 13, 0x68, a0
  494. restore_msa_upper 14, 0x70, a0
  495. restore_msa_upper 15, 0x78, a0
  496. restore_msa_upper 16, 0x80, a0
  497. restore_msa_upper 17, 0x88, a0
  498. restore_msa_upper 18, 0x90, a0
  499. restore_msa_upper 19, 0x98, a0
  500. restore_msa_upper 20, 0xa0, a0
  501. restore_msa_upper 21, 0xa8, a0
  502. restore_msa_upper 22, 0xb0, a0
  503. restore_msa_upper 23, 0xb8, a0
  504. restore_msa_upper 24, 0xc0, a0
  505. restore_msa_upper 25, 0xc8, a0
  506. restore_msa_upper 26, 0xd0, a0
  507. restore_msa_upper 27, 0xd8, a0
  508. restore_msa_upper 28, 0xe0, a0
  509. restore_msa_upper 29, 0xe8, a0
  510. restore_msa_upper 30, 0xf0, a0
  511. restore_msa_upper 31, 0xf8, a0
  512. jr ra
  513. li v0, 0
  514. END(_restore_msa_all_upper)
  515. #endif /* CONFIG_CPU_HAS_MSA */
  516. .set reorder
  517. .type fault, @function
  518. .ent fault
  519. fault: li v0, -EFAULT # failure
  520. jr ra
  521. .end fault