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