blob: 792abd0dfae1907948bb730a5e52eebe978e987d [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 @
37 adrne lr, 1b
38 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
49 adrne lr, 1b
50 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
55 adrne lr, 1b
56 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
73 stmib sp, {r1 - lr}
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 mov r1, #\reason
75 .endm
76
77__pabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010078 inv_entry BAD_PREFETCH
79 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010080ENDPROC(__pabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82__dabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010083 inv_entry BAD_DATA
84 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010085ENDPROC(__dabt_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87__irq_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010088 inv_entry BAD_IRQ
89 b common_invalid
Catalin Marinas93ed3972008-08-28 11:22:32 +010090ENDPROC(__irq_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92__und_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010093 inv_entry BAD_UNDEFINSTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Russell Kingccea7a12005-05-31 22:22:32 +010095 @
96 @ XXX fall through to common_invalid
97 @
98
99@
100@ common_invalid - generic code for failed exception (re-entrant version of handlers)
101@
102common_invalid:
103 zero_fp
104
105 ldmia r0, {r4 - r6}
106 add r0, sp, #S_PC @ here for interlock avoidance
107 mov r7, #-1 @ "" "" "" ""
108 str r4, [sp] @ save preserved r0
109 stmia r0, {r5 - r7} @ lr_<exception>,
110 @ cpsr_<exception>, "old_r0"
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 b bad_mode
Catalin Marinas93ed3972008-08-28 11:22:32 +0100114ENDPROC(__und_invalid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/*
117 * SVC mode handlers
118 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000119
120#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
121#define SPFIX(code...) code
122#else
123#define SPFIX(code...)
124#endif
125
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500126 .macro svc_entry, stack_hole=0
Catalin Marinasc4c57162009-02-16 11:42:09 +0100127 UNWIND(.fnstart )
128 UNWIND(.save {r0 - pc} )
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500129 sub sp, sp, #(S_FRAME_SIZE + \stack_hole)
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000130 SPFIX( tst sp, #4 )
131 SPFIX( bicne sp, sp, #4 )
Russell Kingccea7a12005-05-31 22:22:32 +0100132 stmib sp, {r1 - r12}
133
134 ldmia r0, {r1 - r3}
135 add r5, sp, #S_SP @ here for interlock avoidance
136 mov r4, #-1 @ "" "" "" ""
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500137 add r0, sp, #(S_FRAME_SIZE + \stack_hole)
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000138 SPFIX( addne r0, r0, #4 )
Russell Kingccea7a12005-05-31 22:22:32 +0100139 str r1, [sp] @ save the "real" r0 copied
140 @ from the exception stack
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 mov r1, lr
143
144 @
145 @ We are now ready to fill in the remaining blanks on the stack:
146 @
147 @ r0 - sp_svc
148 @ r1 - lr_svc
149 @ r2 - lr_<exception>, already fixed up for correct return/restart
150 @ r3 - spsr_<exception>
151 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
152 @
153 stmia r5, {r0 - r4}
Uwe Kleine-König0d928b02009-08-13 20:38:17 +0200154
155 asm_trace_hardirqs_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .endm
157
158 .align 5
159__dabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100160 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 @
163 @ get ready to re-enable interrupts if appropriate
164 @
165 mrs r9, cpsr
166 tst r3, #PSR_I_BIT
167 biceq r9, r9, #PSR_I_BIT
168
169 @
170 @ Call the processor-specific abort handler:
171 @
172 @ r2 - aborted context pc
173 @ r3 - aborted context cpsr
174 @
175 @ The abort handler must return the aborted address in r0, and
176 @ the fault status register in r1. r9 must be preserved.
177 @
Paul Brook48d79272008-04-18 22:43:07 +0100178#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 ldr r4, .LCprocfns
180 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100181 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#else
Paul Brook48d79272008-04-18 22:43:07 +0100183 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#endif
185
186 @
187 @ set desired IRQ state, then call main handler
188 @
189 msr cpsr_c, r9
190 mov r2, sp
191 bl do_DataAbort
192
193 @
194 @ IRQs off again before pulling preserved data off the stack
195 @
Russell King1ec42c02005-04-26 15:18:26 +0100196 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 @
199 @ restore SPSR and restart the instruction
200 @
201 ldr r0, [sp, #S_PSR]
202 msr spsr_cxsf, r0
203 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
Catalin Marinasc4c57162009-02-16 11:42:09 +0100204 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100205ENDPROC(__dabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 .align 5
208__irq_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100209 svc_entry
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100212 get_thread_info tsk
213 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
214 add r7, r8, #1 @ increment it
215 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100217
Russell King187a51a2005-05-21 18:14:44 +0100218 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#ifdef CONFIG_PREEMPT
Russell King28fab1a2008-04-13 17:47:35 +0100220 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Russell King706fdd92005-05-21 18:15:45 +0100221 ldr r0, [tsk, #TI_FLAGS] @ get flags
Russell King28fab1a2008-04-13 17:47:35 +0100222 teq r8, #0 @ if preempt count != 0
223 movne r0, #0 @ force flags to 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 tst r0, #_TIF_NEED_RESCHED
225 blne svc_preempt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#endif
227 ldr r0, [sp, #S_PSR] @ irqs are already disabled
228 msr spsr_cxsf, r0
Russell King7ad1bcb2006-08-27 12:07:02 +0100229#ifdef CONFIG_TRACE_IRQFLAGS
230 tst r0, #PSR_I_BIT
231 bleq trace_hardirqs_on
232#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
Catalin Marinasc4c57162009-02-16 11:42:09 +0100234 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100235ENDPROC(__irq_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 .ltorg
238
239#ifdef CONFIG_PREEMPT
240svc_preempt:
Russell King28fab1a2008-04-13 17:47:35 +0100241 mov r8, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421: bl preempt_schedule_irq @ irq en/disable is done inside
Russell King706fdd92005-05-21 18:15:45 +0100243 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 tst r0, #_TIF_NEED_RESCHED
Russell King28fab1a2008-04-13 17:47:35 +0100245 moveq pc, r8 @ go again
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 b 1b
247#endif
248
249 .align 5
250__und_svc:
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500251#ifdef CONFIG_KPROBES
252 @ If a kprobe is about to simulate a "stmdb sp..." instruction,
253 @ it obviously needs free stack space which then will belong to
254 @ the saved context.
255 svc_entry 64
256#else
Russell Kingccea7a12005-05-31 22:22:32 +0100257 svc_entry
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500258#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 @
261 @ call emulation code, which returns using r9 if it has emulated
262 @ the instruction, or the more conventional lr if we are to treat
263 @ this as a real undefined instruction
264 @
265 @ r0 - instruction
266 @
267 ldr r0, [r2, #-4]
268 adr r9, 1f
269 bl call_fpe
270
271 mov r0, sp @ struct pt_regs *regs
272 bl do_undefinstr
273
274 @
275 @ IRQs off again before pulling preserved data off the stack
276 @
Russell King1ec42c02005-04-26 15:18:26 +01002771: disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279 @
280 @ restore SPSR and restart the instruction
281 @
282 ldr lr, [sp, #S_PSR] @ Get SVC cpsr
283 msr spsr_cxsf, lr
284 ldmia sp, {r0 - pc}^ @ Restore SVC registers
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
299 @
300 @ set args, then call main handler
301 @
302 @ r0 - address of faulting instruction
303 @ r1 - pointer to registers on stack
304 @
Paul Brook48d79272008-04-18 22:43:07 +0100305#ifdef MULTI_PABORT
306 mov r0, r2 @ pass address of aborted instruction.
307 ldr r4, .LCprocfns
308 mov lr, pc
309 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
310#else
311 CPU_PABORT_HANDLER(r0, r2)
312#endif
313 msr cpsr_c, r9 @ Maybe enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 mov r1, sp @ regs
315 bl do_PrefetchAbort @ call abort handler
316
317 @
318 @ IRQs off again before pulling preserved data off the stack
319 @
Russell King1ec42c02005-04-26 15:18:26 +0100320 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 @
323 @ restore SPSR and restart the instruction
324 @
325 ldr r0, [sp, #S_PSR]
326 msr spsr_cxsf, r0
327 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
Catalin Marinasc4c57162009-02-16 11:42:09 +0100328 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100329ENDPROC(__pabt_svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 .align 5
Russell King49f680e2005-05-31 18:02:00 +0100332.LCcralign:
333 .word cr_alignment
Paul Brook48d79272008-04-18 22:43:07 +0100334#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335.LCprocfns:
336 .word processor
337#endif
338.LCfp:
339 .word fp_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341/*
342 * User mode handlers
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000343 *
344 * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000346
347#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
348#error "sizeof(struct pt_regs) must be a multiple of 8"
349#endif
350
Russell Kingccea7a12005-05-31 22:22:32 +0100351 .macro usr_entry
Catalin Marinasc4c57162009-02-16 11:42:09 +0100352 UNWIND(.fnstart )
353 UNWIND(.cantunwind ) @ don't unwind the user space
Russell Kingccea7a12005-05-31 22:22:32 +0100354 sub sp, sp, #S_FRAME_SIZE
355 stmib sp, {r1 - r12}
356
357 ldmia r0, {r1 - r3}
358 add r0, sp, #S_PC @ here for interlock avoidance
359 mov r4, #-1 @ "" "" "" ""
360
361 str r1, [sp] @ save the "real" r0 copied
362 @ from the exception stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 @
365 @ We are now ready to fill in the remaining blanks on the stack:
366 @
367 @ r2 - lr_<exception>, already fixed up for correct return/restart
368 @ r3 - spsr_<exception>
369 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
370 @
371 @ Also, separately save sp_usr and lr_usr
372 @
Russell Kingccea7a12005-05-31 22:22:32 +0100373 stmia r0, {r2 - r4}
374 stmdb r0, {sp, lr}^
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 @
377 @ Enable the alignment trap while in kernel mode
378 @
Russell King49f680e2005-05-31 18:02:00 +0100379 alignment_trap r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 @
382 @ Clear FP to mark the first stack frame
383 @
384 zero_fp
Uwe Kleine-König0d928b02009-08-13 20:38:17 +0200385
386 asm_trace_hardirqs_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 .endm
388
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100389 .macro kuser_cmpxchg_check
390#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
391#ifndef CONFIG_MMU
392#warning "NPTL on non MMU needs fixing"
393#else
394 @ Make sure our user space atomic helper is restarted
395 @ if it was interrupted in a critical region. Here we
396 @ perform a quick test inline since it should be false
397 @ 99.9999% of the time. The rest is done out of line.
398 cmp r2, #TASK_SIZE
399 blhs kuser_cmpxchg_fixup
400#endif
401#endif
402 .endm
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .align 5
405__dabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100406 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100407 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 @
410 @ Call the processor-specific abort handler:
411 @
412 @ r2 - aborted context pc
413 @ r3 - aborted context cpsr
414 @
415 @ The abort handler must return the aborted address in r0, and
416 @ the fault status register in r1.
417 @
Paul Brook48d79272008-04-18 22:43:07 +0100418#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 ldr r4, .LCprocfns
420 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100421 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#else
Paul Brook48d79272008-04-18 22:43:07 +0100423 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#endif
425
426 @
427 @ IRQs on, then call the main handler
428 @
Russell King1ec42c02005-04-26 15:18:26 +0100429 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 mov r2, sp
431 adr lr, ret_from_exception
432 b do_DataAbort
Catalin Marinasc4c57162009-02-16 11:42:09 +0100433 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100434ENDPROC(__dabt_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436 .align 5
437__irq_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100438 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100439 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100443 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
444 add r7, r8, #1 @ increment it
445 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100447
Russell King187a51a2005-05-21 18:14:44 +0100448 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100450 ldr r0, [tsk, #TI_PREEMPT]
451 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 strne r0, [r0, -r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#endif
Russell King7ad1bcb2006-08-27 12:07:02 +0100455#ifdef CONFIG_TRACE_IRQFLAGS
456 bl trace_hardirqs_on
457#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 mov why, #0
460 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100461 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100462ENDPROC(__irq_usr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 .ltorg
465
466 .align 5
467__und_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100468 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 @
471 @ fall through to the emulation code, which returns using r9 if
472 @ it has emulated the instruction, or the more conventional lr
473 @ if we are to treat this as a real undefined instruction
474 @
475 @ r0 - instruction
476 @
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 adr r9, ret_from_exception
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000478 adr lr, __und_usr_unknown
Paul Brookcb170a42008-04-18 22:43:08 +0100479 tst r3, #PSR_T_BIT @ Thumb mode?
480 subeq r4, r2, #4 @ ARM instr at LR - 4
481 subne r4, r2, #2 @ Thumb instr at LR - 2
4821: ldreqt r0, [r4]
Catalin Marinas26584852009-05-30 14:00:18 +0100483#ifdef CONFIG_CPU_ENDIAN_BE8
484 reveq r0, r0 @ little endian instruction
485#endif
Paul Brookcb170a42008-04-18 22:43:08 +0100486 beq call_fpe
487 @ Thumb instruction
488#if __LINUX_ARM_ARCH__ >= 7
4892: ldrht r5, [r4], #2
490 and r0, r5, #0xf800 @ mask bits 111x x... .... ....
491 cmp r0, #0xe800 @ 32bit instruction if xx != 0
492 blo __und_usr_unknown
4933: ldrht r0, [r4]
494 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
495 orr r0, r0, r5, lsl #16
496#else
497 b __und_usr_unknown
498#endif
Catalin Marinasc4c57162009-02-16 11:42:09 +0100499 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100500ENDPROC(__und_usr)
Paul Brookcb170a42008-04-18 22:43:08 +0100501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 @
503 @ fallthrough to call_fpe
504 @
505
506/*
507 * The out of line fixup for the ldrt above.
508 */
509 .section .fixup, "ax"
Paul Brookcb170a42008-04-18 22:43:08 +01005104: mov pc, r9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .previous
512 .section __ex_table,"a"
Paul Brookcb170a42008-04-18 22:43:08 +0100513 .long 1b, 4b
514#if __LINUX_ARM_ARCH__ >= 7
515 .long 2b, 4b
516 .long 3b, 4b
517#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .previous
519
520/*
521 * Check whether the instruction is a co-processor instruction.
522 * If yes, we need to call the relevant co-processor handler.
523 *
524 * Note that we don't do a full check here for the co-processor
525 * instructions; all instructions with bit 27 set are well
526 * defined. The only instructions that should fault are the
527 * co-processor instructions. However, we have to watch out
528 * for the ARM6/ARM7 SWI bug.
529 *
Catalin Marinasb5872db2008-01-10 19:16:17 +0100530 * NEON is a special case that has to be handled here. Not all
531 * NEON instructions are co-processor instructions, so we have
532 * to make a special case of checking for them. Plus, there's
533 * five groups of them, so we have a table of mask/opcode pairs
534 * to check against, and if any match then we branch off into the
535 * NEON handler code.
536 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 * Emulators may wish to make use of the following registers:
538 * r0 = instruction opcode.
539 * r2 = PC+4
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000540 * r9 = normal "successful" return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 * r10 = this threads thread_info structure.
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000542 * lr = unrecognised instruction return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
Paul Brookcb170a42008-04-18 22:43:08 +0100544 @
545 @ Fall-through from Thumb-2 __und_usr
546 @
547#ifdef CONFIG_NEON
548 adr r6, .LCneon_thumb_opcodes
549 b 2f
550#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551call_fpe:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100552#ifdef CONFIG_NEON
Paul Brookcb170a42008-04-18 22:43:08 +0100553 adr r6, .LCneon_arm_opcodes
Catalin Marinasb5872db2008-01-10 19:16:17 +01005542:
555 ldr r7, [r6], #4 @ mask value
556 cmp r7, #0 @ end mask?
557 beq 1f
558 and r8, r0, r7
559 ldr r7, [r6], #4 @ opcode bits matching in mask
560 cmp r8, r7 @ NEON instruction?
561 bne 2b
562 get_thread_info r10
563 mov r7, #1
564 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
565 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
566 b do_vfp @ let VFP handler handle this
5671:
568#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
Paul Brookcb170a42008-04-18 22:43:08 +0100570 tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
572 and r8, r0, #0x0f000000 @ mask out op-code bits
573 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
574#endif
575 moveq pc, lr
576 get_thread_info r10 @ get current thread
577 and r8, r0, #0x00000f00 @ mask out CP number
578 mov r7, #1
579 add r6, r10, #TI_USED_CP
580 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
581#ifdef CONFIG_IWMMXT
582 @ Test if we need to give access to iWMMXt coprocessors
583 ldr r5, [r10, #TI_FLAGS]
584 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
585 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
586 bcs iwmmxt_task_enable
587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 add pc, pc, r8, lsr #6
589 mov r0, r0
590
591 mov pc, lr @ CP#0
592 b do_fpe @ CP#1 (FPE)
593 b do_fpe @ CP#2 (FPE)
594 mov 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 mov pc, lr @ CP#4
601 mov pc, lr @ CP#5
602 mov pc, lr @ CP#6
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100603#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 mov pc, lr @ CP#7
605 mov pc, lr @ CP#8
606 mov pc, lr @ CP#9
607#ifdef CONFIG_VFP
608 b do_vfp @ CP#10 (VFP)
609 b do_vfp @ CP#11 (VFP)
610#else
611 mov pc, lr @ CP#10 (VFP)
612 mov pc, lr @ CP#11 (VFP)
613#endif
614 mov pc, lr @ CP#12
615 mov pc, lr @ CP#13
616 mov pc, lr @ CP#14 (Debug)
617 mov pc, lr @ CP#15 (Control)
618
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
658 .data
659ENTRY(fp_enter)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000660 .word no_fp
Nicolas Pitre785d3cd2007-12-03 15:27:56 -0500661 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000663no_fp: mov pc, lr
664
665__und_usr_unknown:
Russell Kingecbab712009-01-27 23:20:00 +0000666 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 mov r0, sp
668 adr lr, ret_from_exception
669 b do_undefinstr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100670ENDPROC(__und_usr_unknown)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 .align 5
673__pabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100674 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Paul Brook48d79272008-04-18 22:43:07 +0100676#ifdef MULTI_PABORT
677 mov r0, r2 @ pass address of aborted instruction.
678 ldr r4, .LCprocfns
679 mov lr, pc
680 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
681#else
682 CPU_PABORT_HANDLER(r0, r2)
683#endif
Russell King1ec42c02005-04-26 15:18:26 +0100684 enable_irq @ Enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 mov r1, sp @ regs
686 bl do_PrefetchAbort @ call abort handler
Catalin Marinasc4c57162009-02-16 11:42:09 +0100687 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* fall through */
689/*
690 * This is the return code to user mode for abort handlers
691 */
692ENTRY(ret_from_exception)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100693 UNWIND(.fnstart )
694 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 get_thread_info tsk
696 mov why, #0
697 b ret_to_user
Catalin Marinasc4c57162009-02-16 11:42:09 +0100698 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100699ENDPROC(__pabt_usr)
700ENDPROC(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702/*
703 * Register switch for ARMv3 and ARMv4 processors
704 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
705 * previous and next are guaranteed not to be the same.
706 */
707ENTRY(__switch_to)
Catalin Marinasc4c57162009-02-16 11:42:09 +0100708 UNWIND(.fnstart )
709 UNWIND(.cantunwind )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 add ip, r1, #TI_CPU_SAVE
711 ldr r3, [r2, #TI_TP_VALUE]
712 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
Russell Kingd6551e82006-06-21 13:31:52 +0100713#ifdef CONFIG_MMU
714 ldr r6, [r2, #TI_CPU_DOMAIN]
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000715#endif
Russell Kingb8763862005-08-10 14:52:52 +0100716#if __LINUX_ARM_ARCH__ >= 6
Russell King43cc1982006-02-22 21:13:28 +0000717#ifdef CONFIG_CPU_32v6K
Russell Kingb8763862005-08-10 14:52:52 +0100718 clrex
719#else
Russell King73394322005-09-23 21:49:58 +0100720 strex r5, r4, [ip] @ Clear exclusive monitor
Russell Kingb8763862005-08-10 14:52:52 +0100721#endif
722#endif
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100723#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100724 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100725#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 mov r4, #0xffff0fff
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100727 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
728#endif
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000729#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000731#endif
Russell Kingd6551e82006-06-21 13:31:52 +0100732 mov r5, r0
733 add r4, r2, #TI_CPU_SAVE
734 ldr r0, =thread_notify_head
735 mov r1, #THREAD_NOTIFY_SWITCH
736 bl atomic_notifier_call_chain
737 mov r0, r5
738 ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
Catalin Marinasc4c57162009-02-16 11:42:09 +0100739 UNWIND(.fnend )
Catalin Marinas93ed3972008-08-28 11:22:32 +0100740ENDPROC(__switch_to)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100743
744/*
745 * User helpers.
746 *
747 * These are segment of kernel provided user code reachable from user space
748 * at a fixed address in kernel memory. This is used to provide user space
749 * with some operations which require kernel help because of unimplemented
750 * native feature and/or instructions in many ARM CPUs. The idea is for
751 * this code to be executed directly in user mode for best efficiency but
752 * which is too intimate with the kernel counter part to be left to user
753 * libraries. In fact this code might even differ from one CPU to another
754 * depending on the available instruction set and restrictions like on
755 * SMP systems. In other words, the kernel reserves the right to change
756 * this code as needed without warning. Only the entry points and their
757 * results are guaranteed to be stable.
758 *
759 * Each segment is 32-byte aligned and will be moved to the top of the high
760 * vector page. New segments (if ever needed) must be added in front of
761 * existing ones. This mechanism should be used only for things that are
762 * really small and justified, and not be abused freely.
763 *
764 * User space is expected to implement those things inline when optimizing
765 * for a processor that has the necessary native support, but only if such
766 * resulting binaries are already to be incompatible with earlier ARM
767 * processors due to the use of unsupported instructions other than what
768 * is provided here. In other words don't make binaries unable to run on
769 * earlier processors just for the sake of not using these kernel helpers
770 * if your compiled code is not going to use the new instructions for other
771 * purpose.
772 */
773
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100774 .macro usr_ret, reg
775#ifdef CONFIG_ARM_THUMB
776 bx \reg
777#else
778 mov pc, \reg
779#endif
780 .endm
781
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100782 .align 5
783 .globl __kuser_helper_start
784__kuser_helper_start:
785
786/*
787 * Reference prototype:
788 *
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000789 * void __kernel_memory_barrier(void)
790 *
791 * Input:
792 *
793 * lr = return address
794 *
795 * Output:
796 *
797 * none
798 *
799 * Clobbered:
800 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100801 * none
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000802 *
803 * Definition and user space usage example:
804 *
805 * typedef void (__kernel_dmb_t)(void);
806 * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
807 *
808 * Apply any needed memory barrier to preserve consistency with data modified
809 * manually and __kuser_cmpxchg usage.
810 *
811 * This could be used as follows:
812 *
813 * #define __kernel_dmb() \
814 * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
Paul Brook6896eec2006-03-28 22:19:29 +0100815 * : : : "r0", "lr","cc" )
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000816 */
817
818__kuser_memory_barrier: @ 0xffff0fa0
Russell Kingbac4e962009-05-25 20:58:00 +0100819 smp_dmb
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100820 usr_ret lr
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000821
822 .align 5
823
824/*
825 * Reference prototype:
826 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100827 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
828 *
829 * Input:
830 *
831 * r0 = oldval
832 * r1 = newval
833 * r2 = ptr
834 * lr = return address
835 *
836 * Output:
837 *
838 * r0 = returned value (zero or non-zero)
839 * C flag = set if r0 == 0, clear if r0 != 0
840 *
841 * Clobbered:
842 *
843 * r3, ip, flags
844 *
845 * Definition and user space usage example:
846 *
847 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
848 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
849 *
850 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
851 * Return zero if *ptr was changed or non-zero if no exchange happened.
852 * The C flag is also set if *ptr was changed to allow for assembly
853 * optimization in the calling code.
854 *
Nicolas Pitre5964eae2006-02-08 21:19:37 +0000855 * Notes:
856 *
857 * - This routine already includes memory barriers as needed.
858 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100859 * For example, a user space atomic_add implementation could look like this:
860 *
861 * #define atomic_add(ptr, val) \
862 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
863 * register unsigned int __result asm("r1"); \
864 * asm volatile ( \
865 * "1: @ atomic_add\n\t" \
866 * "ldr r0, [r2]\n\t" \
867 * "mov r3, #0xffff0fff\n\t" \
868 * "add lr, pc, #4\n\t" \
869 * "add r1, r0, %2\n\t" \
870 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
871 * "bcc 1b" \
872 * : "=&r" (__result) \
873 * : "r" (__ptr), "rIL" (val) \
874 * : "r0","r3","ip","lr","cc","memory" ); \
875 * __result; })
876 */
877
878__kuser_cmpxchg: @ 0xffff0fc0
879
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100880#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100881
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100882 /*
883 * Poor you. No fast solution possible...
884 * The kernel itself must perform the operation.
885 * A special ghost syscall is used for that (see traps.c).
886 */
Nicolas Pitre5e097442006-01-18 22:38:49 +0000887 stmfd sp!, {r7, lr}
888 mov r7, #0xff00 @ 0xfff0 into r7 for EABI
889 orr r7, r7, #0xf0
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100890 swi #0x9ffff0
Nicolas Pitre5e097442006-01-18 22:38:49 +0000891 ldmfd sp!, {r7, pc}
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100892
893#elif __LINUX_ARM_ARCH__ < 6
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100894
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000895#ifdef CONFIG_MMU
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100896
897 /*
898 * The only thing that can break atomicity in this cmpxchg
899 * implementation is either an IRQ or a data abort exception
900 * causing another process/thread to be scheduled in the middle
901 * of the critical sequence. To prevent this, code is added to
902 * the IRQ and data abort exception handlers to set the pc back
903 * to the beginning of the critical section if it is found to be
904 * within that critical section (see kuser_cmpxchg_fixup).
905 */
9061: ldr r3, [r2] @ load current val
907 subs r3, r3, r0 @ compare with oldval
9082: streq r1, [r2] @ store newval if eq
909 rsbs r0, r3, #0 @ set return val and C flag
910 usr_ret lr
911
912 .text
913kuser_cmpxchg_fixup:
914 @ Called from kuser_cmpxchg_check macro.
915 @ r2 = address of interrupted insn (must be preserved).
916 @ sp = saved regs. r7 and r8 are clobbered.
917 @ 1b = first critical insn, 2b = last critical insn.
918 @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
919 mov r7, #0xffff0fff
920 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
921 subs r8, r2, r7
922 rsbcss r8, r8, #(2b - 1b)
923 strcs r7, [sp, #S_PC]
924 mov pc, lr
925 .previous
926
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000927#else
928#warning "NPTL on non MMU needs fixing"
929 mov r0, #-1
930 adds r0, r0, #0
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100931 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100932#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100933
934#else
935
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000936#ifdef CONFIG_SMP
937 mcr p15, 0, r0, c7, c10, 5 @ dmb
938#endif
Nicolas Pitreb49c0f22007-11-20 17:20:29 +01009391: ldrex r3, [r2]
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100940 subs r3, r3, r0
941 strexeq r3, r1, [r2]
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100942 teqeq r3, #1
943 beq 1b
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100944 rsbs r0, r3, #0
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100945 /* beware -- each __kuser slot must be 8 instructions max */
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000946#ifdef CONFIG_SMP
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100947 b __kuser_memory_barrier
948#else
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100949 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100950#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100951
952#endif
953
954 .align 5
955
956/*
957 * Reference prototype:
958 *
959 * int __kernel_get_tls(void)
960 *
961 * Input:
962 *
963 * lr = return address
964 *
965 * Output:
966 *
967 * r0 = TLS value
968 *
969 * Clobbered:
970 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100971 * none
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100972 *
973 * Definition and user space usage example:
974 *
975 * typedef int (__kernel_get_tls_t)(void);
976 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
977 *
978 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
979 *
980 * This could be used as follows:
981 *
982 * #define __kernel_get_tls() \
983 * ({ register unsigned int __val asm("r0"); \
984 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
985 * : "=r" (__val) : : "lr","cc" ); \
986 * __val; })
987 */
988
989__kuser_get_tls: @ 0xffff0fe0
990
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100991#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100992 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100993#else
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100994 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100995#endif
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100996 usr_ret lr
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100997
998 .rep 5
999 .word 0 @ pad up to __kuser_helper_version
1000 .endr
1001
1002/*
1003 * Reference declaration:
1004 *
1005 * extern unsigned int __kernel_helper_version;
1006 *
1007 * Definition and user space usage example:
1008 *
1009 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
1010 *
1011 * User space may read this to determine the curent number of helpers
1012 * available.
1013 */
1014
1015__kuser_helper_version: @ 0xffff0ffc
1016 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
1017
1018 .globl __kuser_helper_end
1019__kuser_helper_end:
1020
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022/*
1023 * Vector stubs.
1024 *
Russell King79335232005-04-26 15:17:42 +01001025 * This code is copied to 0xffff0200 so we can use branches in the
1026 * vectors, rather than ldr's. Note that this code must not
1027 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 *
1029 * Common stub entry macro:
1030 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
Russell Kingccea7a12005-05-31 22:22:32 +01001031 *
1032 * SP points to a minimal amount of processor-private memory, the address
1033 * of which is copied into r0 for the mode specific abort handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001035 .macro vector_stub, name, mode, correction=0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .align 5
1037
1038vector_\name:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .if \correction
1040 sub lr, lr, #\correction
1041 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Russell Kingccea7a12005-05-31 22:22:32 +01001043 @
1044 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1045 @ (parent CPSR)
1046 @
1047 stmia sp, {r0, lr} @ save r0, lr
1048 mrs lr, spsr
1049 str lr, [sp, #8] @ save spsr
1050
1051 @
1052 @ Prepare for SVC32 mode. IRQs remain disabled.
1053 @
1054 mrs r0, cpsr
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001055 eor r0, r0, #(\mode ^ SVC_MODE)
Russell Kingccea7a12005-05-31 22:22:32 +01001056 msr spsr_cxsf, r0
1057
1058 @
1059 @ the branch table must immediately follow this code
1060 @
Russell Kingccea7a12005-05-31 22:22:32 +01001061 and lr, lr, #0x0f
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001062 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 ldr lr, [pc, lr, lsl #2]
Russell Kingccea7a12005-05-31 22:22:32 +01001064 movs pc, lr @ branch to handler in SVC mode
Catalin Marinas93ed3972008-08-28 11:22:32 +01001065ENDPROC(vector_\name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .endm
1067
Russell King79335232005-04-26 15:17:42 +01001068 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069__stubs_start:
1070/*
1071 * Interrupt dispatcher
1072 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001073 vector_stub irq, IRQ_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 .long __irq_usr @ 0 (USR_26 / USR_32)
1076 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1077 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1078 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1079 .long __irq_invalid @ 4
1080 .long __irq_invalid @ 5
1081 .long __irq_invalid @ 6
1082 .long __irq_invalid @ 7
1083 .long __irq_invalid @ 8
1084 .long __irq_invalid @ 9
1085 .long __irq_invalid @ a
1086 .long __irq_invalid @ b
1087 .long __irq_invalid @ c
1088 .long __irq_invalid @ d
1089 .long __irq_invalid @ e
1090 .long __irq_invalid @ f
1091
1092/*
1093 * Data abort dispatcher
1094 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1095 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001096 vector_stub dabt, ABT_MODE, 8
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 .long __dabt_usr @ 0 (USR_26 / USR_32)
1099 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1100 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1101 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1102 .long __dabt_invalid @ 4
1103 .long __dabt_invalid @ 5
1104 .long __dabt_invalid @ 6
1105 .long __dabt_invalid @ 7
1106 .long __dabt_invalid @ 8
1107 .long __dabt_invalid @ 9
1108 .long __dabt_invalid @ a
1109 .long __dabt_invalid @ b
1110 .long __dabt_invalid @ c
1111 .long __dabt_invalid @ d
1112 .long __dabt_invalid @ e
1113 .long __dabt_invalid @ f
1114
1115/*
1116 * Prefetch abort dispatcher
1117 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1118 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001119 vector_stub pabt, ABT_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 .long __pabt_usr @ 0 (USR_26 / USR_32)
1122 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1123 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1124 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1125 .long __pabt_invalid @ 4
1126 .long __pabt_invalid @ 5
1127 .long __pabt_invalid @ 6
1128 .long __pabt_invalid @ 7
1129 .long __pabt_invalid @ 8
1130 .long __pabt_invalid @ 9
1131 .long __pabt_invalid @ a
1132 .long __pabt_invalid @ b
1133 .long __pabt_invalid @ c
1134 .long __pabt_invalid @ d
1135 .long __pabt_invalid @ e
1136 .long __pabt_invalid @ f
1137
1138/*
1139 * Undef instr entry dispatcher
1140 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1141 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001142 vector_stub und, UND_MODE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 .long __und_usr @ 0 (USR_26 / USR_32)
1145 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1146 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1147 .long __und_svc @ 3 (SVC_26 / SVC_32)
1148 .long __und_invalid @ 4
1149 .long __und_invalid @ 5
1150 .long __und_invalid @ 6
1151 .long __und_invalid @ 7
1152 .long __und_invalid @ 8
1153 .long __und_invalid @ 9
1154 .long __und_invalid @ a
1155 .long __und_invalid @ b
1156 .long __und_invalid @ c
1157 .long __und_invalid @ d
1158 .long __und_invalid @ e
1159 .long __und_invalid @ f
1160
1161 .align 5
1162
1163/*=============================================================================
1164 * Undefined FIQs
1165 *-----------------------------------------------------------------------------
1166 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1167 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1168 * Basically to switch modes, we *HAVE* to clobber one register... brain
1169 * damage alert! I don't think that we can execute any code in here in any
1170 * other mode than FIQ... Ok you can switch to another mode, but you can't
1171 * get out of that mode without clobbering one register.
1172 */
1173vector_fiq:
1174 disable_fiq
1175 subs pc, lr, #4
1176
1177/*=============================================================================
1178 * Address exception handler
1179 *-----------------------------------------------------------------------------
1180 * These aren't too critical.
1181 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1182 */
1183
1184vector_addrexcptn:
1185 b vector_addrexcptn
1186
1187/*
1188 * We group all the following data together to optimise
1189 * for CPUs with separate I & D caches.
1190 */
1191 .align 5
1192
1193.LCvswi:
1194 .word vector_swi
1195
Russell King79335232005-04-26 15:17:42 +01001196 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197__stubs_end:
1198
Russell King79335232005-04-26 15:17:42 +01001199 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Russell King79335232005-04-26 15:17:42 +01001201 .globl __vectors_start
1202__vectors_start:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 swi SYS_ERROR0
Russell King79335232005-04-26 15:17:42 +01001204 b vector_und + stubs_offset
1205 ldr pc, .LCvswi + stubs_offset
1206 b vector_pabt + stubs_offset
1207 b vector_dabt + stubs_offset
1208 b vector_addrexcptn + stubs_offset
1209 b vector_irq + stubs_offset
1210 b vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Russell King79335232005-04-26 15:17:42 +01001212 .globl __vectors_end
1213__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 .data
1216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .globl cr_alignment
1218 .globl cr_no_alignment
1219cr_alignment:
1220 .space 4
1221cr_no_alignment:
1222 .space 4