blob: a866dce611d0cb2a190dab8381ecf63b54ff5bd1 [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>
Russell Kingcc20d422009-11-09 23:53:29 +000024#include <asm/unistd.h>
Tony Lindgrenf159f4e2010-07-05 14:53:10 +010025#include <asm/tls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include "entry-header.S"
Magnus Dammcd544ce2010-12-22 13:20:08 +010028#include <asm/entry-macro-multi.S>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/*
Russell King187a51a2005-05-21 18:14:44 +010031 * Interrupt handling. Preserves r7, r8, r9
32 */
33 .macro irq_handler
eric miao52108642010-12-13 09:42:34 +010034#ifdef CONFIG_MULTI_IRQ_HANDLER
35 ldr r5, =handle_arch_irq
36 mov r0, sp
37 ldr r5, [r5]
38 adr lr, BSYM(9997f)
39 teq r5, #0
40 movne pc, r5
41#endif
Magnus Dammcd544ce2010-12-22 13:20:08 +010042 arch_irq_handler_default
eric miao52108642010-12-13 09:42:34 +0100439997:
Russell King187a51a2005-05-21 18:14:44 +010044 .endm
45
Nicolas Pitre785d3cd2007-12-03 15:27:56 -050046#ifdef CONFIG_KPROBES
47 .section .kprobes.text,"ax",%progbits
48#else
49 .text
50#endif
51
Russell King187a51a2005-05-21 18:14:44 +010052/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * Invalid mode handlers
54 */
Russell Kingccea7a12005-05-31 22:22:32 +010055 .macro inv_entry, reason
56 sub sp, sp, #S_FRAME_SIZE
Catalin Marinasb86040a2009-07-24 12:32:54 +010057 ARM( stmib sp, {r1 - lr} )
58 THUMB( stmia sp, {r0 - r12} )
59 THUMB( str sp, [sp, #S_SP] )
60 THUMB( str lr, [sp, #S_LR] )
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 mov r1, #\reason
62 .endm
63
64__pabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010065 inv_entry BAD_PREFETCH
66 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010067ENDPROC(__pabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69__dabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010070 inv_entry BAD_DATA
71 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010072ENDPROC(__dabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74__irq_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010075 inv_entry BAD_IRQ
76 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010077ENDPROC(__irq_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79__und_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010080 inv_entry BAD_UNDEFINSTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Russell Kingccea7a12005-05-31 22:22:32 +010082 @
83 @ XXX fall through to common_invalid
84 @
85
86@
87@ common_invalid - generic code for failed exception (re-entrant version of handlers)
88@
89common_invalid:
90 zero_fp
91
92 ldmia r0, {r4 - r6}
93 add r0, sp, #S_PC @ here for interlock avoidance
94 mov r7, #-1 @ "" "" "" ""
95 str r4, [sp] @ save preserved r0
96 stmia r0, {r5 - r7} @ lr_<exception>,
97 @ cpsr_<exception>, "old_r0"
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 b bad_mode
Catalin Marinas93ed3972008-08-28 11:22:32 +0100101ENDPROC(__und_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/*
104 * SVC mode handlers
105 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000106
107#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
108#define SPFIX(code...) code
109#else
110#define SPFIX(code...)
111#endif
112
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500113 .macro svc_entry, stack_hole=0
Catalin Marinasc4c57162009-02-16 11:42:09 +0100114 UNWIND(.fnstart )
115 UNWIND(.save {r0 - pc} )
Catalin Marinasb86040a2009-07-24 12:32:54 +0100116 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
117#ifdef CONFIG_THUMB2_KERNEL
118 SPFIX( str r0, [sp] ) @ temporarily saved
119 SPFIX( mov r0, sp )
120 SPFIX( tst r0, #4 ) @ test original stack alignment
121 SPFIX( ldr r0, [sp] ) @ restored
122#else
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000123 SPFIX( tst sp, #4 )
Catalin Marinasb86040a2009-07-24 12:32:54 +0100124#endif
125 SPFIX( subeq sp, sp, #4 )
126 stmia sp, {r1 - r12}
Russell Kingccea7a12005-05-31 22:22:32 +0100127
128 ldmia r0, {r1 - r3}
Catalin Marinasb86040a2009-07-24 12:32:54 +0100129 add r5, sp, #S_SP - 4 @ here for interlock avoidance
Russell Kingccea7a12005-05-31 22:22:32 +0100130 mov r4, #-1 @ "" "" "" ""
Catalin Marinasb86040a2009-07-24 12:32:54 +0100131 add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4)
132 SPFIX( addeq r0, r0, #4 )
133 str r1, [sp, #-4]! @ save the "real" r0 copied
Russell Kingccea7a12005-05-31 22:22:32 +0100134 @ from the exception stack
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 mov r1, lr
137
138 @
139 @ We are now ready to fill in the remaining blanks on the stack:
140 @
141 @ r0 - sp_svc
142 @ r1 - lr_svc
143 @ r2 - lr_<exception>, already fixed up for correct return/restart
144 @ r3 - spsr_<exception>
145 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
146 @
147 stmia r5, {r0 - r4}
148 .endm
149
150 .align 5
151__dabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100152 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 @
155 @ get ready to re-enable interrupts if appropriate
156 @
157 mrs r9, cpsr
158 tst r3, #PSR_I_BIT
159 biceq r9, r9, #PSR_I_BIT
160
161 @
162 @ Call the processor-specific abort handler:
163 @
164 @ r2 - aborted context pc
165 @ r3 - aborted context cpsr
166 @
167 @ The abort handler must return the aborted address in r0, and
168 @ the fault status register in r1. r9 must be preserved.
169 @
Paul Brook48d79272008-04-18 22:43:07 +0100170#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 ldr r4, .LCprocfns
172 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100173 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#else
Paul Brook48d79272008-04-18 22:43:07 +0100175 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#endif
177
178 @
179 @ set desired IRQ state, then call main handler
180 @
181 msr cpsr_c, r9
182 mov r2, sp
183 bl do_DataAbort
184
185 @
186 @ IRQs off again before pulling preserved data off the stack
187 @
Russell Kingac788842010-07-10 10:10:18 +0100188 disable_irq_notrace
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 @
191 @ restore SPSR and restart the instruction
192 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100193 ldr r2, [sp, #S_PSR]
194 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100195 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100196ENDPROC(__dabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 .align 5
199__irq_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100200 svc_entry
201
Russell Kingac788842010-07-10 10:10:18 +0100202#ifdef CONFIG_TRACE_IRQFLAGS
203 bl trace_hardirqs_off
204#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100206 get_thread_info tsk
207 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
208 add r7, r8, #1 @ increment it
209 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100211
Russell King187a51a2005-05-21 18:14:44 +0100212 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#ifdef CONFIG_PREEMPT
Russell King28fab1a2008-04-13 17:47:35 +0100214 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Russell King706fdd92005-05-21 18:15:45 +0100215 ldr r0, [tsk, #TI_FLAGS] @ get flags
Russell King28fab1a2008-04-13 17:47:35 +0100216 teq r8, #0 @ if preempt count != 0
217 movne r0, #0 @ force flags to 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 tst r0, #_TIF_NEED_RESCHED
219 blne svc_preempt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100221 ldr r4, [sp, #S_PSR] @ irqs are already disabled
Russell King7ad1bcb2006-08-27 12:07:02 +0100222#ifdef CONFIG_TRACE_IRQFLAGS
Catalin Marinasb86040a2009-07-24 12:32:54 +0100223 tst r4, #PSR_I_BIT
Russell King7ad1bcb2006-08-27 12:07:02 +0100224 bleq trace_hardirqs_on
225#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100226 svc_exit r4 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100227 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100228ENDPROC(__irq_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 .ltorg
231
232#ifdef CONFIG_PREEMPT
233svc_preempt:
Russell King28fab1a2008-04-13 17:47:35 +0100234 mov r8, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351: bl preempt_schedule_irq @ irq en/disable is done inside
Russell King706fdd92005-05-21 18:15:45 +0100236 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 tst r0, #_TIF_NEED_RESCHED
Russell King28fab1a2008-04-13 17:47:35 +0100238 moveq pc, r8 @ go again
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 b 1b
240#endif
241
242 .align 5
243__und_svc:
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500244#ifdef CONFIG_KPROBES
245 @ If a kprobe is about to simulate a "stmdb sp..." instruction,
246 @ it obviously needs free stack space which then will belong to
247 @ the saved context.
248 svc_entry 64
249#else
Russell Kingccea7a12005-05-31 22:22:32 +0100250 svc_entry
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500251#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 @
254 @ call emulation code, which returns using r9 if it has emulated
255 @ the instruction, or the more conventional lr if we are to treat
256 @ this as a real undefined instruction
257 @
258 @ r0 - instruction
259 @
Catalin Marinas83e686e2009-09-18 23:27:07 +0100260#ifndef CONFIG_THUMB2_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 ldr r0, [r2, #-4]
Catalin Marinas83e686e2009-09-18 23:27:07 +0100262#else
263 ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2
264 and r9, r0, #0xf800
265 cmp r9, #0xe800 @ 32-bit instruction if xx >= 0
266 ldrhhs r9, [r2] @ bottom 16 bits
267 orrhs r0, r9, r0, lsl #16
268#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100269 adr r9, BSYM(1f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 bl call_fpe
271
272 mov r0, sp @ struct pt_regs *regs
273 bl do_undefinstr
274
275 @
276 @ IRQs off again before pulling preserved data off the stack
277 @
Russell Kingac788842010-07-10 10:10:18 +01002781: disable_irq_notrace
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 @
281 @ restore SPSR and restart the instruction
282 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100283 ldr r2, [sp, #S_PSR] @ Get SVC cpsr
284 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100285 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100286ENDPROC(__und_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 .align 5
289__pabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100290 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 @
293 @ re-enable interrupts if appropriate
294 @
295 mrs r9, cpsr
296 tst r3, #PSR_I_BIT
297 biceq r9, r9, #PSR_I_BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Paul Brook48d79272008-04-18 22:43:07 +0100299 mov r0, r2 @ pass address of aborted instruction.
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100300#ifdef MULTI_PABORT
Paul Brook48d79272008-04-18 22:43:07 +0100301 ldr r4, .LCprocfns
302 mov lr, pc
303 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
304#else
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100305 bl CPU_PABORT_HANDLER
Paul Brook48d79272008-04-18 22:43:07 +0100306#endif
307 msr cpsr_c, r9 @ Maybe enable interrupts
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100308 mov r2, sp @ regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 bl do_PrefetchAbort @ call abort handler
310
311 @
312 @ IRQs off again before pulling preserved data off the stack
313 @
Russell Kingac788842010-07-10 10:10:18 +0100314 disable_irq_notrace
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 @
317 @ restore SPSR and restart the instruction
318 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100319 ldr r2, [sp, #S_PSR]
320 svc_exit r2 @ return from exception
Catalin Marinasc4c57162009-02-16 11:42:09 +0100321 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100322ENDPROC(__pabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 .align 5
Russell King49f680e2005-05-31 18:02:00 +0100325.LCcralign:
326 .word cr_alignment
Paul Brook48d79272008-04-18 22:43:07 +0100327#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328.LCprocfns:
329 .word processor
330#endif
331.LCfp:
332 .word fp_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334/*
335 * User mode handlers
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000336 *
337 * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000339
340#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
341#error "sizeof(struct pt_regs) must be a multiple of 8"
342#endif
343
Russell Kingccea7a12005-05-31 22:22:32 +0100344 .macro usr_entry
Catalin Marinasc4c57162009-02-16 11:42:09 +0100345 UNWIND(.fnstart )
346 UNWIND(.cantunwind ) @ don't unwind the user space
Russell Kingccea7a12005-05-31 22:22:32 +0100347 sub sp, sp, #S_FRAME_SIZE
Catalin Marinasb86040a2009-07-24 12:32:54 +0100348 ARM( stmib sp, {r1 - r12} )
349 THUMB( stmia sp, {r0 - r12} )
Russell Kingccea7a12005-05-31 22:22:32 +0100350
351 ldmia r0, {r1 - r3}
352 add r0, sp, #S_PC @ here for interlock avoidance
353 mov r4, #-1 @ "" "" "" ""
354
355 str r1, [sp] @ save the "real" r0 copied
356 @ from the exception stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 @
359 @ We are now ready to fill in the remaining blanks on the stack:
360 @
361 @ r2 - lr_<exception>, already fixed up for correct return/restart
362 @ r3 - spsr_<exception>
363 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
364 @
365 @ Also, separately save sp_usr and lr_usr
366 @
Russell Kingccea7a12005-05-31 22:22:32 +0100367 stmia r0, {r2 - r4}
Catalin Marinasb86040a2009-07-24 12:32:54 +0100368 ARM( stmdb r0, {sp, lr}^ )
369 THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 @
372 @ Enable the alignment trap while in kernel mode
373 @
Russell King49f680e2005-05-31 18:02:00 +0100374 alignment_trap r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 @
377 @ Clear FP to mark the first stack frame
378 @
379 zero_fp
380 .endm
381
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100382 .macro kuser_cmpxchg_check
383#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
384#ifndef CONFIG_MMU
385#warning "NPTL on non MMU needs fixing"
386#else
387 @ Make sure our user space atomic helper is restarted
388 @ if it was interrupted in a critical region. Here we
389 @ perform a quick test inline since it should be false
390 @ 99.9999% of the time. The rest is done out of line.
391 cmp r2, #TASK_SIZE
392 blhs kuser_cmpxchg_fixup
393#endif
394#endif
395 .endm
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 .align 5
398__dabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100399 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100400 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 @
403 @ Call the processor-specific abort handler:
404 @
405 @ r2 - aborted context pc
406 @ r3 - aborted context cpsr
407 @
408 @ The abort handler must return the aborted address in r0, and
409 @ the fault status register in r1.
410 @
Paul Brook48d79272008-04-18 22:43:07 +0100411#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 ldr r4, .LCprocfns
413 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100414 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#else
Paul Brook48d79272008-04-18 22:43:07 +0100416 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#endif
418
419 @
420 @ IRQs on, then call the main handler
421 @
Russell King1ec42c02005-04-26 15:18:26 +0100422 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 mov r2, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +0100424 adr lr, BSYM(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 b do_DataAbort
Catalin Marinasc4c57162009-02-16 11:42:09 +0100426 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100427ENDPROC(__dabt_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 .align 5
430__irq_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100431 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100432 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100436 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
437 add r7, r8, #1 @ increment it
438 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100440
Russell King187a51a2005-05-21 18:14:44 +0100441 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100443 ldr r0, [tsk, #TI_PREEMPT]
444 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 teq r0, r7
Catalin Marinasb86040a2009-07-24 12:32:54 +0100446 ARM( strne r0, [r0, -r0] )
447 THUMB( movne r0, #0 )
448 THUMB( strne r0, [r0] )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 mov why, #0
452 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100453 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100454ENDPROC(__irq_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 .ltorg
457
458 .align 5
459__und_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100460 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 @
463 @ fall through to the emulation code, which returns using r9 if
464 @ it has emulated the instruction, or the more conventional lr
465 @ if we are to treat this as a real undefined instruction
466 @
467 @ r0 - instruction
468 @
Catalin Marinasb86040a2009-07-24 12:32:54 +0100469 adr r9, BSYM(ret_from_exception)
470 adr lr, BSYM(__und_usr_unknown)
Paul Brookcb170a42008-04-18 22:43:08 +0100471 tst r3, #PSR_T_BIT @ Thumb mode?
Catalin Marinasb86040a2009-07-24 12:32:54 +0100472 itet eq @ explicit IT needed for the 1f label
Paul Brookcb170a42008-04-18 22:43:08 +0100473 subeq r4, r2, #4 @ ARM instr at LR - 4
474 subne r4, r2, #2 @ Thumb instr at LR - 2
4751: ldreqt r0, [r4]
Catalin Marinas26584852009-05-30 14:00:18 +0100476#ifdef CONFIG_CPU_ENDIAN_BE8
477 reveq r0, r0 @ little endian instruction
478#endif
Paul Brookcb170a42008-04-18 22:43:08 +0100479 beq call_fpe
480 @ Thumb instruction
481#if __LINUX_ARM_ARCH__ >= 7
Catalin Marinasb86040a2009-07-24 12:32:54 +01004822:
483 ARM( ldrht r5, [r4], #2 )
484 THUMB( ldrht r5, [r4] )
485 THUMB( add r4, r4, #2 )
Paul Brookcb170a42008-04-18 22:43:08 +0100486 and r0, r5, #0xf800 @ mask bits 111x x... .... ....
487 cmp r0, #0xe800 @ 32bit instruction if xx != 0
488 blo __und_usr_unknown
4893: ldrht r0, [r4]
490 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
491 orr r0, r0, r5, lsl #16
492#else
493 b __und_usr_unknown
494#endif
Catalin Marinasc4c57162009-02-16 11:42:09 +0100495 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100496ENDPROC(__und_usr)
Paul Brookcb170a42008-04-18 22:43:08 +0100497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 @
499 @ fallthrough to call_fpe
500 @
501
502/*
503 * The out of line fixup for the ldrt above.
504 */
Russell King42604152010-04-19 10:15:03 +0100505 .pushsection .fixup, "ax"
Paul Brookcb170a42008-04-18 22:43:08 +01005064: mov pc, r9
Russell King42604152010-04-19 10:15:03 +0100507 .popsection
508 .pushsection __ex_table,"a"
Paul Brookcb170a42008-04-18 22:43:08 +0100509 .long 1b, 4b
510#if __LINUX_ARM_ARCH__ >= 7
511 .long 2b, 4b
512 .long 3b, 4b
513#endif
Russell King42604152010-04-19 10:15:03 +0100514 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516/*
517 * Check whether the instruction is a co-processor instruction.
518 * If yes, we need to call the relevant co-processor handler.
519 *
520 * Note that we don't do a full check here for the co-processor
521 * instructions; all instructions with bit 27 set are well
522 * defined. The only instructions that should fault are the
523 * co-processor instructions. However, we have to watch out
524 * for the ARM6/ARM7 SWI bug.
525 *
Catalin Marinasb5872db2008-01-10 19:16:17 +0100526 * NEON is a special case that has to be handled here. Not all
527 * NEON instructions are co-processor instructions, so we have
528 * to make a special case of checking for them. Plus, there's
529 * five groups of them, so we have a table of mask/opcode pairs
530 * to check against, and if any match then we branch off into the
531 * NEON handler code.
532 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * Emulators may wish to make use of the following registers:
534 * r0 = instruction opcode.
535 * r2 = PC+4
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000536 * r9 = normal "successful" return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 * r10 = this threads thread_info structure.
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000538 * lr = unrecognised instruction return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 */
Paul Brookcb170a42008-04-18 22:43:08 +0100540 @
541 @ Fall-through from Thumb-2 __und_usr
542 @
543#ifdef CONFIG_NEON
544 adr r6, .LCneon_thumb_opcodes
545 b 2f
546#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547call_fpe:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100548#ifdef CONFIG_NEON
Paul Brookcb170a42008-04-18 22:43:08 +0100549 adr r6, .LCneon_arm_opcodes
Catalin Marinasb5872db2008-01-10 19:16:17 +01005502:
551 ldr r7, [r6], #4 @ mask value
552 cmp r7, #0 @ end mask?
553 beq 1f
554 and r8, r0, r7
555 ldr r7, [r6], #4 @ opcode bits matching in mask
556 cmp r8, r7 @ NEON instruction?
557 bne 2b
558 get_thread_info r10
559 mov r7, #1
560 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
561 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
562 b do_vfp @ let VFP handler handle this
5631:
564#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
Paul Brookcb170a42008-04-18 22:43:08 +0100566 tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
568 and r8, r0, #0x0f000000 @ mask out op-code bits
569 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
570#endif
571 moveq pc, lr
572 get_thread_info r10 @ get current thread
573 and r8, r0, #0x00000f00 @ mask out CP number
Catalin Marinasb86040a2009-07-24 12:32:54 +0100574 THUMB( lsr r8, r8, #8 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 mov r7, #1
576 add r6, r10, #TI_USED_CP
Catalin Marinasb86040a2009-07-24 12:32:54 +0100577 ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[]
578 THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#ifdef CONFIG_IWMMXT
580 @ Test if we need to give access to iWMMXt coprocessors
581 ldr r5, [r10, #TI_FLAGS]
582 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
583 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
584 bcs iwmmxt_task_enable
585#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100586 ARM( add pc, pc, r8, lsr #6 )
587 THUMB( lsl r8, r8, #2 )
588 THUMB( add pc, r8 )
589 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Catalin Marinasa771fe62009-10-12 17:31:20 +0100591 movw_pc lr @ CP#0
Catalin Marinasb86040a2009-07-24 12:32:54 +0100592 W(b) do_fpe @ CP#1 (FPE)
593 W(b) do_fpe @ CP#2 (FPE)
Catalin Marinasa771fe62009-10-12 17:31:20 +0100594 movw_pc lr @ CP#3
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100595#ifdef CONFIG_CRUNCH
596 b crunch_task_enable @ CP#4 (MaverickCrunch)
597 b crunch_task_enable @ CP#5 (MaverickCrunch)
598 b crunch_task_enable @ CP#6 (MaverickCrunch)
599#else
Catalin Marinasa771fe62009-10-12 17:31:20 +0100600 movw_pc lr @ CP#4
601 movw_pc lr @ CP#5
602 movw_pc lr @ CP#6
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100603#endif
Catalin Marinasa771fe62009-10-12 17:31:20 +0100604 movw_pc lr @ CP#7
605 movw_pc lr @ CP#8
606 movw_pc lr @ CP#9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#ifdef CONFIG_VFP
Catalin Marinasb86040a2009-07-24 12:32:54 +0100608 W(b) do_vfp @ CP#10 (VFP)
609 W(b) do_vfp @ CP#11 (VFP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#else
Catalin Marinasa771fe62009-10-12 17:31:20 +0100611 movw_pc lr @ CP#10 (VFP)
612 movw_pc lr @ CP#11 (VFP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613#endif
Catalin Marinasa771fe62009-10-12 17:31:20 +0100614 movw_pc lr @ CP#12
615 movw_pc lr @ CP#13
616 movw_pc lr @ CP#14 (Debug)
617 movw_pc lr @ CP#15 (Control)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Catalin Marinasb5872db2008-01-10 19:16:17 +0100619#ifdef CONFIG_NEON
620 .align 6
621
Paul Brookcb170a42008-04-18 22:43:08 +0100622.LCneon_arm_opcodes:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100623 .word 0xfe000000 @ mask
624 .word 0xf2000000 @ opcode
625
626 .word 0xff100000 @ mask
627 .word 0xf4000000 @ opcode
628
629 .word 0x00000000 @ mask
630 .word 0x00000000 @ opcode
Paul Brookcb170a42008-04-18 22:43:08 +0100631
632.LCneon_thumb_opcodes:
633 .word 0xef000000 @ mask
634 .word 0xef000000 @ opcode
635
636 .word 0xff100000 @ mask
637 .word 0xf9000000 @ opcode
638
639 .word 0x00000000 @ mask
640 .word 0x00000000 @ opcode
Catalin Marinasb5872db2008-01-10 19:16:17 +0100641#endif
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643do_fpe:
Russell King5d25ac02006-03-15 12:33:43 +0000644 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 ldr r4, .LCfp
646 add r10, r10, #TI_FPSTATE @ r10 = workspace
647 ldr pc, [r4] @ Call FP module USR entry point
648
649/*
650 * The FP module is called with these registers set:
651 * r0 = instruction
652 * r2 = PC+4
653 * r9 = normal "successful" return address
654 * r10 = FP workspace
655 * lr = unrecognised FP instruction return address
656 */
657
Santosh Shilimkar124efc22010-04-30 10:45:46 +0100658 .pushsection .data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659ENTRY(fp_enter)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000660 .word no_fp
Santosh Shilimkar124efc22010-04-30 10:45:46 +0100661 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Catalin Marinas83e686e2009-09-18 23:27:07 +0100663ENTRY(no_fp)
664 mov pc, lr
665ENDPROC(no_fp)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000666
667__und_usr_unknown:
Russell Kingecbab712009-01-27 23:20:00 +0000668 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 mov r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +0100670 adr lr, BSYM(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 b do_undefinstr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100672ENDPROC(__und_usr_unknown)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 .align 5
675__pabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100676 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Paul Brook48d79272008-04-18 22:43:07 +0100678 mov r0, r2 @ pass address of aborted instruction.
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100679#ifdef MULTI_PABORT
Paul Brook48d79272008-04-18 22:43:07 +0100680 ldr r4, .LCprocfns
681 mov lr, pc
682 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
683#else
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100684 bl CPU_PABORT_HANDLER
Paul Brook48d79272008-04-18 22:43:07 +0100685#endif
Russell King1ec42c02005-04-26 15:18:26 +0100686 enable_irq @ Enable interrupts
Kirill A. Shutemov4fb28472009-09-25 13:39:47 +0100687 mov r2, sp @ regs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 bl do_PrefetchAbort @ call abort handler
Catalin Marinasc4c57162009-02-16 11:42:09 +0100689 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /* fall through */
691/*
692 * This is the return code to user mode for abort handlers
693 */
694ENTRY(ret_from_exception)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100695 UNWIND(.fnstart )
696 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 get_thread_info tsk
698 mov why, #0
699 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100700 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100701ENDPROC(__pabt_usr)
702ENDPROC(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704/*
705 * Register switch for ARMv3 and ARMv4 processors
706 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
707 * previous and next are guaranteed not to be the same.
708 */
709ENTRY(__switch_to)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100710 UNWIND(.fnstart )
711 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 add ip, r1, #TI_CPU_SAVE
713 ldr r3, [r2, #TI_TP_VALUE]
Catalin Marinasb86040a2009-07-24 12:32:54 +0100714 ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack
715 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
716 THUMB( str sp, [ip], #4 )
717 THUMB( str lr, [ip], #4 )
Catalin Marinas247055a2010-09-13 16:03:21 +0100718#ifdef CONFIG_CPU_USE_DOMAINS
Russell Kingd6551e82006-06-21 13:31:52 +0100719 ldr r6, [r2, #TI_CPU_DOMAIN]
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000720#endif
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100721 set_tls r3, r4, r5
Nicolas Pitredf0698b2010-06-07 21:50:33 -0400722#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
723 ldr r7, [r2, #TI_TASK]
724 ldr r8, =__stack_chk_guard
725 ldr r7, [r7, #TSK_STACK_CANARY]
726#endif
Catalin Marinas247055a2010-09-13 16:03:21 +0100727#ifdef CONFIG_CPU_USE_DOMAINS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000729#endif
Russell Kingd6551e82006-06-21 13:31:52 +0100730 mov r5, r0
731 add r4, r2, #TI_CPU_SAVE
732 ldr r0, =thread_notify_head
733 mov r1, #THREAD_NOTIFY_SWITCH
734 bl atomic_notifier_call_chain
Nicolas Pitredf0698b2010-06-07 21:50:33 -0400735#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
736 str r7, [r8]
737#endif
Catalin Marinasb86040a2009-07-24 12:32:54 +0100738 THUMB( mov ip, r4 )
Russell Kingd6551e82006-06-21 13:31:52 +0100739 mov r0, r5
Catalin Marinasb86040a2009-07-24 12:32:54 +0100740 ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously
741 THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously
742 THUMB( ldr sp, [ip], #4 )
743 THUMB( ldr pc, [ip] )
Catalin Marinasc4c57162009-02-16 11:42:09 +0100744 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100745ENDPROC(__switch_to)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100748
749/*
750 * User helpers.
751 *
752 * These are segment of kernel provided user code reachable from user space
753 * at a fixed address in kernel memory. This is used to provide user space
754 * with some operations which require kernel help because of unimplemented
755 * native feature and/or instructions in many ARM CPUs. The idea is for
756 * this code to be executed directly in user mode for best efficiency but
757 * which is too intimate with the kernel counter part to be left to user
758 * libraries. In fact this code might even differ from one CPU to another
759 * depending on the available instruction set and restrictions like on
760 * SMP systems. In other words, the kernel reserves the right to change
761 * this code as needed without warning. Only the entry points and their
762 * results are guaranteed to be stable.
763 *
764 * Each segment is 32-byte aligned and will be moved to the top of the high
765 * vector page. New segments (if ever needed) must be added in front of
766 * existing ones. This mechanism should be used only for things that are
767 * really small and justified, and not be abused freely.
768 *
769 * User space is expected to implement those things inline when optimizing
770 * for a processor that has the necessary native support, but only if such
771 * resulting binaries are already to be incompatible with earlier ARM
772 * processors due to the use of unsupported instructions other than what
773 * is provided here. In other words don't make binaries unable to run on
774 * earlier processors just for the sake of not using these kernel helpers
775 * if your compiled code is not going to use the new instructions for other
776 * purpose.
777 */
Catalin Marinasb86040a2009-07-24 12:32:54 +0100778 THUMB( .arm )
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100779
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100780 .macro usr_ret, reg
781#ifdef CONFIG_ARM_THUMB
782 bx \reg
783#else
784 mov pc, \reg
785#endif
786 .endm
787
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100788 .align 5
789 .globl __kuser_helper_start
790__kuser_helper_start:
791
792/*
793 * Reference prototype:
794 *
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000795 * void __kernel_memory_barrier(void)
796 *
797 * Input:
798 *
799 * lr = return address
800 *
801 * Output:
802 *
803 * none
804 *
805 * Clobbered:
806 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100807 * none
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000808 *
809 * Definition and user space usage example:
810 *
811 * typedef void (__kernel_dmb_t)(void);
812 * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
813 *
814 * Apply any needed memory barrier to preserve consistency with data modified
815 * manually and __kuser_cmpxchg usage.
816 *
817 * This could be used as follows:
818 *
819 * #define __kernel_dmb() \
820 * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
Paul Brook6896eec2006-03-28 22:19:29 +0100821 * : : : "r0", "lr","cc" )
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000822 */
823
824__kuser_memory_barrier: @ 0xffff0fa0
Russell Kingbac4e962009-05-25 20:58:00 +0100825 smp_dmb
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100826 usr_ret lr
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000827
828 .align 5
829
830/*
831 * Reference prototype:
832 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100833 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
834 *
835 * Input:
836 *
837 * r0 = oldval
838 * r1 = newval
839 * r2 = ptr
840 * lr = return address
841 *
842 * Output:
843 *
844 * r0 = returned value (zero or non-zero)
845 * C flag = set if r0 == 0, clear if r0 != 0
846 *
847 * Clobbered:
848 *
849 * r3, ip, flags
850 *
851 * Definition and user space usage example:
852 *
853 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
854 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
855 *
856 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
857 * Return zero if *ptr was changed or non-zero if no exchange happened.
858 * The C flag is also set if *ptr was changed to allow for assembly
859 * optimization in the calling code.
860 *
Nicolas Pitre5964eae2006-02-08 21:19:37 +0000861 * Notes:
862 *
863 * - This routine already includes memory barriers as needed.
864 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100865 * For example, a user space atomic_add implementation could look like this:
866 *
867 * #define atomic_add(ptr, val) \
868 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
869 * register unsigned int __result asm("r1"); \
870 * asm volatile ( \
871 * "1: @ atomic_add\n\t" \
872 * "ldr r0, [r2]\n\t" \
873 * "mov r3, #0xffff0fff\n\t" \
874 * "add lr, pc, #4\n\t" \
875 * "add r1, r0, %2\n\t" \
876 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
877 * "bcc 1b" \
878 * : "=&r" (__result) \
879 * : "r" (__ptr), "rIL" (val) \
880 * : "r0","r3","ip","lr","cc","memory" ); \
881 * __result; })
882 */
883
884__kuser_cmpxchg: @ 0xffff0fc0
885
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100886#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100887
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100888 /*
889 * Poor you. No fast solution possible...
890 * The kernel itself must perform the operation.
891 * A special ghost syscall is used for that (see traps.c).
892 */
Nicolas Pitre5e097442006-01-18 22:38:49 +0000893 stmfd sp!, {r7, lr}
Russell Kingcc20d422009-11-09 23:53:29 +0000894 ldr r7, =1f @ it's 20 bits
895 swi __ARM_NR_cmpxchg
Nicolas Pitre5e097442006-01-18 22:38:49 +0000896 ldmfd sp!, {r7, pc}
Russell Kingcc20d422009-11-09 23:53:29 +00008971: .word __ARM_NR_cmpxchg
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100898
899#elif __LINUX_ARM_ARCH__ < 6
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100900
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000901#ifdef CONFIG_MMU
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100902
903 /*
904 * The only thing that can break atomicity in this cmpxchg
905 * implementation is either an IRQ or a data abort exception
906 * causing another process/thread to be scheduled in the middle
907 * of the critical sequence. To prevent this, code is added to
908 * the IRQ and data abort exception handlers to set the pc back
909 * to the beginning of the critical section if it is found to be
910 * within that critical section (see kuser_cmpxchg_fixup).
911 */
9121: ldr r3, [r2] @ load current val
913 subs r3, r3, r0 @ compare with oldval
9142: streq r1, [r2] @ store newval if eq
915 rsbs r0, r3, #0 @ set return val and C flag
916 usr_ret lr
917
918 .text
919kuser_cmpxchg_fixup:
920 @ Called from kuser_cmpxchg_check macro.
921 @ r2 = address of interrupted insn (must be preserved).
922 @ sp = saved regs. r7 and r8 are clobbered.
923 @ 1b = first critical insn, 2b = last critical insn.
924 @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
925 mov r7, #0xffff0fff
926 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
927 subs r8, r2, r7
928 rsbcss r8, r8, #(2b - 1b)
929 strcs r7, [sp, #S_PC]
930 mov pc, lr
931 .previous
932
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000933#else
934#warning "NPTL on non MMU needs fixing"
935 mov r0, #-1
936 adds r0, r0, #0
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100937 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100938#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100939
940#else
941
Russell King7511bce2010-01-12 18:59:16 +0000942 smp_dmb
Nicolas Pitreb49c0f22007-11-20 17:20:29 +01009431: ldrex r3, [r2]
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100944 subs r3, r3, r0
945 strexeq r3, r1, [r2]
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100946 teqeq r3, #1
947 beq 1b
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100948 rsbs r0, r3, #0
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100949 /* beware -- each __kuser slot must be 8 instructions max */
Russell Kingf00ec482010-09-04 10:47:48 +0100950 ALT_SMP(b __kuser_memory_barrier)
951 ALT_UP(usr_ret lr)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100952
953#endif
954
955 .align 5
956
957/*
958 * Reference prototype:
959 *
960 * int __kernel_get_tls(void)
961 *
962 * Input:
963 *
964 * lr = return address
965 *
966 * Output:
967 *
968 * r0 = TLS value
969 *
970 * Clobbered:
971 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100972 * none
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100973 *
974 * Definition and user space usage example:
975 *
976 * typedef int (__kernel_get_tls_t)(void);
977 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
978 *
979 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
980 *
981 * This could be used as follows:
982 *
983 * #define __kernel_get_tls() \
984 * ({ register unsigned int __val asm("r0"); \
985 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
986 * : "=r" (__val) : : "lr","cc" ); \
987 * __val; })
988 */
989
990__kuser_get_tls: @ 0xffff0fe0
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100991 ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100992 usr_ret lr
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100993 mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code
994 .rep 4
995 .word 0 @ 0xffff0ff0 software TLS value, then
996 .endr @ pad up to __kuser_helper_version
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100997
998/*
999 * Reference declaration:
1000 *
1001 * extern unsigned int __kernel_helper_version;
1002 *
1003 * Definition and user space usage example:
1004 *
1005 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
1006 *
1007 * User space may read this to determine the curent number of helpers
1008 * available.
1009 */
1010
1011__kuser_helper_version: @ 0xffff0ffc
1012 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
1013
1014 .globl __kuser_helper_end
1015__kuser_helper_end:
1016
Catalin Marinasb86040a2009-07-24 12:32:54 +01001017 THUMB( .thumb )
Nicolas Pitre2d2669b2005-04-29 22:08:33 +01001018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019/*
1020 * Vector stubs.
1021 *
Russell King79335232005-04-26 15:17:42 +01001022 * This code is copied to 0xffff0200 so we can use branches in the
1023 * vectors, rather than ldr's. Note that this code must not
1024 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 *
1026 * Common stub entry macro:
1027 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
Russell Kingccea7a12005-05-31 22:22:32 +01001028 *
1029 * SP points to a minimal amount of processor-private memory, the address
1030 * of which is copied into r0 for the mode specific abort handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001032 .macro vector_stub, name, mode, correction=0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .align 5
1034
1035vector_\name:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .if \correction
1037 sub lr, lr, #\correction
1038 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Russell Kingccea7a12005-05-31 22:22:32 +01001040 @
1041 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1042 @ (parent CPSR)
1043 @
1044 stmia sp, {r0, lr} @ save r0, lr
1045 mrs lr, spsr
1046 str lr, [sp, #8] @ save spsr
1047
1048 @
1049 @ Prepare for SVC32 mode. IRQs remain disabled.
1050 @
1051 mrs r0, cpsr
Catalin Marinasb86040a2009-07-24 12:32:54 +01001052 eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
Russell Kingccea7a12005-05-31 22:22:32 +01001053 msr spsr_cxsf, r0
1054
1055 @
1056 @ the branch table must immediately follow this code
1057 @
Russell Kingccea7a12005-05-31 22:22:32 +01001058 and lr, lr, #0x0f
Catalin Marinasb86040a2009-07-24 12:32:54 +01001059 THUMB( adr r0, 1f )
1060 THUMB( ldr lr, [r0, lr, lsl #2] )
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001061 mov r0, sp
Catalin Marinasb86040a2009-07-24 12:32:54 +01001062 ARM( ldr lr, [pc, lr, lsl #2] )
Russell Kingccea7a12005-05-31 22:22:32 +01001063 movs pc, lr @ branch to handler in SVC mode
Catalin Marinas93ed3972008-08-28 11:22:32 +01001064ENDPROC(vector_\name)
Catalin Marinas88987ef2009-07-24 12:32:52 +01001065
1066 .align 2
1067 @ handler addresses follow this label
10681:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .endm
1070
Russell King79335232005-04-26 15:17:42 +01001071 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072__stubs_start:
1073/*
1074 * Interrupt dispatcher
1075 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001076 vector_stub irq, IRQ_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 .long __irq_usr @ 0 (USR_26 / USR_32)
1079 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1080 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1081 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1082 .long __irq_invalid @ 4
1083 .long __irq_invalid @ 5
1084 .long __irq_invalid @ 6
1085 .long __irq_invalid @ 7
1086 .long __irq_invalid @ 8
1087 .long __irq_invalid @ 9
1088 .long __irq_invalid @ a
1089 .long __irq_invalid @ b
1090 .long __irq_invalid @ c
1091 .long __irq_invalid @ d
1092 .long __irq_invalid @ e
1093 .long __irq_invalid @ f
1094
1095/*
1096 * Data abort dispatcher
1097 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1098 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001099 vector_stub dabt, ABT_MODE, 8
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 .long __dabt_usr @ 0 (USR_26 / USR_32)
1102 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1103 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1104 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1105 .long __dabt_invalid @ 4
1106 .long __dabt_invalid @ 5
1107 .long __dabt_invalid @ 6
1108 .long __dabt_invalid @ 7
1109 .long __dabt_invalid @ 8
1110 .long __dabt_invalid @ 9
1111 .long __dabt_invalid @ a
1112 .long __dabt_invalid @ b
1113 .long __dabt_invalid @ c
1114 .long __dabt_invalid @ d
1115 .long __dabt_invalid @ e
1116 .long __dabt_invalid @ f
1117
1118/*
1119 * Prefetch abort dispatcher
1120 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1121 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001122 vector_stub pabt, ABT_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 .long __pabt_usr @ 0 (USR_26 / USR_32)
1125 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1126 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1127 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1128 .long __pabt_invalid @ 4
1129 .long __pabt_invalid @ 5
1130 .long __pabt_invalid @ 6
1131 .long __pabt_invalid @ 7
1132 .long __pabt_invalid @ 8
1133 .long __pabt_invalid @ 9
1134 .long __pabt_invalid @ a
1135 .long __pabt_invalid @ b
1136 .long __pabt_invalid @ c
1137 .long __pabt_invalid @ d
1138 .long __pabt_invalid @ e
1139 .long __pabt_invalid @ f
1140
1141/*
1142 * Undef instr entry dispatcher
1143 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1144 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001145 vector_stub und, UND_MODE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 .long __und_usr @ 0 (USR_26 / USR_32)
1148 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1149 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1150 .long __und_svc @ 3 (SVC_26 / SVC_32)
1151 .long __und_invalid @ 4
1152 .long __und_invalid @ 5
1153 .long __und_invalid @ 6
1154 .long __und_invalid @ 7
1155 .long __und_invalid @ 8
1156 .long __und_invalid @ 9
1157 .long __und_invalid @ a
1158 .long __und_invalid @ b
1159 .long __und_invalid @ c
1160 .long __und_invalid @ d
1161 .long __und_invalid @ e
1162 .long __und_invalid @ f
1163
1164 .align 5
1165
1166/*=============================================================================
1167 * Undefined FIQs
1168 *-----------------------------------------------------------------------------
1169 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1170 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1171 * Basically to switch modes, we *HAVE* to clobber one register... brain
1172 * damage alert! I don't think that we can execute any code in here in any
1173 * other mode than FIQ... Ok you can switch to another mode, but you can't
1174 * get out of that mode without clobbering one register.
1175 */
1176vector_fiq:
1177 disable_fiq
1178 subs pc, lr, #4
1179
1180/*=============================================================================
1181 * Address exception handler
1182 *-----------------------------------------------------------------------------
1183 * These aren't too critical.
1184 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1185 */
1186
1187vector_addrexcptn:
1188 b vector_addrexcptn
1189
1190/*
1191 * We group all the following data together to optimise
1192 * for CPUs with separate I & D caches.
1193 */
1194 .align 5
1195
1196.LCvswi:
1197 .word vector_swi
1198
Russell King79335232005-04-26 15:17:42 +01001199 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200__stubs_end:
1201
Russell King79335232005-04-26 15:17:42 +01001202 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Russell King79335232005-04-26 15:17:42 +01001204 .globl __vectors_start
1205__vectors_start:
Catalin Marinasb86040a2009-07-24 12:32:54 +01001206 ARM( swi SYS_ERROR0 )
1207 THUMB( svc #0 )
1208 THUMB( nop )
1209 W(b) vector_und + stubs_offset
1210 W(ldr) pc, .LCvswi + stubs_offset
1211 W(b) vector_pabt + stubs_offset
1212 W(b) vector_dabt + stubs_offset
1213 W(b) vector_addrexcptn + stubs_offset
1214 W(b) vector_irq + stubs_offset
1215 W(b) vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Russell King79335232005-04-26 15:17:42 +01001217 .globl __vectors_end
1218__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 .data
1221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .globl cr_alignment
1223 .globl cr_no_alignment
1224cr_alignment:
1225 .space 4
1226cr_no_alignment:
1227 .space 4
eric miao52108642010-12-13 09:42:34 +01001228
1229#ifdef CONFIG_MULTI_IRQ_HANDLER
1230 .globl handle_arch_irq
1231handle_arch_irq:
1232 .space 4
1233#endif