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