/*1* linux/arch/arm/kernel/entry-armv.S2*3* Copyright (C) 1996,1997,1998 Russell King.4* ARM700 fix by Matthew Godbolt ([email protected])5* nommu support by Hyok S. Choi ([email protected])6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License version 2 as9* published by the Free Software Foundation.10*11* Low-level vector interface routines12*13* Note: there is a StrongARM bug in the STMIA rn, {regs}^ instruction14* that causes it to save wrong values... Be aware!15*/1617#include <asm/memory.h>18#include <asm/glue-df.h>19#include <asm/glue-pf.h>20#include <asm/vfpmacros.h>21#include <mach/entry-macro.S>22#include <asm/thread_notify.h>23#include <asm/unwind.h>24#include <asm/unistd.h>25#include <asm/tls.h>2627#include "entry-header.S"28#include <asm/entry-macro-multi.S>2930/*31* Interrupt handling. Preserves r7, r8, r932*/33.macro irq_handler34#ifdef CONFIG_MULTI_IRQ_HANDLER35ldr r5, =handle_arch_irq36mov r0, sp37ldr r5, [r5]38adr lr, BSYM(9997f)39teq r5, #040movne pc, r541#endif42arch_irq_handler_default439997:44.endm4546#ifdef CONFIG_KPROBES47.section .kprobes.text,"ax",%progbits48#else49.text50#endif5152/*53* Invalid mode handlers54*/55.macro inv_entry, reason56sub sp, sp, #S_FRAME_SIZE57ARM( stmib sp, {r1 - lr} )58THUMB( stmia sp, {r0 - r12} )59THUMB( str sp, [sp, #S_SP] )60THUMB( str lr, [sp, #S_LR] )61mov r1, #\reason62.endm6364__pabt_invalid:65inv_entry BAD_PREFETCH66b common_invalid67ENDPROC(__pabt_invalid)6869__dabt_invalid:70inv_entry BAD_DATA71b common_invalid72ENDPROC(__dabt_invalid)7374__irq_invalid:75inv_entry BAD_IRQ76b common_invalid77ENDPROC(__irq_invalid)7879__und_invalid:80inv_entry BAD_UNDEFINSTR8182@83@ XXX fall through to common_invalid84@8586@87@ common_invalid - generic code for failed exception (re-entrant version of handlers)88@89common_invalid:90zero_fp9192ldmia r0, {r4 - r6}93add r0, sp, #S_PC @ here for interlock avoidance94mov r7, #-1 @ "" "" "" ""95str r4, [sp] @ save preserved r096stmia r0, {r5 - r7} @ lr_<exception>,97@ cpsr_<exception>, "old_r0"9899mov r0, sp100b bad_mode101ENDPROC(__und_invalid)102103/*104* SVC mode handlers105*/106107#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)108#define SPFIX(code...) code109#else110#define SPFIX(code...)111#endif112113.macro svc_entry, stack_hole=0114UNWIND(.fnstart )115UNWIND(.save {r0 - pc} )116sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)117#ifdef CONFIG_THUMB2_KERNEL118SPFIX( str r0, [sp] ) @ temporarily saved119SPFIX( mov r0, sp )120SPFIX( tst r0, #4 ) @ test original stack alignment121SPFIX( ldr r0, [sp] ) @ restored122#else123SPFIX( tst sp, #4 )124#endif125SPFIX( subeq sp, sp, #4 )126stmia sp, {r1 - r12}127128ldmia r0, {r1 - r3}129add r5, sp, #S_SP - 4 @ here for interlock avoidance130mov r4, #-1 @ "" "" "" ""131add r0, sp, #(S_FRAME_SIZE + \stack_hole - 4)132SPFIX( addeq r0, r0, #4 )133str r1, [sp, #-4]! @ save the "real" r0 copied134@ from the exception stack135136mov r1, lr137138@139@ We are now ready to fill in the remaining blanks on the stack:140@141@ r0 - sp_svc142@ r1 - lr_svc143@ r2 - lr_<exception>, already fixed up for correct return/restart144@ r3 - spsr_<exception>145@ r4 - orig_r0 (see pt_regs definition in ptrace.h)146@147stmia r5, {r0 - r4}148.endm149150.align 5151__dabt_svc:152svc_entry153154@155@ get ready to re-enable interrupts if appropriate156@157mrs r9, cpsr158tst r3, #PSR_I_BIT159biceq r9, r9, #PSR_I_BIT160161@162@ Call the processor-specific abort handler:163@164@ r2 - aborted context pc165@ r3 - aborted context cpsr166@167@ The abort handler must return the aborted address in r0, and168@ the fault status register in r1. r9 must be preserved.169@170#ifdef MULTI_DABORT171ldr r4, .LCprocfns172mov lr, pc173ldr pc, [r4, #PROCESSOR_DABT_FUNC]174#else175bl CPU_DABORT_HANDLER176#endif177178@179@ set desired IRQ state, then call main handler180@181debug_entry r1182msr cpsr_c, r9183mov r2, sp184bl do_DataAbort185186@187@ IRQs off again before pulling preserved data off the stack188@189disable_irq_notrace190191@192@ restore SPSR and restart the instruction193@194ldr r2, [sp, #S_PSR]195svc_exit r2 @ return from exception196UNWIND(.fnend )197ENDPROC(__dabt_svc)198199.align 5200__irq_svc:201svc_entry202203#ifdef CONFIG_TRACE_IRQFLAGS204bl trace_hardirqs_off205#endif206#ifdef CONFIG_PREEMPT207get_thread_info tsk208ldr r8, [tsk, #TI_PREEMPT] @ get preempt count209add r7, r8, #1 @ increment it210str r7, [tsk, #TI_PREEMPT]211#endif212213irq_handler214#ifdef CONFIG_PREEMPT215str r8, [tsk, #TI_PREEMPT] @ restore preempt count216ldr r0, [tsk, #TI_FLAGS] @ get flags217teq r8, #0 @ if preempt count != 0218movne r0, #0 @ force flags to 0219tst r0, #_TIF_NEED_RESCHED220blne svc_preempt221#endif222ldr r4, [sp, #S_PSR] @ irqs are already disabled223#ifdef CONFIG_TRACE_IRQFLAGS224tst r4, #PSR_I_BIT225bleq trace_hardirqs_on226#endif227svc_exit r4 @ return from exception228UNWIND(.fnend )229ENDPROC(__irq_svc)230231.ltorg232233#ifdef CONFIG_PREEMPT234svc_preempt:235mov r8, lr2361: bl preempt_schedule_irq @ irq en/disable is done inside237ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS238tst r0, #_TIF_NEED_RESCHED239moveq pc, r8 @ go again240b 1b241#endif242243.align 5244__und_svc:245#ifdef CONFIG_KPROBES246@ If a kprobe is about to simulate a "stmdb sp..." instruction,247@ it obviously needs free stack space which then will belong to248@ the saved context.249svc_entry 64250#else251svc_entry252#endif253254@255@ call emulation code, which returns using r9 if it has emulated256@ the instruction, or the more conventional lr if we are to treat257@ this as a real undefined instruction258@259@ r0 - instruction260@261#ifndef CONFIG_THUMB2_KERNEL262ldr r0, [r2, #-4]263#else264ldrh r0, [r2, #-2] @ Thumb instruction at LR - 2265and r9, r0, #0xf800266cmp r9, #0xe800 @ 32-bit instruction if xx >= 0267ldrhhs r9, [r2] @ bottom 16 bits268orrhs r0, r9, r0, lsl #16269#endif270adr r9, BSYM(1f)271bl call_fpe272273mov r0, sp @ struct pt_regs *regs274bl do_undefinstr275276@277@ IRQs off again before pulling preserved data off the stack278@2791: disable_irq_notrace280281@282@ restore SPSR and restart the instruction283@284ldr r2, [sp, #S_PSR] @ Get SVC cpsr285svc_exit r2 @ return from exception286UNWIND(.fnend )287ENDPROC(__und_svc)288289.align 5290__pabt_svc:291svc_entry292293@294@ re-enable interrupts if appropriate295@296mrs r9, cpsr297tst r3, #PSR_I_BIT298biceq r9, r9, #PSR_I_BIT299300mov r0, r2 @ pass address of aborted instruction.301#ifdef MULTI_PABORT302ldr r4, .LCprocfns303mov lr, pc304ldr pc, [r4, #PROCESSOR_PABT_FUNC]305#else306bl CPU_PABORT_HANDLER307#endif308debug_entry r1309msr cpsr_c, r9 @ Maybe enable interrupts310mov r2, sp @ regs311bl do_PrefetchAbort @ call abort handler312313@314@ IRQs off again before pulling preserved data off the stack315@316disable_irq_notrace317318@319@ restore SPSR and restart the instruction320@321ldr r2, [sp, #S_PSR]322svc_exit r2 @ return from exception323UNWIND(.fnend )324ENDPROC(__pabt_svc)325326.align 5327.LCcralign:328.word cr_alignment329#ifdef MULTI_DABORT330.LCprocfns:331.word processor332#endif333.LCfp:334.word fp_enter335336/*337* User mode handlers338*339* EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE340*/341342#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)343#error "sizeof(struct pt_regs) must be a multiple of 8"344#endif345346.macro usr_entry347UNWIND(.fnstart )348UNWIND(.cantunwind ) @ don't unwind the user space349sub sp, sp, #S_FRAME_SIZE350ARM( stmib sp, {r1 - r12} )351THUMB( stmia sp, {r0 - r12} )352353ldmia r0, {r1 - r3}354add r0, sp, #S_PC @ here for interlock avoidance355mov r4, #-1 @ "" "" "" ""356357str r1, [sp] @ save the "real" r0 copied358@ from the exception stack359360@361@ We are now ready to fill in the remaining blanks on the stack:362@363@ r2 - lr_<exception>, already fixed up for correct return/restart364@ r3 - spsr_<exception>365@ r4 - orig_r0 (see pt_regs definition in ptrace.h)366@367@ Also, separately save sp_usr and lr_usr368@369stmia r0, {r2 - r4}370ARM( stmdb r0, {sp, lr}^ )371THUMB( store_user_sp_lr r0, r1, S_SP - S_PC )372373@374@ Enable the alignment trap while in kernel mode375@376alignment_trap r0377378@379@ Clear FP to mark the first stack frame380@381zero_fp382.endm383384.macro kuser_cmpxchg_check385#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)386#ifndef CONFIG_MMU387#warning "NPTL on non MMU needs fixing"388#else389@ Make sure our user space atomic helper is restarted390@ if it was interrupted in a critical region. Here we391@ perform a quick test inline since it should be false392@ 99.9999% of the time. The rest is done out of line.393cmp r2, #TASK_SIZE394blhs kuser_cmpxchg_fixup395#endif396#endif397.endm398399.align 5400__dabt_usr:401usr_entry402kuser_cmpxchg_check403404@405@ Call the processor-specific abort handler:406@407@ r2 - aborted context pc408@ r3 - aborted context cpsr409@410@ The abort handler must return the aborted address in r0, and411@ the fault status register in r1.412@413#ifdef MULTI_DABORT414ldr r4, .LCprocfns415mov lr, pc416ldr pc, [r4, #PROCESSOR_DABT_FUNC]417#else418bl CPU_DABORT_HANDLER419#endif420421@422@ IRQs on, then call the main handler423@424debug_entry r1425enable_irq426mov r2, sp427adr lr, BSYM(ret_from_exception)428b do_DataAbort429UNWIND(.fnend )430ENDPROC(__dabt_usr)431432.align 5433__irq_usr:434usr_entry435kuser_cmpxchg_check436437#ifdef CONFIG_IRQSOFF_TRACER438bl trace_hardirqs_off439#endif440441get_thread_info tsk442#ifdef CONFIG_PREEMPT443ldr r8, [tsk, #TI_PREEMPT] @ get preempt count444add r7, r8, #1 @ increment it445str r7, [tsk, #TI_PREEMPT]446#endif447448irq_handler449#ifdef CONFIG_PREEMPT450ldr r0, [tsk, #TI_PREEMPT]451str r8, [tsk, #TI_PREEMPT]452teq r0, r7453ARM( strne r0, [r0, -r0] )454THUMB( movne r0, #0 )455THUMB( strne r0, [r0] )456#endif457458mov why, #0459b ret_to_user_from_irq460UNWIND(.fnend )461ENDPROC(__irq_usr)462463.ltorg464465.align 5466__und_usr:467usr_entry468469@470@ fall through to the emulation code, which returns using r9 if471@ it has emulated the instruction, or the more conventional lr472@ if we are to treat this as a real undefined instruction473@474@ r0 - instruction475@476adr r9, BSYM(ret_from_exception)477adr lr, BSYM(__und_usr_unknown)478tst r3, #PSR_T_BIT @ Thumb mode?479itet eq @ explicit IT needed for the 1f label480subeq r4, r2, #4 @ ARM instr at LR - 4481subne r4, r2, #2 @ Thumb instr at LR - 24821: ldreqt r0, [r4]483#ifdef CONFIG_CPU_ENDIAN_BE8484reveq r0, r0 @ little endian instruction485#endif486beq call_fpe487@ Thumb instruction488#if __LINUX_ARM_ARCH__ >= 74892:490ARM( ldrht r5, [r4], #2 )491THUMB( ldrht r5, [r4] )492THUMB( add r4, r4, #2 )493and r0, r5, #0xf800 @ mask bits 111x x... .... ....494cmp r0, #0xe800 @ 32bit instruction if xx != 0495blo __und_usr_unknown4963: ldrht r0, [r4]497add r2, r2, #2 @ r2 is PC + 2, make it PC + 4498orr r0, r0, r5, lsl #16499#else500b __und_usr_unknown501#endif502UNWIND(.fnend )503ENDPROC(__und_usr)504505@506@ fallthrough to call_fpe507@508509/*510* The out of line fixup for the ldrt above.511*/512.pushsection .fixup, "ax"5134: mov pc, r9514.popsection515.pushsection __ex_table,"a"516.long 1b, 4b517#if __LINUX_ARM_ARCH__ >= 7518.long 2b, 4b519.long 3b, 4b520#endif521.popsection522523/*524* Check whether the instruction is a co-processor instruction.525* If yes, we need to call the relevant co-processor handler.526*527* Note that we don't do a full check here for the co-processor528* instructions; all instructions with bit 27 set are well529* defined. The only instructions that should fault are the530* co-processor instructions. However, we have to watch out531* for the ARM6/ARM7 SWI bug.532*533* NEON is a special case that has to be handled here. Not all534* NEON instructions are co-processor instructions, so we have535* to make a special case of checking for them. Plus, there's536* five groups of them, so we have a table of mask/opcode pairs537* to check against, and if any match then we branch off into the538* NEON handler code.539*540* Emulators may wish to make use of the following registers:541* r0 = instruction opcode.542* r2 = PC+4543* r9 = normal "successful" return address544* r10 = this threads thread_info structure.545* lr = unrecognised instruction return address546*/547@548@ Fall-through from Thumb-2 __und_usr549@550#ifdef CONFIG_NEON551adr r6, .LCneon_thumb_opcodes552b 2f553#endif554call_fpe:555#ifdef CONFIG_NEON556adr r6, .LCneon_arm_opcodes5572:558ldr r7, [r6], #4 @ mask value559cmp r7, #0 @ end mask?560beq 1f561and r8, r0, r7562ldr r7, [r6], #4 @ opcode bits matching in mask563cmp r8, r7 @ NEON instruction?564bne 2b565get_thread_info r10566mov r7, #1567strb r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used568strb r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used569b do_vfp @ let VFP handler handle this5701:571#endif572tst r0, #0x08000000 @ only CDP/CPRT/LDC/STC have bit 27573tstne r0, #0x04000000 @ bit 26 set on both ARM and Thumb-2574#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)575and r8, r0, #0x0f000000 @ mask out op-code bits576teqne r8, #0x0f000000 @ SWI (ARM6/7 bug)?577#endif578moveq pc, lr579get_thread_info r10 @ get current thread580and r8, r0, #0x00000f00 @ mask out CP number581THUMB( lsr r8, r8, #8 )582mov r7, #1583add r6, r10, #TI_USED_CP584ARM( strb r7, [r6, r8, lsr #8] ) @ set appropriate used_cp[]585THUMB( strb r7, [r6, r8] ) @ set appropriate used_cp[]586#ifdef CONFIG_IWMMXT587@ Test if we need to give access to iWMMXt coprocessors588ldr r5, [r10, #TI_FLAGS]589rsbs r7, r8, #(1 << 8) @ CP 0 or 1 only590movcss r7, r5, lsr #(TIF_USING_IWMMXT + 1)591bcs iwmmxt_task_enable592#endif593ARM( add pc, pc, r8, lsr #6 )594THUMB( lsl r8, r8, #2 )595THUMB( add pc, r8 )596nop597598movw_pc lr @ CP#0599W(b) do_fpe @ CP#1 (FPE)600W(b) do_fpe @ CP#2 (FPE)601movw_pc lr @ CP#3602#ifdef CONFIG_CRUNCH603b crunch_task_enable @ CP#4 (MaverickCrunch)604b crunch_task_enable @ CP#5 (MaverickCrunch)605b crunch_task_enable @ CP#6 (MaverickCrunch)606#else607movw_pc lr @ CP#4608movw_pc lr @ CP#5609movw_pc lr @ CP#6610#endif611movw_pc lr @ CP#7612movw_pc lr @ CP#8613movw_pc lr @ CP#9614#ifdef CONFIG_VFP615W(b) do_vfp @ CP#10 (VFP)616W(b) do_vfp @ CP#11 (VFP)617#else618movw_pc lr @ CP#10 (VFP)619movw_pc lr @ CP#11 (VFP)620#endif621movw_pc lr @ CP#12622movw_pc lr @ CP#13623movw_pc lr @ CP#14 (Debug)624movw_pc lr @ CP#15 (Control)625626#ifdef CONFIG_NEON627.align 6628629.LCneon_arm_opcodes:630.word 0xfe000000 @ mask631.word 0xf2000000 @ opcode632633.word 0xff100000 @ mask634.word 0xf4000000 @ opcode635636.word 0x00000000 @ mask637.word 0x00000000 @ opcode638639.LCneon_thumb_opcodes:640.word 0xef000000 @ mask641.word 0xef000000 @ opcode642643.word 0xff100000 @ mask644.word 0xf9000000 @ opcode645646.word 0x00000000 @ mask647.word 0x00000000 @ opcode648#endif649650do_fpe:651enable_irq652ldr r4, .LCfp653add r10, r10, #TI_FPSTATE @ r10 = workspace654ldr pc, [r4] @ Call FP module USR entry point655656/*657* The FP module is called with these registers set:658* r0 = instruction659* r2 = PC+4660* r9 = normal "successful" return address661* r10 = FP workspace662* lr = unrecognised FP instruction return address663*/664665.pushsection .data666ENTRY(fp_enter)667.word no_fp668.popsection669670ENTRY(no_fp)671mov pc, lr672ENDPROC(no_fp)673674__und_usr_unknown:675enable_irq676mov r0, sp677adr lr, BSYM(ret_from_exception)678b do_undefinstr679ENDPROC(__und_usr_unknown)680681.align 5682__pabt_usr:683usr_entry684685mov r0, r2 @ pass address of aborted instruction.686#ifdef MULTI_PABORT687ldr r4, .LCprocfns688mov lr, pc689ldr pc, [r4, #PROCESSOR_PABT_FUNC]690#else691bl CPU_PABORT_HANDLER692#endif693debug_entry r1694enable_irq @ Enable interrupts695mov r2, sp @ regs696bl do_PrefetchAbort @ call abort handler697UNWIND(.fnend )698/* fall through */699/*700* This is the return code to user mode for abort handlers701*/702ENTRY(ret_from_exception)703UNWIND(.fnstart )704UNWIND(.cantunwind )705get_thread_info tsk706mov why, #0707b ret_to_user708UNWIND(.fnend )709ENDPROC(__pabt_usr)710ENDPROC(ret_from_exception)711712/*713* Register switch for ARMv3 and ARMv4 processors714* r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info715* previous and next are guaranteed not to be the same.716*/717ENTRY(__switch_to)718UNWIND(.fnstart )719UNWIND(.cantunwind )720add ip, r1, #TI_CPU_SAVE721ldr r3, [r2, #TI_TP_VALUE]722ARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stack723THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack724THUMB( str sp, [ip], #4 )725THUMB( str lr, [ip], #4 )726#ifdef CONFIG_CPU_USE_DOMAINS727ldr r6, [r2, #TI_CPU_DOMAIN]728#endif729set_tls r3, r4, r5730#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)731ldr r7, [r2, #TI_TASK]732ldr r8, =__stack_chk_guard733ldr r7, [r7, #TSK_STACK_CANARY]734#endif735#ifdef CONFIG_CPU_USE_DOMAINS736mcr p15, 0, r6, c3, c0, 0 @ Set domain register737#endif738mov r5, r0739add r4, r2, #TI_CPU_SAVE740ldr r0, =thread_notify_head741mov r1, #THREAD_NOTIFY_SWITCH742bl atomic_notifier_call_chain743#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)744str r7, [r8]745#endif746THUMB( mov ip, r4 )747mov r0, r5748ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previously749THUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previously750THUMB( ldr sp, [ip], #4 )751THUMB( ldr pc, [ip] )752UNWIND(.fnend )753ENDPROC(__switch_to)754755__INIT756757/*758* User helpers.759*760* These are segment of kernel provided user code reachable from user space761* at a fixed address in kernel memory. This is used to provide user space762* with some operations which require kernel help because of unimplemented763* native feature and/or instructions in many ARM CPUs. The idea is for764* this code to be executed directly in user mode for best efficiency but765* which is too intimate with the kernel counter part to be left to user766* libraries. In fact this code might even differ from one CPU to another767* depending on the available instruction set and restrictions like on768* SMP systems. In other words, the kernel reserves the right to change769* this code as needed without warning. Only the entry points and their770* results are guaranteed to be stable.771*772* Each segment is 32-byte aligned and will be moved to the top of the high773* vector page. New segments (if ever needed) must be added in front of774* existing ones. This mechanism should be used only for things that are775* really small and justified, and not be abused freely.776*777* User space is expected to implement those things inline when optimizing778* for a processor that has the necessary native support, but only if such779* resulting binaries are already to be incompatible with earlier ARM780* processors due to the use of unsupported instructions other than what781* is provided here. In other words don't make binaries unable to run on782* earlier processors just for the sake of not using these kernel helpers783* if your compiled code is not going to use the new instructions for other784* purpose.785*/786THUMB( .arm )787788.macro usr_ret, reg789#ifdef CONFIG_ARM_THUMB790bx \reg791#else792mov pc, \reg793#endif794.endm795796.align 5797.globl __kuser_helper_start798__kuser_helper_start:799800/*801* Reference prototype:802*803* void __kernel_memory_barrier(void)804*805* Input:806*807* lr = return address808*809* Output:810*811* none812*813* Clobbered:814*815* none816*817* Definition and user space usage example:818*819* typedef void (__kernel_dmb_t)(void);820* #define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)821*822* Apply any needed memory barrier to preserve consistency with data modified823* manually and __kuser_cmpxchg usage.824*825* This could be used as follows:826*827* #define __kernel_dmb() \828* asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \829* : : : "r0", "lr","cc" )830*/831832__kuser_memory_barrier: @ 0xffff0fa0833smp_dmb arm834usr_ret lr835836.align 5837838/*839* Reference prototype:840*841* int __kernel_cmpxchg(int oldval, int newval, int *ptr)842*843* Input:844*845* r0 = oldval846* r1 = newval847* r2 = ptr848* lr = return address849*850* Output:851*852* r0 = returned value (zero or non-zero)853* C flag = set if r0 == 0, clear if r0 != 0854*855* Clobbered:856*857* r3, ip, flags858*859* Definition and user space usage example:860*861* typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);862* #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)863*864* Atomically store newval in *ptr if *ptr is equal to oldval for user space.865* Return zero if *ptr was changed or non-zero if no exchange happened.866* The C flag is also set if *ptr was changed to allow for assembly867* optimization in the calling code.868*869* Notes:870*871* - This routine already includes memory barriers as needed.872*873* For example, a user space atomic_add implementation could look like this:874*875* #define atomic_add(ptr, val) \876* ({ register unsigned int *__ptr asm("r2") = (ptr); \877* register unsigned int __result asm("r1"); \878* asm volatile ( \879* "1: @ atomic_add\n\t" \880* "ldr r0, [r2]\n\t" \881* "mov r3, #0xffff0fff\n\t" \882* "add lr, pc, #4\n\t" \883* "add r1, r0, %2\n\t" \884* "add pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \885* "bcc 1b" \886* : "=&r" (__result) \887* : "r" (__ptr), "rIL" (val) \888* : "r0","r3","ip","lr","cc","memory" ); \889* __result; })890*/891892__kuser_cmpxchg: @ 0xffff0fc0893894#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)895896/*897* Poor you. No fast solution possible...898* The kernel itself must perform the operation.899* A special ghost syscall is used for that (see traps.c).900*/901stmfd sp!, {r7, lr}902ldr r7, 1f @ it's 20 bits903swi __ARM_NR_cmpxchg904ldmfd sp!, {r7, pc}9051: .word __ARM_NR_cmpxchg906907#elif __LINUX_ARM_ARCH__ < 6908909#ifdef CONFIG_MMU910911/*912* The only thing that can break atomicity in this cmpxchg913* implementation is either an IRQ or a data abort exception914* causing another process/thread to be scheduled in the middle915* of the critical sequence. To prevent this, code is added to916* the IRQ and data abort exception handlers to set the pc back917* to the beginning of the critical section if it is found to be918* within that critical section (see kuser_cmpxchg_fixup).919*/9201: ldr r3, [r2] @ load current val921subs r3, r3, r0 @ compare with oldval9222: streq r1, [r2] @ store newval if eq923rsbs r0, r3, #0 @ set return val and C flag924usr_ret lr925926.text927kuser_cmpxchg_fixup:928@ Called from kuser_cmpxchg_check macro.929@ r2 = address of interrupted insn (must be preserved).930@ sp = saved regs. r7 and r8 are clobbered.931@ 1b = first critical insn, 2b = last critical insn.932@ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.933mov r7, #0xffff0fff934sub r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))935subs r8, r2, r7936rsbcss r8, r8, #(2b - 1b)937strcs r7, [sp, #S_PC]938mov pc, lr939.previous940941#else942#warning "NPTL on non MMU needs fixing"943mov r0, #-1944adds r0, r0, #0945usr_ret lr946#endif947948#else949950smp_dmb arm9511: ldrex r3, [r2]952subs r3, r3, r0953strexeq r3, r1, [r2]954teqeq r3, #1955beq 1b956rsbs r0, r3, #0957/* beware -- each __kuser slot must be 8 instructions max */958ALT_SMP(b __kuser_memory_barrier)959ALT_UP(usr_ret lr)960961#endif962963.align 5964965/*966* Reference prototype:967*968* int __kernel_get_tls(void)969*970* Input:971*972* lr = return address973*974* Output:975*976* r0 = TLS value977*978* Clobbered:979*980* none981*982* Definition and user space usage example:983*984* typedef int (__kernel_get_tls_t)(void);985* #define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)986*987* Get the TLS value as previously set via the __ARM_NR_set_tls syscall.988*989* This could be used as follows:990*991* #define __kernel_get_tls() \992* ({ register unsigned int __val asm("r0"); \993* asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \994* : "=r" (__val) : : "lr","cc" ); \995* __val; })996*/997998__kuser_get_tls: @ 0xffff0fe0999ldr r0, [pc, #(16 - 8)] @ read TLS, set in kuser_get_tls_init1000usr_ret lr1001mrc p15, 0, r0, c13, c0, 3 @ 0xffff0fe8 hardware TLS code1002.rep 41003.word 0 @ 0xffff0ff0 software TLS value, then1004.endr @ pad up to __kuser_helper_version10051006/*1007* Reference declaration:1008*1009* extern unsigned int __kernel_helper_version;1010*1011* Definition and user space usage example:1012*1013* #define __kernel_helper_version (*(unsigned int *)0xffff0ffc)1014*1015* User space may read this to determine the curent number of helpers1016* available.1017*/10181019__kuser_helper_version: @ 0xffff0ffc1020.word ((__kuser_helper_end - __kuser_helper_start) >> 5)10211022.globl __kuser_helper_end1023__kuser_helper_end:10241025THUMB( .thumb )10261027/*1028* Vector stubs.1029*1030* This code is copied to 0xffff0200 so we can use branches in the1031* vectors, rather than ldr's. Note that this code must not1032* exceed 0x300 bytes.1033*1034* Common stub entry macro:1035* Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC1036*1037* SP points to a minimal amount of processor-private memory, the address1038* of which is copied into r0 for the mode specific abort handler.1039*/1040.macro vector_stub, name, mode, correction=01041.align 510421043vector_\name:1044.if \correction1045sub lr, lr, #\correction1046.endif10471048@1049@ Save r0, lr_<exception> (parent PC) and spsr_<exception>1050@ (parent CPSR)1051@1052stmia sp, {r0, lr} @ save r0, lr1053mrs lr, spsr1054str lr, [sp, #8] @ save spsr10551056@1057@ Prepare for SVC32 mode. IRQs remain disabled.1058@1059mrs r0, cpsr1060eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)1061msr spsr_cxsf, r010621063@1064@ the branch table must immediately follow this code1065@1066and lr, lr, #0x0f1067THUMB( adr r0, 1f )1068THUMB( ldr lr, [r0, lr, lsl #2] )1069mov r0, sp1070ARM( ldr lr, [pc, lr, lsl #2] )1071movs pc, lr @ branch to handler in SVC mode1072ENDPROC(vector_\name)10731074.align 21075@ handler addresses follow this label10761:1077.endm10781079.globl __stubs_start1080__stubs_start:1081/*1082* Interrupt dispatcher1083*/1084vector_stub irq, IRQ_MODE, 410851086.long __irq_usr @ 0 (USR_26 / USR_32)1087.long __irq_invalid @ 1 (FIQ_26 / FIQ_32)1088.long __irq_invalid @ 2 (IRQ_26 / IRQ_32)1089.long __irq_svc @ 3 (SVC_26 / SVC_32)1090.long __irq_invalid @ 41091.long __irq_invalid @ 51092.long __irq_invalid @ 61093.long __irq_invalid @ 71094.long __irq_invalid @ 81095.long __irq_invalid @ 91096.long __irq_invalid @ a1097.long __irq_invalid @ b1098.long __irq_invalid @ c1099.long __irq_invalid @ d1100.long __irq_invalid @ e1101.long __irq_invalid @ f11021103/*1104* Data abort dispatcher1105* Enter in ABT mode, spsr = USR CPSR, lr = USR PC1106*/1107vector_stub dabt, ABT_MODE, 811081109.long __dabt_usr @ 0 (USR_26 / USR_32)1110.long __dabt_invalid @ 1 (FIQ_26 / FIQ_32)1111.long __dabt_invalid @ 2 (IRQ_26 / IRQ_32)1112.long __dabt_svc @ 3 (SVC_26 / SVC_32)1113.long __dabt_invalid @ 41114.long __dabt_invalid @ 51115.long __dabt_invalid @ 61116.long __dabt_invalid @ 71117.long __dabt_invalid @ 81118.long __dabt_invalid @ 91119.long __dabt_invalid @ a1120.long __dabt_invalid @ b1121.long __dabt_invalid @ c1122.long __dabt_invalid @ d1123.long __dabt_invalid @ e1124.long __dabt_invalid @ f11251126/*1127* Prefetch abort dispatcher1128* Enter in ABT mode, spsr = USR CPSR, lr = USR PC1129*/1130vector_stub pabt, ABT_MODE, 411311132.long __pabt_usr @ 0 (USR_26 / USR_32)1133.long __pabt_invalid @ 1 (FIQ_26 / FIQ_32)1134.long __pabt_invalid @ 2 (IRQ_26 / IRQ_32)1135.long __pabt_svc @ 3 (SVC_26 / SVC_32)1136.long __pabt_invalid @ 41137.long __pabt_invalid @ 51138.long __pabt_invalid @ 61139.long __pabt_invalid @ 71140.long __pabt_invalid @ 81141.long __pabt_invalid @ 91142.long __pabt_invalid @ a1143.long __pabt_invalid @ b1144.long __pabt_invalid @ c1145.long __pabt_invalid @ d1146.long __pabt_invalid @ e1147.long __pabt_invalid @ f11481149/*1150* Undef instr entry dispatcher1151* Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC1152*/1153vector_stub und, UND_MODE11541155.long __und_usr @ 0 (USR_26 / USR_32)1156.long __und_invalid @ 1 (FIQ_26 / FIQ_32)1157.long __und_invalid @ 2 (IRQ_26 / IRQ_32)1158.long __und_svc @ 3 (SVC_26 / SVC_32)1159.long __und_invalid @ 41160.long __und_invalid @ 51161.long __und_invalid @ 61162.long __und_invalid @ 71163.long __und_invalid @ 81164.long __und_invalid @ 91165.long __und_invalid @ a1166.long __und_invalid @ b1167.long __und_invalid @ c1168.long __und_invalid @ d1169.long __und_invalid @ e1170.long __und_invalid @ f11711172.align 511731174/*=============================================================================1175* Undefined FIQs1176*-----------------------------------------------------------------------------1177* Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC1178* MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.1179* Basically to switch modes, we *HAVE* to clobber one register... brain1180* damage alert! I don't think that we can execute any code in here in any1181* other mode than FIQ... Ok you can switch to another mode, but you can't1182* get out of that mode without clobbering one register.1183*/1184vector_fiq:1185disable_fiq1186subs pc, lr, #411871188/*=============================================================================1189* Address exception handler1190*-----------------------------------------------------------------------------1191* These aren't too critical.1192* (they're not supposed to happen, and won't happen in 32-bit data mode).1193*/11941195vector_addrexcptn:1196b vector_addrexcptn11971198/*1199* We group all the following data together to optimise1200* for CPUs with separate I & D caches.1201*/1202.align 512031204.LCvswi:1205.word vector_swi12061207.globl __stubs_end1208__stubs_end:12091210.equ stubs_offset, __vectors_start + 0x200 - __stubs_start12111212.globl __vectors_start1213__vectors_start:1214ARM( swi SYS_ERROR0 )1215THUMB( svc #0 )1216THUMB( nop )1217W(b) vector_und + stubs_offset1218W(ldr) pc, .LCvswi + stubs_offset1219W(b) vector_pabt + stubs_offset1220W(b) vector_dabt + stubs_offset1221W(b) vector_addrexcptn + stubs_offset1222W(b) vector_irq + stubs_offset1223W(b) vector_fiq + stubs_offset12241225.globl __vectors_end1226__vectors_end:12271228.data12291230.globl cr_alignment1231.globl cr_no_alignment1232cr_alignment:1233.space 41234cr_no_alignment:1235.space 412361237#ifdef CONFIG_MULTI_IRQ_HANDLER1238.globl handle_arch_irq1239handle_arch_irq:1240.space 41241#endif124212431244