2 * linux/arch/arm/kernel/entry-armv.S
4 * Copyright (C) 1996,1997,1998 Russell King.
5 * ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
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.
11 * Low-level vector interface routines
13 * Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction that causes
14 * it to save wrong values... Be aware!
16 #include <linux/config.h>
17 #include <linux/init.h>
19 #include <asm/thread_info.h>
21 #include <asm/ptrace.h>
22 #include <asm/vfpmacros.h>
24 #include "entry-header.S"
27 * Invalid mode handlers
29 .macro inv_entry, sym, reason
30 sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
31 stmia sp, {r0 - lr} @ Save XXX r0 - lr
37 inv_entry abt, BAD_PREFETCH
41 inv_entry abt, BAD_DATA
45 inv_entry irq, BAD_IRQ
49 inv_entry und, BAD_UNDEFINSTR
52 ldmia r4, {r5 - r7} @ Get XXX pc, cpsr, old_r0
54 stmia r4, {r5 - r7} @ Save XXX pc, cpsr, old_r0
56 and r2, r6, #31 @ int mode
63 sub sp, sp, #S_FRAME_SIZE
64 stmia sp, {r0 - r12} @ save r0 - r12
66 add r0, sp, #S_FRAME_SIZE
67 ldmia r2, {r2 - r4} @ get pc, cpsr
72 @ We are now ready to fill in the remaining blanks on the stack:
76 @ r2 - lr_<exception>, already fixed up for correct return/restart
77 @ r3 - spsr_<exception>
78 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
88 @ get ready to re-enable interrupts if appropriate
92 biceq r9, r9, #PSR_I_BIT
95 @ Call the processor-specific abort handler:
97 @ r2 - aborted context pc
98 @ r3 - aborted context cpsr
100 @ The abort handler must return the aborted address in r0, and
101 @ the fault status register in r1. r9 must be preserved.
112 @ set desired IRQ state, then call main handler
119 @ IRQs off again before pulling preserved data off the stack
124 @ restore SPSR and restart the instruction
128 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
133 #ifdef CONFIG_PREEMPT
135 ldr r9, [r8, #TI_PREEMPT] @ get preempt count
136 add r7, r9, #1 @ increment it
137 str r7, [r8, #TI_PREEMPT]
139 1: get_irqnr_and_base r0, r6, r5, lr
142 @ routine called with r0 = irq number, r1 = struct pt_regs *
146 #ifdef CONFIG_PREEMPT
147 ldr r0, [r8, #TI_FLAGS] @ get flags
148 tst r0, #_TIF_NEED_RESCHED
151 ldr r0, [r8, #TI_PREEMPT] @ read preempt value
153 str r9, [r8, #TI_PREEMPT] @ restore preempt count
154 strne r0, [r0, -r0] @ bug()
156 ldr r0, [sp, #S_PSR] @ irqs are already disabled
158 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
162 #ifdef CONFIG_PREEMPT
164 teq r9, #0 @ was preempt count = 0
165 ldreq r6, .LCirq_stat
167 ldr r0, [r6, #4] @ local_irq_count
168 ldr r1, [r6, #8] @ local_bh_count
171 mov r7, #0 @ preempt_schedule_irq
172 str r7, [r8, #TI_PREEMPT] @ expects preempt_count == 0
173 1: bl preempt_schedule_irq @ irq en/disable is done inside
174 ldr r0, [r8, #TI_FLAGS] @ get new tasks TI_FLAGS
175 tst r0, #_TIF_NEED_RESCHED
176 beq preempt_return @ go again
185 @ call emulation code, which returns using r9 if it has emulated
186 @ the instruction, or the more conventional lr if we are to treat
187 @ this as a real undefined instruction
195 mov r0, sp @ struct pt_regs *regs
199 @ IRQs off again before pulling preserved data off the stack
204 @ restore SPSR and restart the instruction
206 ldr lr, [sp, #S_PSR] @ Get SVC cpsr
208 ldmia sp, {r0 - pc}^ @ Restore SVC registers
215 @ re-enable interrupts if appropriate
219 biceq r9, r9, #PSR_I_BIT
223 @ set args, then call main handler
225 @ r0 - address of faulting instruction
226 @ r1 - pointer to registers on stack
228 mov r0, r2 @ address (pc)
230 bl do_PrefetchAbort @ call abort handler
233 @ IRQs off again before pulling preserved data off the stack
238 @ restore SPSR and restart the instruction
242 ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr
257 #ifdef CONFIG_PREEMPT
265 .macro usr_entry, sym
266 sub sp, sp, #S_FRAME_SIZE @ Allocate frame size in one go
267 stmia sp, {r0 - r12} @ save r0 - r12
270 ldmia r7, {r2 - r4} @ Get USR pc, cpsr
273 @ We are now ready to fill in the remaining blanks on the stack:
275 @ r2 - lr_<exception>, already fixed up for correct return/restart
276 @ r3 - spsr_<exception>
277 @ r4 - orig_r0 (see pt_regs definition in ptrace.h)
279 @ Also, separately save sp_usr and lr_usr
288 alignment_trap r7, r0, __temp_abt
292 @ Call the processor-specific abort handler:
294 @ r2 - aborted context pc
295 @ r3 - aborted context cpsr
297 @ The abort handler must return the aborted address in r0, and
298 @ the fault status register in r1.
309 @ IRQs on, then call the main handler
313 adr lr, ret_from_exception
319 alignment_trap r7, r0, __temp_irq
321 #ifdef CONFIG_PREEMPT
323 ldr r9, [r8, #TI_PREEMPT] @ get preempt count
324 add r7, r9, #1 @ increment it
325 str r7, [r8, #TI_PREEMPT]
327 1: get_irqnr_and_base r0, r6, r5, lr
331 @ routine called with r0 = irq number, r1 = struct pt_regs *
334 #ifdef CONFIG_PREEMPT
335 ldr r0, [r8, #TI_PREEMPT]
337 str r9, [r8, #TI_PREEMPT]
351 alignment_trap r7, r0, __temp_und
353 tst r3, #PSR_T_BIT @ Thumb mode?
354 bne fpundefinstr @ ignore FP
358 @ fall through to the emulation code, which returns using r9 if
359 @ it has emulated the instruction, or the more conventional lr
360 @ if we are to treat this as a real undefined instruction
365 adr r9, ret_from_exception
368 @ fallthrough to call_fpe
372 * The out of line fixup for the ldrt above.
374 .section .fixup, "ax"
377 .section __ex_table,"a"
382 * Check whether the instruction is a co-processor instruction.
383 * If yes, we need to call the relevant co-processor handler.
385 * Note that we don't do a full check here for the co-processor
386 * instructions; all instructions with bit 27 set are well
387 * defined. The only instructions that should fault are the
388 * co-processor instructions. However, we have to watch out
389 * for the ARM6/ARM7 SWI bug.
391 * Emulators may wish to make use of the following registers:
392 * r0 = instruction opcode.
394 * r10 = this threads thread_info structure.
397 tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27
398 #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
399 and r8, r0, #0x0f000000 @ mask out op-code bits
400 teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?
403 get_thread_info r10 @ get current thread
404 and r8, r0, #0x00000f00 @ mask out CP number
406 add r6, r10, #TI_USED_CP
407 strb r7, [r6, r8, lsr #8] @ set appropriate used_cp[]
409 @ Test if we need to give access to iWMMXt coprocessors
410 ldr r5, [r10, #TI_FLAGS]
411 rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only
412 movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)
413 bcs iwmmxt_task_enable
416 add pc, pc, r8, lsr #6
420 b do_fpe @ CP#1 (FPE)
421 b do_fpe @ CP#2 (FPE)
430 b do_vfp @ CP#10 (VFP)
431 b do_vfp @ CP#11 (VFP)
433 mov pc, lr @ CP#10 (VFP)
434 mov pc, lr @ CP#11 (VFP)
438 mov pc, lr @ CP#14 (Debug)
439 mov pc, lr @ CP#15 (Control)
443 add r10, r10, #TI_FPSTATE @ r10 = workspace
444 ldr pc, [r4] @ Call FP module USR entry point
447 * The FP module is called with these registers set:
450 * r9 = normal "successful" return address
452 * lr = unrecognised FP instruction return address
462 adr lr, ret_from_exception
468 alignment_trap r7, r0, __temp_abt
470 enable_irq r0 @ Enable interrupts
471 mov r0, r2 @ address (pc)
473 bl do_PrefetchAbort @ call abort handler
476 * This is the return code to user mode for abort handlers
478 ENTRY(ret_from_exception)
484 * Register switch for ARMv3 and ARMv4 processors
485 * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
486 * previous and next are guaranteed not to be the same.
489 add ip, r1, #TI_CPU_SAVE
490 ldr r3, [r2, #TI_TP_VALUE]
491 stmia ip!, {r4 - sl, fp, sp, lr} @ Store most regs on stack
492 ldr r6, [r2, #TI_CPU_DOMAIN]!
493 #if defined(CONFIG_CPU_XSCALE) && !defined(CONFIG_IWMMXT)
498 str r3, [r4, #-3] @ Set TLS ptr
499 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
501 @ Always disable VFP so we can lazily save/restore the old
502 @ state. This occurs in the context of the previous thread.
504 bic r4, r4, #FPEXC_ENABLE
507 #if defined(CONFIG_IWMMXT)
508 bl iwmmxt_task_switch
509 #elif defined(CONFIG_CPU_XSCALE)
510 add r4, r2, #40 @ cpu_context_save->extra
514 ldmib r2, {r4 - sl, fp, sp, pc} @ Load all regs saved previously
520 * This code is copied to 0x200 or 0xffff0200 so we can use branches in the
521 * vectors, rather than ldr's.
523 * Common stub entry macro:
524 * Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
526 .macro vector_stub, name, sym, correction=0
532 sub lr, lr, #\correction
534 str lr, [r13] @ save lr_IRQ
536 str lr, [r13, #4] @ save spsr_IRQ
538 @ now branch to the relevant MODE handling routine
541 bic r13, r13, #MODE_MASK
542 orr r13, r13, #MODE_SVC
543 msr spsr_cxsf, r13 @ switch to SVC_32 mode
546 ldr lr, [pc, lr, lsl #2]
547 movs pc, lr @ Changes mode and branches
552 * Interrupt dispatcher
554 vector_stub irq, irq, 4
556 .long __irq_usr @ 0 (USR_26 / USR_32)
557 .long __irq_invalid @ 1 (FIQ_26 / FIQ_32)
558 .long __irq_invalid @ 2 (IRQ_26 / IRQ_32)
559 .long __irq_svc @ 3 (SVC_26 / SVC_32)
560 .long __irq_invalid @ 4
561 .long __irq_invalid @ 5
562 .long __irq_invalid @ 6
563 .long __irq_invalid @ 7
564 .long __irq_invalid @ 8
565 .long __irq_invalid @ 9
566 .long __irq_invalid @ a
567 .long __irq_invalid @ b
568 .long __irq_invalid @ c
569 .long __irq_invalid @ d
570 .long __irq_invalid @ e
571 .long __irq_invalid @ f
574 * Data abort dispatcher
575 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
577 vector_stub dabt, abt, 8
579 .long __dabt_usr @ 0 (USR_26 / USR_32)
580 .long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)
581 .long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)
582 .long __dabt_svc @ 3 (SVC_26 / SVC_32)
583 .long __dabt_invalid @ 4
584 .long __dabt_invalid @ 5
585 .long __dabt_invalid @ 6
586 .long __dabt_invalid @ 7
587 .long __dabt_invalid @ 8
588 .long __dabt_invalid @ 9
589 .long __dabt_invalid @ a
590 .long __dabt_invalid @ b
591 .long __dabt_invalid @ c
592 .long __dabt_invalid @ d
593 .long __dabt_invalid @ e
594 .long __dabt_invalid @ f
597 * Prefetch abort dispatcher
598 * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
600 vector_stub pabt, abt, 4
602 .long __pabt_usr @ 0 (USR_26 / USR_32)
603 .long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)
604 .long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)
605 .long __pabt_svc @ 3 (SVC_26 / SVC_32)
606 .long __pabt_invalid @ 4
607 .long __pabt_invalid @ 5
608 .long __pabt_invalid @ 6
609 .long __pabt_invalid @ 7
610 .long __pabt_invalid @ 8
611 .long __pabt_invalid @ 9
612 .long __pabt_invalid @ a
613 .long __pabt_invalid @ b
614 .long __pabt_invalid @ c
615 .long __pabt_invalid @ d
616 .long __pabt_invalid @ e
617 .long __pabt_invalid @ f
620 * Undef instr entry dispatcher
621 * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
625 .long __und_usr @ 0 (USR_26 / USR_32)
626 .long __und_invalid @ 1 (FIQ_26 / FIQ_32)
627 .long __und_invalid @ 2 (IRQ_26 / IRQ_32)
628 .long __und_svc @ 3 (SVC_26 / SVC_32)
629 .long __und_invalid @ 4
630 .long __und_invalid @ 5
631 .long __und_invalid @ 6
632 .long __und_invalid @ 7
633 .long __und_invalid @ 8
634 .long __und_invalid @ 9
635 .long __und_invalid @ a
636 .long __und_invalid @ b
637 .long __und_invalid @ c
638 .long __und_invalid @ d
639 .long __und_invalid @ e
640 .long __und_invalid @ f
644 /*=============================================================================
646 *-----------------------------------------------------------------------------
647 * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
648 * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
649 * Basically to switch modes, we *HAVE* to clobber one register... brain
650 * damage alert! I don't think that we can execute any code in here in any
651 * other mode than FIQ... Ok you can switch to another mode, but you can't
652 * get out of that mode without clobbering one register.
658 /*=============================================================================
659 * Address exception handler
660 *-----------------------------------------------------------------------------
661 * These aren't too critical.
662 * (they're not supposed to happen, and won't happen in 32-bit data mode).
669 * We group all the following data together to optimise
670 * for CPUs with separate I & D caches.
686 .equ __real_stubs_start, .LCvectors + 0x200
690 b __real_stubs_start + (vector_und - __stubs_start)
691 ldr pc, __real_stubs_start + (.LCvswi - __stubs_start)
692 b __real_stubs_start + (vector_pabt - __stubs_start)
693 b __real_stubs_start + (vector_dabt - __stubs_start)
694 b __real_stubs_start + (vector_addrexcptn - __stubs_start)
695 b __real_stubs_start + (vector_irq - __stubs_start)
696 b __real_stubs_start + (vector_fiq - __stubs_start)
699 stmfd sp!, {r4 - r6, lr}
702 orr r0, r0, #0x00ff0000 @ high vectors position
703 adr r1, .LCvectors @ set up the vectors
704 ldmia r1, {r1, r2, r3, r4, r5, r6, ip, lr}
705 stmia r0, {r1, r2, r3, r4, r5, r6, ip, lr}
708 adr r0, __stubs_start @ copy stubs to 0x200
714 LOADREGS(fd, sp!, {r4 - r6, pc})
719 * Do not reorder these, and do not insert extra data between...
723 .word 0 @ saved lr_irq
724 .word 0 @ saved spsr_irq
727 .word 0 @ Saved lr_und
728 .word 0 @ Saved spsr_und
731 .word 0 @ Saved lr_abt
732 .word 0 @ Saved spsr_abt
736 .globl cr_no_alignment