blob: 921aaab0c8c5c4f923835a7f6a1117caef33c647 [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 *
10 * Returns : r0 = address of abort
11 * : r1 = FSR, bit 11 = write
12 * : r2-r8 = corrupted
13 * : r9 = preserved
14 * : sp = pointer to registers
15 *
16 * Purpose : obtain information about current aborted instruction.
17 * Note: we read user space. This means we might cause a data
18 * abort here if the I-TLB and D-TLB aren't seeing the same
19 * picture. Unfortunately, this does happen. We live with it.
20 */
21ENTRY(v4t_late_abort)
Russell King3e287be2011-06-26 14:35:07 +010022 tst r5, #PSR_T_BIT @ check for thumb mode
Hyok S. Choi0f45d7f2006-09-28 21:46:16 +090023#ifdef CONFIG_CPU_CP15_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 mrc p15, 0, r1, c5, c0, 0 @ get FSR
25 mrc p15, 0, r0, c6, c0, 0 @ get FAR
Hyok S. Choi0f45d7f2006-09-28 21:46:16 +090026 bic r1, r1, #1 << 11 | 1 << 10 @ clear bits 11 and 10 of FSR
27#else
28 mov r0, #0 @ clear r0, r1 (no FSR/FAR)
29 mov r1, #0
30#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 bne .data_thumb_abort
Russell King3e287be2011-06-26 14:35:07 +010032 ldr r8, [r4] @ read arm instruction
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 tst r8, #1 << 20 @ L = 1 -> write?
34 orreq r1, r1, #1 << 11 @ yes.
35 and r7, r8, #15 << 24
36 add pc, pc, r7, lsr #22 @ Now branch to the relevant processing routine
37 nop
38
39/* 0 */ b .data_arm_lateldrhpost @ ldrh rd, [rn], #m/rm
40/* 1 */ b .data_arm_lateldrhpre @ ldrh rd, [rn, #m/rm]
41/* 2 */ b .data_unknown
42/* 3 */ b .data_unknown
43/* 4 */ b .data_arm_lateldrpostconst @ ldr rd, [rn], #m
44/* 5 */ b .data_arm_lateldrpreconst @ ldr rd, [rn, #m]
45/* 6 */ b .data_arm_lateldrpostreg @ ldr rd, [rn], rm
46/* 7 */ b .data_arm_lateldrprereg @ ldr rd, [rn, rm]
47/* 8 */ b .data_arm_ldmstm @ ldm*a rn, <rlist>
48/* 9 */ b .data_arm_ldmstm @ ldm*b rn, <rlist>
49/* a */ b .data_unknown
50/* b */ b .data_unknown
Russell Kingda740472011-06-26 16:01:26 +010051/* c */ b do_DataAbort @ ldc rd, [rn], #m @ Same as ldr rd, [rn], #m
52/* d */ b do_DataAbort @ ldc rd, [rn, #m]
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/* e */ b .data_unknown
54/* f */
55.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
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 mov r7, #0x11
64 orr r7, r7, #0x1100
65 and r6, r8, r7
Russell King0d147db2011-06-26 14:42:02 +010066 and r9, r8, r7, lsl #1
67 add r6, r6, r9, lsr #1
68 and r9, r8, r7, lsl #2
69 add r6, r6, r9, lsr #2
70 and r9, r8, r7, lsl #3
71 add r6, r6, r9, lsr #3
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 add r6, r6, r6, lsr #8
73 add r6, r6, r6, lsr #4
74 and r6, r6, #15 @ r6 = no. of registers to transfer.
75 and r5, r8, #15 << 16 @ Extract 'n' from instruction
Russell Kinge22c12f2011-06-27 09:52:54 +010076 ldr r7, [r2, r5, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 tst r8, #1 << 23 @ Check U bit
78 subne r7, r7, r6, lsl #2 @ Undo increment
79 addeq r7, r7, r6, lsl #2 @ Undo decrement
Russell Kinge22c12f2011-06-27 09:52:54 +010080 str r7, [r2, r5, lsr #14] @ Put register 'Rn'
Russell Kingda740472011-06-26 16:01:26 +010081 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83.data_arm_lateldrhpre:
84 tst r8, #1 << 21 @ Check writeback bit
Russell Kingda740472011-06-26 16:01:26 +010085 beq do_DataAbort @ No writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -070086.data_arm_lateldrhpost:
87 and r5, 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, r5, r6, lsr #4 @ combine nibbles } else
Russell Kinge22c12f2011-06-27 09:52:54 +010091 ldreq r6, [r2, r5, lsl #2] @ { load Rm value }
Linus Torvalds1da177e2005-04-16 15:20:36 -070092.data_arm_apply_r6_and_rn:
93 and r5, r8, #15 << 16 @ Extract 'n' from instruction
Russell Kinge22c12f2011-06-27 09:52:54 +010094 ldr r7, [r2, r5, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 tst r8, #1 << 23 @ Check U bit
96 subne r7, r7, r6 @ Undo incrmenet
97 addeq r7, r7, r6 @ Undo decrement
Russell Kinge22c12f2011-06-27 09:52:54 +010098 str r7, [r2, r5, lsr #14] @ Put register 'Rn'
Russell Kingda740472011-06-26 16:01:26 +010099 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101.data_arm_lateldrpreconst:
102 tst r8, #1 << 21 @ check writeback bit
Russell Kingda740472011-06-26 16:01:26 +0100103 beq do_DataAbort @ no writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104.data_arm_lateldrpostconst:
Russell King0d147db2011-06-26 14:42:02 +0100105 movs r9, r8, lsl #20 @ Get offset
Russell Kingda740472011-06-26 16:01:26 +0100106 beq do_DataAbort @ zero -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 and r5, r8, #15 << 16 @ Extract 'n' from instruction
Russell Kinge22c12f2011-06-27 09:52:54 +0100108 ldr r7, [r2, r5, lsr #14] @ Get register 'Rn'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 tst r8, #1 << 23 @ Check U bit
Russell King0d147db2011-06-26 14:42:02 +0100110 subne r7, r7, r9, lsr #20 @ Undo increment
111 addeq r7, r7, r9, lsr #20 @ Undo decrement
Russell Kinge22c12f2011-06-27 09:52:54 +0100112 str r7, [r2, r5, lsr #14] @ Put register 'Rn'
Russell Kingda740472011-06-26 16:01:26 +0100113 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115.data_arm_lateldrprereg:
116 tst r8, #1 << 21 @ check writeback bit
Russell Kingda740472011-06-26 16:01:26 +0100117 beq do_DataAbort @ no writeback -> no fixup
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118.data_arm_lateldrpostreg:
119 and r7, r8, #15 @ Extract 'm' from instruction
Russell Kinge22c12f2011-06-27 09:52:54 +0100120 ldr r6, [r2, r7, lsl #2] @ Get register 'Rm'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 mov r5, r8, lsr #7 @ get shift count
122 ands r5, r5, #31
123 and r7, r8, #0x70 @ get shift type
124 orreq r7, r7, #8 @ shift count = 0
125 add pc, pc, r7
126 nop
127
128 mov r6, r6, lsl r5 @ 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 @ 2: MUL?
133 nop
134 b .data_unknown @ 3: MUL?
135 nop
136 mov r6, r6, lsr r5 @ 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 @ 6: MUL?
141 nop
142 b .data_unknown @ 7: MUL?
143 nop
144 mov r6, r6, asr r5 @ 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 @ A: MUL?
149 nop
150 b .data_unknown @ B: MUL?
151 nop
152 mov r6, r6, ror r5 @ 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 @ E: MUL?
157 nop
158 b .data_unknown @ F: MUL?
159
160.data_thumb_abort:
Russell King3e287be2011-06-26 14:35:07 +0100161 ldrh r8, [r4] @ read instruction
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 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
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
Russell Kingda740472011-06-26 16:01:26 +0100174/* 6 */ b do_DataAbort
175/* 7 */ b do_DataAbort
176/* 8 */ b do_DataAbort
177/* 9 */ b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/* 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
185.data_thumb_reg:
186 tst r8, #1 << 9
Russell Kingda740472011-06-26 16:01:26 +0100187 beq do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 tst r8, #1 << 10 @ If 'S' (signed) bit is set
189 movne r1, #0 @ it must be a load instr
Russell Kingda740472011-06-26 16:01:26 +0100190 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192.data_thumb_pushpop:
193 tst r8, #1 << 10
194 beq .data_unknown
195 and r6, r8, #0x55 @ hweight8(r8) + R bit
Russell King0d147db2011-06-26 14:42:02 +0100196 and r9, r8, #0xaa
197 add r6, r6, r9, lsr #1
198 and r9, r6, #0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 and r6, r6, #0x33
Russell King0d147db2011-06-26 14:42:02 +0100200 add r6, r6, r9, lsr #2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 movs r7, r8, lsr #9 @ C = r8 bit 8 (R bit)
202 adc r6, r6, r6, lsr #4 @ high + low nibble + R bit
203 and r6, r6, #15 @ number of regs to transfer
Russell Kinge22c12f2011-06-27 09:52:54 +0100204 ldr r7, [r2, #13 << 2]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 tst r8, #1 << 11
206 addeq r7, r7, r6, lsl #2 @ increment SP if PUSH
207 subne r7, r7, r6, lsl #2 @ decrement SP if POP
Russell Kinge22c12f2011-06-27 09:52:54 +0100208 str r7, [r2, #13 << 2]
Russell Kingda740472011-06-26 16:01:26 +0100209 b do_DataAbort
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211.data_thumb_ldmstm:
212 and r6, r8, #0x55 @ hweight8(r8)
Russell King0d147db2011-06-26 14:42:02 +0100213 and r9, r8, #0xaa
214 add r6, r6, r9, lsr #1
215 and r9, r6, #0xcc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 and r6, r6, #0x33
Russell King0d147db2011-06-26 14:42:02 +0100217 add r6, r6, r9, lsr #2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 add r6, r6, r6, lsr #4
219 and r5, r8, #7 << 8
Russell Kinge22c12f2011-06-27 09:52:54 +0100220 ldr r7, [r2, r5, lsr #6]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 and r6, r6, #15 @ number of regs to transfer
222 sub r7, r7, r6, lsl #2 @ always decrement
Russell Kinge22c12f2011-06-27 09:52:54 +0100223 str r7, [r2, r5, lsr #6]
Russell Kingda740472011-06-26 16:01:26 +0100224 b do_DataAbort