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