/*1* linux/arch/arm/kernel/entry-common.S2*3* Copyright (C) 2000 Russell King4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*/910#include <asm/unistd.h>11#include <asm/ftrace.h>12#include <mach/entry-macro.S>13#include <asm/unwind.h>1415#include "entry-header.S"161718.align 519/*20* This is the fast syscall return path. We do as little as21* possible here, and this includes saving r0 back into the SVC22* stack.23*/24ret_fast_syscall:25UNWIND(.fnstart )26UNWIND(.cantunwind )27disable_irq @ disable interrupts28ldr r1, [tsk, #TI_FLAGS]29tst r1, #_TIF_WORK_MASK30bne fast_work_pending31#if defined(CONFIG_IRQSOFF_TRACER)32asm_trace_hardirqs_on33#endif3435/* perform architecture specific actions before user return */36arch_ret_to_user r1, lr3738restore_user_regs fast = 1, offset = S_OFF39UNWIND(.fnend )4041/*42* Ok, we need to do extra processing, enter the slow path.43*/44fast_work_pending:45str r0, [sp, #S_R0+S_OFF]! @ returned r046work_pending:47tst r1, #_TIF_NEED_RESCHED48bne work_resched49tst r1, #_TIF_SIGPENDING|_TIF_NOTIFY_RESUME50beq no_work_pending51mov r0, sp @ 'regs'52mov r2, why @ 'syscall'53tst r1, #_TIF_SIGPENDING @ delivering a signal?54movne why, #0 @ prevent further restarts55bl do_notify_resume56b ret_slow_syscall @ Check work again5758work_resched:59bl schedule60/*61* "slow" syscall return path. "why" tells us if this was a real syscall.62*/63ENTRY(ret_to_user)64ret_slow_syscall:65disable_irq @ disable interrupts66ENTRY(ret_to_user_from_irq)67ldr r1, [tsk, #TI_FLAGS]68tst r1, #_TIF_WORK_MASK69bne work_pending70no_work_pending:71#if defined(CONFIG_IRQSOFF_TRACER)72asm_trace_hardirqs_on73#endif74/* perform architecture specific actions before user return */75arch_ret_to_user r1, lr7677restore_user_regs fast = 0, offset = 078ENDPROC(ret_to_user_from_irq)79ENDPROC(ret_to_user)8081/*82* This is how we return from a fork.83*/84ENTRY(ret_from_fork)85bl schedule_tail86get_thread_info tsk87ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing88mov why, #189tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?90beq ret_slow_syscall91mov r1, sp92mov r0, #1 @ trace exit [IP = 1]93bl syscall_trace94b ret_slow_syscall95ENDPROC(ret_from_fork)9697.equ NR_syscalls,098#define CALL(x) .equ NR_syscalls,NR_syscalls+199#include "calls.S"100#undef CALL101#define CALL(x) .long x102103#ifdef CONFIG_FUNCTION_TRACER104/*105* When compiling with -pg, gcc inserts a call to the mcount routine at the106* start of every function. In mcount, apart from the function's address (in107* lr), we need to get hold of the function's caller's address.108*109* Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:110*111* bl mcount112*113* These versions have the limitation that in order for the mcount routine to114* be able to determine the function's caller's address, an APCS-style frame115* pointer (which is set up with something like the code below) is required.116*117* mov ip, sp118* push {fp, ip, lr, pc}119* sub fp, ip, #4120*121* With EABI, these frame pointers are not available unless -mapcs-frame is122* specified, and if building as Thumb-2, not even then.123*124* Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,125* with call sites like:126*127* push {lr}128* bl __gnu_mcount_nc129*130* With these compilers, frame pointers are not necessary.131*132* mcount can be thought of as a function called in the middle of a subroutine133* call. As such, it needs to be transparent for both the caller and the134* callee: the original lr needs to be restored when leaving mcount, and no135* registers should be clobbered. (In the __gnu_mcount_nc implementation, we136* clobber the ip register. This is OK because the ARM calling convention137* allows it to be clobbered in subroutines and doesn't use it to hold138* parameters.)139*140* When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0"141* for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see142* arch/arm/kernel/ftrace.c).143*/144145#ifndef CONFIG_OLD_MCOUNT146#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))147#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.148#endif149#endif150151.macro __mcount suffix152mcount_enter153ldr r0, =ftrace_trace_function154ldr r2, [r0]155adr r0, .Lftrace_stub156cmp r0, r2157bne 1f158159#ifdef CONFIG_FUNCTION_GRAPH_TRACER160ldr r1, =ftrace_graph_return161ldr r2, [r1]162cmp r0, r2163bne ftrace_graph_caller\suffix164165ldr r1, =ftrace_graph_entry166ldr r2, [r1]167ldr r0, =ftrace_graph_entry_stub168cmp r0, r2169bne ftrace_graph_caller\suffix170#endif171172mcount_exit1731741: mcount_get_lr r1 @ lr of instrumented func175mov r0, lr @ instrumented function176sub r0, r0, #MCOUNT_INSN_SIZE177adr lr, BSYM(2f)178mov pc, r21792: mcount_exit180.endm181182.macro __ftrace_caller suffix183mcount_enter184185mcount_get_lr r1 @ lr of instrumented func186mov r0, lr @ instrumented function187sub r0, r0, #MCOUNT_INSN_SIZE188189.globl ftrace_call\suffix190ftrace_call\suffix:191bl ftrace_stub192193#ifdef CONFIG_FUNCTION_GRAPH_TRACER194.globl ftrace_graph_call\suffix195ftrace_graph_call\suffix:196mov r0, r0197#endif198199mcount_exit200.endm201202.macro __ftrace_graph_caller203sub r0, fp, #4 @ &lr of instrumented routine (&parent)204#ifdef CONFIG_DYNAMIC_FTRACE205@ called from __ftrace_caller, saved in mcount_enter206ldr r1, [sp, #16] @ instrumented routine (func)207#else208@ called from __mcount, untouched in lr209mov r1, lr @ instrumented routine (func)210#endif211sub r1, r1, #MCOUNT_INSN_SIZE212mov r2, fp @ frame pointer213bl prepare_ftrace_return214mcount_exit215.endm216217#ifdef CONFIG_OLD_MCOUNT218/*219* mcount220*/221222.macro mcount_enter223stmdb sp!, {r0-r3, lr}224.endm225226.macro mcount_get_lr reg227ldr \reg, [fp, #-4]228.endm229230.macro mcount_exit231ldr lr, [fp, #-4]232ldmia sp!, {r0-r3, pc}233.endm234235ENTRY(mcount)236#ifdef CONFIG_DYNAMIC_FTRACE237stmdb sp!, {lr}238ldr lr, [fp, #-4]239ldmia sp!, {pc}240#else241__mcount _old242#endif243ENDPROC(mcount)244245#ifdef CONFIG_DYNAMIC_FTRACE246ENTRY(ftrace_caller_old)247__ftrace_caller _old248ENDPROC(ftrace_caller_old)249#endif250251#ifdef CONFIG_FUNCTION_GRAPH_TRACER252ENTRY(ftrace_graph_caller_old)253__ftrace_graph_caller254ENDPROC(ftrace_graph_caller_old)255#endif256257.purgem mcount_enter258.purgem mcount_get_lr259.purgem mcount_exit260#endif261262/*263* __gnu_mcount_nc264*/265266.macro mcount_enter267stmdb sp!, {r0-r3, lr}268.endm269270.macro mcount_get_lr reg271ldr \reg, [sp, #20]272.endm273274.macro mcount_exit275ldmia sp!, {r0-r3, ip, lr}276mov pc, ip277.endm278279ENTRY(__gnu_mcount_nc)280#ifdef CONFIG_DYNAMIC_FTRACE281mov ip, lr282ldmia sp!, {lr}283mov pc, ip284#else285__mcount286#endif287ENDPROC(__gnu_mcount_nc)288289#ifdef CONFIG_DYNAMIC_FTRACE290ENTRY(ftrace_caller)291__ftrace_caller292ENDPROC(ftrace_caller)293#endif294295#ifdef CONFIG_FUNCTION_GRAPH_TRACER296ENTRY(ftrace_graph_caller)297__ftrace_graph_caller298ENDPROC(ftrace_graph_caller)299#endif300301.purgem mcount_enter302.purgem mcount_get_lr303.purgem mcount_exit304305#ifdef CONFIG_FUNCTION_GRAPH_TRACER306.globl return_to_handler307return_to_handler:308stmdb sp!, {r0-r3}309mov r0, fp @ frame pointer310bl ftrace_return_to_handler311mov lr, r0 @ r0 has real ret addr312ldmia sp!, {r0-r3}313mov pc, lr314#endif315316ENTRY(ftrace_stub)317.Lftrace_stub:318mov pc, lr319ENDPROC(ftrace_stub)320321#endif /* CONFIG_FUNCTION_TRACER */322323/*=============================================================================324* SWI handler325*-----------------------------------------------------------------------------326*/327328/* If we're optimising for StrongARM the resulting code won't329run on an ARM7 and we can save a couple of instructions.330--pb */331#ifdef CONFIG_CPU_ARM710332#define A710(code...) code333.Larm710bug:334ldmia sp, {r0 - lr}^ @ Get calling r0 - lr335mov r0, r0336add sp, sp, #S_FRAME_SIZE337subs pc, lr, #4338#else339#define A710(code...)340#endif341342.align 5343ENTRY(vector_swi)344sub sp, sp, #S_FRAME_SIZE345stmia sp, {r0 - r12} @ Calling r0 - r12346ARM( add r8, sp, #S_PC )347ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr348THUMB( mov r8, sp )349THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr350mrs r8, spsr @ called from non-FIQ mode, so ok.351str lr, [sp, #S_PC] @ Save calling PC352str r8, [sp, #S_PSR] @ Save CPSR353str r0, [sp, #S_OLD_R0] @ Save OLD_R0354zero_fp355356/*357* Get the system call number.358*/359360#if defined(CONFIG_OABI_COMPAT)361362/*363* If we have CONFIG_OABI_COMPAT then we need to look at the swi364* value to determine if it is an EABI or an old ABI call.365*/366#ifdef CONFIG_ARM_THUMB367tst r8, #PSR_T_BIT368movne r10, #0 @ no thumb OABI emulation369ldreq r10, [lr, #-4] @ get SWI instruction370#else371ldr r10, [lr, #-4] @ get SWI instruction372A710( and ip, r10, #0x0f000000 @ check for SWI )373A710( teq ip, #0x0f000000 )374A710( bne .Larm710bug )375#endif376#ifdef CONFIG_CPU_ENDIAN_BE8377rev r10, r10 @ little endian instruction378#endif379380#elif defined(CONFIG_AEABI)381382/*383* Pure EABI user space always put syscall number into scno (r7).384*/385A710( ldr ip, [lr, #-4] @ get SWI instruction )386A710( and ip, ip, #0x0f000000 @ check for SWI )387A710( teq ip, #0x0f000000 )388A710( bne .Larm710bug )389390#elif defined(CONFIG_ARM_THUMB)391392/* Legacy ABI only, possibly thumb mode. */393tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs394addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in395ldreq scno, [lr, #-4]396397#else398399/* Legacy ABI only. */400ldr scno, [lr, #-4] @ get SWI instruction401A710( and ip, scno, #0x0f000000 @ check for SWI )402A710( teq ip, #0x0f000000 )403A710( bne .Larm710bug )404405#endif406407#ifdef CONFIG_ALIGNMENT_TRAP408ldr ip, __cr_alignment409ldr ip, [ip]410mcr p15, 0, ip, c1, c0 @ update control register411#endif412enable_irq413414get_thread_info tsk415adr tbl, sys_call_table @ load syscall table pointer416417#if defined(CONFIG_OABI_COMPAT)418/*419* If the swi argument is zero, this is an EABI call and we do nothing.420*421* If this is an old ABI call, get the syscall number into scno and422* get the old ABI syscall table address.423*/424bics r10, r10, #0xff000000425eorne scno, r10, #__NR_OABI_SYSCALL_BASE426ldrne tbl, =sys_oabi_call_table427#elif !defined(CONFIG_AEABI)428bic scno, scno, #0xff000000 @ mask off SWI op-code429eor scno, scno, #__NR_SYSCALL_BASE @ check OS number430#endif431432ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing433stmdb sp!, {r4, r5} @ push fifth and sixth args434435#ifdef CONFIG_SECCOMP436tst r10, #_TIF_SECCOMP437beq 1f438mov r0, scno439bl __secure_computing440add r0, sp, #S_R0 + S_OFF @ pointer to regs441ldmia r0, {r0 - r3} @ have to reload r0 - r34421:443#endif444445tst r10, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?446bne __sys_trace447448cmp scno, #NR_syscalls @ check upper syscall limit449adr lr, BSYM(ret_fast_syscall) @ return address450ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine451452add r1, sp, #S_OFF4532: mov why, #0 @ no longer a real syscall454cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)455eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back456bcs arm_syscall457b sys_ni_syscall @ not private func458ENDPROC(vector_swi)459460/*461* This is the really slow path. We're going to be doing462* context switches, and waiting for our parent to respond.463*/464__sys_trace:465mov r2, scno466add r1, sp, #S_OFF467mov r0, #0 @ trace entry [IP = 0]468bl syscall_trace469470adr lr, BSYM(__sys_trace_return) @ return address471mov scno, r0 @ syscall number (possibly new)472add r1, sp, #S_R0 + S_OFF @ pointer to regs473cmp scno, #NR_syscalls @ check upper syscall limit474ldmccia r1, {r0 - r3} @ have to reload r0 - r3475ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine476b 2b477478__sys_trace_return:479str r0, [sp, #S_R0 + S_OFF]! @ save returned r0480mov r2, scno481mov r1, sp482mov r0, #1 @ trace exit [IP = 1]483bl syscall_trace484b ret_slow_syscall485486.align 5487#ifdef CONFIG_ALIGNMENT_TRAP488.type __cr_alignment, #object489__cr_alignment:490.word cr_alignment491#endif492.ltorg493494/*495* This is the syscall table declaration for native ABI syscalls.496* With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.497*/498#define ABI(native, compat) native499#ifdef CONFIG_AEABI500#define OBSOLETE(syscall) sys_ni_syscall501#else502#define OBSOLETE(syscall) syscall503#endif504505.type sys_call_table, #object506ENTRY(sys_call_table)507#include "calls.S"508#undef ABI509#undef OBSOLETE510511/*============================================================================512* Special system call wrappers513*/514@ r0 = syscall number515@ r8 = syscall table516sys_syscall:517bic scno, r0, #__NR_OABI_SYSCALL_BASE518cmp scno, #__NR_syscall - __NR_SYSCALL_BASE519cmpne scno, #NR_syscalls @ check range520stmloia sp, {r5, r6} @ shuffle args521movlo r0, r1522movlo r1, r2523movlo r2, r3524movlo r3, r4525ldrlo pc, [tbl, scno, lsl #2]526b sys_ni_syscall527ENDPROC(sys_syscall)528529sys_fork_wrapper:530add r0, sp, #S_OFF531b sys_fork532ENDPROC(sys_fork_wrapper)533534sys_vfork_wrapper:535add r0, sp, #S_OFF536b sys_vfork537ENDPROC(sys_vfork_wrapper)538539sys_execve_wrapper:540add r3, sp, #S_OFF541b sys_execve542ENDPROC(sys_execve_wrapper)543544sys_clone_wrapper:545add ip, sp, #S_OFF546str ip, [sp, #4]547b sys_clone548ENDPROC(sys_clone_wrapper)549550sys_sigreturn_wrapper:551add r0, sp, #S_OFF552mov why, #0 @ prevent syscall restart handling553b sys_sigreturn554ENDPROC(sys_sigreturn_wrapper)555556sys_rt_sigreturn_wrapper:557add r0, sp, #S_OFF558mov why, #0 @ prevent syscall restart handling559b sys_rt_sigreturn560ENDPROC(sys_rt_sigreturn_wrapper)561562sys_sigaltstack_wrapper:563ldr r2, [sp, #S_OFF + S_SP]564b do_sigaltstack565ENDPROC(sys_sigaltstack_wrapper)566567sys_statfs64_wrapper:568teq r1, #88569moveq r1, #84570b sys_statfs64571ENDPROC(sys_statfs64_wrapper)572573sys_fstatfs64_wrapper:574teq r1, #88575moveq r1, #84576b sys_fstatfs64577ENDPROC(sys_fstatfs64_wrapper)578579/*580* Note: off_4k (r5) is always units of 4K. If we can't do the requested581* offset, we return EINVAL.582*/583sys_mmap2:584#if PAGE_SHIFT > 12585tst r5, #PGOFF_MASK586moveq r5, r5, lsr #PAGE_SHIFT - 12587streq r5, [sp, #4]588beq sys_mmap_pgoff589mov r0, #-EINVAL590mov pc, lr591#else592str r5, [sp, #4]593b sys_mmap_pgoff594#endif595ENDPROC(sys_mmap2)596597#ifdef CONFIG_OABI_COMPAT598599/*600* These are syscalls with argument register differences601*/602603sys_oabi_pread64:604stmia sp, {r3, r4}605b sys_pread64606ENDPROC(sys_oabi_pread64)607608sys_oabi_pwrite64:609stmia sp, {r3, r4}610b sys_pwrite64611ENDPROC(sys_oabi_pwrite64)612613sys_oabi_truncate64:614mov r3, r2615mov r2, r1616b sys_truncate64617ENDPROC(sys_oabi_truncate64)618619sys_oabi_ftruncate64:620mov r3, r2621mov r2, r1622b sys_ftruncate64623ENDPROC(sys_oabi_ftruncate64)624625sys_oabi_readahead:626str r3, [sp]627mov r3, r2628mov r2, r1629b sys_readahead630ENDPROC(sys_oabi_readahead)631632/*633* Let's declare a second syscall table for old ABI binaries634* using the compatibility syscall entries.635*/636#define ABI(native, compat) compat637#define OBSOLETE(syscall) syscall638639.type sys_oabi_call_table, #object640ENTRY(sys_oabi_call_table)641#include "calls.S"642#undef ABI643#undef OBSOLETE644645#endif646647648649