vfphw.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * linux/arch/arm/vfp/vfphw.S
  3. *
  4. * Copyright (C) 2004 ARM Limited.
  5. * Written by Deep Blue Solutions Limited.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This code is called from the kernel's undefined instruction trap.
  12. * r9 holds the return address for successful handling.
  13. * lr holds the return address for unrecognised instructions.
  14. * r10 points at the start of the private FP workspace in the thread structure
  15. * sp points to a struct pt_regs (as defined in include/asm/proc/ptrace.h)
  16. */
  17. #include <asm/thread_info.h>
  18. #include <asm/vfpmacros.h>
  19. #include "../kernel/entry-header.S"
  20. .macro DBGSTR, str
  21. #ifdef DEBUG
  22. stmfd sp!, {r0-r3, ip, lr}
  23. add r0, pc, #4
  24. bl printk
  25. b 1f
  26. .asciz "<7>VFP: \str\n"
  27. .balign 4
  28. 1: ldmfd sp!, {r0-r3, ip, lr}
  29. #endif
  30. .endm
  31. .macro DBGSTR1, str, arg
  32. #ifdef DEBUG
  33. stmfd sp!, {r0-r3, ip, lr}
  34. mov r1, \arg
  35. add r0, pc, #4
  36. bl printk
  37. b 1f
  38. .asciz "<7>VFP: \str\n"
  39. .balign 4
  40. 1: ldmfd sp!, {r0-r3, ip, lr}
  41. #endif
  42. .endm
  43. .macro DBGSTR3, str, arg1, arg2, arg3
  44. #ifdef DEBUG
  45. stmfd sp!, {r0-r3, ip, lr}
  46. mov r3, \arg3
  47. mov r2, \arg2
  48. mov r1, \arg1
  49. add r0, pc, #4
  50. bl printk
  51. b 1f
  52. .asciz "<7>VFP: \str\n"
  53. .balign 4
  54. 1: ldmfd sp!, {r0-r3, ip, lr}
  55. #endif
  56. .endm
  57. @ VFP hardware support entry point.
  58. @
  59. @ r0 = faulted instruction
  60. @ r2 = faulted PC+4
  61. @ r9 = successful return
  62. @ r10 = vfp_state union
  63. @ r11 = CPU number
  64. @ lr = failure return
  65. ENTRY(vfp_support_entry)
  66. DBGSTR3 "instr %08x pc %08x state %p", r0, r2, r10
  67. VFPFMRX r1, FPEXC @ Is the VFP enabled?
  68. DBGSTR1 "fpexc %08x", r1
  69. tst r1, #FPEXC_EN
  70. bne look_for_VFP_exceptions @ VFP is already enabled
  71. DBGSTR1 "enable %x", r10
  72. ldr r3, last_VFP_context_address
  73. orr r1, r1, #FPEXC_EN @ user FPEXC has the enable bit set
  74. ldr r4, [r3, r11, lsl #2] @ last_VFP_context pointer
  75. bic r5, r1, #FPEXC_EX @ make sure exceptions are disabled
  76. cmp r4, r10
  77. beq check_for_exception @ we are returning to the same
  78. @ process, so the registers are
  79. @ still there. In this case, we do
  80. @ not want to drop a pending exception.
  81. VFPFMXR FPEXC, r5 @ enable VFP, disable any pending
  82. @ exceptions, so we can get at the
  83. @ rest of it
  84. #ifndef CONFIG_SMP
  85. @ Save out the current registers to the old thread state
  86. @ No need for SMP since this is not done lazily
  87. DBGSTR1 "save old state %p", r4
  88. cmp r4, #0
  89. beq no_old_VFP_process
  90. VFPFSTMIA r4, r5 @ save the working registers
  91. VFPFMRX r5, FPSCR @ current status
  92. tst r1, #FPEXC_EX @ is there additional state to save?
  93. beq 1f
  94. VFPFMRX r6, FPINST @ FPINST (only if FPEXC.EX is set)
  95. tst r1, #FPEXC_FP2V @ is there an FPINST2 to read?
  96. beq 1f
  97. VFPFMRX r8, FPINST2 @ FPINST2 if needed (and present)
  98. 1:
  99. stmia r4, {r1, r5, r6, r8} @ save FPEXC, FPSCR, FPINST, FPINST2
  100. @ and point r4 at the word at the
  101. @ start of the register dump
  102. #endif
  103. no_old_VFP_process:
  104. DBGSTR1 "load state %p", r10
  105. str r10, [r3, r11, lsl #2] @ update the last_VFP_context pointer
  106. @ Load the saved state back into the VFP
  107. VFPFLDMIA r10, r5 @ reload the working registers while
  108. @ FPEXC is in a safe state
  109. ldmia r10, {r1, r5, r6, r8} @ load FPEXC, FPSCR, FPINST, FPINST2
  110. tst r1, #FPEXC_EX @ is there additional state to restore?
  111. beq 1f
  112. VFPFMXR FPINST, r6 @ restore FPINST (only if FPEXC.EX is set)
  113. tst r1, #FPEXC_FP2V @ is there an FPINST2 to write?
  114. beq 1f
  115. VFPFMXR FPINST2, r8 @ FPINST2 if needed (and present)
  116. 1:
  117. VFPFMXR FPSCR, r5 @ restore status
  118. check_for_exception:
  119. tst r1, #FPEXC_EX
  120. bne process_exception @ might as well handle the pending
  121. @ exception before retrying branch
  122. @ out before setting an FPEXC that
  123. @ stops us reading stuff
  124. VFPFMXR FPEXC, r1 @ restore FPEXC last
  125. sub r2, r2, #4
  126. str r2, [sp, #S_PC] @ retry the instruction
  127. #ifdef CONFIG_PREEMPT
  128. get_thread_info r10
  129. ldr r4, [r10, #TI_PREEMPT] @ get preempt count
  130. sub r11, r4, #1 @ decrement it
  131. str r11, [r10, #TI_PREEMPT]
  132. #endif
  133. mov pc, r9 @ we think we have handled things
  134. look_for_VFP_exceptions:
  135. @ Check for synchronous or asynchronous exception
  136. tst r1, #FPEXC_EX | FPEXC_DEX
  137. bne process_exception
  138. @ On some implementations of the VFP subarch 1, setting FPSCR.IXE
  139. @ causes all the CDP instructions to be bounced synchronously without
  140. @ setting the FPEXC.EX bit
  141. VFPFMRX r5, FPSCR
  142. tst r5, #FPSCR_IXE
  143. bne process_exception
  144. @ Fall into hand on to next handler - appropriate coproc instr
  145. @ not recognised by VFP
  146. DBGSTR "not VFP"
  147. #ifdef CONFIG_PREEMPT
  148. get_thread_info r10
  149. ldr r4, [r10, #TI_PREEMPT] @ get preempt count
  150. sub r11, r4, #1 @ decrement it
  151. str r11, [r10, #TI_PREEMPT]
  152. #endif
  153. mov pc, lr
  154. process_exception:
  155. DBGSTR "bounce"
  156. mov r2, sp @ nothing stacked - regdump is at TOS
  157. mov lr, r9 @ setup for a return to the user code.
  158. @ Now call the C code to package up the bounce to the support code
  159. @ r0 holds the trigger instruction
  160. @ r1 holds the FPEXC value
  161. @ r2 pointer to register dump
  162. b VFP_bounce @ we have handled this - the support
  163. @ code will raise an exception if
  164. @ required. If not, the user code will
  165. @ retry the faulted instruction
  166. ENDPROC(vfp_support_entry)
  167. ENTRY(vfp_save_state)
  168. @ Save the current VFP state
  169. @ r0 - save location
  170. @ r1 - FPEXC
  171. DBGSTR1 "save VFP state %p", r0
  172. VFPFSTMIA r0, r2 @ save the working registers
  173. VFPFMRX r2, FPSCR @ current status
  174. tst r1, #FPEXC_EX @ is there additional state to save?
  175. beq 1f
  176. VFPFMRX r3, FPINST @ FPINST (only if FPEXC.EX is set)
  177. tst r1, #FPEXC_FP2V @ is there an FPINST2 to read?
  178. beq 1f
  179. VFPFMRX r12, FPINST2 @ FPINST2 if needed (and present)
  180. 1:
  181. stmia r0, {r1, r2, r3, r12} @ save FPEXC, FPSCR, FPINST, FPINST2
  182. mov pc, lr
  183. ENDPROC(vfp_save_state)
  184. last_VFP_context_address:
  185. .word last_VFP_context
  186. ENTRY(vfp_get_float)
  187. add pc, pc, r0, lsl #3
  188. mov r0, r0
  189. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  190. mrc p10, 0, r0, c\dr, c0, 0 @ fmrs r0, s0
  191. mov pc, lr
  192. mrc p10, 0, r0, c\dr, c0, 4 @ fmrs r0, s1
  193. mov pc, lr
  194. .endr
  195. ENDPROC(vfp_get_float)
  196. ENTRY(vfp_put_float)
  197. add pc, pc, r1, lsl #3
  198. mov r0, r0
  199. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  200. mcr p10, 0, r0, c\dr, c0, 0 @ fmsr r0, s0
  201. mov pc, lr
  202. mcr p10, 0, r0, c\dr, c0, 4 @ fmsr r0, s1
  203. mov pc, lr
  204. .endr
  205. ENDPROC(vfp_put_float)
  206. ENTRY(vfp_get_double)
  207. add pc, pc, r0, lsl #3
  208. mov r0, r0
  209. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  210. fmrrd r0, r1, d\dr
  211. mov pc, lr
  212. .endr
  213. #ifdef CONFIG_VFPv3
  214. @ d16 - d31 registers
  215. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  216. mrrc p11, 3, r0, r1, c\dr @ fmrrd r0, r1, d\dr
  217. mov pc, lr
  218. .endr
  219. #endif
  220. @ virtual register 16 (or 32 if VFPv3) for compare with zero
  221. mov r0, #0
  222. mov r1, #0
  223. mov pc, lr
  224. ENDPROC(vfp_get_double)
  225. ENTRY(vfp_put_double)
  226. add pc, pc, r2, lsl #3
  227. mov r0, r0
  228. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  229. fmdrr d\dr, r0, r1
  230. mov pc, lr
  231. .endr
  232. #ifdef CONFIG_VFPv3
  233. @ d16 - d31 registers
  234. .irp dr,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  235. mcrr p11, 3, r1, r2, c\dr @ fmdrr r1, r2, d\dr
  236. mov pc, lr
  237. .endr
  238. #endif
  239. ENDPROC(vfp_put_double)