blob: 6fd1460111ec0ba99148401a468e95dc60d9e6ec [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 Kingbce495d2005-04-26 15:21:02 +010021#include <asm/arch/entry-macro.S>
Russell Kingd6551e82006-06-21 13:31:52 +010022#include <asm/thread_notify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include "entry-header.S"
25
26/*
Russell King187a51a2005-05-21 18:14:44 +010027 * Interrupt handling. Preserves r7, r8, r9
28 */
29 .macro irq_handler
Dan Williamsf80dff92007-02-16 22:16:32 +010030 get_irqnr_preamble r5, lr
Russell King187a51a2005-05-21 18:14:44 +0100311: get_irqnr_and_base r0, r6, r5, lr
32 movne r1, sp
33 @
34 @ routine called with r0 = irq number, r1 = struct pt_regs *
35 @
36 adrne lr, 1b
37 bne asm_do_IRQ
Russell King791be9b2005-05-21 18:16:44 +010038
39#ifdef CONFIG_SMP
40 /*
41 * XXX
42 *
43 * this macro assumes that irqstat (r6) and base (r5) are
44 * preserved from get_irqnr_and_base above
45 */
46 test_for_ipi r0, r6, r5, lr
47 movne r0, sp
48 adrne lr, 1b
49 bne do_IPI
Russell King37ee16a2005-11-08 19:08:05 +000050
51#ifdef CONFIG_LOCAL_TIMERS
52 test_for_ltirq r0, r6, r5, lr
53 movne r0, sp
54 adrne lr, 1b
55 bne do_local_timer
56#endif
Russell King791be9b2005-05-21 18:16:44 +010057#endif
58
Russell King187a51a2005-05-21 18:14:44 +010059 .endm
60
Nicolas Pitre785d3cd2007-12-03 15:27:56 -050061#ifdef CONFIG_KPROBES
62 .section .kprobes.text,"ax",%progbits
63#else
64 .text
65#endif
66
Russell King187a51a2005-05-21 18:14:44 +010067/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 * Invalid mode handlers
69 */
Russell Kingccea7a12005-05-31 22:22:32 +010070 .macro inv_entry, reason
71 sub sp, sp, #S_FRAME_SIZE
72 stmib sp, {r1 - lr}
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 mov r1, #\reason
74 .endm
75
76__pabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010077 inv_entry BAD_PREFETCH
78 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80__dabt_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010081 inv_entry BAD_DATA
82 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84__irq_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010085 inv_entry BAD_IRQ
86 b common_invalid
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88__und_invalid:
Russell Kingccea7a12005-05-31 22:22:32 +010089 inv_entry BAD_UNDEFINSTR
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Russell Kingccea7a12005-05-31 22:22:32 +010091 @
92 @ XXX fall through to common_invalid
93 @
94
95@
96@ common_invalid - generic code for failed exception (re-entrant version of handlers)
97@
98common_invalid:
99 zero_fp
100
101 ldmia r0, {r4 - r6}
102 add r0, sp, #S_PC @ here for interlock avoidance
103 mov r7, #-1 @ "" "" "" ""
104 str r4, [sp] @ save preserved r0
105 stmia r0, {r5 - r7} @ lr_<exception>,
106 @ cpsr_<exception>, "old_r0"
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 b bad_mode
110
111/*
112 * SVC mode handlers
113 */
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000114
115#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
116#define SPFIX(code...) code
117#else
118#define SPFIX(code...)
119#endif
120
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500121 .macro svc_entry, stack_hole=0
122 sub sp, sp, #(S_FRAME_SIZE + \stack_hole)
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000123 SPFIX( tst sp, #4 )
124 SPFIX( bicne sp, sp, #4 )
Russell Kingccea7a12005-05-31 22:22:32 +0100125 stmib sp, {r1 - r12}
126
127 ldmia r0, {r1 - r3}
128 add r5, sp, #S_SP @ here for interlock avoidance
129 mov r4, #-1 @ "" "" "" ""
Nicolas Pitred30a0c82007-12-14 15:56:01 -0500130 add r0, sp, #(S_FRAME_SIZE + \stack_hole)
Nicolas Pitre2dede2d2006-01-14 16:18:08 +0000131 SPFIX( addne r0, r0, #4 )
Russell Kingccea7a12005-05-31 22:22:32 +0100132 str r1, [sp] @ save the "real" r0 copied
133 @ from the exception stack
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 mov r1, lr
136
137 @
138 @ We are now ready to fill in the remaining blanks on the stack:
139 @
140 @ r0 - sp_svc
141 @ r1 - lr_svc
142 @ r2 - lr_<exception>, already fixed up for correct return/restart
143 @ r3 - spsr_<exception>
144 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
145 @
146 stmia r5, {r0 - r4}
147 .endm
148
149 .align 5
150__dabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100151 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 @
154 @ get ready to re-enable interrupts if appropriate
155 @
156 mrs r9, cpsr
157 tst r3, #PSR_I_BIT
158 biceq r9, r9, #PSR_I_BIT
159
160 @
161 @ Call the processor-specific abort handler:
162 @
163 @ r2 - aborted context pc
164 @ r3 - aborted context cpsr
165 @
166 @ The abort handler must return the aborted address in r0, and
167 @ the fault status register in r1. r9 must be preserved.
168 @
Paul Brook48d79272008-04-18 22:43:07 +0100169#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 ldr r4, .LCprocfns
171 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100172 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#else
Paul Brook48d79272008-04-18 22:43:07 +0100174 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#endif
176
177 @
178 @ set desired IRQ state, then call main handler
179 @
180 msr cpsr_c, r9
181 mov r2, sp
182 bl do_DataAbort
183
184 @
185 @ IRQs off again before pulling preserved data off the stack
186 @
Russell King1ec42c02005-04-26 15:18:26 +0100187 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 @
190 @ restore SPSR and restart the instruction
191 @
192 ldr r0, [sp, #S_PSR]
193 msr spsr_cxsf, r0
194 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
195
196 .align 5
197__irq_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100198 svc_entry
199
Russell King7ad1bcb2006-08-27 12:07:02 +0100200#ifdef CONFIG_TRACE_IRQFLAGS
201 bl trace_hardirqs_off
202#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100204 get_thread_info tsk
205 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
206 add r7, r8, #1 @ increment it
207 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100209
Russell King187a51a2005-05-21 18:14:44 +0100210 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100212 ldr r0, [tsk, #TI_FLAGS] @ get flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 tst r0, #_TIF_NEED_RESCHED
214 blne svc_preempt
215preempt_return:
Russell King706fdd92005-05-21 18:15:45 +0100216 ldr r0, [tsk, #TI_PREEMPT] @ read preempt value
217 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 strne r0, [r0, -r0] @ bug()
220#endif
221 ldr r0, [sp, #S_PSR] @ irqs are already disabled
222 msr spsr_cxsf, r0
Russell King7ad1bcb2006-08-27 12:07:02 +0100223#ifdef CONFIG_TRACE_IRQFLAGS
224 tst r0, #PSR_I_BIT
225 bleq trace_hardirqs_on
226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
228
229 .ltorg
230
231#ifdef CONFIG_PREEMPT
232svc_preempt:
Russell King706fdd92005-05-21 18:15:45 +0100233 teq r8, #0 @ was preempt count = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 ldreq r6, .LCirq_stat
235 movne pc, lr @ no
236 ldr r0, [r6, #4] @ local_irq_count
237 ldr r1, [r6, #8] @ local_bh_count
238 adds r0, r0, r1
239 movne pc, lr
240 mov r7, #0 @ preempt_schedule_irq
Russell King706fdd92005-05-21 18:15:45 +0100241 str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0
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
245 beq preempt_return @ go again
246 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
285
286 .align 5
287__pabt_svc:
Russell Kingccea7a12005-05-31 22:22:32 +0100288 svc_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 @
291 @ re-enable interrupts if appropriate
292 @
293 mrs r9, cpsr
294 tst r3, #PSR_I_BIT
295 biceq r9, r9, #PSR_I_BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 @
298 @ set args, then call main handler
299 @
300 @ r0 - address of faulting instruction
301 @ r1 - pointer to registers on stack
302 @
Paul Brook48d79272008-04-18 22:43:07 +0100303#ifdef MULTI_PABORT
304 mov r0, r2 @ pass address of aborted instruction.
305 ldr r4, .LCprocfns
306 mov lr, pc
307 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
308#else
309 CPU_PABORT_HANDLER(r0, r2)
310#endif
311 msr cpsr_c, r9 @ Maybe enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 mov r1, sp @ regs
313 bl do_PrefetchAbort @ call abort handler
314
315 @
316 @ IRQs off again before pulling preserved data off the stack
317 @
Russell King1ec42c02005-04-26 15:18:26 +0100318 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 @
321 @ restore SPSR and restart the instruction
322 @
323 ldr r0, [sp, #S_PSR]
324 msr spsr_cxsf, r0
325 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
326
327 .align 5
Russell King49f680e2005-05-31 18:02:00 +0100328.LCcralign:
329 .word cr_alignment
Paul Brook48d79272008-04-18 22:43:07 +0100330#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331.LCprocfns:
332 .word processor
333#endif
334.LCfp:
335 .word fp_enter
336#ifdef CONFIG_PREEMPT
337.LCirq_stat:
338 .word irq_stat
339#endif
340
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
352 sub sp, sp, #S_FRAME_SIZE
353 stmib sp, {r1 - r12}
354
355 ldmia r0, {r1 - r3}
356 add r0, sp, #S_PC @ here for interlock avoidance
357 mov r4, #-1 @ "" "" "" ""
358
359 str r1, [sp] @ save the "real" r0 copied
360 @ from the exception stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 @
363 @ We are now ready to fill in the remaining blanks on the stack:
364 @
365 @ r2 - lr_<exception>, already fixed up for correct return/restart
366 @ r3 - spsr_<exception>
367 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
368 @
369 @ Also, separately save sp_usr and lr_usr
370 @
Russell Kingccea7a12005-05-31 22:22:32 +0100371 stmia r0, {r2 - r4}
372 stmdb r0, {sp, lr}^
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 @
375 @ Enable the alignment trap while in kernel mode
376 @
Russell King49f680e2005-05-31 18:02:00 +0100377 alignment_trap r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 @
380 @ Clear FP to mark the first stack frame
381 @
382 zero_fp
383 .endm
384
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100385 .macro kuser_cmpxchg_check
386#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
387#ifndef CONFIG_MMU
388#warning "NPTL on non MMU needs fixing"
389#else
390 @ Make sure our user space atomic helper is restarted
391 @ if it was interrupted in a critical region. Here we
392 @ perform a quick test inline since it should be false
393 @ 99.9999% of the time. The rest is done out of line.
394 cmp r2, #TASK_SIZE
395 blhs kuser_cmpxchg_fixup
396#endif
397#endif
398 .endm
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .align 5
401__dabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100402 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100403 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 @
406 @ Call the processor-specific abort handler:
407 @
408 @ r2 - aborted context pc
409 @ r3 - aborted context cpsr
410 @
411 @ The abort handler must return the aborted address in r0, and
412 @ the fault status register in r1.
413 @
Paul Brook48d79272008-04-18 22:43:07 +0100414#ifdef MULTI_DABORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 ldr r4, .LCprocfns
416 mov lr, pc
Paul Brook48d79272008-04-18 22:43:07 +0100417 ldr pc, [r4, #PROCESSOR_DABT_FUNC]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#else
Paul Brook48d79272008-04-18 22:43:07 +0100419 bl CPU_DABORT_HANDLER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#endif
421
422 @
423 @ IRQs on, then call the main handler
424 @
Russell King1ec42c02005-04-26 15:18:26 +0100425 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 mov r2, sp
427 adr lr, ret_from_exception
428 b do_DataAbort
429
430 .align 5
431__irq_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100432 usr_entry
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100433 kuser_cmpxchg_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Russell King7ad1bcb2006-08-27 12:07:02 +0100435#ifdef CONFIG_TRACE_IRQFLAGS
436 bl trace_hardirqs_off
437#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100440 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
441 add r7, r8, #1 @ increment it
442 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100444
Russell King187a51a2005-05-21 18:14:44 +0100445 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100447 ldr r0, [tsk, #TI_PREEMPT]
448 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 strne r0, [r0, -r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#endif
Russell King7ad1bcb2006-08-27 12:07:02 +0100452#ifdef CONFIG_TRACE_IRQFLAGS
453 bl trace_hardirqs_on
454#endif
Russell Kingccea7a12005-05-31 22:22:32 +0100455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 mov why, #0
457 b ret_to_user
458
459 .ltorg
460
461 .align 5
462__und_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100463 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 @
466 @ fall through to the emulation code, which returns using r9 if
467 @ it has emulated the instruction, or the more conventional lr
468 @ if we are to treat this as a real undefined instruction
469 @
470 @ r0 - instruction
471 @
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 adr r9, ret_from_exception
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000473 adr lr, __und_usr_unknown
Paul Brookcb170a42008-04-18 22:43:08 +0100474 tst r3, #PSR_T_BIT @ Thumb mode?
475 subeq r4, r2, #4 @ ARM instr at LR - 4
476 subne r4, r2, #2 @ Thumb instr at LR - 2
4771: ldreqt r0, [r4]
478 beq call_fpe
479 @ Thumb instruction
480#if __LINUX_ARM_ARCH__ >= 7
4812: ldrht r5, [r4], #2
482 and r0, r5, #0xf800 @ mask bits 111x x... .... ....
483 cmp r0, #0xe800 @ 32bit instruction if xx != 0
484 blo __und_usr_unknown
4853: ldrht r0, [r4]
486 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
487 orr r0, r0, r5, lsl #16
488#else
489 b __und_usr_unknown
490#endif
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 @
493 @ fallthrough to call_fpe
494 @
495
496/*
497 * The out of line fixup for the ldrt above.
498 */
499 .section .fixup, "ax"
Paul Brookcb170a42008-04-18 22:43:08 +01005004: mov pc, r9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .previous
502 .section __ex_table,"a"
Paul Brookcb170a42008-04-18 22:43:08 +0100503 .long 1b, 4b
504#if __LINUX_ARM_ARCH__ >= 7
505 .long 2b, 4b
506 .long 3b, 4b
507#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .previous
509
510/*
511 * Check whether the instruction is a co-processor instruction.
512 * If yes, we need to call the relevant co-processor handler.
513 *
514 * Note that we don't do a full check here for the co-processor
515 * instructions; all instructions with bit 27 set are well
516 * defined. The only instructions that should fault are the
517 * co-processor instructions. However, we have to watch out
518 * for the ARM6/ARM7 SWI bug.
519 *
Catalin Marinasb5872db2008-01-10 19:16:17 +0100520 * NEON is a special case that has to be handled here. Not all
521 * NEON instructions are co-processor instructions, so we have
522 * to make a special case of checking for them. Plus, there's
523 * five groups of them, so we have a table of mask/opcode pairs
524 * to check against, and if any match then we branch off into the
525 * NEON handler code.
526 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 * Emulators may wish to make use of the following registers:
528 * r0 = instruction opcode.
529 * r2 = PC+4
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000530 * r9 = normal "successful" return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * r10 = this threads thread_info structure.
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000532 * lr = unrecognised instruction return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 */
Paul Brookcb170a42008-04-18 22:43:08 +0100534 @
535 @ Fall-through from Thumb-2 __und_usr
536 @
537#ifdef CONFIG_NEON
538 adr r6, .LCneon_thumb_opcodes
539 b 2f
540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541call_fpe:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100542#ifdef CONFIG_NEON
Paul Brookcb170a42008-04-18 22:43:08 +0100543 adr r6, .LCneon_arm_opcodes
Catalin Marinasb5872db2008-01-10 19:16:17 +01005442:
545 ldr r7, [r6], #4 @ mask value
546 cmp r7, #0 @ end mask?
547 beq 1f
548 and r8, r0, r7
549 ldr r7, [r6], #4 @ opcode bits matching in mask
550 cmp r8, r7 @ NEON instruction?
551 bne 2b
552 get_thread_info r10
553 mov r7, #1
554 strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
555 strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
556 b do_vfp @ let VFP handler handle this
5571:
558#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
Paul Brookcb170a42008-04-18 22:43:08 +0100560 tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
562 and r8, r0, #0x0f000000 @ mask out op-code bits
563 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
564#endif
565 moveq pc, lr
566 get_thread_info r10 @ get current thread
567 and r8, r0, #0x00000f00 @ mask out CP number
568 mov r7, #1
569 add r6, r10, #TI_USED_CP
570 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
571#ifdef CONFIG_IWMMXT
572 @ Test if we need to give access to iWMMXt coprocessors
573 ldr r5, [r10, #TI_FLAGS]
574 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
575 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
576 bcs iwmmxt_task_enable
577#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 add pc, pc, r8, lsr #6
579 mov r0, r0
580
581 mov pc, lr @ CP#0
582 b do_fpe @ CP#1 (FPE)
583 b do_fpe @ CP#2 (FPE)
584 mov pc, lr @ CP#3
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100585#ifdef CONFIG_CRUNCH
586 b crunch_task_enable @ CP#4 (MaverickCrunch)
587 b crunch_task_enable @ CP#5 (MaverickCrunch)
588 b crunch_task_enable @ CP#6 (MaverickCrunch)
589#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 mov pc, lr @ CP#4
591 mov pc, lr @ CP#5
592 mov pc, lr @ CP#6
Lennert Buytenhekc17fad12006-06-27 23:03:03 +0100593#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 mov pc, lr @ CP#7
595 mov pc, lr @ CP#8
596 mov pc, lr @ CP#9
597#ifdef CONFIG_VFP
598 b do_vfp @ CP#10 (VFP)
599 b do_vfp @ CP#11 (VFP)
600#else
601 mov pc, lr @ CP#10 (VFP)
602 mov pc, lr @ CP#11 (VFP)
603#endif
604 mov pc, lr @ CP#12
605 mov pc, lr @ CP#13
606 mov pc, lr @ CP#14 (Debug)
607 mov pc, lr @ CP#15 (Control)
608
Catalin Marinasb5872db2008-01-10 19:16:17 +0100609#ifdef CONFIG_NEON
610 .align 6
611
Paul Brookcb170a42008-04-18 22:43:08 +0100612.LCneon_arm_opcodes:
Catalin Marinasb5872db2008-01-10 19:16:17 +0100613 .word 0xfe000000 @ mask
614 .word 0xf2000000 @ opcode
615
616 .word 0xff100000 @ mask
617 .word 0xf4000000 @ opcode
618
619 .word 0x00000000 @ mask
620 .word 0x00000000 @ opcode
Paul Brookcb170a42008-04-18 22:43:08 +0100621
622.LCneon_thumb_opcodes:
623 .word 0xef000000 @ mask
624 .word 0xef000000 @ opcode
625
626 .word 0xff100000 @ mask
627 .word 0xf9000000 @ opcode
628
629 .word 0x00000000 @ mask
630 .word 0x00000000 @ opcode
Catalin Marinasb5872db2008-01-10 19:16:17 +0100631#endif
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633do_fpe:
Russell King5d25ac02006-03-15 12:33:43 +0000634 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 ldr r4, .LCfp
636 add r10, r10, #TI_FPSTATE @ r10 = workspace
637 ldr pc, [r4] @ Call FP module USR entry point
638
639/*
640 * The FP module is called with these registers set:
641 * r0 = instruction
642 * r2 = PC+4
643 * r9 = normal "successful" return address
644 * r10 = FP workspace
645 * lr = unrecognised FP instruction return address
646 */
647
648 .data
649ENTRY(fp_enter)
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000650 .word no_fp
Nicolas Pitre785d3cd2007-12-03 15:27:56 -0500651 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Russell Kingdb6ccbb2007-01-06 22:53:48 +0000653no_fp: mov pc, lr
654
655__und_usr_unknown:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 mov r0, sp
657 adr lr, ret_from_exception
658 b do_undefinstr
659
660 .align 5
661__pabt_usr:
Russell Kingccea7a12005-05-31 22:22:32 +0100662 usr_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Paul Brook48d79272008-04-18 22:43:07 +0100664#ifdef MULTI_PABORT
665 mov r0, r2 @ pass address of aborted instruction.
666 ldr r4, .LCprocfns
667 mov lr, pc
668 ldr pc, [r4, #PROCESSOR_PABT_FUNC]
669#else
670 CPU_PABORT_HANDLER(r0, r2)
671#endif
Russell King1ec42c02005-04-26 15:18:26 +0100672 enable_irq @ Enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 mov r1, sp @ regs
674 bl do_PrefetchAbort @ call abort handler
675 /* fall through */
676/*
677 * This is the return code to user mode for abort handlers
678 */
679ENTRY(ret_from_exception)
680 get_thread_info tsk
681 mov why, #0
682 b ret_to_user
683
684/*
685 * Register switch for ARMv3 and ARMv4 processors
686 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
687 * previous and next are guaranteed not to be the same.
688 */
689ENTRY(__switch_to)
690 add ip, r1, #TI_CPU_SAVE
691 ldr r3, [r2, #TI_TP_VALUE]
692 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
Russell Kingd6551e82006-06-21 13:31:52 +0100693#ifdef CONFIG_MMU
694 ldr r6, [r2, #TI_CPU_DOMAIN]
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000695#endif
Russell Kingb8763862005-08-10 14:52:52 +0100696#if __LINUX_ARM_ARCH__ >= 6
Russell King43cc1982006-02-22 21:13:28 +0000697#ifdef CONFIG_CPU_32v6K
Russell Kingb8763862005-08-10 14:52:52 +0100698 clrex
699#else
Russell King73394322005-09-23 21:49:58 +0100700 strex r5, r4, [ip] @ Clear exclusive monitor
Russell Kingb8763862005-08-10 14:52:52 +0100701#endif
702#endif
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100703#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100704 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100705#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 mov r4, #0xffff0fff
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100707 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
708#endif
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000709#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
Hyok S. Choiafeb90c2006-01-13 21:05:25 +0000711#endif
Russell Kingd6551e82006-06-21 13:31:52 +0100712 mov r5, r0
713 add r4, r2, #TI_CPU_SAVE
714 ldr r0, =thread_notify_head
715 mov r1, #THREAD_NOTIFY_SWITCH
716 bl atomic_notifier_call_chain
717 mov r0, r5
718 ldmia r4, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100721
722/*
723 * User helpers.
724 *
725 * These are segment of kernel provided user code reachable from user space
726 * at a fixed address in kernel memory. This is used to provide user space
727 * with some operations which require kernel help because of unimplemented
728 * native feature and/or instructions in many ARM CPUs. The idea is for
729 * this code to be executed directly in user mode for best efficiency but
730 * which is too intimate with the kernel counter part to be left to user
731 * libraries. In fact this code might even differ from one CPU to another
732 * depending on the available instruction set and restrictions like on
733 * SMP systems. In other words, the kernel reserves the right to change
734 * this code as needed without warning. Only the entry points and their
735 * results are guaranteed to be stable.
736 *
737 * Each segment is 32-byte aligned and will be moved to the top of the high
738 * vector page. New segments (if ever needed) must be added in front of
739 * existing ones. This mechanism should be used only for things that are
740 * really small and justified, and not be abused freely.
741 *
742 * User space is expected to implement those things inline when optimizing
743 * for a processor that has the necessary native support, but only if such
744 * resulting binaries are already to be incompatible with earlier ARM
745 * processors due to the use of unsupported instructions other than what
746 * is provided here. In other words don't make binaries unable to run on
747 * earlier processors just for the sake of not using these kernel helpers
748 * if your compiled code is not going to use the new instructions for other
749 * purpose.
750 */
751
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100752 .macro usr_ret, reg
753#ifdef CONFIG_ARM_THUMB
754 bx \reg
755#else
756 mov pc, \reg
757#endif
758 .endm
759
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100760 .align 5
761 .globl __kuser_helper_start
762__kuser_helper_start:
763
764/*
765 * Reference prototype:
766 *
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000767 * void __kernel_memory_barrier(void)
768 *
769 * Input:
770 *
771 * lr = return address
772 *
773 * Output:
774 *
775 * none
776 *
777 * Clobbered:
778 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100779 * none
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000780 *
781 * Definition and user space usage example:
782 *
783 * typedef void (__kernel_dmb_t)(void);
784 * #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
785 *
786 * Apply any needed memory barrier to preserve consistency with data modified
787 * manually and __kuser_cmpxchg usage.
788 *
789 * This could be used as follows:
790 *
791 * #define __kernel_dmb() \
792 * asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
Paul Brook6896eec2006-03-28 22:19:29 +0100793 * : : : "r0", "lr","cc" )
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000794 */
795
796__kuser_memory_barrier: @ 0xffff0fa0
797
798#if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
799 mcr p15, 0, r0, c7, c10, 5 @ dmb
800#endif
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100801 usr_ret lr
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000802
803 .align 5
804
805/*
806 * Reference prototype:
807 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100808 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
809 *
810 * Input:
811 *
812 * r0 = oldval
813 * r1 = newval
814 * r2 = ptr
815 * lr = return address
816 *
817 * Output:
818 *
819 * r0 = returned value (zero or non-zero)
820 * C flag = set if r0 == 0, clear if r0 != 0
821 *
822 * Clobbered:
823 *
824 * r3, ip, flags
825 *
826 * Definition and user space usage example:
827 *
828 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
829 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
830 *
831 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
832 * Return zero if *ptr was changed or non-zero if no exchange happened.
833 * The C flag is also set if *ptr was changed to allow for assembly
834 * optimization in the calling code.
835 *
Nicolas Pitre5964eae2006-02-08 21:19:37 +0000836 * Notes:
837 *
838 * - This routine already includes memory barriers as needed.
839 *
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100840 * For example, a user space atomic_add implementation could look like this:
841 *
842 * #define atomic_add(ptr, val) \
843 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
844 * register unsigned int __result asm("r1"); \
845 * asm volatile ( \
846 * "1: @ atomic_add\n\t" \
847 * "ldr r0, [r2]\n\t" \
848 * "mov r3, #0xffff0fff\n\t" \
849 * "add lr, pc, #4\n\t" \
850 * "add r1, r0, %2\n\t" \
851 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
852 * "bcc 1b" \
853 * : "=&r" (__result) \
854 * : "r" (__ptr), "rIL" (val) \
855 * : "r0","r3","ip","lr","cc","memory" ); \
856 * __result; })
857 */
858
859__kuser_cmpxchg: @ 0xffff0fc0
860
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100861#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100862
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100863 /*
864 * Poor you. No fast solution possible...
865 * The kernel itself must perform the operation.
866 * A special ghost syscall is used for that (see traps.c).
867 */
Nicolas Pitre5e097442006-01-18 22:38:49 +0000868 stmfd sp!, {r7, lr}
869 mov r7, #0xff00 @ 0xfff0 into r7 for EABI
870 orr r7, r7, #0xf0
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100871 swi #0x9ffff0
Nicolas Pitre5e097442006-01-18 22:38:49 +0000872 ldmfd sp!, {r7, pc}
Nicolas Pitredcef1f62005-06-08 19:00:47 +0100873
874#elif __LINUX_ARM_ARCH__ < 6
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100875
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000876#ifdef CONFIG_MMU
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100877
878 /*
879 * The only thing that can break atomicity in this cmpxchg
880 * implementation is either an IRQ or a data abort exception
881 * causing another process/thread to be scheduled in the middle
882 * of the critical sequence. To prevent this, code is added to
883 * the IRQ and data abort exception handlers to set the pc back
884 * to the beginning of the critical section if it is found to be
885 * within that critical section (see kuser_cmpxchg_fixup).
886 */
8871: ldr r3, [r2] @ load current val
888 subs r3, r3, r0 @ compare with oldval
8892: streq r1, [r2] @ store newval if eq
890 rsbs r0, r3, #0 @ set return val and C flag
891 usr_ret lr
892
893 .text
894kuser_cmpxchg_fixup:
895 @ Called from kuser_cmpxchg_check macro.
896 @ r2 = address of interrupted insn (must be preserved).
897 @ sp = saved regs. r7 and r8 are clobbered.
898 @ 1b = first critical insn, 2b = last critical insn.
899 @ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
900 mov r7, #0xffff0fff
901 sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
902 subs r8, r2, r7
903 rsbcss r8, r8, #(2b - 1b)
904 strcs r7, [sp, #S_PC]
905 mov pc, lr
906 .previous
907
Nicolas Pitre49bca4c2006-02-08 21:19:37 +0000908#else
909#warning "NPTL on non MMU needs fixing"
910 mov r0, #-1
911 adds r0, r0, #0
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100912 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100913#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100914
915#else
916
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000917#ifdef CONFIG_SMP
918 mcr p15, 0, r0, c7, c10, 5 @ dmb
919#endif
Nicolas Pitreb49c0f22007-11-20 17:20:29 +01009201: ldrex r3, [r2]
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100921 subs r3, r3, r0
922 strexeq r3, r1, [r2]
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100923 teqeq r3, #1
924 beq 1b
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100925 rsbs r0, r3, #0
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100926 /* beware -- each __kuser slot must be 8 instructions max */
Nicolas Pitre7c612bf2005-12-19 22:20:51 +0000927#ifdef CONFIG_SMP
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100928 b __kuser_memory_barrier
929#else
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100930 usr_ret lr
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100931#endif
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100932
933#endif
934
935 .align 5
936
937/*
938 * Reference prototype:
939 *
940 * int __kernel_get_tls(void)
941 *
942 * Input:
943 *
944 * lr = return address
945 *
946 * Output:
947 *
948 * r0 = TLS value
949 *
950 * Clobbered:
951 *
Nicolas Pitreb49c0f22007-11-20 17:20:29 +0100952 * none
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100953 *
954 * Definition and user space usage example:
955 *
956 * typedef int (__kernel_get_tls_t)(void);
957 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
958 *
959 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
960 *
961 * This could be used as follows:
962 *
963 * #define __kernel_get_tls() \
964 * ({ register unsigned int __val asm("r0"); \
965 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
966 * : "=r" (__val) : : "lr","cc" ); \
967 * __val; })
968 */
969
970__kuser_get_tls: @ 0xffff0fe0
971
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100972#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100973 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100974#else
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100975 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100976#endif
Nicolas Pitreba9b5d72006-08-18 17:20:15 +0100977 usr_ret lr
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100978
979 .rep 5
980 .word 0 @ pad up to __kuser_helper_version
981 .endr
982
983/*
984 * Reference declaration:
985 *
986 * extern unsigned int __kernel_helper_version;
987 *
988 * Definition and user space usage example:
989 *
990 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
991 *
992 * User space may read this to determine the curent number of helpers
993 * available.
994 */
995
996__kuser_helper_version: @ 0xffff0ffc
997 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
998
999 .globl __kuser_helper_end
1000__kuser_helper_end:
1001
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003/*
1004 * Vector stubs.
1005 *
Russell King79335232005-04-26 15:17:42 +01001006 * This code is copied to 0xffff0200 so we can use branches in the
1007 * vectors, rather than ldr's. Note that this code must not
1008 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 *
1010 * Common stub entry macro:
1011 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
Russell Kingccea7a12005-05-31 22:22:32 +01001012 *
1013 * SP points to a minimal amount of processor-private memory, the address
1014 * of which is copied into r0 for the mode specific abort handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001016 .macro vector_stub, name, mode, correction=0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .align 5
1018
1019vector_\name:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .if \correction
1021 sub lr, lr, #\correction
1022 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Russell Kingccea7a12005-05-31 22:22:32 +01001024 @
1025 @ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1026 @ (parent CPSR)
1027 @
1028 stmia sp, {r0, lr} @ save r0, lr
1029 mrs lr, spsr
1030 str lr, [sp, #8] @ save spsr
1031
1032 @
1033 @ Prepare for SVC32 mode. IRQs remain disabled.
1034 @
1035 mrs r0, cpsr
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001036 eor r0, r0, #(\mode ^ SVC_MODE)
Russell Kingccea7a12005-05-31 22:22:32 +01001037 msr spsr_cxsf, r0
1038
1039 @
1040 @ the branch table must immediately follow this code
1041 @
Russell Kingccea7a12005-05-31 22:22:32 +01001042 and lr, lr, #0x0f
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001043 mov r0, sp
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 ldr lr, [pc, lr, lsl #2]
Russell Kingccea7a12005-05-31 22:22:32 +01001045 movs pc, lr @ branch to handler in SVC mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .endm
1047
Russell King79335232005-04-26 15:17:42 +01001048 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049__stubs_start:
1050/*
1051 * Interrupt dispatcher
1052 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001053 vector_stub irq, IRQ_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 .long __irq_usr @ 0 (USR_26 / USR_32)
1056 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
1057 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
1058 .long __irq_svc @ 3 (SVC_26 / SVC_32)
1059 .long __irq_invalid @ 4
1060 .long __irq_invalid @ 5
1061 .long __irq_invalid @ 6
1062 .long __irq_invalid @ 7
1063 .long __irq_invalid @ 8
1064 .long __irq_invalid @ 9
1065 .long __irq_invalid @ a
1066 .long __irq_invalid @ b
1067 .long __irq_invalid @ c
1068 .long __irq_invalid @ d
1069 .long __irq_invalid @ e
1070 .long __irq_invalid @ f
1071
1072/*
1073 * Data abort dispatcher
1074 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1075 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001076 vector_stub dabt, ABT_MODE, 8
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 .long __dabt_usr @ 0 (USR_26 / USR_32)
1079 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
1080 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
1081 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
1082 .long __dabt_invalid @ 4
1083 .long __dabt_invalid @ 5
1084 .long __dabt_invalid @ 6
1085 .long __dabt_invalid @ 7
1086 .long __dabt_invalid @ 8
1087 .long __dabt_invalid @ 9
1088 .long __dabt_invalid @ a
1089 .long __dabt_invalid @ b
1090 .long __dabt_invalid @ c
1091 .long __dabt_invalid @ d
1092 .long __dabt_invalid @ e
1093 .long __dabt_invalid @ f
1094
1095/*
1096 * Prefetch abort dispatcher
1097 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
1098 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001099 vector_stub pabt, ABT_MODE, 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 .long __pabt_usr @ 0 (USR_26 / USR_32)
1102 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
1103 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
1104 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
1105 .long __pabt_invalid @ 4
1106 .long __pabt_invalid @ 5
1107 .long __pabt_invalid @ 6
1108 .long __pabt_invalid @ 7
1109 .long __pabt_invalid @ 8
1110 .long __pabt_invalid @ 9
1111 .long __pabt_invalid @ a
1112 .long __pabt_invalid @ b
1113 .long __pabt_invalid @ c
1114 .long __pabt_invalid @ d
1115 .long __pabt_invalid @ e
1116 .long __pabt_invalid @ f
1117
1118/*
1119 * Undef instr entry dispatcher
1120 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1121 */
Nicolas Pitreb7ec4792005-11-06 14:42:37 +00001122 vector_stub und, UND_MODE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 .long __und_usr @ 0 (USR_26 / USR_32)
1125 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
1126 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
1127 .long __und_svc @ 3 (SVC_26 / SVC_32)
1128 .long __und_invalid @ 4
1129 .long __und_invalid @ 5
1130 .long __und_invalid @ 6
1131 .long __und_invalid @ 7
1132 .long __und_invalid @ 8
1133 .long __und_invalid @ 9
1134 .long __und_invalid @ a
1135 .long __und_invalid @ b
1136 .long __und_invalid @ c
1137 .long __und_invalid @ d
1138 .long __und_invalid @ e
1139 .long __und_invalid @ f
1140
1141 .align 5
1142
1143/*=============================================================================
1144 * Undefined FIQs
1145 *-----------------------------------------------------------------------------
1146 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
1147 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
1148 * Basically to switch modes, we *HAVE* to clobber one register... brain
1149 * damage alert! I don't think that we can execute any code in here in any
1150 * other mode than FIQ... Ok you can switch to another mode, but you can't
1151 * get out of that mode without clobbering one register.
1152 */
1153vector_fiq:
1154 disable_fiq
1155 subs pc, lr, #4
1156
1157/*=============================================================================
1158 * Address exception handler
1159 *-----------------------------------------------------------------------------
1160 * These aren't too critical.
1161 * (they're not supposed to happen, and won't happen in 32-bit data mode).
1162 */
1163
1164vector_addrexcptn:
1165 b vector_addrexcptn
1166
1167/*
1168 * We group all the following data together to optimise
1169 * for CPUs with separate I & D caches.
1170 */
1171 .align 5
1172
1173.LCvswi:
1174 .word vector_swi
1175
Russell King79335232005-04-26 15:17:42 +01001176 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177__stubs_end:
1178
Russell King79335232005-04-26 15:17:42 +01001179 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Russell King79335232005-04-26 15:17:42 +01001181 .globl __vectors_start
1182__vectors_start:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 swi SYS_ERROR0
Russell King79335232005-04-26 15:17:42 +01001184 b vector_und + stubs_offset
1185 ldr pc, .LCvswi + stubs_offset
1186 b vector_pabt + stubs_offset
1187 b vector_dabt + stubs_offset
1188 b vector_addrexcptn + stubs_offset
1189 b vector_irq + stubs_offset
1190 b vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Russell King79335232005-04-26 15:17:42 +01001192 .globl __vectors_end
1193__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 .data
1196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 .globl cr_alignment
1198 .globl cr_no_alignment
1199cr_alignment:
1200 .space 4
1201cr_no_alignment:
1202 .space 4