Add a prefetch abort handler
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / kernel / entry-armv.S
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/kernel/entry-armv.S
3 *
4 * Copyright (C) 1996,1997,1998 Russell King.
5 * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
afeb90ca 6 * nommu support by Hyok S. Choi (hyok.choi@samsung.com)
1da177e4
LT
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Low-level vector interface routines
13 *
70b6f2b4
NP
14 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction
15 * that causes it to save wrong values... Be aware!
1da177e4 16 */
1da177e4 17
f09b9979 18#include <asm/memory.h>
1da177e4 19#include <asm/glue.h>
1da177e4 20#include <asm/vfpmacros.h>
bce495d8 21#include <asm/arch/entry-macro.S>
d6551e88 22#include <asm/thread_notify.h>
1da177e4
LT
23
24#include "entry-header.S"
25
187a51ad
RK
26/*
27 * Interrupt handling. Preserves r7, r8, r9
28 */
29 .macro irq_handler
f80dff9d 30 get_irqnr_preamble r5, lr
187a51ad
RK
311: get_irqnr_and_base r0, r6, r5, lr
32 movne r1, sp
33 @
34 @ routine called with r0 = irq number, r1 = struct pt_regs *
35 @
36 adrne lr, 1b
37 bne asm_do_IRQ
791be9b9
RK
38
39#ifdef CONFIG_SMP
40 /*
41 * XXX
42 *
43 * this macro assumes that irqstat (r6) and base (r5) are
44 * preserved from get_irqnr_and_base above
45 */
46 test_for_ipi r0, r6, r5, lr
47 movne r0, sp
48 adrne lr, 1b
49 bne do_IPI
37ee16ae
RK
50
51#ifdef CONFIG_LOCAL_TIMERS
52 test_for_ltirq r0, r6, r5, lr
53 movne r0, sp
54 adrne lr, 1b
55 bne do_local_timer
56#endif
791be9b9
RK
57#endif
58
187a51ad
RK
59 .endm
60
785d3cd2
NP
61#ifdef CONFIG_KPROBES
62 .section .kprobes.text,"ax",%progbits
63#else
64 .text
65#endif
66
1da177e4
LT
67/*
68 * Invalid mode handlers
69 */
ccea7a19
RK
70 .macro inv_entry, reason
71 sub sp, sp, #S_FRAME_SIZE
72 stmib sp, {r1 - lr}
1da177e4
LT
73 mov r1, #\reason
74 .endm
75
76__pabt_invalid:
ccea7a19
RK
77 inv_entry BAD_PREFETCH
78 b common_invalid
1da177e4
LT
79
80__dabt_invalid:
ccea7a19
RK
81 inv_entry BAD_DATA
82 b common_invalid
1da177e4
LT
83
84__irq_invalid:
ccea7a19
RK
85 inv_entry BAD_IRQ
86 b common_invalid
1da177e4
LT
87
88__und_invalid:
ccea7a19
RK
89 inv_entry BAD_UNDEFINSTR
90
91 @
92 @ XXX fall through to common_invalid
93 @
94
95@
96@ common_invalid - generic code for failed exception (re-entrant version of handlers)
97@
98common_invalid:
99 zero_fp
100
101 ldmia r0, {r4 - r6}
102 add r0, sp, #S_PC @ here for interlock avoidance
103 mov r7, #-1 @ "" "" "" ""
104 str r4, [sp] @ save preserved r0
105 stmia r0, {r5 - r7} @ lr_<exception>,
106 @ cpsr_<exception>, "old_r0"
1da177e4 107
1da177e4 108 mov r0, sp
1da177e4
LT
109 b bad_mode
110
111/*
112 * SVC mode handlers
113 */
2dede2d8
NP
114
115#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
116#define SPFIX(code...) code
117#else
118#define SPFIX(code...)
119#endif
120
d30a0c8b
NP
121 .macro svc_entry, stack_hole=0
122 sub sp, sp, #(S_FRAME_SIZE + \stack_hole)
2dede2d8
NP
123 SPFIX( tst sp, #4 )
124 SPFIX( bicne sp, sp, #4 )
ccea7a19
RK
125 stmib sp, {r1 - r12}
126
127 ldmia r0, {r1 - r3}
128 add r5, sp, #S_SP @ here for interlock avoidance
129 mov r4, #-1 @ "" "" "" ""
d30a0c8b 130 add r0, sp, #(S_FRAME_SIZE + \stack_hole)
2dede2d8 131 SPFIX( addne r0, r0, #4 )
ccea7a19
RK
132 str r1, [sp] @ save the "real" r0 copied
133 @ from the exception stack
134
1da177e4
LT
135 mov r1, lr
136
137 @
138 @ We are now ready to fill in the remaining blanks on the stack:
139 @
140 @ r0 - sp_svc
141 @ r1 - lr_svc
142 @ r2 - lr_<exception>, already fixed up for correct return/restart
143 @ r3 - spsr_<exception>
144 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
145 @
146 stmia r5, {r0 - r4}
147 .endm
148
149 .align 5
150__dabt_svc:
ccea7a19 151 svc_entry
1da177e4
LT
152
153 @
154 @ get ready to re-enable interrupts if appropriate
155 @
156 mrs r9, cpsr
157 tst r3, #PSR_I_BIT
158 biceq r9, r9, #PSR_I_BIT
159
160 @
161 @ Call the processor-specific abort handler:
162 @
163 @ r2 - aborted context pc
164 @ r3 - aborted context cpsr
165 @
166 @ The abort handler must return the aborted address in r0, and
167 @ the fault status register in r1. r9 must be preserved.
168 @
48d7927b 169#ifdef MULTI_DABORT
1da177e4
LT
170 ldr r4, .LCprocfns
171 mov lr, pc
48d7927b 172 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
1da177e4 173#else
48d7927b 174 bl CPU_DABORT_HANDLER
1da177e4
LT
175#endif
176
177 @
178 @ set desired IRQ state, then call main handler
179 @
180 msr cpsr_c, r9
181 mov r2, sp
182 bl do_DataAbort
183
184 @
185 @ IRQs off again before pulling preserved data off the stack
186 @
1ec42c0c 187 disable_irq
1da177e4
LT
188
189 @
190 @ restore SPSR and restart the instruction
191 @
192 ldr r0, [sp, #S_PSR]
193 msr spsr_cxsf, r0
194 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
195
196 .align 5
197__irq_svc:
ccea7a19
RK
198 svc_entry
199
7ad1bcb2
RK
200#ifdef CONFIG_TRACE_IRQFLAGS
201 bl trace_hardirqs_off
202#endif
1da177e4 203#ifdef CONFIG_PREEMPT
706fdd9f
RK
204 get_thread_info tsk
205 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
206 add r7, r8, #1 @ increment it
207 str r7, [tsk, #TI_PREEMPT]
1da177e4 208#endif
ccea7a19 209
187a51ad 210 irq_handler
1da177e4 211#ifdef CONFIG_PREEMPT
706fdd9f 212 ldr r0, [tsk, #TI_FLAGS] @ get flags
1da177e4
LT
213 tst r0, #_TIF_NEED_RESCHED
214 blne svc_preempt
215preempt_return:
706fdd9f
RK
216 ldr r0, [tsk, #TI_PREEMPT] @ read preempt value
217 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
1da177e4 218 teq r0, r7
1da177e4
LT
219 strne r0, [r0, -r0] @ bug()
220#endif
221 ldr r0, [sp, #S_PSR] @ irqs are already disabled
222 msr spsr_cxsf, r0
7ad1bcb2
RK
223#ifdef CONFIG_TRACE_IRQFLAGS
224 tst r0, #PSR_I_BIT
225 bleq trace_hardirqs_on
226#endif
1da177e4
LT
227 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
228
229 .ltorg
230
231#ifdef CONFIG_PREEMPT
232svc_preempt:
706fdd9f 233 teq r8, #0 @ was preempt count = 0
1da177e4
LT
234 ldreq r6, .LCirq_stat
235 movne pc, lr @ no
236 ldr r0, [r6, #4] @ local_irq_count
237 ldr r1, [r6, #8] @ local_bh_count
238 adds r0, r0, r1
239 movne pc, lr
240 mov r7, #0 @ preempt_schedule_irq
706fdd9f 241 str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0
1da177e4 2421: bl preempt_schedule_irq @ irq en/disable is done inside
706fdd9f 243 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
1da177e4
LT
244 tst r0, #_TIF_NEED_RESCHED
245 beq preempt_return @ go again
246 b 1b
247#endif
248
249 .align 5
250__und_svc:
d30a0c8b
NP
251#ifdef CONFIG_KPROBES
252 @ If a kprobe is about to simulate a "stmdb sp..." instruction,
253 @ it obviously needs free stack space which then will belong to
254 @ the saved context.
255 svc_entry 64
256#else
ccea7a19 257 svc_entry
d30a0c8b 258#endif
1da177e4
LT
259
260 @
261 @ call emulation code, which returns using r9 if it has emulated
262 @ the instruction, or the more conventional lr if we are to treat
263 @ this as a real undefined instruction
264 @
265 @ r0 - instruction
266 @
267 ldr r0, [r2, #-4]
268 adr r9, 1f
269 bl call_fpe
270
271 mov r0, sp @ struct pt_regs *regs
272 bl do_undefinstr
273
274 @
275 @ IRQs off again before pulling preserved data off the stack
276 @
1ec42c0c 2771: disable_irq
1da177e4
LT
278
279 @
280 @ restore SPSR and restart the instruction
281 @
282 ldr lr, [sp, #S_PSR] @ Get SVC cpsr
283 msr spsr_cxsf, lr
284 ldmia sp, {r0 - pc}^ @ Restore SVC registers
285
286 .align 5
287__pabt_svc:
ccea7a19 288 svc_entry
1da177e4
LT
289
290 @
291 @ re-enable interrupts if appropriate
292 @
293 mrs r9, cpsr
294 tst r3, #PSR_I_BIT
295 biceq r9, r9, #PSR_I_BIT
1da177e4
LT
296
297 @
298 @ set args, then call main handler
299 @
300 @ r0 - address of faulting instruction
301 @ r1 - pointer to registers on stack
302 @
48d7927b
PB
303#ifdef MULTI_PABORT
304 mov r0, r2 @ pass address of aborted instruction.
305 ldr r4, .LCprocfns
306 mov lr, pc
307 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
308#else
309 CPU_PABORT_HANDLER(r0, r2)
310#endif
311 msr cpsr_c, r9 @ Maybe enable interrupts
1da177e4
LT
312 mov r1, sp @ regs
313 bl do_PrefetchAbort @ call abort handler
314
315 @
316 @ IRQs off again before pulling preserved data off the stack
317 @
1ec42c0c 318 disable_irq
1da177e4
LT
319
320 @
321 @ restore SPSR and restart the instruction
322 @
323 ldr r0, [sp, #S_PSR]
324 msr spsr_cxsf, r0
325 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
326
327 .align 5
49f680ea
RK
328.LCcralign:
329 .word cr_alignment
48d7927b 330#ifdef MULTI_DABORT
1da177e4
LT
331.LCprocfns:
332 .word processor
333#endif
334.LCfp:
335 .word fp_enter
336#ifdef CONFIG_PREEMPT
337.LCirq_stat:
338 .word irq_stat
339#endif
340
341/*
342 * User mode handlers
2dede2d8
NP
343 *
344 * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
1da177e4 345 */
2dede2d8
NP
346
347#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
348#error "sizeof(struct pt_regs) must be a multiple of 8"
349#endif
350
ccea7a19
RK
351 .macro usr_entry
352 sub sp, sp, #S_FRAME_SIZE
353 stmib sp, {r1 - r12}
354
355 ldmia r0, {r1 - r3}
356 add r0, sp, #S_PC @ here for interlock avoidance
357 mov r4, #-1 @ "" "" "" ""
358
359 str r1, [sp] @ save the "real" r0 copied
360 @ from the exception stack
1da177e4
LT
361
362 @
363 @ We are now ready to fill in the remaining blanks on the stack:
364 @
365 @ r2 - lr_<exception>, already fixed up for correct return/restart
366 @ r3 - spsr_<exception>
367 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
368 @
369 @ Also, separately save sp_usr and lr_usr
370 @
ccea7a19
RK
371 stmia r0, {r2 - r4}
372 stmdb r0, {sp, lr}^
1da177e4
LT
373
374 @
375 @ Enable the alignment trap while in kernel mode
376 @
49f680ea 377 alignment_trap r0
1da177e4
LT
378
379 @
380 @ Clear FP to mark the first stack frame
381 @
382 zero_fp
383 .endm
384
b49c0f24
NP
385 .macro kuser_cmpxchg_check
386#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
387#ifndef CONFIG_MMU
388#warning "NPTL on non MMU needs fixing"
389#else
390 @ Make sure our user space atomic helper is restarted
391 @ if it was interrupted in a critical region. Here we
392 @ perform a quick test inline since it should be false
393 @ 99.9999% of the time. The rest is done out of line.
394 cmp r2, #TASK_SIZE
395 blhs kuser_cmpxchg_fixup
396#endif
397#endif
398 .endm
399
1da177e4
LT
400 .align 5
401__dabt_usr:
ccea7a19 402 usr_entry
b49c0f24 403 kuser_cmpxchg_check
1da177e4
LT
404
405 @
406 @ Call the processor-specific abort handler:
407 @
408 @ r2 - aborted context pc
409 @ r3 - aborted context cpsr
410 @
411 @ The abort handler must return the aborted address in r0, and
412 @ the fault status register in r1.
413 @
48d7927b 414#ifdef MULTI_DABORT
1da177e4
LT
415 ldr r4, .LCprocfns
416 mov lr, pc
48d7927b 417 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
1da177e4 418#else
48d7927b 419 bl CPU_DABORT_HANDLER
1da177e4
LT
420#endif
421
422 @
423 @ IRQs on, then call the main handler
424 @
1ec42c0c 425 enable_irq
1da177e4
LT
426 mov r2, sp
427 adr lr, ret_from_exception
428 b do_DataAbort
429
430 .align 5
431__irq_usr:
ccea7a19 432 usr_entry
b49c0f24 433 kuser_cmpxchg_check
1da177e4 434
7ad1bcb2
RK
435#ifdef CONFIG_TRACE_IRQFLAGS
436 bl trace_hardirqs_off
437#endif
706fdd9f 438 get_thread_info tsk
1da177e4 439#ifdef CONFIG_PREEMPT
706fdd9f
RK
440 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
441 add r7, r8, #1 @ increment it
442 str r7, [tsk, #TI_PREEMPT]
1da177e4 443#endif
ccea7a19 444
187a51ad 445 irq_handler
1da177e4 446#ifdef CONFIG_PREEMPT
706fdd9f
RK
447 ldr r0, [tsk, #TI_PREEMPT]
448 str r8, [tsk, #TI_PREEMPT]
1da177e4 449 teq r0, r7
1da177e4 450 strne r0, [r0, -r0]
1da177e4 451#endif
7ad1bcb2
RK
452#ifdef CONFIG_TRACE_IRQFLAGS
453 bl trace_hardirqs_on
454#endif
ccea7a19 455
1da177e4
LT
456 mov why, #0
457 b ret_to_user
458
459 .ltorg
460
461 .align 5
462__und_usr:
ccea7a19 463 usr_entry
1da177e4
LT
464
465 tst r3, #PSR_T_BIT @ Thumb mode?
db6ccbb6 466 bne __und_usr_unknown @ ignore FP
1da177e4
LT
467 sub r4, r2, #4
468
469 @
470 @ fall through to the emulation code, which returns using r9 if
471 @ it has emulated the instruction, or the more conventional lr
472 @ if we are to treat this as a real undefined instruction
473 @
474 @ r0 - instruction
475 @
1da177e4 476 adr r9, ret_from_exception
db6ccbb6 477 adr lr, __und_usr_unknown
d28a170d 4781: ldrt r0, [r4]
1da177e4
LT
479 @
480 @ fallthrough to call_fpe
481 @
482
483/*
484 * The out of line fixup for the ldrt above.
485 */
486 .section .fixup, "ax"
4872: mov pc, r9
488 .previous
489 .section __ex_table,"a"
490 .long 1b, 2b
491 .previous
492
493/*
494 * Check whether the instruction is a co-processor instruction.
495 * If yes, we need to call the relevant co-processor handler.
496 *
497 * Note that we don't do a full check here for the co-processor
498 * instructions; all instructions with bit 27 set are well
499 * defined. The only instructions that should fault are the
500 * co-processor instructions. However, we have to watch out
501 * for the ARM6/ARM7 SWI bug.
502 *
b5872db4
CM
503 * NEON is a special case that has to be handled here. Not all
504 * NEON instructions are co-processor instructions, so we have
505 * to make a special case of checking for them. Plus, there's
506 * five groups of them, so we have a table of mask/opcode pairs
507 * to check against, and if any match then we branch off into the
508 * NEON handler code.
509 *
1da177e4
LT
510 * Emulators may wish to make use of the following registers:
511 * r0 = instruction opcode.
512 * r2 = PC+4
db6ccbb6 513 * r9 = normal "successful" return address
1da177e4 514 * r10 = this threads thread_info structure.
db6ccbb6 515 * lr = unrecognised instruction return address
1da177e4
LT
516 */
517call_fpe:
b5872db4
CM
518#ifdef CONFIG_NEON
519 adr r6, .LCneon_opcodes
5202:
521 ldr r7, [r6], #4 @ mask value
522 cmp r7, #0 @ end mask?
523 beq 1f
524 and r8, r0, r7
525 ldr r7, [r6], #4 @ opcode bits matching in mask
526 cmp r8, r7 @ NEON instruction?
527 bne 2b
528 get_thread_info r10
529 mov r7, #1
530 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
531 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
532 b do_vfp @ let VFP handler handle this
5331:
534#endif
1da177e4
LT
535 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
536#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
537 and r8, r0, #0x0f000000 @ mask out op-code bits
538 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
539#endif
540 moveq pc, lr
541 get_thread_info r10 @ get current thread
542 and r8, r0, #0x00000f00 @ mask out CP number
543 mov r7, #1
544 add r6, r10, #TI_USED_CP
545 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
546#ifdef CONFIG_IWMMXT
547 @ Test if we need to give access to iWMMXt coprocessors
548 ldr r5, [r10, #TI_FLAGS]
549 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
550 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
551 bcs iwmmxt_task_enable
552#endif
1da177e4
LT
553 add pc, pc, r8, lsr #6
554 mov r0, r0
555
556 mov pc, lr @ CP#0
557 b do_fpe @ CP#1 (FPE)
558 b do_fpe @ CP#2 (FPE)
559 mov pc, lr @ CP#3
c17fad11
LB
560#ifdef CONFIG_CRUNCH
561 b crunch_task_enable @ CP#4 (MaverickCrunch)
562 b crunch_task_enable @ CP#5 (MaverickCrunch)
563 b crunch_task_enable @ CP#6 (MaverickCrunch)
564#else
1da177e4
LT
565 mov pc, lr @ CP#4
566 mov pc, lr @ CP#5
567 mov pc, lr @ CP#6
c17fad11 568#endif
1da177e4
LT
569 mov pc, lr @ CP#7
570 mov pc, lr @ CP#8
571 mov pc, lr @ CP#9
572#ifdef CONFIG_VFP
573 b do_vfp @ CP#10 (VFP)
574 b do_vfp @ CP#11 (VFP)
575#else
576 mov pc, lr @ CP#10 (VFP)
577 mov pc, lr @ CP#11 (VFP)
578#endif
579 mov pc, lr @ CP#12
580 mov pc, lr @ CP#13
581 mov pc, lr @ CP#14 (Debug)
582 mov pc, lr @ CP#15 (Control)
583
b5872db4
CM
584#ifdef CONFIG_NEON
585 .align 6
586
587.LCneon_opcodes:
588 .word 0xfe000000 @ mask
589 .word 0xf2000000 @ opcode
590
591 .word 0xff100000 @ mask
592 .word 0xf4000000 @ opcode
593
594 .word 0x00000000 @ mask
595 .word 0x00000000 @ opcode
596#endif
597
1da177e4 598do_fpe:
5d25ac03 599 enable_irq
1da177e4
LT
600 ldr r4, .LCfp
601 add r10, r10, #TI_FPSTATE @ r10 = workspace
602 ldr pc, [r4] @ Call FP module USR entry point
603
604/*
605 * The FP module is called with these registers set:
606 * r0 = instruction
607 * r2 = PC+4
608 * r9 = normal "successful" return address
609 * r10 = FP workspace
610 * lr = unrecognised FP instruction return address
611 */
612
613 .data
614ENTRY(fp_enter)
db6ccbb6 615 .word no_fp
785d3cd2 616 .previous
1da177e4 617
db6ccbb6
RK
618no_fp: mov pc, lr
619
620__und_usr_unknown:
1da177e4
LT
621 mov r0, sp
622 adr lr, ret_from_exception
623 b do_undefinstr
624
625 .align 5
626__pabt_usr:
ccea7a19 627 usr_entry
1da177e4 628
48d7927b
PB
629#ifdef MULTI_PABORT
630 mov r0, r2 @ pass address of aborted instruction.
631 ldr r4, .LCprocfns
632 mov lr, pc
633 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
634#else
635 CPU_PABORT_HANDLER(r0, r2)
636#endif
1ec42c0c 637 enable_irq @ Enable interrupts
1da177e4
LT
638 mov r1, sp @ regs
639 bl do_PrefetchAbort @ call abort handler
640 /* fall through */
641/*
642 * This is the return code to user mode for abort handlers
643 */
644ENTRY(ret_from_exception)
645 get_thread_info tsk
646 mov why, #0
647 b ret_to_user
648
649/*
650 * Register switch for ARMv3 and ARMv4 processors
651 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
652 * previous and next are guaranteed not to be the same.
653 */
654ENTRY(__switch_to)
655 add ip, r1, #TI_CPU_SAVE
656 ldr r3, [r2, #TI_TP_VALUE]
657 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
d6551e88
RK
658#ifdef CONFIG_MMU
659 ldr r6, [r2, #TI_CPU_DOMAIN]
afeb90ca 660#endif
b876386e 661#if __LINUX_ARM_ARCH__ >= 6
43cc1981 662#ifdef CONFIG_CPU_32v6K
b876386e
RK
663 clrex
664#else
73394322 665 strex r5, r4, [ip] @ Clear exclusive monitor
b876386e
RK
666#endif
667#endif
4b0e07a5 668#if defined(CONFIG_HAS_TLS_REG)
2d2669b6 669 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
4b0e07a5 670#elif !defined(CONFIG_TLS_REG_EMUL)
1da177e4 671 mov r4, #0xffff0fff
2d2669b6
NP
672 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
673#endif
afeb90ca 674#ifdef CONFIG_MMU
1da177e4 675 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
1da177e4 676#endif
d6551e88
RK
677 mov r5, r0
678 add r4, r2, #TI_CPU_SAVE
679 ldr r0, =thread_notify_head
680 mov r1, #THREAD_NOTIFY_SWITCH
681 bl atomic_notifier_call_chain
682 mov r0, r5
683 ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
1da177e4
LT
684
685 __INIT
2d2669b6
NP
686
687/*
688 * User helpers.
689 *
690 * These are segment of kernel provided user code reachable from user space
691 * at a fixed address in kernel memory. This is used to provide user space
692 * with some operations which require kernel help because of unimplemented
693 * native feature and/or instructions in many ARM CPUs. The idea is for
694 * this code to be executed directly in user mode for best efficiency but
695 * which is too intimate with the kernel counter part to be left to user
696 * libraries. In fact this code might even differ from one CPU to another
697 * depending on the available instruction set and restrictions like on
698 * SMP systems. In other words, the kernel reserves the right to change
699 * this code as needed without warning. Only the entry points and their
700 * results are guaranteed to be stable.
701 *
702 * Each segment is 32-byte aligned and will be moved to the top of the high
703 * vector page. New segments (if ever needed) must be added in front of
704 * existing ones. This mechanism should be used only for things that are
705 * really small and justified, and not be abused freely.
706 *
707 * User space is expected to implement those things inline when optimizing
708 * for a processor that has the necessary native support, but only if such
709 * resulting binaries are already to be incompatible with earlier ARM
710 * processors due to the use of unsupported instructions other than what
711 * is provided here. In other words don't make binaries unable to run on
712 * earlier processors just for the sake of not using these kernel helpers
713 * if your compiled code is not going to use the new instructions for other
714 * purpose.
715 */
716
ba9b5d76
NP
717 .macro usr_ret, reg
718#ifdef CONFIG_ARM_THUMB
719 bx \reg
720#else
721 mov pc, \reg
722#endif
723 .endm
724
2d2669b6
NP
725 .align 5
726 .globl __kuser_helper_start
727__kuser_helper_start:
728
7c612bfd
NP
729/*
730 * Reference prototype:
731 *
732 * void __kernel_memory_barrier(void)
733 *
734 * Input:
735 *
736 * lr = return address
737 *
738 * Output:
739 *
740 * none
741 *
742 * Clobbered:
743 *
b49c0f24 744 * none
7c612bfd
NP
745 *
746 * Definition and user space usage example:
747 *
748 * typedef void (__kernel_dmb_t)(void);
749 * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
750 *
751 * Apply any needed memory barrier to preserve consistency with data modified
752 * manually and __kuser_cmpxchg usage.
753 *
754 * This could be used as follows:
755 *
756 * #define __kernel_dmb() \
757 * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
6896eec0 758 * : : : "r0", "lr","cc" )
7c612bfd
NP
759 */
760
761__kuser_memory_barrier: @ 0xffff0fa0
762
763#if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
764 mcr p15, 0, r0, c7, c10, 5 @ dmb
765#endif
ba9b5d76 766 usr_ret lr
7c612bfd
NP
767
768 .align 5
769
2d2669b6
NP
770/*
771 * Reference prototype:
772 *
773 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
774 *
775 * Input:
776 *
777 * r0 = oldval
778 * r1 = newval
779 * r2 = ptr
780 * lr = return address
781 *
782 * Output:
783 *
784 * r0 = returned value (zero or non-zero)
785 * C flag = set if r0 == 0, clear if r0 != 0
786 *
787 * Clobbered:
788 *
789 * r3, ip, flags
790 *
791 * Definition and user space usage example:
792 *
793 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
794 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
795 *
796 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
797 * Return zero if *ptr was changed or non-zero if no exchange happened.
798 * The C flag is also set if *ptr was changed to allow for assembly
799 * optimization in the calling code.
800 *
5964eae8
NP
801 * Notes:
802 *
803 * - This routine already includes memory barriers as needed.
804 *
2d2669b6
NP
805 * For example, a user space atomic_add implementation could look like this:
806 *
807 * #define atomic_add(ptr, val) \
808 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
809 * register unsigned int __result asm("r1"); \
810 * asm volatile ( \
811 * "1: @ atomic_add\n\t" \
812 * "ldr r0, [r2]\n\t" \
813 * "mov r3, #0xffff0fff\n\t" \
814 * "add lr, pc, #4\n\t" \
815 * "add r1, r0, %2\n\t" \
816 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
817 * "bcc 1b" \
818 * : "=&r" (__result) \
819 * : "r" (__ptr), "rIL" (val) \
820 * : "r0","r3","ip","lr","cc","memory" ); \
821 * __result; })
822 */
823
824__kuser_cmpxchg: @ 0xffff0fc0
825
dcef1f63 826#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
2d2669b6 827
dcef1f63
NP
828 /*
829 * Poor you. No fast solution possible...
830 * The kernel itself must perform the operation.
831 * A special ghost syscall is used for that (see traps.c).
832 */
5e097445
NP
833 stmfd sp!, {r7, lr}
834 mov r7, #0xff00 @ 0xfff0 into r7 for EABI
835 orr r7, r7, #0xf0
dcef1f63 836 swi #0x9ffff0
5e097445 837 ldmfd sp!, {r7, pc}
dcef1f63
NP
838
839#elif __LINUX_ARM_ARCH__ < 6
2d2669b6 840
b49c0f24
NP
841#ifdef CONFIG_MMU
842
2d2669b6 843 /*
b49c0f24
NP
844 * The only thing that can break atomicity in this cmpxchg
845 * implementation is either an IRQ or a data abort exception
846 * causing another process/thread to be scheduled in the middle
847 * of the critical sequence. To prevent this, code is added to
848 * the IRQ and data abort exception handlers to set the pc back
849 * to the beginning of the critical section if it is found to be
850 * within that critical section (see kuser_cmpxchg_fixup).
2d2669b6 851 */
b49c0f24
NP
8521: ldr r3, [r2] @ load current val
853 subs r3, r3, r0 @ compare with oldval
8542: streq r1, [r2] @ store newval if eq
855 rsbs r0, r3, #0 @ set return val and C flag
856 usr_ret lr
857
858 .text
859kuser_cmpxchg_fixup:
860 @ Called from kuser_cmpxchg_check macro.
861 @ r2 = address of interrupted insn (must be preserved).
862 @ sp = saved regs. r7 and r8 are clobbered.
863 @ 1b = first critical insn, 2b = last critical insn.
864 @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
865 mov r7, #0xffff0fff
866 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
867 subs r8, r2, r7
868 rsbcss r8, r8, #(2b - 1b)
869 strcs r7, [sp, #S_PC]
870 mov pc, lr
871 .previous
872
49bca4c2
NP
873#else
874#warning "NPTL on non MMU needs fixing"
875 mov r0, #-1
876 adds r0, r0, #0
ba9b5d76 877 usr_ret lr
b49c0f24 878#endif
2d2669b6
NP
879
880#else
881
7c612bfd
NP
882#ifdef CONFIG_SMP
883 mcr p15, 0, r0, c7, c10, 5 @ dmb
884#endif
b49c0f24 8851: ldrex r3, [r2]
2d2669b6
NP
886 subs r3, r3, r0
887 strexeq r3, r1, [r2]
b49c0f24
NP
888 teqeq r3, #1
889 beq 1b
2d2669b6 890 rsbs r0, r3, #0
b49c0f24 891 /* beware -- each __kuser slot must be 8 instructions max */
7c612bfd 892#ifdef CONFIG_SMP
b49c0f24
NP
893 b __kuser_memory_barrier
894#else
ba9b5d76 895 usr_ret lr
b49c0f24 896#endif
2d2669b6
NP
897
898#endif
899
900 .align 5
901
902/*
903 * Reference prototype:
904 *
905 * int __kernel_get_tls(void)
906 *
907 * Input:
908 *
909 * lr = return address
910 *
911 * Output:
912 *
913 * r0 = TLS value
914 *
915 * Clobbered:
916 *
b49c0f24 917 * none
2d2669b6
NP
918 *
919 * Definition and user space usage example:
920 *
921 * typedef int (__kernel_get_tls_t)(void);
922 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
923 *
924 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
925 *
926 * This could be used as follows:
927 *
928 * #define __kernel_get_tls() \
929 * ({ register unsigned int __val asm("r0"); \
930 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
931 * : "=r" (__val) : : "lr","cc" ); \
932 * __val; })
933 */
934
935__kuser_get_tls: @ 0xffff0fe0
936
4b0e07a5 937#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
2d2669b6 938 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
2d2669b6 939#else
2d2669b6 940 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
2d2669b6 941#endif
ba9b5d76 942 usr_ret lr
2d2669b6
NP
943
944 .rep 5
945 .word 0 @ pad up to __kuser_helper_version
946 .endr
947
948/*
949 * Reference declaration:
950 *
951 * extern unsigned int __kernel_helper_version;
952 *
953 * Definition and user space usage example:
954 *
955 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
956 *
957 * User space may read this to determine the curent number of helpers
958 * available.
959 */
960
961__kuser_helper_version: @ 0xffff0ffc
962 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
963
964 .globl __kuser_helper_end
965__kuser_helper_end:
966
967
1da177e4
LT
968/*
969 * Vector stubs.
970 *
7933523d
RK
971 * This code is copied to 0xffff0200 so we can use branches in the
972 * vectors, rather than ldr's. Note that this code must not
973 * exceed 0x300 bytes.
1da177e4
LT
974 *
975 * Common stub entry macro:
976 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
ccea7a19
RK
977 *
978 * SP points to a minimal amount of processor-private memory, the address
979 * of which is copied into r0 for the mode specific abort handler.
1da177e4 980 */
b7ec4795 981 .macro vector_stub, name, mode, correction=0
1da177e4
LT
982 .align 5
983
984vector_\name:
1da177e4
LT
985 .if \correction
986 sub lr, lr, #\correction
987 .endif
ccea7a19
RK
988
989 @
990 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
991 @ (parent CPSR)
992 @
993 stmia sp, {r0, lr} @ save r0, lr
1da177e4 994 mrs lr, spsr
ccea7a19
RK
995 str lr, [sp, #8] @ save spsr
996
1da177e4 997 @
ccea7a19 998 @ Prepare for SVC32 mode. IRQs remain disabled.
1da177e4 999 @
ccea7a19 1000 mrs r0, cpsr
b7ec4795 1001 eor r0, r0, #(\mode ^ SVC_MODE)
ccea7a19 1002 msr spsr_cxsf, r0
1da177e4 1003
ccea7a19
RK
1004 @
1005 @ the branch table must immediately follow this code
1006 @
ccea7a19 1007 and lr, lr, #0x0f
b7ec4795 1008 mov r0, sp
1da177e4 1009 ldr lr, [pc, lr, lsl #2]
ccea7a19 1010 movs pc, lr @ branch to handler in SVC mode
1da177e4
LT
1011 .endm
1012
7933523d 1013 .globl __stubs_start
1da177e4
LT
1014__stubs_start:
1015/*
1016 * Interrupt dispatcher
1017 */
b7ec4795 1018 vector_stub irq, IRQ_MODE, 4
1da177e4
LT
1019
1020 .long __irq_usr @ 0 (USR_26 / USR_32)
1021 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1022 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1023 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1024 .long __irq_invalid @ 4
1025 .long __irq_invalid @ 5
1026 .long __irq_invalid @ 6
1027 .long __irq_invalid @ 7
1028 .long __irq_invalid @ 8
1029 .long __irq_invalid @ 9
1030 .long __irq_invalid @ a
1031 .long __irq_invalid @ b
1032 .long __irq_invalid @ c
1033 .long __irq_invalid @ d
1034 .long __irq_invalid @ e
1035 .long __irq_invalid @ f
1036
1037/*
1038 * Data abort dispatcher
1039 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1040 */
b7ec4795 1041 vector_stub dabt, ABT_MODE, 8
1da177e4
LT
1042
1043 .long __dabt_usr @ 0 (USR_26 / USR_32)
1044 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1045 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1046 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1047 .long __dabt_invalid @ 4
1048 .long __dabt_invalid @ 5
1049 .long __dabt_invalid @ 6
1050 .long __dabt_invalid @ 7
1051 .long __dabt_invalid @ 8
1052 .long __dabt_invalid @ 9
1053 .long __dabt_invalid @ a
1054 .long __dabt_invalid @ b
1055 .long __dabt_invalid @ c
1056 .long __dabt_invalid @ d
1057 .long __dabt_invalid @ e
1058 .long __dabt_invalid @ f
1059
1060/*
1061 * Prefetch abort dispatcher
1062 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1063 */
b7ec4795 1064 vector_stub pabt, ABT_MODE, 4
1da177e4
LT
1065
1066 .long __pabt_usr @ 0 (USR_26 / USR_32)
1067 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1068 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1069 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1070 .long __pabt_invalid @ 4
1071 .long __pabt_invalid @ 5
1072 .long __pabt_invalid @ 6
1073 .long __pabt_invalid @ 7
1074 .long __pabt_invalid @ 8
1075 .long __pabt_invalid @ 9
1076 .long __pabt_invalid @ a
1077 .long __pabt_invalid @ b
1078 .long __pabt_invalid @ c
1079 .long __pabt_invalid @ d
1080 .long __pabt_invalid @ e
1081 .long __pabt_invalid @ f
1082
1083/*
1084 * Undef instr entry dispatcher
1085 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1086 */
b7ec4795 1087 vector_stub und, UND_MODE
1da177e4
LT
1088
1089 .long __und_usr @ 0 (USR_26 / USR_32)
1090 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1091 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1092 .long __und_svc @ 3 (SVC_26 / SVC_32)
1093 .long __und_invalid @ 4
1094 .long __und_invalid @ 5
1095 .long __und_invalid @ 6
1096 .long __und_invalid @ 7
1097 .long __und_invalid @ 8
1098 .long __und_invalid @ 9
1099 .long __und_invalid @ a
1100 .long __und_invalid @ b
1101 .long __und_invalid @ c
1102 .long __und_invalid @ d
1103 .long __und_invalid @ e
1104 .long __und_invalid @ f
1105
1106 .align 5
1107
1108/*=============================================================================
1109 * Undefined FIQs
1110 *-----------------------------------------------------------------------------
1111 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1112 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1113 * Basically to switch modes, we *HAVE* to clobber one register... brain
1114 * damage alert! I don't think that we can execute any code in here in any
1115 * other mode than FIQ... Ok you can switch to another mode, but you can't
1116 * get out of that mode without clobbering one register.
1117 */
1118vector_fiq:
1119 disable_fiq
1120 subs pc, lr, #4
1121
1122/*=============================================================================
1123 * Address exception handler
1124 *-----------------------------------------------------------------------------
1125 * These aren't too critical.
1126 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1127 */
1128
1129vector_addrexcptn:
1130 b vector_addrexcptn
1131
1132/*
1133 * We group all the following data together to optimise
1134 * for CPUs with separate I & D caches.
1135 */
1136 .align 5
1137
1138.LCvswi:
1139 .word vector_swi
1140
7933523d 1141 .globl __stubs_end
1da177e4
LT
1142__stubs_end:
1143
7933523d 1144 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
1da177e4 1145
7933523d
RK
1146 .globl __vectors_start
1147__vectors_start:
1da177e4 1148 swi SYS_ERROR0
7933523d
RK
1149 b vector_und + stubs_offset
1150 ldr pc, .LCvswi + stubs_offset
1151 b vector_pabt + stubs_offset
1152 b vector_dabt + stubs_offset
1153 b vector_addrexcptn + stubs_offset
1154 b vector_irq + stubs_offset
1155 b vector_fiq + stubs_offset
1156
1157 .globl __vectors_end
1158__vectors_end:
1da177e4
LT
1159
1160 .data
1161
1da177e4
LT
1162 .globl cr_alignment
1163 .globl cr_no_alignment
1164cr_alignment:
1165 .space 4
1166cr_no_alignment:
1167 .space 4