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