blob: 0a2ba51cf35df1602db7d5a692c7c712a4bcf0d3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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)
Hyok S. Choiafeb90c2006-01-13 21:05:25 +00006 * nommu support by Hyok S. Choi (hyok.choi@samsung.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 *
Nicolas Pitre70b6f2b2007-12-04 14:33:33 +010014 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction
15 * that causes it to save wrong values... Be aware!
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Nicolas Pitref09b9972005-10-29 21:44:55 +010018#include <asm/memory.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/glue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/vfpmacros.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010021#include <mach/entry-macro.S>
Russell Kingd6551e82006-06-21 13:31:52 +010022#include <asm/thread_notify.h>
Catalin Marinasc4c57162009-02-16 11:42:09 +010023#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#include "entry-header.S"
26
27/*
Russell King187a51a2005-05-21 18:14:44 +010028 * Interrupt handling. Preserves r7, r8, r9
29 */
30 .macro irq_handler
Dan Williamsf80dff92007-02-16 22:16:32 +010031 get_irqnr_preamble r5, lr
Russell King187a51a2005-05-21 18:14:44 +0100321: get_irqnr_and_base r0, r6, r5, lr
33 movne r1, sp
34 @
35 @ routine called with r0 = irq number, r1 = struct pt_regs *
36 @
Catalin Marinasb86040a2009-07-24 12:32:54 +010037 adrne lr, BSYM(1b)
Russell King187a51a2005-05-21 18:14:44 +010038 bne asm_do_IRQ
Russell King791be9b2005-05-21 18:16:44 +010039
40#ifdef CONFIG_SMP
41 /*
42 * XXX
43 *
44 * this macro assumes that irqstat (r6) and base (r5) are
45 * preserved from get_irqnr_and_base above
46 */
47 test_for_ipi r0, r6, r5, lr
48 movne r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +010049 adrne lr, BSYM(1b)
Russell King791be9b2005-05-21 18:16:44 +010050 bne do_IPI
Russell King37ee16a2005-11-08 19:08:05 +000051
52#ifdef CONFIG_LOCAL_TIMERS
53 test_for_ltirq r0, r6, r5, lr
54 movne r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +010055 adrne lr, BSYM(1b)
Russell King37ee16a2005-11-08 19:08:05 +000056 bne do_local_timer
57#endif
Russell King791be9b2005-05-21 18:16:44 +010058#endif
59
Russell King187a51a2005-05-21 18:14:44 +010060 .endm
61
Nicolas Pitre785d3cd2007-12-03 15:27:56 -050062#ifdef CONFIG_KPROBES
63 .section .kprobes.text,"ax",%progbits
64#else
65 .text
66#endif
67
Russell King187a51a2005-05-21 18:14:44 +010068/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * Invalid mode handlers
70 */
Russell Kingccea7a12005-05-31 22:22:32 +010071 .macro inv_entry, reason
72 sub sp, sp, #S_FRAME_SIZE
Catalin Marinasb86040a2009-07-24 12:32:54 +010073 ARM( stmib sp, {r1 - lr} )
74 THUMB( stmia sp, {r0 - r12} )
75 THUMB( str sp, [sp, #S_SP] )
76 THUMB( str lr, [sp, #S_LR] )
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 mov r1, #\reason
78 .endm
79
80__pabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010081 inv_entry BAD_PREFETCH
82 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010083ENDPROC(__pabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85__dabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010086 inv_entry BAD_DATA
87 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010088ENDPROC(__dabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90__irq_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010091 inv_entry BAD_IRQ
92 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010093ENDPROC(__irq_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95__und_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010096 inv_entry BAD_UNDEFINSTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Russell Kingccea7a12005-05-31 22:22:32 +010098 @
99 @ XXX fall through to common_invalid
100 @
101
102@
103@ common_invalid - generic code for failed exception (re-entrant version of handlers)
104@
105common_invalid:
106 zero_fp
107
108 ldmia r0, {r4 - r6}
109 add r0, sp, #S_PC @ here for interlock avoidance
110 mov r7, #-1 @ "" "" "" ""
111 str r4, [sp] @ save preserved r0
112 stmia r0, {r5 - r7} @ lr_<exception>,
113 @ cpsr_<exception>, "old_r0"
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 b bad_mode
Catalin Marinas93ed3972008-08-28 11:22:32 +0100117ENDPROC(__und_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119/*
120 * SVC mode handlers
121 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000122
123#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
124#define SPFIX(code...) code
125#else
126#define SPFIX(code...)
127#endif
128
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500129 .macro svc_entry, stack_hole=0
Catalin Marinasc4c57162009-02-16 11:42:09 +0100130 UNWIND(.fnstart )
131 UNWIND(.save {r0 - pc} )
Catalin Marinasb86040a2009-07-24 12:32:54 +0100132 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
133#ifdef CONFIG_THUMB2_KERNEL
134 SPFIX( str r0, [sp] ) @ temporarily saved
135 SPFIX( mov r0, sp )
136 SPFIX( tst r0, #4 ) @ test original stack alignment
137 SPFIX( ldr r0, [sp] ) @ restored
138#else
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000139 SPFIX( tst sp, #4 )
Catalin Marinasb86040a2009-07-24 12:32:54 +0100140#endif
141 SPFIX( subeq sp, sp, #4 )
142 stmia sp, {r1 - r12}
Russell Kingccea7a12005-05-31 22:22:32 +0100143
144 ldmia r0, {r1 - r3}
Catalin Marinasb86040a2009-07-24 12:32:54 +0100145 add r5, sp, #S_SP - 4 @ here for interlock avoidance
Russell Kingccea7a12005-05-31 22:22:32 +0100146 mov r4, #-1 @ "" "" "" ""
Catalin Marinasb86040a2009-07-24 12:32:54 +0100147 add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4)
148 SPFIX( addeq r0, r0, #4 )
149 str r1, [sp, #-4]! @ save the "real" r0 copied
Russell Kingccea7a12005-05-31 22:22:32 +0100150 @ from the exception stack
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 mov r1, lr
153
154 @
155 @ We are now ready to fill in the remaining blanks on the stack:
156 @
157 @ r0 - sp_svc
158 @ r1 - lr_svc
159 @ r2 - lr_<exception>, already fixed up for correct return/restart
160 @ r3 - spsr_<exception>
161 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
162 @
163 stmia r5, {r0 - r4}
Uwe Kleine-König0d928b02009-08-13 20:38:17 +0200164
165 asm_trace_hardirqs_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 .endm
167
168 .align 5
169__dabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100170 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 @
173 @ get ready to re-enable interrupts if appropriate
174 @
175 mrs r9, cpsr
176 tst r3, #PSR_I_BIT
177 biceq r9, r9, #PSR_I_BIT
178
179 @
180 @ Call the processor-specific abort handler:
181 @
182 @ r2 - aborted context pc
183 @ r3 - aborted context cpsr
184 @
185 @ The abort handler must return the aborted address in r0, and
186 @ the fault status register in r1. r9 must be preserved.
187 @
Paul Brook48d79272008-04-18 22:43:07 +0100188#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 ldr r4, .LCprocfns
190 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100191 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#else
Paul Brook48d79272008-04-18 22:43:07 +0100193 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#endif
195
196 @
197 @ set desired IRQ state, then call main handler
198 @
199 msr cpsr_c, r9
200 mov r2, sp
201 bl do_DataAbort
202
203 @
204 @ IRQs off again before pulling preserved data off the stack
205 @
Russell King1ec42c02005-04-26 15:18:26 +0100206 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 @
209 @ restore SPSR and restart the instruction
210 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100211 ldr r2, [sp, #S_PSR]
212 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100213 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100214ENDPROC(__dabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 .align 5
217__irq_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100218 svc_entry
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100221 get_thread_info tsk
222 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
223 add r7, r8, #1 @ increment it
224 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100226
Russell King187a51a2005-05-21 18:14:44 +0100227 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#ifdef CONFIG_PREEMPT
Russell King28fab1a2008-04-13 17:47:35 +0100229 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Russell King706fdd92005-05-21 18:15:45 +0100230 ldr r0, [tsk, #TI_FLAGS] @ get flags
Russell King28fab1a2008-04-13 17:47:35 +0100231 teq r8, #0 @ if preempt count != 0
232 movne r0, #0 @ force flags to 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 tst r0, #_TIF_NEED_RESCHED
234 blne svc_preempt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100236 ldr r4, [sp, #S_PSR] @ irqs are already disabled
Russell King7ad1bcb2006-08-27 12:07:02 +0100237#ifdef CONFIG_TRACE_IRQFLAGS
Catalin Marinasb86040a2009-07-24 12:32:54 +0100238 tst r4, #PSR_I_BIT
Russell King7ad1bcb2006-08-27 12:07:02 +0100239 bleq trace_hardirqs_on
240#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100241 svc_exit r4 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100242 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100243ENDPROC(__irq_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 .ltorg
246
247#ifdef CONFIG_PREEMPT
248svc_preempt:
Russell King28fab1a2008-04-13 17:47:35 +0100249 mov r8, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501: bl preempt_schedule_irq @ irq en/disable is done inside
Russell King706fdd92005-05-21 18:15:45 +0100251 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 tst r0, #_TIF_NEED_RESCHED
Russell King28fab1a2008-04-13 17:47:35 +0100253 moveq pc, r8 @ go again
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 b 1b
255#endif
256
257 .align 5
258__und_svc:
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500259#ifdef CONFIG_KPROBES
260 @ If a kprobe is about to simulate a "stmdb sp..." instruction,
261 @ it obviously needs free stack space which then will belong to
262 @ the saved context.
263 svc_entry 64
264#else
Russell Kingccea7a12005-05-31 22:22:32 +0100265 svc_entry
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500266#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 @
269 @ call emulation code, which returns using r9 if it has emulated
270 @ the instruction, or the more conventional lr if we are to treat
271 @ this as a real undefined instruction
272 @
273 @ r0 - instruction
274 @
Catalin Marinas83e686e2009-09-18 23:27:07 +0100275#ifndef CONFIG_THUMB2_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 ldr r0, [r2, #-4]
Catalin Marinas83e686e2009-09-18 23:27:07 +0100277#else
278 ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2
279 and r9, r0, #0xf800
280 cmp r9, #0xe800 @ 32-bit instruction if xx >= 0
281 ldrhhs r9, [r2] @ bottom 16 bits
282 orrhs r0, r9, r0, lsl #16
283#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100284 adr r9, BSYM(1f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 bl call_fpe
286
287 mov r0, sp @ struct pt_regs *regs
288 bl do_undefinstr
289
290 @
291 @ IRQs off again before pulling preserved data off the stack
292 @
Russell King1ec42c02005-04-26 15:18:26 +01002931: disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 @
296 @ restore SPSR and restart the instruction
297 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100298 ldr r2, [sp, #S_PSR] @ Get SVC cpsr
299 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100300 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100301ENDPROC(__und_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 .align 5
304__pabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100305 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 @
308 @ re-enable interrupts if appropriate
309 @
310 mrs r9, cpsr
311 tst r3, #PSR_I_BIT
312 biceq r9, r9, #PSR_I_BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 @
315 @ set args, then call main handler
316 @
317 @ r0 - address of faulting instruction
318 @ r1 - pointer to registers on stack
319 @
Paul Brook48d79272008-04-18 22:43:07 +0100320#ifdef MULTI_PABORT
321 mov r0, r2 @ pass address of aborted instruction.
322 ldr r4, .LCprocfns
323 mov lr, pc
324 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
325#else
326 CPU_PABORT_HANDLER(r0, r2)
327#endif
328 msr cpsr_c, r9 @ Maybe enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 mov r1, sp @ regs
330 bl do_PrefetchAbort @ call abort handler
331
332 @
333 @ IRQs off again before pulling preserved data off the stack
334 @
Russell King1ec42c02005-04-26 15:18:26 +0100335 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 @
338 @ restore SPSR and restart the instruction
339 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100340 ldr r2, [sp, #S_PSR]
341 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100342 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100343ENDPROC(__pabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 .align 5
Russell King49f680e2005-05-31 18:02:00 +0100346.LCcralign:
347 .word cr_alignment
Paul Brook48d79272008-04-18 22:43:07 +0100348#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349.LCprocfns:
350 .word processor
351#endif
352.LCfp:
353 .word fp_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355/*
356 * User mode handlers
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000357 *
358 * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000360
361#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
362#error "sizeof(struct pt_regs) must be a multiple of 8"
363#endif
364
Russell Kingccea7a12005-05-31 22:22:32 +0100365 .macro usr_entry
Catalin Marinasc4c57162009-02-16 11:42:09 +0100366 UNWIND(.fnstart )
367 UNWIND(.cantunwind ) @ don't unwind the user space
Russell Kingccea7a12005-05-31 22:22:32 +0100368 sub sp, sp, #S_FRAME_SIZE
Catalin Marinasb86040a2009-07-24 12:32:54 +0100369 ARM( stmib sp, {r1 - r12} )
370 THUMB( stmia sp, {r0 - r12} )
Russell Kingccea7a12005-05-31 22:22:32 +0100371
372 ldmia r0, {r1 - r3}
373 add r0, sp, #S_PC @ here for interlock avoidance
374 mov r4, #-1 @ "" "" "" ""
375
376 str r1, [sp] @ save the "real" r0 copied
377 @ from the exception stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 @
380 @ We are now ready to fill in the remaining blanks on the stack:
381 @
382 @ r2 - lr_<exception>, already fixed up for correct return/restart
383 @ r3 - spsr_<exception>
384 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
385 @
386 @ Also, separately save sp_usr and lr_usr
387 @
Russell Kingccea7a12005-05-31 22:22:32 +0100388 stmia r0, {r2 - r4}
Catalin Marinasb86040a2009-07-24 12:32:54 +0100389 ARM( stmdb r0, {sp, lr}^ )
390 THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 @
393 @ Enable the alignment trap while in kernel mode
394 @
Russell King49f680e2005-05-31 18:02:00 +0100395 alignment_trap r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 @
398 @ Clear FP to mark the first stack frame
399 @
400 zero_fp
Uwe Kleine-König0d928b02009-08-13 20:38:17 +0200401
402 asm_trace_hardirqs_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .endm
404
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100405 .macro kuser_cmpxchg_check
406#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
407#ifndef CONFIG_MMU
408#warning "NPTL on non MMU needs fixing"
409#else
410 @ Make sure our user space atomic helper is restarted
411 @ if it was interrupted in a critical region. Here we
412 @ perform a quick test inline since it should be false
413 @ 99.9999% of the time. The rest is done out of line.
414 cmp r2, #TASK_SIZE
415 blhs kuser_cmpxchg_fixup
416#endif
417#endif
418 .endm
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 .align 5
421__dabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100422 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100423 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 @
426 @ Call the processor-specific abort handler:
427 @
428 @ r2 - aborted context pc
429 @ r3 - aborted context cpsr
430 @
431 @ The abort handler must return the aborted address in r0, and
432 @ the fault status register in r1.
433 @
Paul Brook48d79272008-04-18 22:43:07 +0100434#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 ldr r4, .LCprocfns
436 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100437 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#else
Paul Brook48d79272008-04-18 22:43:07 +0100439 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#endif
441
442 @
443 @ IRQs on, then call the main handler
444 @
Russell King1ec42c02005-04-26 15:18:26 +0100445 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 mov r2, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +0100447 adr lr, BSYM(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 b do_DataAbort
Catalin Marinasc4c57162009-02-16 11:42:09 +0100449 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100450ENDPROC(__dabt_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 .align 5
453__irq_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100454 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100455 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100459 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
460 add r7, r8, #1 @ increment it
461 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100463
Russell King187a51a2005-05-21 18:14:44 +0100464 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100466 ldr r0, [tsk, #TI_PREEMPT]
467 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 teq r0, r7
Catalin Marinasb86040a2009-07-24 12:32:54 +0100469 ARM( strne r0, [r0, -r0] )
470 THUMB( movne r0, #0 )
471 THUMB( strne r0, [r0] )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#endif
Russell King7ad1bcb2006-08-27 12:07:02 +0100473#ifdef CONFIG_TRACE_IRQFLAGS
474 bl trace_hardirqs_on
475#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 mov why, #0
478 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100479 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100480ENDPROC(__irq_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 .ltorg
483
484 .align 5
485__und_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100486 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 @
489 @ fall through to the emulation code, which returns using r9 if
490 @ it has emulated the instruction, or the more conventional lr
491 @ if we are to treat this as a real undefined instruction
492 @
493 @ r0 - instruction
494 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100495 adr r9, BSYM(ret_from_exception)
496 adr lr, BSYM(__und_usr_unknown)
Paul Brookcb170a42008-04-18 22:43:08 +0100497 tst r3, #PSR_T_BIT @ Thumb mode?
Catalin Marinasb86040a2009-07-24 12:32:54 +0100498 itet eq @ explicit IT needed for the 1f label
Paul Brookcb170a42008-04-18 22:43:08 +0100499 subeq r4, r2, #4 @ ARM instr at LR - 4
500 subne r4, r2, #2 @ Thumb instr at LR - 2
5011: ldreqt r0, [r4]
Catalin Marinas26584852009-05-30 14:00:18 +0100502#ifdef CONFIG_CPU_ENDIAN_BE8
503 reveq r0, r0 @ little endian instruction
504#endif
Paul Brookcb170a42008-04-18 22:43:08 +0100505 beq call_fpe
506 @ Thumb instruction
507#if __LINUX_ARM_ARCH__ >= 7
Catalin Marinasb86040a2009-07-24 12:32:54 +01005082:
509 ARM( ldrht r5, [r4], #2 )
510 THUMB( ldrht r5, [r4] )
511 THUMB( add r4, r4, #2 )
Paul Brookcb170a42008-04-18 22:43:08 +0100512 and r0, r5, #0xf800 @ mask bits 111x x... .... ....
513 cmp r0, #0xe800 @ 32bit instruction if xx != 0
514 blo __und_usr_unknown
5153: ldrht r0, [r4]
516 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
517 orr r0, r0, r5, lsl #16
518#else
519 b __und_usr_unknown
520#endif
Catalin Marinasc4c57162009-02-16 11:42:09 +0100521 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100522ENDPROC(__und_usr)
Paul Brookcb170a42008-04-18 22:43:08 +0100523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 @
525 @ fallthrough to call_fpe
526 @
527
528/*
529 * The out of line fixup for the ldrt above.
530 */
531 .section .fixup, "ax"
Paul Brookcb170a42008-04-18 22:43:08 +01005324: mov pc, r9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .previous
534 .section __ex_table,"a"
Paul Brookcb170a42008-04-18 22:43:08 +0100535 .long 1b, 4b
536#if __LINUX_ARM_ARCH__ >= 7
537 .long 2b, 4b
538 .long 3b, 4b
539#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 .previous
541
542/*
543 * Check whether the instruction is a co-processor instruction.
544 * If yes, we need to call the relevant co-processor handler.
545 *
546 * Note that we don't do a full check here for the co-processor
547 * instructions; all instructions with bit 27 set are well
548 * defined. The only instructions that should fault are the
549 * co-processor instructions. However, we have to watch out
550 * for the ARM6/ARM7 SWI bug.
551 *
Catalin Marinasb5872db2008-01-10 19:16:17 +0100552 * NEON is a special case that has to be handled here. Not all
553 * NEON instructions are co-processor instructions, so we have
554 * to make a special case of checking for them. Plus, there's
555 * five groups of them, so we have a table of mask/opcode pairs
556 * to check against, and if any match then we branch off into the
557 * NEON handler code.
558 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 * Emulators may wish to make use of the following registers:
560 * r0 = instruction opcode.
561 * r2 = PC+4
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000562 * r9 = normal "successful" return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 * r10 = this threads thread_info structure.
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000564 * lr = unrecognised instruction return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 */
Paul Brookcb170a42008-04-18 22:43:08 +0100566 @
567 @ Fall-through from Thumb-2 __und_usr
568 @
569#ifdef CONFIG_NEON
570 adr r6, .LCneon_thumb_opcodes
571 b 2f
572#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573call_fpe:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100574#ifdef CONFIG_NEON
Paul Brookcb170a42008-04-18 22:43:08 +0100575 adr r6, .LCneon_arm_opcodes
Catalin Marinasb5872db2008-01-10 19:16:17 +01005762:
577 ldr r7, [r6], #4 @ mask value
578 cmp r7, #0 @ end mask?
579 beq 1f
580 and r8, r0, r7
581 ldr r7, [r6], #4 @ opcode bits matching in mask
582 cmp r8, r7 @ NEON instruction?
583 bne 2b
584 get_thread_info r10
585 mov r7, #1
586 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
587 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
588 b do_vfp @ let VFP handler handle this
5891:
590#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
Paul Brookcb170a42008-04-18 22:43:08 +0100592 tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
594 and r8, r0, #0x0f000000 @ mask out op-code bits
595 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
596#endif
597 moveq pc, lr
598 get_thread_info r10 @ get current thread
599 and r8, r0, #0x00000f00 @ mask out CP number
Catalin Marinasb86040a2009-07-24 12:32:54 +0100600 THUMB( lsr r8, r8, #8 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 mov r7, #1
602 add r6, r10, #TI_USED_CP
Catalin Marinasb86040a2009-07-24 12:32:54 +0100603 ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[]
604 THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#ifdef CONFIG_IWMMXT
606 @ Test if we need to give access to iWMMXt coprocessors
607 ldr r5, [r10, #TI_FLAGS]
608 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
609 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
610 bcs iwmmxt_task_enable
611#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100612 ARM( add pc, pc, r8, lsr #6 )
613 THUMB( lsl r8, r8, #2 )
614 THUMB( add pc, r8 )
615 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Catalin Marinasb86040a2009-07-24 12:32:54 +0100617 W(mov) pc, lr @ CP#0
618 W(b) do_fpe @ CP#1 (FPE)
619 W(b) do_fpe @ CP#2 (FPE)
620 W(mov) pc, lr @ CP#3
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100621#ifdef CONFIG_CRUNCH
622 b crunch_task_enable @ CP#4 (MaverickCrunch)
623 b crunch_task_enable @ CP#5 (MaverickCrunch)
624 b crunch_task_enable @ CP#6 (MaverickCrunch)
625#else
Catalin Marinasb86040a2009-07-24 12:32:54 +0100626 W(mov) pc, lr @ CP#4
627 W(mov) pc, lr @ CP#5
628 W(mov) pc, lr @ CP#6
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100629#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100630 W(mov) pc, lr @ CP#7
631 W(mov) pc, lr @ CP#8
632 W(mov) pc, lr @ CP#9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#ifdef CONFIG_VFP
Catalin Marinasb86040a2009-07-24 12:32:54 +0100634 W(b) do_vfp @ CP#10 (VFP)
635 W(b) do_vfp @ CP#11 (VFP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636#else
Catalin Marinasb86040a2009-07-24 12:32:54 +0100637 W(mov) pc, lr @ CP#10 (VFP)
638 W(mov) pc, lr @ CP#11 (VFP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100640 W(mov) pc, lr @ CP#12
641 W(mov) pc, lr @ CP#13
642 W(mov) pc, lr @ CP#14 (Debug)
643 W(mov) pc, lr @ CP#15 (Control)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Catalin Marinasb5872db2008-01-10 19:16:17 +0100645#ifdef CONFIG_NEON
646 .align 6
647
Paul Brookcb170a42008-04-18 22:43:08 +0100648.LCneon_arm_opcodes:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100649 .word 0xfe000000 @ mask
650 .word 0xf2000000 @ opcode
651
652 .word 0xff100000 @ mask
653 .word 0xf4000000 @ opcode
654
655 .word 0x00000000 @ mask
656 .word 0x00000000 @ opcode
Paul Brookcb170a42008-04-18 22:43:08 +0100657
658.LCneon_thumb_opcodes:
659 .word 0xef000000 @ mask
660 .word 0xef000000 @ opcode
661
662 .word 0xff100000 @ mask
663 .word 0xf9000000 @ opcode
664
665 .word 0x00000000 @ mask
666 .word 0x00000000 @ opcode
Catalin Marinasb5872db2008-01-10 19:16:17 +0100667#endif
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669do_fpe:
Russell King5d25ac02006-03-15 12:33:43 +0000670 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 ldr r4, .LCfp
672 add r10, r10, #TI_FPSTATE @ r10 = workspace
673 ldr pc, [r4] @ Call FP module USR entry point
674
675/*
676 * The FP module is called with these registers set:
677 * r0 = instruction
678 * r2 = PC+4
679 * r9 = normal "successful" return address
680 * r10 = FP workspace
681 * lr = unrecognised FP instruction return address
682 */
683
684 .data
685ENTRY(fp_enter)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000686 .word no_fp
Nicolas Pitre785d3cd2007-12-03 15:27:56 -0500687 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Catalin Marinas83e686e2009-09-18 23:27:07 +0100689ENTRY(no_fp)
690 mov pc, lr
691ENDPROC(no_fp)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000692
693__und_usr_unknown:
Russell Kingecbab712009-01-27 23:20:00 +0000694 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 mov r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +0100696 adr lr, BSYM(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 b do_undefinstr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100698ENDPROC(__und_usr_unknown)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 .align 5
701__pabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100702 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Paul Brook48d79272008-04-18 22:43:07 +0100704#ifdef MULTI_PABORT
705 mov r0, r2 @ pass address of aborted instruction.
706 ldr r4, .LCprocfns
707 mov lr, pc
708 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
709#else
710 CPU_PABORT_HANDLER(r0, r2)
711#endif
Russell King1ec42c02005-04-26 15:18:26 +0100712 enable_irq @ Enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 mov r1, sp @ regs
714 bl do_PrefetchAbort @ call abort handler
Catalin Marinasc4c57162009-02-16 11:42:09 +0100715 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 /* fall through */
717/*
718 * This is the return code to user mode for abort handlers
719 */
720ENTRY(ret_from_exception)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100721 UNWIND(.fnstart )
722 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 get_thread_info tsk
724 mov why, #0
725 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100726 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100727ENDPROC(__pabt_usr)
728ENDPROC(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730/*
731 * Register switch for ARMv3 and ARMv4 processors
732 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
733 * previous and next are guaranteed not to be the same.
734 */
735ENTRY(__switch_to)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100736 UNWIND(.fnstart )
737 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 add ip, r1, #TI_CPU_SAVE
739 ldr r3, [r2, #TI_TP_VALUE]
Catalin Marinasb86040a2009-07-24 12:32:54 +0100740 ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack
741 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
742 THUMB( str sp, [ip], #4 )
743 THUMB( str lr, [ip], #4 )
Russell Kingd6551e82006-06-21 13:31:52 +0100744#ifdef CONFIG_MMU
745 ldr r6, [r2, #TI_CPU_DOMAIN]
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000746#endif
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100747#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100748 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100749#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 mov r4, #0xffff0fff
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100751 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
752#endif
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000753#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000755#endif
Russell Kingd6551e82006-06-21 13:31:52 +0100756 mov r5, r0
757 add r4, r2, #TI_CPU_SAVE
758 ldr r0, =thread_notify_head
759 mov r1, #THREAD_NOTIFY_SWITCH
760 bl atomic_notifier_call_chain
Catalin Marinasb86040a2009-07-24 12:32:54 +0100761 THUMB( mov ip, r4 )
Russell Kingd6551e82006-06-21 13:31:52 +0100762 mov r0, r5
Catalin Marinasb86040a2009-07-24 12:32:54 +0100763 ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously
764 THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously
765 THUMB( ldr sp, [ip], #4 )
766 THUMB( ldr pc, [ip] )
Catalin Marinasc4c57162009-02-16 11:42:09 +0100767 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100768ENDPROC(__switch_to)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100771
772/*
773 * User helpers.
774 *
775 * These are segment of kernel provided user code reachable from user space
776 * at a fixed address in kernel memory. This is used to provide user space
777 * with some operations which require kernel help because of unimplemented
778 * native feature and/or instructions in many ARM CPUs. The idea is for
779 * this code to be executed directly in user mode for best efficiency but
780 * which is too intimate with the kernel counter part to be left to user
781 * libraries. In fact this code might even differ from one CPU to another
782 * depending on the available instruction set and restrictions like on
783 * SMP systems. In other words, the kernel reserves the right to change
784 * this code as needed without warning. Only the entry points and their
785 * results are guaranteed to be stable.
786 *
787 * Each segment is 32-byte aligned and will be moved to the top of the high
788 * vector page. New segments (if ever needed) must be added in front of
789 * existing ones. This mechanism should be used only for things that are
790 * really small and justified, and not be abused freely.
791 *
792 * User space is expected to implement those things inline when optimizing
793 * for a processor that has the necessary native support, but only if such
794 * resulting binaries are already to be incompatible with earlier ARM
795 * processors due to the use of unsupported instructions other than what
796 * is provided here. In other words don't make binaries unable to run on
797 * earlier processors just for the sake of not using these kernel helpers
798 * if your compiled code is not going to use the new instructions for other
799 * purpose.
800 */
Catalin Marinasb86040a2009-07-24 12:32:54 +0100801 THUMB( .arm )
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100802
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100803 .macro usr_ret, reg
804#ifdef CONFIG_ARM_THUMB
805 bx \reg
806#else
807 mov pc, \reg
808#endif
809 .endm
810
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100811 .align 5
812 .globl __kuser_helper_start
813__kuser_helper_start:
814
815/*
816 * Reference prototype:
817 *
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000818 * void __kernel_memory_barrier(void)
819 *
820 * Input:
821 *
822 * lr = return address
823 *
824 * Output:
825 *
826 * none
827 *
828 * Clobbered:
829 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100830 * none
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000831 *
832 * Definition and user space usage example:
833 *
834 * typedef void (__kernel_dmb_t)(void);
835 * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
836 *
837 * Apply any needed memory barrier to preserve consistency with data modified
838 * manually and __kuser_cmpxchg usage.
839 *
840 * This could be used as follows:
841 *
842 * #define __kernel_dmb() \
843 * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
Paul Brook6896eec2006-03-28 22:19:29 +0100844 * : : : "r0", "lr","cc" )
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000845 */
846
847__kuser_memory_barrier: @ 0xffff0fa0
Russell Kingbac4e962009-05-25 20:58:00 +0100848 smp_dmb
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100849 usr_ret lr
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000850
851 .align 5
852
853/*
854 * Reference prototype:
855 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100856 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
857 *
858 * Input:
859 *
860 * r0 = oldval
861 * r1 = newval
862 * r2 = ptr
863 * lr = return address
864 *
865 * Output:
866 *
867 * r0 = returned value (zero or non-zero)
868 * C flag = set if r0 == 0, clear if r0 != 0
869 *
870 * Clobbered:
871 *
872 * r3, ip, flags
873 *
874 * Definition and user space usage example:
875 *
876 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
877 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
878 *
879 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
880 * Return zero if *ptr was changed or non-zero if no exchange happened.
881 * The C flag is also set if *ptr was changed to allow for assembly
882 * optimization in the calling code.
883 *
Nicolas Pitre5964eae2006-02-08 21:19:37 +0000884 * Notes:
885 *
886 * - This routine already includes memory barriers as needed.
887 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100888 * For example, a user space atomic_add implementation could look like this:
889 *
890 * #define atomic_add(ptr, val) \
891 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
892 * register unsigned int __result asm("r1"); \
893 * asm volatile ( \
894 * "1: @ atomic_add\n\t" \
895 * "ldr r0, [r2]\n\t" \
896 * "mov r3, #0xffff0fff\n\t" \
897 * "add lr, pc, #4\n\t" \
898 * "add r1, r0, %2\n\t" \
899 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
900 * "bcc 1b" \
901 * : "=&r" (__result) \
902 * : "r" (__ptr), "rIL" (val) \
903 * : "r0","r3","ip","lr","cc","memory" ); \
904 * __result; })
905 */
906
907__kuser_cmpxchg: @ 0xffff0fc0
908
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100909#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100910
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100911 /*
912 * Poor you. No fast solution possible...
913 * The kernel itself must perform the operation.
914 * A special ghost syscall is used for that (see traps.c).
915 */
Nicolas Pitre5e097442006-01-18 22:38:49 +0000916 stmfd sp!, {r7, lr}
917 mov r7, #0xff00 @ 0xfff0 into r7 for EABI
918 orr r7, r7, #0xf0
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100919 swi #0x9ffff0
Nicolas Pitre5e097442006-01-18 22:38:49 +0000920 ldmfd sp!, {r7, pc}
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100921
922#elif __LINUX_ARM_ARCH__ < 6
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100923
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000924#ifdef CONFIG_MMU
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100925
926 /*
927 * The only thing that can break atomicity in this cmpxchg
928 * implementation is either an IRQ or a data abort exception
929 * causing another process/thread to be scheduled in the middle
930 * of the critical sequence. To prevent this, code is added to
931 * the IRQ and data abort exception handlers to set the pc back
932 * to the beginning of the critical section if it is found to be
933 * within that critical section (see kuser_cmpxchg_fixup).
934 */
9351: ldr r3, [r2] @ load current val
936 subs r3, r3, r0 @ compare with oldval
9372: streq r1, [r2] @ store newval if eq
938 rsbs r0, r3, #0 @ set return val and C flag
939 usr_ret lr
940
941 .text
942kuser_cmpxchg_fixup:
943 @ Called from kuser_cmpxchg_check macro.
944 @ r2 = address of interrupted insn (must be preserved).
945 @ sp = saved regs. r7 and r8 are clobbered.
946 @ 1b = first critical insn, 2b = last critical insn.
947 @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
948 mov r7, #0xffff0fff
949 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
950 subs r8, r2, r7
951 rsbcss r8, r8, #(2b - 1b)
952 strcs r7, [sp, #S_PC]
953 mov pc, lr
954 .previous
955
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000956#else
957#warning "NPTL on non MMU needs fixing"
958 mov r0, #-1
959 adds r0, r0, #0
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100960 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100961#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100962
963#else
964
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000965#ifdef CONFIG_SMP
966 mcr p15, 0, r0, c7, c10, 5 @ dmb
967#endif
Nicolas Pitreb49c0f22007-11-20 17:20:29 +01009681: ldrex r3, [r2]
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100969 subs r3, r3, r0
970 strexeq r3, r1, [r2]
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100971 teqeq r3, #1
972 beq 1b
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100973 rsbs r0, r3, #0
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100974 /* beware -- each __kuser slot must be 8 instructions max */
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000975#ifdef CONFIG_SMP
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100976 b __kuser_memory_barrier
977#else
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100978 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100979#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100980
981#endif
982
983 .align 5
984
985/*
986 * Reference prototype:
987 *
988 * int __kernel_get_tls(void)
989 *
990 * Input:
991 *
992 * lr = return address
993 *
994 * Output:
995 *
996 * r0 = TLS value
997 *
998 * Clobbered:
999 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +01001000 * none
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001001 *
1002 * Definition and user space usage example:
1003 *
1004 * typedef int (__kernel_get_tls_t)(void);
1005 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
1006 *
1007 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
1008 *
1009 * This could be used as follows:
1010 *
1011 * #define __kernel_get_tls() \
1012 * ({ register unsigned int __val asm("r0"); \
1013 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
1014 * : "=r" (__val) : : "lr","cc" ); \
1015 * __val; })
1016 */
1017
1018__kuser_get_tls: @ 0xffff0fe0
1019
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +01001020#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001021 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001022#else
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001023 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001024#endif
Nicolas Pitreba9b5d72006-08-18 17:20:15 +01001025 usr_ret lr
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001026
1027 .rep 5
1028 .word 0 @ pad up to __kuser_helper_version
1029 .endr
1030
1031/*
1032 * Reference declaration:
1033 *
1034 * extern unsigned int __kernel_helper_version;
1035 *
1036 * Definition and user space usage example:
1037 *
1038 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
1039 *
1040 * User space may read this to determine the curent number of helpers
1041 * available.
1042 */
1043
1044__kuser_helper_version: @ 0xffff0ffc
1045 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
1046
1047 .globl __kuser_helper_end
1048__kuser_helper_end:
1049
Catalin Marinasb86040a2009-07-24 12:32:54 +01001050 THUMB( .thumb )
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052/*
1053 * Vector stubs.
1054 *
Russell King79335232005-04-26 15:17:42 +01001055 * This code is copied to 0xffff0200 so we can use branches in the
1056 * vectors, rather than ldr's. Note that this code must not
1057 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 *
1059 * Common stub entry macro:
1060 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
Russell Kingccea7a12005-05-31 22:22:32 +01001061 *
1062 * SP points to a minimal amount of processor-private memory, the address
1063 * of which is copied into r0 for the mode specific abort handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001065 .macro vector_stub, name, mode, correction=0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .align 5
1067
1068vector_\name:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .if \correction
1070 sub lr, lr, #\correction
1071 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Russell Kingccea7a12005-05-31 22:22:32 +01001073 @
1074 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1075 @ (parent CPSR)
1076 @
1077 stmia sp, {r0, lr} @ save r0, lr
1078 mrs lr, spsr
1079 str lr, [sp, #8] @ save spsr
1080
1081 @
1082 @ Prepare for SVC32 mode. IRQs remain disabled.
1083 @
1084 mrs r0, cpsr
Catalin Marinasb86040a2009-07-24 12:32:54 +01001085 eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
Russell Kingccea7a12005-05-31 22:22:32 +01001086 msr spsr_cxsf, r0
1087
1088 @
1089 @ the branch table must immediately follow this code
1090 @
Russell Kingccea7a12005-05-31 22:22:32 +01001091 and lr, lr, #0x0f
Catalin Marinasb86040a2009-07-24 12:32:54 +01001092 THUMB( adr r0, 1f )
1093 THUMB( ldr lr, [r0, lr, lsl #2] )
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001094 mov r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +01001095 ARM( ldr lr, [pc, lr, lsl #2] )
Russell Kingccea7a12005-05-31 22:22:32 +01001096 movs pc, lr @ branch to handler in SVC mode
Catalin Marinas93ed3972008-08-28 11:22:32 +01001097ENDPROC(vector_\name)
Catalin Marinas88987ef2009-07-24 12:32:52 +01001098
1099 .align 2
1100 @ handler addresses follow this label
11011:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .endm
1103
Russell King79335232005-04-26 15:17:42 +01001104 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105__stubs_start:
1106/*
1107 * Interrupt dispatcher
1108 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001109 vector_stub irq, IRQ_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 .long __irq_usr @ 0 (USR_26 / USR_32)
1112 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1113 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1114 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1115 .long __irq_invalid @ 4
1116 .long __irq_invalid @ 5
1117 .long __irq_invalid @ 6
1118 .long __irq_invalid @ 7
1119 .long __irq_invalid @ 8
1120 .long __irq_invalid @ 9
1121 .long __irq_invalid @ a
1122 .long __irq_invalid @ b
1123 .long __irq_invalid @ c
1124 .long __irq_invalid @ d
1125 .long __irq_invalid @ e
1126 .long __irq_invalid @ f
1127
1128/*
1129 * Data abort dispatcher
1130 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1131 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001132 vector_stub dabt, ABT_MODE, 8
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 .long __dabt_usr @ 0 (USR_26 / USR_32)
1135 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1136 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1137 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1138 .long __dabt_invalid @ 4
1139 .long __dabt_invalid @ 5
1140 .long __dabt_invalid @ 6
1141 .long __dabt_invalid @ 7
1142 .long __dabt_invalid @ 8
1143 .long __dabt_invalid @ 9
1144 .long __dabt_invalid @ a
1145 .long __dabt_invalid @ b
1146 .long __dabt_invalid @ c
1147 .long __dabt_invalid @ d
1148 .long __dabt_invalid @ e
1149 .long __dabt_invalid @ f
1150
1151/*
1152 * Prefetch abort dispatcher
1153 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1154 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001155 vector_stub pabt, ABT_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 .long __pabt_usr @ 0 (USR_26 / USR_32)
1158 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1159 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1160 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1161 .long __pabt_invalid @ 4
1162 .long __pabt_invalid @ 5
1163 .long __pabt_invalid @ 6
1164 .long __pabt_invalid @ 7
1165 .long __pabt_invalid @ 8
1166 .long __pabt_invalid @ 9
1167 .long __pabt_invalid @ a
1168 .long __pabt_invalid @ b
1169 .long __pabt_invalid @ c
1170 .long __pabt_invalid @ d
1171 .long __pabt_invalid @ e
1172 .long __pabt_invalid @ f
1173
1174/*
1175 * Undef instr entry dispatcher
1176 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1177 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001178 vector_stub und, UND_MODE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180 .long __und_usr @ 0 (USR_26 / USR_32)
1181 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1182 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1183 .long __und_svc @ 3 (SVC_26 / SVC_32)
1184 .long __und_invalid @ 4
1185 .long __und_invalid @ 5
1186 .long __und_invalid @ 6
1187 .long __und_invalid @ 7
1188 .long __und_invalid @ 8
1189 .long __und_invalid @ 9
1190 .long __und_invalid @ a
1191 .long __und_invalid @ b
1192 .long __und_invalid @ c
1193 .long __und_invalid @ d
1194 .long __und_invalid @ e
1195 .long __und_invalid @ f
1196
1197 .align 5
1198
1199/*=============================================================================
1200 * Undefined FIQs
1201 *-----------------------------------------------------------------------------
1202 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1203 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1204 * Basically to switch modes, we *HAVE* to clobber one register... brain
1205 * damage alert! I don't think that we can execute any code in here in any
1206 * other mode than FIQ... Ok you can switch to another mode, but you can't
1207 * get out of that mode without clobbering one register.
1208 */
1209vector_fiq:
1210 disable_fiq
1211 subs pc, lr, #4
1212
1213/*=============================================================================
1214 * Address exception handler
1215 *-----------------------------------------------------------------------------
1216 * These aren't too critical.
1217 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1218 */
1219
1220vector_addrexcptn:
1221 b vector_addrexcptn
1222
1223/*
1224 * We group all the following data together to optimise
1225 * for CPUs with separate I & D caches.
1226 */
1227 .align 5
1228
1229.LCvswi:
1230 .word vector_swi
1231
Russell King79335232005-04-26 15:17:42 +01001232 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233__stubs_end:
1234
Russell King79335232005-04-26 15:17:42 +01001235 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Russell King79335232005-04-26 15:17:42 +01001237 .globl __vectors_start
1238__vectors_start:
Catalin Marinasb86040a2009-07-24 12:32:54 +01001239 ARM( swi SYS_ERROR0 )
1240 THUMB( svc #0 )
1241 THUMB( nop )
1242 W(b) vector_und + stubs_offset
1243 W(ldr) pc, .LCvswi + stubs_offset
1244 W(b) vector_pabt + stubs_offset
1245 W(b) vector_dabt + stubs_offset
1246 W(b) vector_addrexcptn + stubs_offset
1247 W(b) vector_irq + stubs_offset
1248 W(b) vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Russell King79335232005-04-26 15:17:42 +01001250 .globl __vectors_end
1251__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 .data
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 .globl cr_alignment
1256 .globl cr_no_alignment
1257cr_alignment:
1258 .space 4
1259cr_no_alignment:
1260 .space 4