1/* 2 * linux/arch/arm/kernel/entry-common.S 3 * 4 * Copyright (C) 2000 Russell King 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11#include <asm/unistd.h> 12#include <asm/arch/entry-macro.S> 13 14#include "entry-header.S" 15 16 17 .align 5 18/* 19 * This is the fast syscall return path. We do as little as 20 * possible here, and this includes saving r0 back into the SVC 21 * stack. 22 */ 23ret_fast_syscall: 24 disable_irq @ disable interrupts 25 ldr r1, [tsk, #TI_FLAGS] 26 tst r1, #_TIF_WORK_MASK 27 bne fast_work_pending 28 29 /* perform architecture specific actions before user return */ 30 arch_ret_to_user r1, lr 31 32 @ fast_restore_user_regs 33 ldr r1, [sp, #S_OFF + S_PSR] @ get calling cpsr 34 ldr lr, [sp, #S_OFF + S_PC]! @ get pc 35 msr spsr_cxsf, r1 @ save in spsr_svc 36 ldmdb sp, {r1 - lr}^ @ get calling r1 - lr 37 mov r0, r0 38 add sp, sp, #S_FRAME_SIZE - S_PC 39 movs pc, lr @ return & move spsr_svc into cpsr 40 41/* 42 * Ok, we need to do extra processing, enter the slow path. 43 */ 44fast_work_pending: 45 str r0, [sp, #S_R0+S_OFF]! @ returned r0 46work_pending: 47 tst r1, #_TIF_NEED_RESCHED 48 bne work_resched 49 tst r1, #_TIF_SIGPENDING 50 beq no_work_pending 51 mov r0, sp @ 'regs' 52 mov r2, why @ 'syscall' 53 bl do_notify_resume 54 b ret_slow_syscall @ Check work again 55 56work_resched: 57 bl schedule 58/* 59 * "slow" syscall return path. "why" tells us if this was a real syscall. 60 */ 61ENTRY(ret_to_user) 62ret_slow_syscall: 63 disable_irq @ disable interrupts 64 ldr r1, [tsk, #TI_FLAGS] 65 tst r1, #_TIF_WORK_MASK 66 bne work_pending 67no_work_pending: 68 /* perform architecture specific actions before user return */ 69 arch_ret_to_user r1, lr 70 71 @ slow_restore_user_regs 72 ldr r1, [sp, #S_PSR] @ get calling cpsr 73 ldr lr, [sp, #S_PC]! @ get pc 74 msr spsr_cxsf, r1 @ save in spsr_svc 75 ldmdb sp, {r0 - lr}^ @ get calling r0 - lr 76 mov r0, r0 77 add sp, sp, #S_FRAME_SIZE - S_PC 78 movs pc, lr @ return & move spsr_svc into cpsr 79 80/* 81 * This is how we return from a fork. 82 */ 83ENTRY(ret_from_fork) 84 bl schedule_tail 85 get_thread_info tsk 86 ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing 87 mov why, #1 88 tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls? 89 beq ret_slow_syscall 90 mov r1, sp 91 mov r0, #1 @ trace exit [IP = 1] 92 bl syscall_trace 93 b ret_slow_syscall 94 95 96 .equ NR_syscalls,0 97#define CALL(x) .equ NR_syscalls,NR_syscalls+1 98#include "calls.S" 99#undef CALL 100#define CALL(x) .long x 101 102/*============================================================================= 103 * SWI handler 104 *----------------------------------------------------------------------------- 105 */ 106 107 /* If we're optimising for StrongARM the resulting code won't 108 run on an ARM7 and we can save a couple of instructions. 109 --pb */ 110#ifdef CONFIG_CPU_ARM710 111#define A710(code...) code 112.Larm710bug: 113 ldmia sp, {r0 - lr}^ @ Get calling r0 - lr 114 mov r0, r0 115 add sp, sp, #S_FRAME_SIZE 116 subs pc, lr, #4 117#else 118#define A710(code...) 119#endif 120 121 .align 5 122ENTRY(vector_swi) 123 sub sp, sp, #S_FRAME_SIZE 124 stmia sp, {r0 - r12} @ Calling r0 - r12 125 add r8, sp, #S_PC 126 stmdb r8, {sp, lr}^ @ Calling sp, lr 127 mrs r8, spsr @ called from non-FIQ mode, so ok. 128 str lr, [sp, #S_PC] @ Save calling PC 129 str r8, [sp, #S_PSR] @ Save CPSR 130 str r0, [sp, #S_OLD_R0] @ Save OLD_R0 131 zero_fp 132 133 /* 134 * Get the system call number. 135 */ 136 137#if defined(CONFIG_OABI_COMPAT) 138 139 /* 140 * If we have CONFIG_OABI_COMPAT then we need to look at the swi 141 * value to determine if it is an EABI or an old ABI call. 142 */ 143#ifdef CONFIG_ARM_THUMB 144 tst r8, #PSR_T_BIT 145 movne r10, #0 @ no thumb OABI emulation 146 ldreq r10, [lr, #-4] @ get SWI instruction 147#else 148 ldr r10, [lr, #-4] @ get SWI instruction 149 A710( and ip, r10, #0x0f000000 @ check for SWI ) 150 A710( teq ip, #0x0f000000 ) 151 A710( bne .Larm710bug ) 152#endif 153 154#elif defined(CONFIG_AEABI) 155 156 /* 157 * Pure EABI user space always put syscall number into scno (r7). 158 */ 159 A710( ldr ip, [lr, #-4] @ get SWI instruction ) 160 A710( and ip, ip, #0x0f000000 @ check for SWI ) 161 A710( teq ip, #0x0f000000 ) 162 A710( bne .Larm710bug ) 163 164#elif defined(CONFIG_ARM_THUMB) 165 166 /* Legacy ABI only, possibly thumb mode. */ 167 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs 168 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in 169 ldreq scno, [lr, #-4] 170 171#else 172 173 /* Legacy ABI only. */ 174 ldr scno, [lr, #-4] @ get SWI instruction 175 A710( and ip, scno, #0x0f000000 @ check for SWI ) 176 A710( teq ip, #0x0f000000 ) 177 A710( bne .Larm710bug ) 178 179#endif 180 181#ifdef CONFIG_ALIGNMENT_TRAP 182 ldr ip, __cr_alignment 183 ldr ip, [ip] 184 mcr p15, 0, ip, c1, c0 @ update control register 185#endif 186 enable_irq 187 188 get_thread_info tsk 189 adr tbl, sys_call_table @ load syscall table pointer 190 ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing 191 192#if defined(CONFIG_OABI_COMPAT) 193 /* 194 * If the swi argument is zero, this is an EABI call and we do nothing. 195 * 196 * If this is an old ABI call, get the syscall number into scno and 197 * get the old ABI syscall table address. 198 */ 199 bics r10, r10, #0xff000000 200 eorne scno, r10, #__NR_OABI_SYSCALL_BASE 201 ldrne tbl, =sys_oabi_call_table 202#elif !defined(CONFIG_AEABI) 203 bic scno, scno, #0xff000000 @ mask off SWI op-code 204 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number 205#endif 206 207 stmdb sp!, {r4, r5} @ push fifth and sixth args 208 tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls? 209 bne __sys_trace 210 211 cmp scno, #NR_syscalls @ check upper syscall limit 212 adr lr, ret_fast_syscall @ return address 213 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine 214 215 add r1, sp, #S_OFF 2162: mov why, #0 @ no longer a real syscall 217 cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) 218 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back 219 bcs arm_syscall 220 b sys_ni_syscall @ not private func 221 222 /* 223 * This is the really slow path. We're going to be doing 224 * context switches, and waiting for our parent to respond. 225 */ 226__sys_trace: 227 mov r2, scno 228 add r1, sp, #S_OFF 229 mov r0, #0 @ trace entry [IP = 0] 230 bl syscall_trace 231 232 adr lr, __sys_trace_return @ return address 233 mov scno, r0 @ syscall number (possibly new) 234 add r1, sp, #S_R0 + S_OFF @ pointer to regs 235 cmp scno, #NR_syscalls @ check upper syscall limit 236 ldmccia r1, {r0 - r3} @ have to reload r0 - r3 237 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine 238 b 2b 239 240__sys_trace_return: 241 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 242 mov r2, scno 243 mov r1, sp 244 mov r0, #1 @ trace exit [IP = 1] 245 bl syscall_trace 246 b ret_slow_syscall 247 248 .align 5 249#ifdef CONFIG_ALIGNMENT_TRAP 250 .type __cr_alignment, #object 251__cr_alignment: 252 .word cr_alignment 253#endif 254 .ltorg 255 256/* 257 * This is the syscall table declaration for native ABI syscalls. 258 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall. 259 */ 260#define ABI(native, compat) native 261#ifdef CONFIG_AEABI 262#define OBSOLETE(syscall) sys_ni_syscall 263#else 264#define OBSOLETE(syscall) syscall 265#endif 266 267 .type sys_call_table, #object 268ENTRY(sys_call_table) 269#include "calls.S" 270#undef ABI 271#undef OBSOLETE 272 273/*============================================================================ 274 * Special system call wrappers 275 */ 276@ r0 = syscall number 277@ r8 = syscall table 278 .type sys_syscall, #function 279sys_syscall: 280 bic scno, r0, #__NR_OABI_SYSCALL_BASE 281 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE 282 cmpne scno, #NR_syscalls @ check range 283 stmloia sp, {r5, r6} @ shuffle args 284 movlo r0, r1 285 movlo r1, r2 286 movlo r2, r3 287 movlo r3, r4 288 ldrlo pc, [tbl, scno, lsl #2] 289 b sys_ni_syscall 290 291sys_fork_wrapper: 292 add r0, sp, #S_OFF 293 b sys_fork 294 295sys_vfork_wrapper: 296 add r0, sp, #S_OFF 297 b sys_vfork 298 299sys_execve_wrapper: 300 add r3, sp, #S_OFF 301 b sys_execve 302 303sys_clone_wrapper: 304 add ip, sp, #S_OFF 305 str ip, [sp, #4] 306 b sys_clone 307 308sys_sigsuspend_wrapper: 309 add r3, sp, #S_OFF 310 b sys_sigsuspend 311 312sys_rt_sigsuspend_wrapper: 313 add r2, sp, #S_OFF 314 b sys_rt_sigsuspend 315 316sys_sigreturn_wrapper: 317 add r0, sp, #S_OFF 318 b sys_sigreturn 319 320sys_rt_sigreturn_wrapper: 321 add r0, sp, #S_OFF 322 b sys_rt_sigreturn 323 324sys_sigaltstack_wrapper: 325 ldr r2, [sp, #S_OFF + S_SP] 326 b do_sigaltstack 327 328sys_statfs64_wrapper: 329 teq r1, #88 330 moveq r1, #84 331 b sys_statfs64 332 333sys_fstatfs64_wrapper: 334 teq r1, #88 335 moveq r1, #84 336 b sys_fstatfs64 337 338/* 339 * Note: off_4k (r5) is always units of 4K. If we can't do the requested 340 * offset, we return EINVAL. 341 */ 342sys_mmap2: 343#if PAGE_SHIFT > 12 344 tst r5, #PGOFF_MASK 345 moveq r5, r5, lsr #PAGE_SHIFT - 12 346 streq r5, [sp, #4] 347 beq do_mmap2 348 mov r0, #-EINVAL 349 mov pc, lr 350#else 351 str r5, [sp, #4] 352 b do_mmap2 353#endif 354 355#ifdef CONFIG_OABI_COMPAT 356 357/* 358 * These are syscalls with argument register differences 359 */ 360 361sys_oabi_pread64: 362 stmia sp, {r3, r4} 363 b sys_pread64 364 365sys_oabi_pwrite64: 366 stmia sp, {r3, r4} 367 b sys_pwrite64 368 369sys_oabi_truncate64: 370 mov r3, r2 371 mov r2, r1 372 b sys_truncate64 373 374sys_oabi_ftruncate64: 375 mov r3, r2 376 mov r2, r1 377 b sys_ftruncate64 378 379sys_oabi_readahead: 380 str r3, [sp] 381 mov r3, r2 382 mov r2, r1 383 b sys_readahead 384 385/* 386 * Let's declare a second syscall table for old ABI binaries 387 * using the compatibility syscall entries. 388 */ 389#define ABI(native, compat) compat 390#define OBSOLETE(syscall) syscall 391 392 .type sys_oabi_call_table, #object 393ENTRY(sys_oabi_call_table) 394#include "calls.S" 395#undef ABI 396#undef OBSOLETE 397 398#endif 399 400