blob: 8ff82bc75eb1369d161bd54fb0e3158735f1f019 [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)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Low-level vector interface routines
12 *
13 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction that causes
14 * it to save wrong values... Be aware!
15 */
16#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/glue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/vfpmacros.h>
Nicolas Pitre41e46d62005-05-05 23:24:45 +010020#include <asm/hardware.h> /* should be moved into entry-macro.S */
21#include <asm/arch/irqs.h> /* should be moved into entry-macro.S */
Russell Kingbce495d2005-04-26 15:21:02 +010022#include <asm/arch/entry-macro.S>
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
301: get_irqnr_and_base r0, r6, r5, lr
31 movne r1, sp
32 @
33 @ routine called with r0 = irq number, r1 = struct pt_regs *
34 @
35 adrne lr, 1b
36 bne asm_do_IRQ
37 .endm
38
39/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * Invalid mode handlers
41 */
42 .macro inv_entry, sym, reason
43 sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
44 stmia sp, {r0 - lr} @ Save XXX r0 - lr
45 ldr r4, .LC\sym
46 mov r1, #\reason
47 .endm
48
49__pabt_invalid:
50 inv_entry abt, BAD_PREFETCH
51 b 1f
52
53__dabt_invalid:
54 inv_entry abt, BAD_DATA
55 b 1f
56
57__irq_invalid:
58 inv_entry irq, BAD_IRQ
59 b 1f
60
61__und_invalid:
62 inv_entry und, BAD_UNDEFINSTR
63
641: zero_fp
65 ldmia r4, {r5 - r7} @ Get XXX pc, cpsr, old_r0
66 add r4, sp, #S_PC
67 stmia r4, {r5 - r7} @ Save XXX pc, cpsr, old_r0
68 mov r0, sp
69 and r2, r6, #31 @ int mode
70 b bad_mode
71
72/*
73 * SVC mode handlers
74 */
75 .macro svc_entry, sym
76 sub sp, sp, #S_FRAME_SIZE
77 stmia sp, {r0 - r12} @ save r0 - r12
78 ldr r2, .LC\sym
79 add r0, sp, #S_FRAME_SIZE
80 ldmia r2, {r2 - r4} @ get pc, cpsr
81 add r5, sp, #S_SP
82 mov r1, lr
83
84 @
85 @ We are now ready to fill in the remaining blanks on the stack:
86 @
87 @ r0 - sp_svc
88 @ r1 - lr_svc
89 @ r2 - lr_<exception>, already fixed up for correct return/restart
90 @ r3 - spsr_<exception>
91 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
92 @
93 stmia r5, {r0 - r4}
94 .endm
95
96 .align 5
97__dabt_svc:
98 svc_entry abt
99
100 @
101 @ get ready to re-enable interrupts if appropriate
102 @
103 mrs r9, cpsr
104 tst r3, #PSR_I_BIT
105 biceq r9, r9, #PSR_I_BIT
106
107 @
108 @ Call the processor-specific abort handler:
109 @
110 @ r2 - aborted context pc
111 @ r3 - aborted context cpsr
112 @
113 @ The abort handler must return the aborted address in r0, and
114 @ the fault status register in r1. r9 must be preserved.
115 @
116#ifdef MULTI_ABORT
117 ldr r4, .LCprocfns
118 mov lr, pc
119 ldr pc, [r4]
120#else
121 bl CPU_ABORT_HANDLER
122#endif
123
124 @
125 @ set desired IRQ state, then call main handler
126 @
127 msr cpsr_c, r9
128 mov r2, sp
129 bl do_DataAbort
130
131 @
132 @ IRQs off again before pulling preserved data off the stack
133 @
Russell King1ec42c02005-04-26 15:18:26 +0100134 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 @
137 @ restore SPSR and restart the instruction
138 @
139 ldr r0, [sp, #S_PSR]
140 msr spsr_cxsf, r0
141 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
142
143 .align 5
144__irq_svc:
145 svc_entry irq
146#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100147 get_thread_info tsk
148 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
149 add r7, r8, #1 @ increment it
150 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
Russell King187a51a2005-05-21 18:14:44 +0100152 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100154 ldr r0, [tsk, #TI_FLAGS] @ get flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 tst r0, #_TIF_NEED_RESCHED
156 blne svc_preempt
157preempt_return:
Russell King706fdd92005-05-21 18:15:45 +0100158 ldr r0, [tsk, #TI_PREEMPT] @ read preempt value
159 str r8, [tsk, #TI_PREEMPT] @ restore preempt count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 strne r0, [r0, -r0] @ bug()
162#endif
163 ldr r0, [sp, #S_PSR] @ irqs are already disabled
164 msr spsr_cxsf, r0
165 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
166
167 .ltorg
168
169#ifdef CONFIG_PREEMPT
170svc_preempt:
Russell King706fdd92005-05-21 18:15:45 +0100171 teq r8, #0 @ was preempt count = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ldreq r6, .LCirq_stat
173 movne pc, lr @ no
174 ldr r0, [r6, #4] @ local_irq_count
175 ldr r1, [r6, #8] @ local_bh_count
176 adds r0, r0, r1
177 movne pc, lr
178 mov r7, #0 @ preempt_schedule_irq
Russell King706fdd92005-05-21 18:15:45 +0100179 str r7, [tsk, #TI_PREEMPT] @ expects preempt_count == 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801: bl preempt_schedule_irq @ irq en/disable is done inside
Russell King706fdd92005-05-21 18:15:45 +0100181 ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 tst r0, #_TIF_NEED_RESCHED
183 beq preempt_return @ go again
184 b 1b
185#endif
186
187 .align 5
188__und_svc:
189 svc_entry und
190
191 @
192 @ call emulation code, which returns using r9 if it has emulated
193 @ the instruction, or the more conventional lr if we are to treat
194 @ this as a real undefined instruction
195 @
196 @ r0 - instruction
197 @
198 ldr r0, [r2, #-4]
199 adr r9, 1f
200 bl call_fpe
201
202 mov r0, sp @ struct pt_regs *regs
203 bl do_undefinstr
204
205 @
206 @ IRQs off again before pulling preserved data off the stack
207 @
Russell King1ec42c02005-04-26 15:18:26 +01002081: disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 @
211 @ restore SPSR and restart the instruction
212 @
213 ldr lr, [sp, #S_PSR] @ Get SVC cpsr
214 msr spsr_cxsf, lr
215 ldmia sp, {r0 - pc}^ @ Restore SVC registers
216
217 .align 5
218__pabt_svc:
219 svc_entry abt
220
221 @
222 @ re-enable interrupts if appropriate
223 @
224 mrs r9, cpsr
225 tst r3, #PSR_I_BIT
226 biceq r9, r9, #PSR_I_BIT
227 msr cpsr_c, r9
228
229 @
230 @ set args, then call main handler
231 @
232 @ r0 - address of faulting instruction
233 @ r1 - pointer to registers on stack
234 @
235 mov r0, r2 @ address (pc)
236 mov r1, sp @ regs
237 bl do_PrefetchAbort @ call abort handler
238
239 @
240 @ IRQs off again before pulling preserved data off the stack
241 @
Russell King1ec42c02005-04-26 15:18:26 +0100242 disable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 @
245 @ restore SPSR and restart the instruction
246 @
247 ldr r0, [sp, #S_PSR]
248 msr spsr_cxsf, r0
249 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
250
251 .align 5
252.LCirq:
253 .word __temp_irq
254.LCund:
255 .word __temp_und
256.LCabt:
257 .word __temp_abt
258#ifdef MULTI_ABORT
259.LCprocfns:
260 .word processor
261#endif
262.LCfp:
263 .word fp_enter
264#ifdef CONFIG_PREEMPT
265.LCirq_stat:
266 .word irq_stat
267#endif
268
269/*
270 * User mode handlers
271 */
272 .macro usr_entry, sym
273 sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
274 stmia sp, {r0 - r12} @ save r0 - r12
275 ldr r7, .LC\sym
276 add r5, sp, #S_PC
277 ldmia r7, {r2 - r4} @ Get USR pc, cpsr
278
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100279#if __LINUX_ARM_ARCH__ < 6
280 @ make sure our user space atomic helper is aborted
281 cmp r2, #VIRT_OFFSET
282 bichs r3, r3, #PSR_Z_BIT
283#endif
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 @
286 @ We are now ready to fill in the remaining blanks on the stack:
287 @
288 @ r2 - lr_<exception>, already fixed up for correct return/restart
289 @ r3 - spsr_<exception>
290 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
291 @
292 @ Also, separately save sp_usr and lr_usr
293 @
294 stmia r5, {r2 - r4}
295 stmdb r5, {sp, lr}^
296
297 @
298 @ Enable the alignment trap while in kernel mode
299 @
300 alignment_trap r7, r0, __temp_\sym
301
302 @
303 @ Clear FP to mark the first stack frame
304 @
305 zero_fp
306 .endm
307
308 .align 5
309__dabt_usr:
310 usr_entry abt
311
312 @
313 @ Call the processor-specific abort handler:
314 @
315 @ r2 - aborted context pc
316 @ r3 - aborted context cpsr
317 @
318 @ The abort handler must return the aborted address in r0, and
319 @ the fault status register in r1.
320 @
321#ifdef MULTI_ABORT
322 ldr r4, .LCprocfns
323 mov lr, pc
324 ldr pc, [r4]
325#else
326 bl CPU_ABORT_HANDLER
327#endif
328
329 @
330 @ IRQs on, then call the main handler
331 @
Russell King1ec42c02005-04-26 15:18:26 +0100332 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 mov r2, sp
334 adr lr, ret_from_exception
335 b do_DataAbort
336
337 .align 5
338__irq_usr:
339 usr_entry irq
340
Russell King706fdd92005-05-21 18:15:45 +0100341 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100343 ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
344 add r7, r8, #1 @ increment it
345 str r7, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#endif
Russell King187a51a2005-05-21 18:14:44 +0100347 irq_handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348#ifdef CONFIG_PREEMPT
Russell King706fdd92005-05-21 18:15:45 +0100349 ldr r0, [tsk, #TI_PREEMPT]
350 str r8, [tsk, #TI_PREEMPT]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 teq r0, r7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 strne r0, [r0, -r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#endif
354 mov why, #0
355 b ret_to_user
356
357 .ltorg
358
359 .align 5
360__und_usr:
361 usr_entry und
362
363 tst r3, #PSR_T_BIT @ Thumb mode?
364 bne fpundefinstr @ ignore FP
365 sub r4, r2, #4
366
367 @
368 @ fall through to the emulation code, which returns using r9 if
369 @ it has emulated the instruction, or the more conventional lr
370 @ if we are to treat this as a real undefined instruction
371 @
372 @ r0 - instruction
373 @
3741: ldrt r0, [r4]
375 adr r9, ret_from_exception
376 adr lr, fpundefinstr
377 @
378 @ fallthrough to call_fpe
379 @
380
381/*
382 * The out of line fixup for the ldrt above.
383 */
384 .section .fixup, "ax"
3852: mov pc, r9
386 .previous
387 .section __ex_table,"a"
388 .long 1b, 2b
389 .previous
390
391/*
392 * Check whether the instruction is a co-processor instruction.
393 * If yes, we need to call the relevant co-processor handler.
394 *
395 * Note that we don't do a full check here for the co-processor
396 * instructions; all instructions with bit 27 set are well
397 * defined. The only instructions that should fault are the
398 * co-processor instructions. However, we have to watch out
399 * for the ARM6/ARM7 SWI bug.
400 *
401 * Emulators may wish to make use of the following registers:
402 * r0 = instruction opcode.
403 * r2 = PC+4
404 * r10 = this threads thread_info structure.
405 */
406call_fpe:
407 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
408#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
409 and r8, r0, #0x0f000000 @ mask out op-code bits
410 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
411#endif
412 moveq pc, lr
413 get_thread_info r10 @ get current thread
414 and r8, r0, #0x00000f00 @ mask out CP number
415 mov r7, #1
416 add r6, r10, #TI_USED_CP
417 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
418#ifdef CONFIG_IWMMXT
419 @ Test if we need to give access to iWMMXt coprocessors
420 ldr r5, [r10, #TI_FLAGS]
421 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
422 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
423 bcs iwmmxt_task_enable
424#endif
Russell King1ec42c02005-04-26 15:18:26 +0100425 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 add pc, pc, r8, lsr #6
427 mov r0, r0
428
429 mov pc, lr @ CP#0
430 b do_fpe @ CP#1 (FPE)
431 b do_fpe @ CP#2 (FPE)
432 mov pc, lr @ CP#3
433 mov pc, lr @ CP#4
434 mov pc, lr @ CP#5
435 mov pc, lr @ CP#6
436 mov pc, lr @ CP#7
437 mov pc, lr @ CP#8
438 mov pc, lr @ CP#9
439#ifdef CONFIG_VFP
440 b do_vfp @ CP#10 (VFP)
441 b do_vfp @ CP#11 (VFP)
442#else
443 mov pc, lr @ CP#10 (VFP)
444 mov pc, lr @ CP#11 (VFP)
445#endif
446 mov pc, lr @ CP#12
447 mov pc, lr @ CP#13
448 mov pc, lr @ CP#14 (Debug)
449 mov pc, lr @ CP#15 (Control)
450
451do_fpe:
452 ldr r4, .LCfp
453 add r10, r10, #TI_FPSTATE @ r10 = workspace
454 ldr pc, [r4] @ Call FP module USR entry point
455
456/*
457 * The FP module is called with these registers set:
458 * r0 = instruction
459 * r2 = PC+4
460 * r9 = normal "successful" return address
461 * r10 = FP workspace
462 * lr = unrecognised FP instruction return address
463 */
464
465 .data
466ENTRY(fp_enter)
467 .word fpundefinstr
468 .text
469
470fpundefinstr:
471 mov r0, sp
472 adr lr, ret_from_exception
473 b do_undefinstr
474
475 .align 5
476__pabt_usr:
477 usr_entry abt
478
Russell King1ec42c02005-04-26 15:18:26 +0100479 enable_irq @ Enable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 mov r0, r2 @ address (pc)
481 mov r1, sp @ regs
482 bl do_PrefetchAbort @ call abort handler
483 /* fall through */
484/*
485 * This is the return code to user mode for abort handlers
486 */
487ENTRY(ret_from_exception)
488 get_thread_info tsk
489 mov why, #0
490 b ret_to_user
491
492/*
493 * Register switch for ARMv3 and ARMv4 processors
494 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
495 * previous and next are guaranteed not to be the same.
496 */
497ENTRY(__switch_to)
498 add ip, r1, #TI_CPU_SAVE
499 ldr r3, [r2, #TI_TP_VALUE]
500 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
501 ldr r6, [r2, #TI_CPU_DOMAIN]!
502#if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT)
503 mra r4, r5, acc0
504 stmia ip, {r4, r5}
505#endif
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100506#if defined(CONFIG_HAS_TLS_REG)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100507 mcr p15, 0, r3, c13, c0, 3 @ set TLS register
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100508#elif !defined(CONFIG_TLS_REG_EMUL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 mov r4, #0xffff0fff
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100510 str r3, [r4, #-15] @ TLS val at 0xffff0ff0
511#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
513#ifdef CONFIG_VFP
514 @ Always disable VFP so we can lazily save/restore the old
515 @ state. This occurs in the context of the previous thread.
516 VFPFMRX r4, FPEXC
517 bic r4, r4, #FPEXC_ENABLE
518 VFPFMXR FPEXC, r4
519#endif
520#if defined(CONFIG_IWMMXT)
521 bl iwmmxt_task_switch
522#elif defined(CONFIG_CPU_XSCALE)
523 add r4, r2, #40 @ cpu_context_save->extra
524 ldmib r4, {r4, r5}
525 mar acc0, r4, r5
526#endif
527 ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
528
529 __INIT
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100530
531/*
532 * User helpers.
533 *
534 * These are segment of kernel provided user code reachable from user space
535 * at a fixed address in kernel memory. This is used to provide user space
536 * with some operations which require kernel help because of unimplemented
537 * native feature and/or instructions in many ARM CPUs. The idea is for
538 * this code to be executed directly in user mode for best efficiency but
539 * which is too intimate with the kernel counter part to be left to user
540 * libraries. In fact this code might even differ from one CPU to another
541 * depending on the available instruction set and restrictions like on
542 * SMP systems. In other words, the kernel reserves the right to change
543 * this code as needed without warning. Only the entry points and their
544 * results are guaranteed to be stable.
545 *
546 * Each segment is 32-byte aligned and will be moved to the top of the high
547 * vector page. New segments (if ever needed) must be added in front of
548 * existing ones. This mechanism should be used only for things that are
549 * really small and justified, and not be abused freely.
550 *
551 * User space is expected to implement those things inline when optimizing
552 * for a processor that has the necessary native support, but only if such
553 * resulting binaries are already to be incompatible with earlier ARM
554 * processors due to the use of unsupported instructions other than what
555 * is provided here. In other words don't make binaries unable to run on
556 * earlier processors just for the sake of not using these kernel helpers
557 * if your compiled code is not going to use the new instructions for other
558 * purpose.
559 */
560
561 .align 5
562 .globl __kuser_helper_start
563__kuser_helper_start:
564
565/*
566 * Reference prototype:
567 *
568 * int __kernel_cmpxchg(int oldval, int newval, int *ptr)
569 *
570 * Input:
571 *
572 * r0 = oldval
573 * r1 = newval
574 * r2 = ptr
575 * lr = return address
576 *
577 * Output:
578 *
579 * r0 = returned value (zero or non-zero)
580 * C flag = set if r0 == 0, clear if r0 != 0
581 *
582 * Clobbered:
583 *
584 * r3, ip, flags
585 *
586 * Definition and user space usage example:
587 *
588 * typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
589 * #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
590 *
591 * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
592 * Return zero if *ptr was changed or non-zero if no exchange happened.
593 * The C flag is also set if *ptr was changed to allow for assembly
594 * optimization in the calling code.
595 *
596 * For example, a user space atomic_add implementation could look like this:
597 *
598 * #define atomic_add(ptr, val) \
599 * ({ register unsigned int *__ptr asm("r2") = (ptr); \
600 * register unsigned int __result asm("r1"); \
601 * asm volatile ( \
602 * "1: @ atomic_add\n\t" \
603 * "ldr r0, [r2]\n\t" \
604 * "mov r3, #0xffff0fff\n\t" \
605 * "add lr, pc, #4\n\t" \
606 * "add r1, r0, %2\n\t" \
607 * "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
608 * "bcc 1b" \
609 * : "=&r" (__result) \
610 * : "r" (__ptr), "rIL" (val) \
611 * : "r0","r3","ip","lr","cc","memory" ); \
612 * __result; })
613 */
614
615__kuser_cmpxchg: @ 0xffff0fc0
616
617#if __LINUX_ARM_ARCH__ < 6
618
619#ifdef CONFIG_SMP /* sanity check */
620#error "CONFIG_SMP on a machine supporting pre-ARMv6 processors?"
621#endif
622
623 /*
624 * Theory of operation:
625 *
626 * We set the Z flag before loading oldval. If ever an exception
627 * occurs we can not be sure the loaded value will still be the same
628 * when the exception returns, therefore the user exception handler
629 * will clear the Z flag whenever the interrupted user code was
630 * actually from the kernel address space (see the usr_entry macro).
631 *
632 * The post-increment on the str is used to prevent a race with an
633 * exception happening just after the str instruction which would
634 * clear the Z flag although the exchange was done.
635 */
636 teq ip, ip @ set Z flag
637 ldr ip, [r2] @ load current val
638 add r3, r2, #1 @ prepare store ptr
639 teqeq ip, r0 @ compare with oldval if still allowed
640 streq r1, [r3, #-1]! @ store newval if still allowed
641 subs r0, r2, r3 @ if r2 == r3 the str occured
642 mov pc, lr
643
644#else
645
646 ldrex r3, [r2]
647 subs r3, r3, r0
648 strexeq r3, r1, [r2]
649 rsbs r0, r3, #0
650 mov pc, lr
651
652#endif
653
654 .align 5
655
656/*
657 * Reference prototype:
658 *
659 * int __kernel_get_tls(void)
660 *
661 * Input:
662 *
663 * lr = return address
664 *
665 * Output:
666 *
667 * r0 = TLS value
668 *
669 * Clobbered:
670 *
671 * the Z flag might be lost
672 *
673 * Definition and user space usage example:
674 *
675 * typedef int (__kernel_get_tls_t)(void);
676 * #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
677 *
678 * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
679 *
680 * This could be used as follows:
681 *
682 * #define __kernel_get_tls() \
683 * ({ register unsigned int __val asm("r0"); \
684 * asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
685 * : "=r" (__val) : : "lr","cc" ); \
686 * __val; })
687 */
688
689__kuser_get_tls: @ 0xffff0fe0
690
Nicolas Pitre4b0e07a2005-05-05 23:24:45 +0100691#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
Nicolas Pitre2d2669b2005-04-29 22:08:33 +0100692
693 ldr r0, [pc, #(16 - 8)] @ TLS stored at 0xffff0ff0
694 mov pc, lr
695
696#else
697
698 mrc p15, 0, r0, c13, c0, 3 @ read TLS register
699 mov pc, lr
700
701#endif
702
703 .rep 5
704 .word 0 @ pad up to __kuser_helper_version
705 .endr
706
707/*
708 * Reference declaration:
709 *
710 * extern unsigned int __kernel_helper_version;
711 *
712 * Definition and user space usage example:
713 *
714 * #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
715 *
716 * User space may read this to determine the curent number of helpers
717 * available.
718 */
719
720__kuser_helper_version: @ 0xffff0ffc
721 .word ((__kuser_helper_end - __kuser_helper_start) >> 5)
722
723 .globl __kuser_helper_end
724__kuser_helper_end:
725
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727/*
728 * Vector stubs.
729 *
Russell King79335232005-04-26 15:17:42 +0100730 * This code is copied to 0xffff0200 so we can use branches in the
731 * vectors, rather than ldr's. Note that this code must not
732 * exceed 0x300 bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 *
734 * Common stub entry macro:
735 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
736 */
737 .macro vector_stub, name, sym, correction=0
738 .align 5
739
740vector_\name:
741 ldr r13, .LCs\sym
742 .if \correction
743 sub lr, lr, #\correction
744 .endif
745 str lr, [r13] @ save lr_IRQ
746 mrs lr, spsr
747 str lr, [r13, #4] @ save spsr_IRQ
748 @
749 @ now branch to the relevant MODE handling routine
750 @
751 mrs r13, cpsr
752 bic r13, r13, #MODE_MASK
Russell Kingacaca3c2005-04-26 15:19:48 +0100753 orr r13, r13, #SVC_MODE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 msr spsr_cxsf, r13 @ switch to SVC_32 mode
755
756 and lr, lr, #15
757 ldr lr, [pc, lr, lsl #2]
758 movs pc, lr @ Changes mode and branches
759 .endm
760
Russell King79335232005-04-26 15:17:42 +0100761 .globl __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762__stubs_start:
763/*
764 * Interrupt dispatcher
765 */
766 vector_stub irq, irq, 4
767
768 .long __irq_usr @ 0 (USR_26 / USR_32)
769 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
770 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
771 .long __irq_svc @ 3 (SVC_26 / SVC_32)
772 .long __irq_invalid @ 4
773 .long __irq_invalid @ 5
774 .long __irq_invalid @ 6
775 .long __irq_invalid @ 7
776 .long __irq_invalid @ 8
777 .long __irq_invalid @ 9
778 .long __irq_invalid @ a
779 .long __irq_invalid @ b
780 .long __irq_invalid @ c
781 .long __irq_invalid @ d
782 .long __irq_invalid @ e
783 .long __irq_invalid @ f
784
785/*
786 * Data abort dispatcher
787 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
788 */
789 vector_stub dabt, abt, 8
790
791 .long __dabt_usr @ 0 (USR_26 / USR_32)
792 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
793 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
794 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
795 .long __dabt_invalid @ 4
796 .long __dabt_invalid @ 5
797 .long __dabt_invalid @ 6
798 .long __dabt_invalid @ 7
799 .long __dabt_invalid @ 8
800 .long __dabt_invalid @ 9
801 .long __dabt_invalid @ a
802 .long __dabt_invalid @ b
803 .long __dabt_invalid @ c
804 .long __dabt_invalid @ d
805 .long __dabt_invalid @ e
806 .long __dabt_invalid @ f
807
808/*
809 * Prefetch abort dispatcher
810 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
811 */
812 vector_stub pabt, abt, 4
813
814 .long __pabt_usr @ 0 (USR_26 / USR_32)
815 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
816 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
817 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
818 .long __pabt_invalid @ 4
819 .long __pabt_invalid @ 5
820 .long __pabt_invalid @ 6
821 .long __pabt_invalid @ 7
822 .long __pabt_invalid @ 8
823 .long __pabt_invalid @ 9
824 .long __pabt_invalid @ a
825 .long __pabt_invalid @ b
826 .long __pabt_invalid @ c
827 .long __pabt_invalid @ d
828 .long __pabt_invalid @ e
829 .long __pabt_invalid @ f
830
831/*
832 * Undef instr entry dispatcher
833 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
834 */
835 vector_stub und, und
836
837 .long __und_usr @ 0 (USR_26 / USR_32)
838 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
839 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
840 .long __und_svc @ 3 (SVC_26 / SVC_32)
841 .long __und_invalid @ 4
842 .long __und_invalid @ 5
843 .long __und_invalid @ 6
844 .long __und_invalid @ 7
845 .long __und_invalid @ 8
846 .long __und_invalid @ 9
847 .long __und_invalid @ a
848 .long __und_invalid @ b
849 .long __und_invalid @ c
850 .long __und_invalid @ d
851 .long __und_invalid @ e
852 .long __und_invalid @ f
853
854 .align 5
855
856/*=============================================================================
857 * Undefined FIQs
858 *-----------------------------------------------------------------------------
859 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
860 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
861 * Basically to switch modes, we *HAVE* to clobber one register... brain
862 * damage alert! I don't think that we can execute any code in here in any
863 * other mode than FIQ... Ok you can switch to another mode, but you can't
864 * get out of that mode without clobbering one register.
865 */
866vector_fiq:
867 disable_fiq
868 subs pc, lr, #4
869
870/*=============================================================================
871 * Address exception handler
872 *-----------------------------------------------------------------------------
873 * These aren't too critical.
874 * (they're not supposed to happen, and won't happen in 32-bit data mode).
875 */
876
877vector_addrexcptn:
878 b vector_addrexcptn
879
880/*
881 * We group all the following data together to optimise
882 * for CPUs with separate I & D caches.
883 */
884 .align 5
885
886.LCvswi:
887 .word vector_swi
888
889.LCsirq:
890 .word __temp_irq
891.LCsund:
892 .word __temp_und
893.LCsabt:
894 .word __temp_abt
895
Russell King79335232005-04-26 15:17:42 +0100896 .globl __stubs_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897__stubs_end:
898
Russell King79335232005-04-26 15:17:42 +0100899 .equ stubs_offset, __vectors_start + 0x200 - __stubs_start
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Russell King79335232005-04-26 15:17:42 +0100901 .globl __vectors_start
902__vectors_start:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 swi SYS_ERROR0
Russell King79335232005-04-26 15:17:42 +0100904 b vector_und + stubs_offset
905 ldr pc, .LCvswi + stubs_offset
906 b vector_pabt + stubs_offset
907 b vector_dabt + stubs_offset
908 b vector_addrexcptn + stubs_offset
909 b vector_irq + stubs_offset
910 b vector_fiq + stubs_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Russell King79335232005-04-26 15:17:42 +0100912 .globl __vectors_end
913__vectors_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 .data
916
917/*
918 * Do not reorder these, and do not insert extra data between...
919 */
920
921__temp_irq:
922 .word 0 @ saved lr_irq
923 .word 0 @ saved spsr_irq
924 .word -1 @ old_r0
925__temp_und:
926 .word 0 @ Saved lr_und
927 .word 0 @ Saved spsr_und
928 .word -1 @ old_r0
929__temp_abt:
930 .word 0 @ Saved lr_abt
931 .word 0 @ Saved spsr_abt
932 .word -1 @ old_r0
933
934 .globl cr_alignment
935 .globl cr_no_alignment
936cr_alignment:
937 .space 4
938cr_no_alignment:
939 .space 4