11da177e4SLinus Torvalds/* 21da177e4SLinus Torvalds * linux/arch/arm/kernel/entry-common.S 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 2000 Russell King 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 71da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 81da177e4SLinus Torvalds * published by the Free Software Foundation. 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds#include <asm/unistd.h> 12395a59d0SAbhishek Sagar#include <asm/ftrace.h> 13c4c5716eSCatalin Marinas#include <asm/unwind.h> 141da177e4SLinus Torvalds 1513a5045dSRob Herring#ifdef CONFIG_NEED_RET_TO_USER 1613a5045dSRob Herring#include <mach/entry-macro.S> 1713a5045dSRob Herring#else 1813a5045dSRob Herring .macro arch_ret_to_user, tmp1, tmp2 1913a5045dSRob Herring .endm 2013a5045dSRob Herring#endif 2113a5045dSRob Herring 221da177e4SLinus Torvalds#include "entry-header.S" 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds .align 5 261da177e4SLinus Torvalds/* 271da177e4SLinus Torvalds * This is the fast syscall return path. We do as little as 281da177e4SLinus Torvalds * possible here, and this includes saving r0 back into the SVC 291da177e4SLinus Torvalds * stack. 301da177e4SLinus Torvalds */ 311da177e4SLinus Torvaldsret_fast_syscall: 32c4c5716eSCatalin Marinas UNWIND(.fnstart ) 33c4c5716eSCatalin Marinas UNWIND(.cantunwind ) 341ec42c0cSRussell King disable_irq @ disable interrupts 351da177e4SLinus Torvalds ldr r1, [tsk, #TI_FLAGS] 361da177e4SLinus Torvalds tst r1, #_TIF_WORK_MASK 371da177e4SLinus Torvalds bne fast_work_pending 38d13e5eddSTodd Android Poynor#if defined(CONFIG_IRQSOFF_TRACER) 39d13e5eddSTodd Android Poynor asm_trace_hardirqs_on 40d13e5eddSTodd Android Poynor#endif 41f4dc9a4cSRussell King 42f80dff9dSDan Williams /* perform architecture specific actions before user return */ 43f80dff9dSDan Williams arch_ret_to_user r1, lr 44b0088480SKevin Hilman ct_user_enter 45f80dff9dSDan Williams 46b86040a5SCatalin Marinas restore_user_regs fast = 1, offset = S_OFF 47c4c5716eSCatalin Marinas UNWIND(.fnend ) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds/* 501da177e4SLinus Torvalds * Ok, we need to do extra processing, enter the slow path. 511da177e4SLinus Torvalds */ 521da177e4SLinus Torvaldsfast_work_pending: 531da177e4SLinus Torvalds str r0, [sp, #S_R0+S_OFF]! @ returned r0 541da177e4SLinus Torvaldswork_pending: 551da177e4SLinus Torvalds mov r0, sp @ 'regs' 561da177e4SLinus Torvalds mov r2, why @ 'syscall' 570a267fa6SAl Viro bl do_work_pending 5866285217SAl Viro cmp r0, #0 5981783786SAl Viro beq no_work_pending 6066285217SAl Viro movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE) 6181783786SAl Viro ldmia sp, {r0 - r6} @ have to reload r0 - r6 6281783786SAl Viro b local_restart @ ... and off we go 6381783786SAl Viro 641da177e4SLinus Torvalds/* 651da177e4SLinus Torvalds * "slow" syscall return path. "why" tells us if this was a real syscall. 661da177e4SLinus Torvalds */ 671da177e4SLinus TorvaldsENTRY(ret_to_user) 681da177e4SLinus Torvaldsret_slow_syscall: 691ec42c0cSRussell King disable_irq @ disable interrupts 709fc2552aSMing LeiENTRY(ret_to_user_from_irq) 711da177e4SLinus Torvalds ldr r1, [tsk, #TI_FLAGS] 721da177e4SLinus Torvalds tst r1, #_TIF_WORK_MASK 731da177e4SLinus Torvalds bne work_pending 741da177e4SLinus Torvaldsno_work_pending: 75d13e5eddSTodd Android Poynor#if defined(CONFIG_IRQSOFF_TRACER) 76d13e5eddSTodd Android Poynor asm_trace_hardirqs_on 77d13e5eddSTodd Android Poynor#endif 78f80dff9dSDan Williams /* perform architecture specific actions before user return */ 79f80dff9dSDan Williams arch_ret_to_user r1, lr 80b0088480SKevin Hilman ct_user_enter save = 0 81f80dff9dSDan Williams 82b86040a5SCatalin Marinas restore_user_regs fast = 0, offset = 0 839fc2552aSMing LeiENDPROC(ret_to_user_from_irq) 8493ed3970SCatalin MarinasENDPROC(ret_to_user) 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds/* 871da177e4SLinus Torvalds * This is how we return from a fork. 881da177e4SLinus Torvalds */ 891da177e4SLinus TorvaldsENTRY(ret_from_fork) 901da177e4SLinus Torvalds bl schedule_tail 919fff2fa0SAl Viro cmp r5, #0 929fff2fa0SAl Viro movne r0, r4 9368687c84SRussell King adrne lr, BSYM(1f) 949fff2fa0SAl Viro movne pc, r5 9568687c84SRussell King1: get_thread_info tsk 961da177e4SLinus Torvalds b ret_slow_syscall 9793ed3970SCatalin MarinasENDPROC(ret_from_fork) 981da177e4SLinus Torvalds 99fa1b4f91SAl Viro .equ NR_syscalls,0 100fa1b4f91SAl Viro#define CALL(x) .equ NR_syscalls,NR_syscalls+1 1011da177e4SLinus Torvalds#include "calls.S" 1021f66e06fSWade Farnsworth 1031f66e06fSWade Farnsworth/* 1041f66e06fSWade Farnsworth * Ensure that the system call table is equal to __NR_syscalls, 1051f66e06fSWade Farnsworth * which is the value the rest of the system sees 1061f66e06fSWade Farnsworth */ 1071f66e06fSWade Farnsworth.ifne NR_syscalls - __NR_syscalls 1081f66e06fSWade Farnsworth.error "__NR_syscalls is not equal to the size of the syscall table" 1091f66e06fSWade Farnsworth.endif 1101f66e06fSWade Farnsworth 111fa1b4f91SAl Viro#undef CALL 112fa1b4f91SAl Viro#define CALL(x) .long x 1131da177e4SLinus Torvalds 114606576ceSSteven Rostedt#ifdef CONFIG_FUNCTION_TRACER 115686ff228SRabin Vincent/* 116686ff228SRabin Vincent * When compiling with -pg, gcc inserts a call to the mcount routine at the 117686ff228SRabin Vincent * start of every function. In mcount, apart from the function's address (in 118686ff228SRabin Vincent * lr), we need to get hold of the function's caller's address. 119686ff228SRabin Vincent * 120686ff228SRabin Vincent * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this: 121686ff228SRabin Vincent * 122686ff228SRabin Vincent * bl mcount 123686ff228SRabin Vincent * 124686ff228SRabin Vincent * These versions have the limitation that in order for the mcount routine to 125686ff228SRabin Vincent * be able to determine the function's caller's address, an APCS-style frame 126686ff228SRabin Vincent * pointer (which is set up with something like the code below) is required. 127686ff228SRabin Vincent * 128686ff228SRabin Vincent * mov ip, sp 129686ff228SRabin Vincent * push {fp, ip, lr, pc} 130686ff228SRabin Vincent * sub fp, ip, #4 131686ff228SRabin Vincent * 132686ff228SRabin Vincent * With EABI, these frame pointers are not available unless -mapcs-frame is 133686ff228SRabin Vincent * specified, and if building as Thumb-2, not even then. 134686ff228SRabin Vincent * 135686ff228SRabin Vincent * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount, 136686ff228SRabin Vincent * with call sites like: 137686ff228SRabin Vincent * 138686ff228SRabin Vincent * push {lr} 139686ff228SRabin Vincent * bl __gnu_mcount_nc 140686ff228SRabin Vincent * 141686ff228SRabin Vincent * With these compilers, frame pointers are not necessary. 142686ff228SRabin Vincent * 143686ff228SRabin Vincent * mcount can be thought of as a function called in the middle of a subroutine 144686ff228SRabin Vincent * call. As such, it needs to be transparent for both the caller and the 145686ff228SRabin Vincent * callee: the original lr needs to be restored when leaving mcount, and no 146686ff228SRabin Vincent * registers should be clobbered. (In the __gnu_mcount_nc implementation, we 147686ff228SRabin Vincent * clobber the ip register. This is OK because the ARM calling convention 148686ff228SRabin Vincent * allows it to be clobbered in subroutines and doesn't use it to hold 149686ff228SRabin Vincent * parameters.) 1503b6c223bSRabin Vincent * 1513b6c223bSRabin Vincent * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0" 1523b6c223bSRabin Vincent * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see 1533b6c223bSRabin Vincent * arch/arm/kernel/ftrace.c). 154686ff228SRabin Vincent */ 15509bfafacSRabin Vincent 15609bfafacSRabin Vincent#ifndef CONFIG_OLD_MCOUNT 15709bfafacSRabin Vincent#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) 15809bfafacSRabin Vincent#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0. 15909bfafacSRabin Vincent#endif 16009bfafacSRabin Vincent#endif 16109bfafacSRabin Vincent 162d68133b5SRabin Vincent.macro mcount_adjust_addr rd, rn 163d68133b5SRabin Vincent bic \rd, \rn, #1 @ clear the Thumb bit if present 164d68133b5SRabin Vincent sub \rd, \rd, #MCOUNT_INSN_SIZE 165d68133b5SRabin Vincent.endm 166d68133b5SRabin Vincent 167d3b9dc9dSRabin Vincent.macro __mcount suffix 168d3b9dc9dSRabin Vincent mcount_enter 169181f817eSUwe Kleine-König ldr r0, =ftrace_trace_function 170181f817eSUwe Kleine-König ldr r2, [r0] 171a3ba87a6SRabin Vincent adr r0, .Lftrace_stub 172181f817eSUwe Kleine-König cmp r0, r2 173d3b9dc9dSRabin Vincent bne 1f 174181f817eSUwe Kleine-König 175376cfa87STim Bird#ifdef CONFIG_FUNCTION_GRAPH_TRACER 176376cfa87STim Bird ldr r1, =ftrace_graph_return 177376cfa87STim Bird ldr r2, [r1] 178376cfa87STim Bird cmp r0, r2 179376cfa87STim Bird bne ftrace_graph_caller\suffix 180376cfa87STim Bird 181376cfa87STim Bird ldr r1, =ftrace_graph_entry 182376cfa87STim Bird ldr r2, [r1] 183376cfa87STim Bird ldr r0, =ftrace_graph_entry_stub 184376cfa87STim Bird cmp r0, r2 185376cfa87STim Bird bne ftrace_graph_caller\suffix 186376cfa87STim Bird#endif 187376cfa87STim Bird 188d3b9dc9dSRabin Vincent mcount_exit 189181f817eSUwe Kleine-König 190d3b9dc9dSRabin Vincent1: mcount_get_lr r1 @ lr of instrumented func 191d68133b5SRabin Vincent mcount_adjust_addr r0, lr @ instrumented function 192d3b9dc9dSRabin Vincent adr lr, BSYM(2f) 193181f817eSUwe Kleine-König mov pc, r2 194d3b9dc9dSRabin Vincent2: mcount_exit 195d3b9dc9dSRabin Vincent.endm 196d3b9dc9dSRabin Vincent 197d3b9dc9dSRabin Vincent.macro __ftrace_caller suffix 198d3b9dc9dSRabin Vincent mcount_enter 199d3b9dc9dSRabin Vincent 200d3b9dc9dSRabin Vincent mcount_get_lr r1 @ lr of instrumented func 201d68133b5SRabin Vincent mcount_adjust_addr r0, lr @ instrumented function 202d3b9dc9dSRabin Vincent 203d3b9dc9dSRabin Vincent .globl ftrace_call\suffix 204d3b9dc9dSRabin Vincentftrace_call\suffix: 205d3b9dc9dSRabin Vincent bl ftrace_stub 206d3b9dc9dSRabin Vincent 207dd686eb1SRabin Vincent#ifdef CONFIG_FUNCTION_GRAPH_TRACER 208dd686eb1SRabin Vincent .globl ftrace_graph_call\suffix 209dd686eb1SRabin Vincentftrace_graph_call\suffix: 210dd686eb1SRabin Vincent mov r0, r0 211dd686eb1SRabin Vincent#endif 212dd686eb1SRabin Vincent 213d3b9dc9dSRabin Vincent mcount_exit 214d3b9dc9dSRabin Vincent.endm 215181f817eSUwe Kleine-König 216376cfa87STim Bird.macro __ftrace_graph_caller 217376cfa87STim Bird sub r0, fp, #4 @ &lr of instrumented routine (&parent) 218dd686eb1SRabin Vincent#ifdef CONFIG_DYNAMIC_FTRACE 219dd686eb1SRabin Vincent @ called from __ftrace_caller, saved in mcount_enter 220dd686eb1SRabin Vincent ldr r1, [sp, #16] @ instrumented routine (func) 221d68133b5SRabin Vincent mcount_adjust_addr r1, r1 222dd686eb1SRabin Vincent#else 223dd686eb1SRabin Vincent @ called from __mcount, untouched in lr 224d68133b5SRabin Vincent mcount_adjust_addr r1, lr @ instrumented routine (func) 225dd686eb1SRabin Vincent#endif 226376cfa87STim Bird mov r2, fp @ frame pointer 227376cfa87STim Bird bl prepare_ftrace_return 228376cfa87STim Bird mcount_exit 229376cfa87STim Bird.endm 230014c257cSAbhishek Sagar 23109bfafacSRabin Vincent#ifdef CONFIG_OLD_MCOUNT 23209bfafacSRabin Vincent/* 233d3b9dc9dSRabin Vincent * mcount 23409bfafacSRabin Vincent */ 235014c257cSAbhishek Sagar 236d3b9dc9dSRabin Vincent.macro mcount_enter 237d3b9dc9dSRabin Vincent stmdb sp!, {r0-r3, lr} 238d3b9dc9dSRabin Vincent.endm 239d3b9dc9dSRabin Vincent 240d3b9dc9dSRabin Vincent.macro mcount_get_lr reg 241d3b9dc9dSRabin Vincent ldr \reg, [fp, #-4] 242d3b9dc9dSRabin Vincent.endm 243d3b9dc9dSRabin Vincent 244d3b9dc9dSRabin Vincent.macro mcount_exit 245d3b9dc9dSRabin Vincent ldr lr, [fp, #-4] 246014c257cSAbhishek Sagar ldmia sp!, {r0-r3, pc} 247d3b9dc9dSRabin Vincent.endm 248d3b9dc9dSRabin Vincent 249d3b9dc9dSRabin VincentENTRY(mcount) 250d3b9dc9dSRabin Vincent#ifdef CONFIG_DYNAMIC_FTRACE 251d3b9dc9dSRabin Vincent stmdb sp!, {lr} 252d3b9dc9dSRabin Vincent ldr lr, [fp, #-4] 253d3b9dc9dSRabin Vincent ldmia sp!, {pc} 254d3b9dc9dSRabin Vincent#else 255d3b9dc9dSRabin Vincent __mcount _old 256d3b9dc9dSRabin Vincent#endif 25772fa62faSRabin VincentENDPROC(mcount) 258d3b9dc9dSRabin Vincent 259d3b9dc9dSRabin Vincent#ifdef CONFIG_DYNAMIC_FTRACE 260d3b9dc9dSRabin VincentENTRY(ftrace_caller_old) 261d3b9dc9dSRabin Vincent __ftrace_caller _old 262d3b9dc9dSRabin VincentENDPROC(ftrace_caller_old) 26309bfafacSRabin Vincent#endif 264014c257cSAbhishek Sagar 265376cfa87STim Bird#ifdef CONFIG_FUNCTION_GRAPH_TRACER 266376cfa87STim BirdENTRY(ftrace_graph_caller_old) 267376cfa87STim Bird __ftrace_graph_caller 268376cfa87STim BirdENDPROC(ftrace_graph_caller_old) 269376cfa87STim Bird#endif 270376cfa87STim Bird 271d3b9dc9dSRabin Vincent.purgem mcount_enter 272d3b9dc9dSRabin Vincent.purgem mcount_get_lr 273d3b9dc9dSRabin Vincent.purgem mcount_exit 274d3b9dc9dSRabin Vincent#endif 275d3b9dc9dSRabin Vincent 276d3b9dc9dSRabin Vincent/* 277d3b9dc9dSRabin Vincent * __gnu_mcount_nc 278d3b9dc9dSRabin Vincent */ 279d3b9dc9dSRabin Vincent 280d3b9dc9dSRabin Vincent.macro mcount_enter 281d3b9dc9dSRabin Vincent stmdb sp!, {r0-r3, lr} 282d3b9dc9dSRabin Vincent.endm 283d3b9dc9dSRabin Vincent 284d3b9dc9dSRabin Vincent.macro mcount_get_lr reg 285d3b9dc9dSRabin Vincent ldr \reg, [sp, #20] 286d3b9dc9dSRabin Vincent.endm 287d3b9dc9dSRabin Vincent 288d3b9dc9dSRabin Vincent.macro mcount_exit 289d3b9dc9dSRabin Vincent ldmia sp!, {r0-r3, ip, lr} 290d3b9dc9dSRabin Vincent mov pc, ip 291d3b9dc9dSRabin Vincent.endm 292d3b9dc9dSRabin Vincent 293d3b9dc9dSRabin VincentENTRY(__gnu_mcount_nc) 294d3b9dc9dSRabin Vincent#ifdef CONFIG_DYNAMIC_FTRACE 295d3b9dc9dSRabin Vincent mov ip, lr 296d3b9dc9dSRabin Vincent ldmia sp!, {lr} 297d3b9dc9dSRabin Vincent mov pc, ip 298d3b9dc9dSRabin Vincent#else 299d3b9dc9dSRabin Vincent __mcount 300d3b9dc9dSRabin Vincent#endif 301d3b9dc9dSRabin VincentENDPROC(__gnu_mcount_nc) 302d3b9dc9dSRabin Vincent 303d3b9dc9dSRabin Vincent#ifdef CONFIG_DYNAMIC_FTRACE 304d3b9dc9dSRabin VincentENTRY(ftrace_caller) 305d3b9dc9dSRabin Vincent __ftrace_caller 306d3b9dc9dSRabin VincentENDPROC(ftrace_caller) 307d3b9dc9dSRabin Vincent#endif 308d3b9dc9dSRabin Vincent 309376cfa87STim Bird#ifdef CONFIG_FUNCTION_GRAPH_TRACER 310376cfa87STim BirdENTRY(ftrace_graph_caller) 311376cfa87STim Bird __ftrace_graph_caller 312376cfa87STim BirdENDPROC(ftrace_graph_caller) 313376cfa87STim Bird#endif 314376cfa87STim Bird 315d3b9dc9dSRabin Vincent.purgem mcount_enter 316d3b9dc9dSRabin Vincent.purgem mcount_get_lr 317d3b9dc9dSRabin Vincent.purgem mcount_exit 318014c257cSAbhishek Sagar 319376cfa87STim Bird#ifdef CONFIG_FUNCTION_GRAPH_TRACER 320376cfa87STim Bird .globl return_to_handler 321376cfa87STim Birdreturn_to_handler: 322376cfa87STim Bird stmdb sp!, {r0-r3} 323376cfa87STim Bird mov r0, fp @ frame pointer 324376cfa87STim Bird bl ftrace_return_to_handler 325376cfa87STim Bird mov lr, r0 @ r0 has real ret addr 326376cfa87STim Bird ldmia sp!, {r0-r3} 327376cfa87STim Bird mov pc, lr 328376cfa87STim Bird#endif 329014c257cSAbhishek Sagar 33072fa62faSRabin VincentENTRY(ftrace_stub) 331a3ba87a6SRabin Vincent.Lftrace_stub: 332014c257cSAbhishek Sagar mov pc, lr 33372fa62faSRabin VincentENDPROC(ftrace_stub) 334014c257cSAbhishek Sagar 335606576ceSSteven Rostedt#endif /* CONFIG_FUNCTION_TRACER */ 336014c257cSAbhishek Sagar 3371da177e4SLinus Torvalds/*============================================================================= 3381da177e4SLinus Torvalds * SWI handler 3391da177e4SLinus Torvalds *----------------------------------------------------------------------------- 3401da177e4SLinus Torvalds */ 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds .align 5 3431da177e4SLinus TorvaldsENTRY(vector_swi) 344f4dc9a4cSRussell King sub sp, sp, #S_FRAME_SIZE 345f4dc9a4cSRussell King stmia sp, {r0 - r12} @ Calling r0 - r12 346b86040a5SCatalin Marinas ARM( add r8, sp, #S_PC ) 347b86040a5SCatalin Marinas ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr 348b86040a5SCatalin Marinas THUMB( mov r8, sp ) 349b86040a5SCatalin Marinas THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr 350f4dc9a4cSRussell King mrs r8, spsr @ called from non-FIQ mode, so ok. 351f4dc9a4cSRussell King str lr, [sp, #S_PC] @ Save calling PC 352f4dc9a4cSRussell King str r8, [sp, #S_PSR] @ Save CPSR 353f4dc9a4cSRussell King str r0, [sp, #S_OLD_R0] @ Save OLD_R0 3541da177e4SLinus Torvalds zero_fp 355e0f9f4a6SRussell King 356e0f9f4a6SRussell King /* 357e0f9f4a6SRussell King * Get the system call number. 358e0f9f4a6SRussell King */ 3593f2829a3SNicolas Pitre 360dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT) 3613f2829a3SNicolas Pitre 362dd35afc2SNicolas Pitre /* 363dd35afc2SNicolas Pitre * If we have CONFIG_OABI_COMPAT then we need to look at the swi 364dd35afc2SNicolas Pitre * value to determine if it is an EABI or an old ABI call. 365dd35afc2SNicolas Pitre */ 366dd35afc2SNicolas Pitre#ifdef CONFIG_ARM_THUMB 367dd35afc2SNicolas Pitre tst r8, #PSR_T_BIT 368dd35afc2SNicolas Pitre movne r10, #0 @ no thumb OABI emulation 369dd35afc2SNicolas Pitre ldreq r10, [lr, #-4] @ get SWI instruction 370dd35afc2SNicolas Pitre#else 371dd35afc2SNicolas Pitre ldr r10, [lr, #-4] @ get SWI instruction 372dd35afc2SNicolas Pitre#endif 37326584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8 37426584853SCatalin Marinas rev r10, r10 @ little endian instruction 37526584853SCatalin Marinas#endif 376dd35afc2SNicolas Pitre 377dd35afc2SNicolas Pitre#elif defined(CONFIG_AEABI) 378dd35afc2SNicolas Pitre 379dd35afc2SNicolas Pitre /* 380dd35afc2SNicolas Pitre * Pure EABI user space always put syscall number into scno (r7). 381dd35afc2SNicolas Pitre */ 3823f2829a3SNicolas Pitre#elif defined(CONFIG_ARM_THUMB) 383dd35afc2SNicolas Pitre /* Legacy ABI only, possibly thumb mode. */ 384e0f9f4a6SRussell King tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs 385e0f9f4a6SRussell King addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in 386e0f9f4a6SRussell King ldreq scno, [lr, #-4] 387dd35afc2SNicolas Pitre 388e0f9f4a6SRussell King#else 389dd35afc2SNicolas Pitre /* Legacy ABI only. */ 390e0f9f4a6SRussell King ldr scno, [lr, #-4] @ get SWI instruction 391e0f9f4a6SRussell King#endif 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP 3941da177e4SLinus Torvalds ldr ip, __cr_alignment 3951da177e4SLinus Torvalds ldr ip, [ip] 3961da177e4SLinus Torvalds mcr p15, 0, ip, c1, c0 @ update control register 3971da177e4SLinus Torvalds#endif 3981ec42c0cSRussell King enable_irq 399b0088480SKevin Hilman ct_user_exit 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds get_thread_info tsk 402dd35afc2SNicolas Pitre adr tbl, sys_call_table @ load syscall table pointer 403dd35afc2SNicolas Pitre 404dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT) 405dd35afc2SNicolas Pitre /* 406dd35afc2SNicolas Pitre * If the swi argument is zero, this is an EABI call and we do nothing. 407dd35afc2SNicolas Pitre * 408dd35afc2SNicolas Pitre * If this is an old ABI call, get the syscall number into scno and 409dd35afc2SNicolas Pitre * get the old ABI syscall table address. 410dd35afc2SNicolas Pitre */ 411dd35afc2SNicolas Pitre bics r10, r10, #0xff000000 412dd35afc2SNicolas Pitre eorne scno, r10, #__NR_OABI_SYSCALL_BASE 413dd35afc2SNicolas Pitre ldrne tbl, =sys_oabi_call_table 414dd35afc2SNicolas Pitre#elif !defined(CONFIG_AEABI) 4151da177e4SLinus Torvalds bic scno, scno, #0xff000000 @ mask off SWI op-code 416e0f9f4a6SRussell King eor scno, scno, #__NR_SYSCALL_BASE @ check OS number 4173f2829a3SNicolas Pitre#endif 418dd35afc2SNicolas Pitre 41981783786SAl Virolocal_restart: 42070c70d97SNicolas Pitre ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing 4213f2829a3SNicolas Pitre stmdb sp!, {r4, r5} @ push fifth and sixth args 42270c70d97SNicolas Pitre 42329ef73b7SNathaniel Husted tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? 4241da177e4SLinus Torvalds bne __sys_trace 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds cmp scno, #NR_syscalls @ check upper syscall limit 427b86040a5SCatalin Marinas adr lr, BSYM(ret_fast_syscall) @ return address 4281da177e4SLinus Torvalds ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds add r1, sp, #S_OFF 4311da177e4SLinus Torvalds2: mov why, #0 @ no longer a real syscall 432e0f9f4a6SRussell King cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) 433e0f9f4a6SRussell King eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back 4341da177e4SLinus Torvalds bcs arm_syscall 4351da177e4SLinus Torvalds b sys_ni_syscall @ not private func 43693ed3970SCatalin MarinasENDPROC(vector_swi) 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds /* 4391da177e4SLinus Torvalds * This is the really slow path. We're going to be doing 4401da177e4SLinus Torvalds * context switches, and waiting for our parent to respond. 4411da177e4SLinus Torvalds */ 4421da177e4SLinus Torvalds__sys_trace: 443ad722541SWill Deacon mov r1, scno 444ad722541SWill Deacon add r0, sp, #S_OFF 445ad722541SWill Deacon bl syscall_trace_enter 4461da177e4SLinus Torvalds 447b86040a5SCatalin Marinas adr lr, BSYM(__sys_trace_return) @ return address 4483f471126SNicolas Pitre mov scno, r0 @ syscall number (possibly new) 4491da177e4SLinus Torvalds add r1, sp, #S_R0 + S_OFF @ pointer to regs 4501da177e4SLinus Torvalds cmp scno, #NR_syscalls @ check upper syscall limit 451c7aa00dbSWill Deacon ldmccia r1, {r0 - r6} @ have to reload r0 - r6 452c7aa00dbSWill Deacon stmccia sp, {r4, r5} @ and update the stack args 4531da177e4SLinus Torvalds ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine 454ad75b514SKees Cook cmp scno, #-1 @ skip the syscall? 455ad75b514SKees Cook bne 2b 456ad75b514SKees Cook add sp, sp, #S_OFF @ restore stack 457ad75b514SKees Cook b ret_slow_syscall 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds__sys_trace_return: 4601da177e4SLinus Torvalds str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 461ad722541SWill Deacon mov r0, sp 462ad722541SWill Deacon bl syscall_trace_exit 4631da177e4SLinus Torvalds b ret_slow_syscall 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds .align 5 4661da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP 4671da177e4SLinus Torvalds .type __cr_alignment, #object 4681da177e4SLinus Torvalds__cr_alignment: 4691da177e4SLinus Torvalds .word cr_alignment 4701da177e4SLinus Torvalds#endif 471dd35afc2SNicolas Pitre .ltorg 472dd35afc2SNicolas Pitre 473dd35afc2SNicolas Pitre/* 474dd35afc2SNicolas Pitre * This is the syscall table declaration for native ABI syscalls. 475dd35afc2SNicolas Pitre * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall. 476dd35afc2SNicolas Pitre */ 477dd35afc2SNicolas Pitre#define ABI(native, compat) native 478dd35afc2SNicolas Pitre#ifdef CONFIG_AEABI 479dd35afc2SNicolas Pitre#define OBSOLETE(syscall) sys_ni_syscall 480dd35afc2SNicolas Pitre#else 481dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall 482dd35afc2SNicolas Pitre#endif 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds .type sys_call_table, #object 4851da177e4SLinus TorvaldsENTRY(sys_call_table) 4861da177e4SLinus Torvalds#include "calls.S" 487dd35afc2SNicolas Pitre#undef ABI 488dd35afc2SNicolas Pitre#undef OBSOLETE 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds/*============================================================================ 4911da177e4SLinus Torvalds * Special system call wrappers 4921da177e4SLinus Torvalds */ 4931da177e4SLinus Torvalds@ r0 = syscall number 494567bd980SRussell King@ r8 = syscall table 4951da177e4SLinus Torvaldssys_syscall: 4965247593cSPaul Brook bic scno, r0, #__NR_OABI_SYSCALL_BASE 4971da177e4SLinus Torvalds cmp scno, #__NR_syscall - __NR_SYSCALL_BASE 4981da177e4SLinus Torvalds cmpne scno, #NR_syscalls @ check range 4991da177e4SLinus Torvalds stmloia sp, {r5, r6} @ shuffle args 5001da177e4SLinus Torvalds movlo r0, r1 5011da177e4SLinus Torvalds movlo r1, r2 5021da177e4SLinus Torvalds movlo r2, r3 5031da177e4SLinus Torvalds movlo r3, r4 5041da177e4SLinus Torvalds ldrlo pc, [tbl, scno, lsl #2] 5051da177e4SLinus Torvalds b sys_ni_syscall 50693ed3970SCatalin MarinasENDPROC(sys_syscall) 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvaldssys_sigreturn_wrapper: 5091da177e4SLinus Torvalds add r0, sp, #S_OFF 510653d48b2SAl Viro mov why, #0 @ prevent syscall restart handling 5111da177e4SLinus Torvalds b sys_sigreturn 51293ed3970SCatalin MarinasENDPROC(sys_sigreturn_wrapper) 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvaldssys_rt_sigreturn_wrapper: 5151da177e4SLinus Torvalds add r0, sp, #S_OFF 516653d48b2SAl Viro mov why, #0 @ prevent syscall restart handling 5171da177e4SLinus Torvalds b sys_rt_sigreturn 51893ed3970SCatalin MarinasENDPROC(sys_rt_sigreturn_wrapper) 5191da177e4SLinus Torvalds 520713c4815SNicolas Pitresys_statfs64_wrapper: 521713c4815SNicolas Pitre teq r1, #88 522713c4815SNicolas Pitre moveq r1, #84 523713c4815SNicolas Pitre b sys_statfs64 52493ed3970SCatalin MarinasENDPROC(sys_statfs64_wrapper) 525713c4815SNicolas Pitre 526713c4815SNicolas Pitresys_fstatfs64_wrapper: 527713c4815SNicolas Pitre teq r1, #88 528713c4815SNicolas Pitre moveq r1, #84 529713c4815SNicolas Pitre b sys_fstatfs64 53093ed3970SCatalin MarinasENDPROC(sys_fstatfs64_wrapper) 531713c4815SNicolas Pitre 5321da177e4SLinus Torvalds/* 5331da177e4SLinus Torvalds * Note: off_4k (r5) is always units of 4K. If we can't do the requested 5341da177e4SLinus Torvalds * offset, we return EINVAL. 5351da177e4SLinus Torvalds */ 5361da177e4SLinus Torvaldssys_mmap2: 5371da177e4SLinus Torvalds#if PAGE_SHIFT > 12 5381da177e4SLinus Torvalds tst r5, #PGOFF_MASK 5391da177e4SLinus Torvalds moveq r5, r5, lsr #PAGE_SHIFT - 12 5401da177e4SLinus Torvalds streq r5, [sp, #4] 541f8b72560SAl Viro beq sys_mmap_pgoff 5421da177e4SLinus Torvalds mov r0, #-EINVAL 5437999d8d7SRussell King mov pc, lr 5441da177e4SLinus Torvalds#else 5451da177e4SLinus Torvalds str r5, [sp, #4] 546f8b72560SAl Viro b sys_mmap_pgoff 5471da177e4SLinus Torvalds#endif 54893ed3970SCatalin MarinasENDPROC(sys_mmap2) 549687ad019SNicolas Pitre 550687ad019SNicolas Pitre#ifdef CONFIG_OABI_COMPAT 551dd35afc2SNicolas Pitre 552687ad019SNicolas Pitre/* 553687ad019SNicolas Pitre * These are syscalls with argument register differences 554687ad019SNicolas Pitre */ 555687ad019SNicolas Pitre 556687ad019SNicolas Pitresys_oabi_pread64: 557687ad019SNicolas Pitre stmia sp, {r3, r4} 558687ad019SNicolas Pitre b sys_pread64 55993ed3970SCatalin MarinasENDPROC(sys_oabi_pread64) 560687ad019SNicolas Pitre 561687ad019SNicolas Pitresys_oabi_pwrite64: 562687ad019SNicolas Pitre stmia sp, {r3, r4} 563687ad019SNicolas Pitre b sys_pwrite64 56493ed3970SCatalin MarinasENDPROC(sys_oabi_pwrite64) 565687ad019SNicolas Pitre 566687ad019SNicolas Pitresys_oabi_truncate64: 567687ad019SNicolas Pitre mov r3, r2 568687ad019SNicolas Pitre mov r2, r1 569687ad019SNicolas Pitre b sys_truncate64 57093ed3970SCatalin MarinasENDPROC(sys_oabi_truncate64) 571687ad019SNicolas Pitre 572687ad019SNicolas Pitresys_oabi_ftruncate64: 573687ad019SNicolas Pitre mov r3, r2 574687ad019SNicolas Pitre mov r2, r1 575687ad019SNicolas Pitre b sys_ftruncate64 57693ed3970SCatalin MarinasENDPROC(sys_oabi_ftruncate64) 577687ad019SNicolas Pitre 578687ad019SNicolas Pitresys_oabi_readahead: 579687ad019SNicolas Pitre str r3, [sp] 580687ad019SNicolas Pitre mov r3, r2 581687ad019SNicolas Pitre mov r2, r1 582687ad019SNicolas Pitre b sys_readahead 58393ed3970SCatalin MarinasENDPROC(sys_oabi_readahead) 584687ad019SNicolas Pitre 585dd35afc2SNicolas Pitre/* 586dd35afc2SNicolas Pitre * Let's declare a second syscall table for old ABI binaries 587dd35afc2SNicolas Pitre * using the compatibility syscall entries. 588dd35afc2SNicolas Pitre */ 589dd35afc2SNicolas Pitre#define ABI(native, compat) compat 590dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall 591dd35afc2SNicolas Pitre 592dd35afc2SNicolas Pitre .type sys_oabi_call_table, #object 593dd35afc2SNicolas PitreENTRY(sys_oabi_call_table) 594dd35afc2SNicolas Pitre#include "calls.S" 595dd35afc2SNicolas Pitre#undef ABI 596dd35afc2SNicolas Pitre#undef OBSOLETE 597dd35afc2SNicolas Pitre 598687ad019SNicolas Pitre#endif 599687ad019SNicolas Pitre 600