abort-lv4t.S 6.7 KB

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