blob: 4cdfab31a0b612d11f1ad88c7985e007620fdca1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/linkage.h>
2#include <asm/assembler.h>
3/*
4 * Function: v4t_late_abort
5 *
Russell Kingda740472011-06-26 16:01:26 +01006 * Params : r2 = pt_regs
7 * : r4 = aborted context pc
Russell King3e287be2011-06-26 14:35:07 +01008 * : r5 = aborted context psr
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Russell King04946fb2016-10-18 10:24:49 +010010 * Returns : r4-r5, r9-r11, r13 preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
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 */
17ENTRY(v4t_late_abort)
Russell King3e287be2011-06-26 14:35:07 +010018 tst r5, #PSR_T_BIT @ check for thumb mode
Hyok S. Choi0f45d7f2006-09-28 21:46:16 +090019#ifdef CONFIG_CPU_CP15_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 mrc p15, 0, r1, c5, c0, 0 @ get FSR
21 mrc p15, 0, r0, c6, c0, 0 @ get FAR
Hyok S. Choi0f45d7f2006-09-28 21:46:16 +090022 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 bne .data_thumb_abort
Russell King3e287be2011-06-26 14:35:07 +010028 ldr r8, [r4] @ read arm instruction
Russell King2190fed2015-08-20 10:32:02 +010029 uaccess_disable ip @ disable userspace access
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 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
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
Russell Kingda740472011-06-26 16:01:26 +010048/* c */ b do_DataAbort @ ldc rd, [rn], #m @ Same as ldr rd, [rn], #m
49/* d */ b do_DataAbort @ ldc rd, [rn, #m]
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* e */ b .data_unknown
Russell King04946fb2016-10-18 10:24:49 +010051/* f */ b .data_unknown
52
53.data_unknown_r9:
54 ldr r9, [sp], #4
Linus Torvalds1da177e2005-04-16 15:20:36 -070055.data_unknown: @ Part of jumptable
Russell King3e287be2011-06-26 14:35:07 +010056 mov r0, r4
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 mov r1, r8
Russell Kingda740472011-06-26 16:01:26 +010058 b baddataabort
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60.data_arm_ldmstm:
61 tst r8, #1 << 21 @ check writeback bit
Russell Kingda740472011-06-26 16:01:26 +010062 beq do_DataAbort @ no writeback -> no fixup
Russell King04946fb2016-10-18 10:24:49 +010063 str r9, [sp, #-4]!
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 mov r7, #0x11
65 orr r7, r7, #0x1100
66 and r6, r8, r7
Russell King0d147db2011-06-26 14:42:02 +010067 and r9, r8, r7, lsl #1
68 add r6, r6, r9, lsr #1
69 and r9, r8, r7, lsl #2
70 add r6, r6, r9, lsr #2
71 and r9, r8, r7, lsl #3
72 add r6, r6, r9, lsr #3
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 add r6, r6, r6, lsr #8
74 add r6, r6, r6, lsr #4
75 and r6, r6, #15 @ r6 = no. of registers to transfer.
Russell King40f0b902011-06-27 12:27:47 +010076 and r9, r8, #15 << 16 @ Extract 'n' from instruction
77 ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 tst r8, #1 << 23 @ Check U bit
79 subne r7, r7, r6, lsl #2 @ Undo increment
80 addeq r7, r7, r6, lsl #2 @ Undo decrement
Russell King40f0b902011-06-27 12:27:47 +010081 str r7, [r2, r9, lsr #14] @ Put register 'Rn'
Russell King04946fb2016-10-18 10:24:49 +010082 ldr r9, [sp], #4
Russell Kingda740472011-06-26 16:01:26 +010083 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85.data_arm_lateldrhpre:
86 tst r8, #1 << 21 @ Check writeback bit
Russell Kingda740472011-06-26 16:01:26 +010087 beq do_DataAbort @ No writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -070088.data_arm_lateldrhpost:
Russell King04946fb2016-10-18 10:24:49 +010089 str r9, [sp, #-4]!
Russell King40f0b902011-06-27 12:27:47 +010090 and r9, r8, #0x00f @ get Rm / low nibble of immediate value
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 tst r8, #1 << 22 @ if (immediate offset)
92 andne r6, r8, #0xf00 @ { immediate high nibble
Russell King40f0b902011-06-27 12:27:47 +010093 orrne r6, r9, r6, lsr #4 @ combine nibbles } else
94 ldreq r6, [r2, r9, lsl #2] @ { load Rm value }
Linus Torvalds1da177e2005-04-16 15:20:36 -070095.data_arm_apply_r6_and_rn:
Russell King40f0b902011-06-27 12:27:47 +010096 and r9, r8, #15 << 16 @ Extract 'n' from instruction
97 ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 tst r8, #1 << 23 @ Check U bit
99 subne r7, r7, r6 @ Undo incrmenet
100 addeq r7, r7, r6 @ Undo decrement
Russell King40f0b902011-06-27 12:27:47 +0100101 str r7, [r2, r9, lsr #14] @ Put register 'Rn'
Russell King04946fb2016-10-18 10:24:49 +0100102 ldr r9, [sp], #4
Russell Kingda740472011-06-26 16:01:26 +0100103 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105.data_arm_lateldrpreconst:
106 tst r8, #1 << 21 @ check writeback bit
Russell Kingda740472011-06-26 16:01:26 +0100107 beq do_DataAbort @ no writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108.data_arm_lateldrpostconst:
Russell King108f6af2011-06-27 12:23:11 +0100109 movs r6, r8, lsl #20 @ Get offset
Russell Kingda740472011-06-26 16:01:26 +0100110 beq do_DataAbort @ zero -> no fixup
Russell King04946fb2016-10-18 10:24:49 +0100111 str r9, [sp, #-4]!
Russell King40f0b902011-06-27 12:27:47 +0100112 and r9, r8, #15 << 16 @ Extract 'n' from instruction
113 ldr r7, [r2, r9, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 tst r8, #1 << 23 @ Check U bit
Russell King108f6af2011-06-27 12:23:11 +0100115 subne r7, r7, r6, lsr #20 @ Undo increment
116 addeq r7, r7, r6, lsr #20 @ Undo decrement
Russell King40f0b902011-06-27 12:27:47 +0100117 str r7, [r2, r9, lsr #14] @ Put register 'Rn'
Russell King04946fb2016-10-18 10:24:49 +0100118 ldr r9, [sp], #4
Russell Kingda740472011-06-26 16:01:26 +0100119 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121.data_arm_lateldrprereg:
122 tst r8, #1 << 21 @ check writeback bit
Russell Kingda740472011-06-26 16:01:26 +0100123 beq do_DataAbort @ no writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124.data_arm_lateldrpostreg:
125 and r7, r8, #15 @ Extract 'm' from instruction
Russell Kinge22c12f2011-06-27 09:52:54 +0100126 ldr r6, [r2, r7, lsl #2] @ Get register 'Rm'
Russell King04946fb2016-10-18 10:24:49 +0100127 str r9, [sp, #-4]!
Russell King40f0b902011-06-27 12:27:47 +0100128 mov r9, r8, lsr #7 @ get shift count
129 ands r9, r9, #31
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 and r7, r8, #0x70 @ get shift type
131 orreq r7, r7, #8 @ shift count = 0
132 add pc, pc, r7
133 nop
134
Russell King40f0b902011-06-27 12:27:47 +0100135 mov r6, r6, lsl r9 @ 0: LSL #!0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 b .data_arm_apply_r6_and_rn
137 b .data_arm_apply_r6_and_rn @ 1: LSL #0
138 nop
Russell King04946fb2016-10-18 10:24:49 +0100139 b .data_unknown_r9 @ 2: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 nop
Russell King04946fb2016-10-18 10:24:49 +0100141 b .data_unknown_r9 @ 3: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 nop
Russell King40f0b902011-06-27 12:27:47 +0100143 mov r6, r6, lsr r9 @ 4: LSR #!0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 b .data_arm_apply_r6_and_rn
145 mov r6, r6, lsr #32 @ 5: LSR #32
146 b .data_arm_apply_r6_and_rn
Russell King04946fb2016-10-18 10:24:49 +0100147 b .data_unknown_r9 @ 6: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 nop
Russell King04946fb2016-10-18 10:24:49 +0100149 b .data_unknown_r9 @ 7: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 nop
Russell King40f0b902011-06-27 12:27:47 +0100151 mov r6, r6, asr r9 @ 8: ASR #!0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 b .data_arm_apply_r6_and_rn
153 mov r6, r6, asr #32 @ 9: ASR #32
154 b .data_arm_apply_r6_and_rn
Russell King04946fb2016-10-18 10:24:49 +0100155 b .data_unknown_r9 @ A: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 nop
Russell King04946fb2016-10-18 10:24:49 +0100157 b .data_unknown_r9 @ B: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 nop
Russell King40f0b902011-06-27 12:27:47 +0100159 mov r6, r6, ror r9 @ C: ROR #!0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 b .data_arm_apply_r6_and_rn
161 mov r6, r6, rrx @ D: RRX
162 b .data_arm_apply_r6_and_rn
Russell King04946fb2016-10-18 10:24:49 +0100163 b .data_unknown_r9 @ E: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 nop
Russell King04946fb2016-10-18 10:24:49 +0100165 b .data_unknown_r9 @ F: MUL?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167.data_thumb_abort:
Russell King3e287be2011-06-26 14:35:07 +0100168 ldrh r8, [r4] @ read instruction
Russell King2190fed2015-08-20 10:32:02 +0100169 uaccess_disable ip @ disable userspace access
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 tst r8, #1 << 11 @ L = 1 -> write?
171 orreq r1, r1, #1 << 8 @ yes
172 and r7, r8, #15 << 12
173 add pc, pc, r7, lsr #10 @ lookup in table
174 nop
175
176/* 0 */ b .data_unknown
177/* 1 */ b .data_unknown
178/* 2 */ b .data_unknown
179/* 3 */ b .data_unknown
180/* 4 */ b .data_unknown
181/* 5 */ b .data_thumb_reg
Russell Kingda740472011-06-26 16:01:26 +0100182/* 6 */ b do_DataAbort
183/* 7 */ b do_DataAbort
184/* 8 */ b do_DataAbort
185/* 9 */ b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/* A */ b .data_unknown
187/* B */ b .data_thumb_pushpop
188/* C */ b .data_thumb_ldmstm
189/* D */ b .data_unknown
190/* E */ b .data_unknown
191/* F */ b .data_unknown
192
193.data_thumb_reg:
194 tst r8, #1 << 9
Russell Kingda740472011-06-26 16:01:26 +0100195 beq do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 tst r8, #1 << 10 @ If 'S' (signed) bit is set
197 movne r1, #0 @ it must be a load instr
Russell Kingda740472011-06-26 16:01:26 +0100198 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200.data_thumb_pushpop:
201 tst r8, #1 << 10
202 beq .data_unknown
Russell King04946fb2016-10-18 10:24:49 +0100203 str r9, [sp, #-4]!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 and r6, r8, #0x55 @ hweight8(r8) + R bit
Russell King0d147db2011-06-26 14:42:02 +0100205 and r9, r8, #0xaa
206 add r6, r6, r9, lsr #1
207 and r9, r6, #0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 and r6, r6, #0x33
Russell King0d147db2011-06-26 14:42:02 +0100209 add r6, r6, r9, lsr #2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 movs r7, r8, lsr #9 @ C = r8 bit 8 (R bit)
211 adc r6, r6, r6, lsr #4 @ high + low nibble + R bit
212 and r6, r6, #15 @ number of regs to transfer
Russell Kinge22c12f2011-06-27 09:52:54 +0100213 ldr r7, [r2, #13 << 2]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 tst r8, #1 << 11
215 addeq r7, r7, r6, lsl #2 @ increment SP if PUSH
216 subne r7, r7, r6, lsl #2 @ decrement SP if POP
Russell Kinge22c12f2011-06-27 09:52:54 +0100217 str r7, [r2, #13 << 2]
Russell King04946fb2016-10-18 10:24:49 +0100218 ldr r9, [sp], #4
Russell Kingda740472011-06-26 16:01:26 +0100219 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221.data_thumb_ldmstm:
Russell King04946fb2016-10-18 10:24:49 +0100222 str r9, [sp, #-4]!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 and r6, r8, #0x55 @ hweight8(r8)
Russell King0d147db2011-06-26 14:42:02 +0100224 and r9, r8, #0xaa
225 add r6, r6, r9, lsr #1
226 and r9, r6, #0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 and r6, r6, #0x33
Russell King0d147db2011-06-26 14:42:02 +0100228 add r6, r6, r9, lsr #2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 add r6, r6, r6, lsr #4
Russell King40f0b902011-06-27 12:27:47 +0100230 and r9, r8, #7 << 8
231 ldr r7, [r2, r9, lsr #6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 and r6, r6, #15 @ number of regs to transfer
233 sub r7, r7, r6, lsl #2 @ always decrement
Russell King40f0b902011-06-27 12:27:47 +0100234 str r7, [r2, r9, lsr #6]
Russell King04946fb2016-10-18 10:24:49 +0100235 ldr r9, [sp], #4
Russell Kingda740472011-06-26 16:01:26 +0100236 b do_DataAbort