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