abort-lv4t.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/linkage.h>
  3. #include <asm/assembler.h>
  4. /*
  5. * Function: v4t_late_abort
  6. *
  7. * Params : r2 = pt_regs
  8. * : r4 = aborted context pc
  9. * : r5 = aborted context psr
  10. *
  11. * Returns : r4-r5, r9-r11, r13 preserved
  12. *
  13. * Purpose : obtain information about current aborted instruction.
  14. * Note: we read user space. This means we might cause a data
  15. * abort here if the I-TLB and D-TLB aren't seeing the same
  16. * picture. Unfortunately, this does happen. We live with it.
  17. */
  18. ENTRY(v4t_late_abort)
  19. tst r5, #PSR_T_BIT @ check for thumb mode
  20. #ifdef CONFIG_CPU_CP15_MMU
  21. mrc p15, 0, r1, c5, c0, 0 @ get FSR
  22. mrc p15, 0, r0, c6, c0, 0 @ get FAR
  23. bic r1, r1, #1 << 11 | 1 << 10 @ clear bits 11 and 10 of FSR
  24. #else
  25. mov r0, #0 @ clear r0, r1 (no FSR/FAR)
  26. mov r1, #0
  27. #endif
  28. bne .data_thumb_abort
  29. ldr r8, [r4] @ read arm instruction
  30. uaccess_disable ip @ disable userspace access
  31. tst r8, #1 << 20 @ L = 1 -> write?
  32. orreq r1, r1, #1 << 11 @ yes.
  33. and r7, r8, #15 << 24
  34. add pc, pc, r7, lsr #22 @ Now branch to the relevant processing routine
  35. nop
  36. /* 0 */ b .data_arm_lateldrhpost @ ldrh rd, [rn], #m/rm
  37. /* 1 */ b .data_arm_lateldrhpre @ ldrh rd, [rn, #m/rm]
  38. /* 2 */ b .data_unknown
  39. /* 3 */ b .data_unknown
  40. /* 4 */ b .data_arm_lateldrpostconst @ ldr rd, [rn], #m
  41. /* 5 */ b .data_arm_lateldrpreconst @ ldr rd, [rn, #m]
  42. /* 6 */ b .data_arm_lateldrpostreg @ ldr rd, [rn], rm
  43. /* 7 */ b .data_arm_lateldrprereg @ ldr rd, [rn, rm]
  44. /* 8 */ b .data_arm_ldmstm @ ldm*a rn, <rlist>
  45. /* 9 */ b .data_arm_ldmstm @ ldm*b rn, <rlist>
  46. /* a */ b .data_unknown
  47. /* b */ b .data_unknown
  48. /* c */ b do_DataAbort @ ldc rd, [rn], #m @ Same as ldr rd, [rn], #m
  49. /* d */ b do_DataAbort @ ldc rd, [rn, #m]
  50. /* e */ b .data_unknown
  51. /* f */ b .data_unknown
  52. .data_unknown_r9:
  53. ldr r9, [sp], #4
  54. .data_unknown: @ Part of jumptable
  55. mov r0, r4
  56. mov r1, r8
  57. b baddataabort
  58. .data_arm_ldmstm:
  59. tst r8, #1 << 21 @ check writeback bit
  60. beq do_DataAbort @ no writeback -> no fixup
  61. str r9, [sp, #-4]!
  62. mov r7, #0x11
  63. orr r7, r7, #0x1100
  64. and r6, r8, r7
  65. and r9, r8, r7, lsl #1
  66. add r6, r6, r9, lsr #1
  67. and r9, r8, r7, lsl #2
  68. add r6, r6, r9, lsr #2
  69. and r9, r8, r7, lsl #3
  70. add r6, r6, r9, lsr #3
  71. add r6, r6, r6, lsr #8
  72. add r6, r6, r6, lsr #4
  73. and r6, r6, #15 @ r6 = no. of registers to transfer.
  74. and r9, r8, #15 << 16 @ Extract 'n' from instruction
  75. ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
  76. tst r8, #1 << 23 @ Check U bit
  77. subne r7, r7, r6, lsl #2 @ Undo increment
  78. addeq r7, r7, r6, lsl #2 @ Undo decrement
  79. str r7, [r2, r9, lsr #14] @ Put register 'Rn'
  80. ldr r9, [sp], #4
  81. b do_DataAbort
  82. .data_arm_lateldrhpre:
  83. tst r8, #1 << 21 @ Check writeback bit
  84. beq do_DataAbort @ No writeback -> no fixup
  85. .data_arm_lateldrhpost:
  86. str r9, [sp, #-4]!
  87. and r9, r8, #0x00f @ get Rm / low nibble of immediate value
  88. tst r8, #1 << 22 @ if (immediate offset)
  89. andne r6, r8, #0xf00 @ { immediate high nibble
  90. orrne r6, r9, r6, lsr #4 @ combine nibbles } else
  91. ldreq r6, [r2, r9, lsl #2] @ { load Rm value }
  92. .data_arm_apply_r6_and_rn:
  93. and r9, r8, #15 << 16 @ Extract 'n' from instruction
  94. ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
  95. tst r8, #1 << 23 @ Check U bit
  96. subne r7, r7, r6 @ Undo incrmenet
  97. addeq r7, r7, r6 @ Undo decrement
  98. str r7, [r2, r9, lsr #14] @ Put register 'Rn'
  99. ldr r9, [sp], #4
  100. b do_DataAbort
  101. .data_arm_lateldrpreconst:
  102. tst r8, #1 << 21 @ check writeback bit
  103. beq do_DataAbort @ no writeback -> no fixup
  104. .data_arm_lateldrpostconst:
  105. movs r6, r8, lsl #20 @ Get offset
  106. beq do_DataAbort @ zero -> no fixup
  107. str r9, [sp, #-4]!
  108. and r9, r8, #15 << 16 @ Extract 'n' from instruction
  109. ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
  110. tst r8, #1 << 23 @ Check U bit
  111. subne r7, r7, r6, lsr #20 @ Undo increment
  112. addeq r7, r7, r6, lsr #20 @ Undo decrement
  113. str r7, [r2, r9, lsr #14] @ Put register 'Rn'
  114. ldr r9, [sp], #4
  115. b do_DataAbort
  116. .data_arm_lateldrprereg:
  117. tst r8, #1 << 21 @ check writeback bit
  118. beq do_DataAbort @ no writeback -> no fixup
  119. .data_arm_lateldrpostreg:
  120. and r7, r8, #15 @ Extract 'm' from instruction
  121. ldr r6, [r2, r7, lsl #2] @ Get register 'Rm'
  122. str r9, [sp, #-4]!
  123. mov r9, r8, lsr #7 @ get shift count
  124. ands r9, r9, #31
  125. and r7, r8, #0x70 @ get shift type
  126. orreq r7, r7, #8 @ shift count = 0
  127. add pc, pc, r7
  128. nop
  129. mov r6, r6, lsl r9 @ 0: LSL #!0
  130. b .data_arm_apply_r6_and_rn
  131. b .data_arm_apply_r6_and_rn @ 1: LSL #0
  132. nop
  133. b .data_unknown_r9 @ 2: MUL?
  134. nop
  135. b .data_unknown_r9 @ 3: MUL?
  136. nop
  137. mov r6, r6, lsr r9 @ 4: LSR #!0
  138. b .data_arm_apply_r6_and_rn
  139. mov r6, r6, lsr #32 @ 5: LSR #32
  140. b .data_arm_apply_r6_and_rn
  141. b .data_unknown_r9 @ 6: MUL?
  142. nop
  143. b .data_unknown_r9 @ 7: MUL?
  144. nop
  145. mov r6, r6, asr r9 @ 8: ASR #!0
  146. b .data_arm_apply_r6_and_rn
  147. mov r6, r6, asr #32 @ 9: ASR #32
  148. b .data_arm_apply_r6_and_rn
  149. b .data_unknown_r9 @ A: MUL?
  150. nop
  151. b .data_unknown_r9 @ B: MUL?
  152. nop
  153. mov r6, r6, ror r9 @ C: ROR #!0
  154. b .data_arm_apply_r6_and_rn
  155. mov r6, r6, rrx @ D: RRX
  156. b .data_arm_apply_r6_and_rn
  157. b .data_unknown_r9 @ E: MUL?
  158. nop
  159. b .data_unknown_r9 @ F: MUL?
  160. .data_thumb_abort:
  161. ldrh r8, [r4] @ read instruction
  162. uaccess_disable ip @ disable userspace access
  163. tst r8, #1 << 11 @ L = 1 -> write?
  164. orreq r1, r1, #1 << 8 @ yes
  165. and r7, r8, #15 << 12
  166. add pc, pc, r7, lsr #10 @ lookup in table
  167. nop
  168. /* 0 */ b .data_unknown
  169. /* 1 */ b .data_unknown
  170. /* 2 */ b .data_unknown
  171. /* 3 */ b .data_unknown
  172. /* 4 */ b .data_unknown
  173. /* 5 */ b .data_thumb_reg
  174. /* 6 */ b do_DataAbort
  175. /* 7 */ b do_DataAbort
  176. /* 8 */ b do_DataAbort
  177. /* 9 */ b do_DataAbort
  178. /* A */ b .data_unknown
  179. /* B */ b .data_thumb_pushpop
  180. /* C */ b .data_thumb_ldmstm
  181. /* D */ b .data_unknown
  182. /* E */ b .data_unknown
  183. /* F */ b .data_unknown
  184. .data_thumb_reg:
  185. tst r8, #1 << 9
  186. beq do_DataAbort
  187. tst r8, #1 << 10 @ If 'S' (signed) bit is set
  188. movne r1, #0 @ it must be a load instr
  189. b do_DataAbort
  190. .data_thumb_pushpop:
  191. tst r8, #1 << 10
  192. beq .data_unknown
  193. str r9, [sp, #-4]!
  194. and r6, r8, #0x55 @ hweight8(r8) + R bit
  195. and r9, r8, #0xaa
  196. add r6, r6, r9, lsr #1
  197. and r9, r6, #0xcc
  198. and r6, r6, #0x33
  199. add r6, r6, r9, lsr #2
  200. movs r7, r8, lsr #9 @ C = r8 bit 8 (R bit)
  201. adc r6, r6, r6, lsr #4 @ high + low nibble + R bit
  202. and r6, r6, #15 @ number of regs to transfer
  203. ldr r7, [r2, #13 << 2]
  204. tst r8, #1 << 11
  205. addeq r7, r7, r6, lsl #2 @ increment SP if PUSH
  206. subne r7, r7, r6, lsl #2 @ decrement SP if POP
  207. str r7, [r2, #13 << 2]
  208. ldr r9, [sp], #4
  209. b do_DataAbort
  210. .data_thumb_ldmstm:
  211. str r9, [sp, #-4]!
  212. and r6, r8, #0x55 @ hweight8(r8)
  213. and r9, r8, #0xaa
  214. add r6, r6, r9, lsr #1
  215. and r9, r6, #0xcc
  216. and r6, r6, #0x33
  217. add r6, r6, r9, lsr #2
  218. add r6, r6, r6, lsr #4
  219. and r9, r8, #7 << 8
  220. ldr r7, [r2, r9, lsr #6]
  221. and r6, r6, #15 @ number of regs to transfer
  222. sub r7, r7, r6, lsl #2 @ always decrement
  223. str r7, [r2, r9, lsr #6]
  224. ldr r9, [sp], #4
  225. b do_DataAbort