Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 11 | #include <asm/assembler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/unistd.h> |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 13 | #include <asm/ftrace.h> |
Catalin Marinas | c4c5716 | 2009-02-16 11:42:09 +0100 | [diff] [blame] | 14 | #include <asm/unwind.h> |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 15 | #ifdef CONFIG_AEABI |
| 16 | #include <asm/unistd-oabi.h> |
| 17 | #endif |
| 18 | |
| 19 | .equ NR_syscalls, __NR_syscalls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Rob Herring | 13a5045 | 2012-02-07 09:28:22 -0600 | [diff] [blame] | 21 | #ifdef CONFIG_NEED_RET_TO_USER |
| 22 | #include <mach/entry-macro.S> |
| 23 | #else |
| 24 | .macro arch_ret_to_user, tmp1, tmp2 |
| 25 | .endm |
| 26 | #endif |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "entry-header.S" |
| 29 | |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 30 | saved_psr .req r8 |
Russell King | fcea452 | 2017-03-24 16:22:10 +0000 | [diff] [blame] | 31 | #if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING) |
| 32 | saved_pc .req r9 |
| 33 | #define TRACE(x...) x |
| 34 | #else |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 35 | saved_pc .req lr |
Russell King | fcea452 | 2017-03-24 16:22:10 +0000 | [diff] [blame] | 36 | #define TRACE(x...) |
| 37 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | .align 5 |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 40 | #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 42 | * This is the fast syscall return path. We do as little as possible here, |
| 43 | * such as avoiding writing r0 to the stack. We only use this path if we |
| 44 | * have tracing and context tracking disabled - the overheads from those |
| 45 | * features make this path too inefficient. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | */ |
| 47 | ret_fast_syscall: |
Catalin Marinas | c4c5716 | 2009-02-16 11:42:09 +0100 | [diff] [blame] | 48 | UNWIND(.fnstart ) |
| 49 | UNWIND(.cantunwind ) |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 50 | disable_irq_notrace @ disable interrupts |
Russell King | 1b97937 | 2015-05-15 11:02:23 +0100 | [diff] [blame] | 51 | ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing |
Thomas Garnier | 73ac5d6 | 2017-06-14 18:12:02 -0700 | [diff] [blame] | 52 | tst r1, #_TIF_SYSCALL_WORK |
| 53 | bne fast_work_pending |
| 54 | tst r1, #_TIF_WORK_MASK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | bne fast_work_pending |
Russell King | f4dc9a4 | 2005-04-26 15:20:34 +0100 | [diff] [blame] | 56 | |
Dan Williams | f80dff9 | 2007-02-16 22:16:32 +0100 | [diff] [blame] | 57 | /* perform architecture specific actions before user return */ |
| 58 | arch_ret_to_user r1, lr |
| 59 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 60 | restore_user_regs fast = 1, offset = S_OFF |
Catalin Marinas | c4c5716 | 2009-02-16 11:42:09 +0100 | [diff] [blame] | 61 | UNWIND(.fnend ) |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 62 | ENDPROC(ret_fast_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 64 | /* Ok, we need to do extra processing, enter the slow path. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | fast_work_pending: |
| 66 | str r0, [sp, #S_R0+S_OFF]! @ returned r0 |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 67 | /* fall through to work_pending */ |
| 68 | #else |
| 69 | /* |
| 70 | * The "replacement" ret_fast_syscall for when tracing or context tracking |
| 71 | * is enabled. As we will need to call out to some C functions, we save |
| 72 | * r0 first to avoid needing to save registers around each C function call. |
| 73 | */ |
| 74 | ret_fast_syscall: |
| 75 | UNWIND(.fnstart ) |
| 76 | UNWIND(.cantunwind ) |
| 77 | str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 |
| 78 | disable_irq_notrace @ disable interrupts |
| 79 | ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing |
Thomas Garnier | 73ac5d6 | 2017-06-14 18:12:02 -0700 | [diff] [blame] | 80 | tst r1, #_TIF_SYSCALL_WORK |
| 81 | bne fast_work_pending |
| 82 | tst r1, #_TIF_WORK_MASK |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 83 | beq no_work_pending |
| 84 | UNWIND(.fnend ) |
| 85 | ENDPROC(ret_fast_syscall) |
| 86 | |
| 87 | /* Slower path - fall through to work_pending */ |
Thomas Garnier | 73ac5d6 | 2017-06-14 18:12:02 -0700 | [diff] [blame] | 88 | fast_work_pending: |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | tst r1, #_TIF_SYSCALL_WORK |
| 92 | bne __sys_trace_return_nosave |
| 93 | slow_work_pending: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | mov r0, sp @ 'regs' |
| 95 | mov r2, why @ 'syscall' |
Al Viro | 0a267fa | 2012-07-19 17:47:55 +0100 | [diff] [blame] | 96 | bl do_work_pending |
Al Viro | 6628521 | 2012-07-19 17:48:50 +0100 | [diff] [blame] | 97 | cmp r0, #0 |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 98 | beq no_work_pending |
Al Viro | 6628521 | 2012-07-19 17:48:50 +0100 | [diff] [blame] | 99 | movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE) |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 100 | ldmia sp, {r0 - r6} @ have to reload r0 - r6 |
| 101 | b local_restart @ ... and off we go |
Drew Richardson | e83dd37 | 2015-08-06 18:50:27 +0100 | [diff] [blame] | 102 | ENDPROC(ret_fast_syscall) |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * "slow" syscall return path. "why" tells us if this was a real syscall. |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 106 | * IRQs may be enabled here, so always disable them. Note that we use the |
| 107 | * "notrace" version to avoid calling into the tracing code unnecessarily. |
| 108 | * do_work_pending() will update this state if necessary. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | */ |
| 110 | ENTRY(ret_to_user) |
| 111 | ret_slow_syscall: |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 112 | disable_irq_notrace @ disable interrupts |
Ming Lei | 9fc2552 | 2011-06-05 02:24:58 +0100 | [diff] [blame] | 113 | ENTRY(ret_to_user_from_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | ldr r1, [tsk, #TI_FLAGS] |
| 115 | tst r1, #_TIF_WORK_MASK |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 116 | bne slow_work_pending |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | no_work_pending: |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 118 | asm_trace_hardirqs_on save = 0 |
Russell King | 651e949 | 2013-03-28 11:44:25 +0000 | [diff] [blame] | 119 | |
Dan Williams | f80dff9 | 2007-02-16 22:16:32 +0100 | [diff] [blame] | 120 | /* perform architecture specific actions before user return */ |
| 121 | arch_ret_to_user r1, lr |
Kevin Hilman | b008848 | 2013-03-28 22:54:40 +0100 | [diff] [blame] | 122 | ct_user_enter save = 0 |
Dan Williams | f80dff9 | 2007-02-16 22:16:32 +0100 | [diff] [blame] | 123 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 124 | restore_user_regs fast = 0, offset = 0 |
Ming Lei | 9fc2552 | 2011-06-05 02:24:58 +0100 | [diff] [blame] | 125 | ENDPROC(ret_to_user_from_irq) |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 126 | ENDPROC(ret_to_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * This is how we return from a fork. |
| 130 | */ |
| 131 | ENTRY(ret_from_fork) |
| 132 | bl schedule_tail |
Al Viro | 9fff2fa | 2012-10-10 22:23:29 -0400 | [diff] [blame] | 133 | cmp r5, #0 |
| 134 | movne r0, r4 |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 135 | badrne lr, 1f |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 136 | retne r5 |
Russell King | 68687c8 | 2012-10-15 00:16:49 +0100 | [diff] [blame] | 137 | 1: get_thread_info tsk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | b ret_slow_syscall |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 139 | ENDPROC(ret_from_fork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /*============================================================================= |
| 142 | * SWI handler |
| 143 | *----------------------------------------------------------------------------- |
| 144 | */ |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | .align 5 |
| 147 | ENTRY(vector_swi) |
Uwe Kleine-König | 19c4d59 | 2010-05-21 18:06:42 +0100 | [diff] [blame] | 148 | #ifdef CONFIG_CPU_V7M |
| 149 | v7m_exception_entry |
| 150 | #else |
Russell King | 5745eef6 | 2016-05-10 16:34:27 +0100 | [diff] [blame] | 151 | sub sp, sp, #PT_REGS_SIZE |
Russell King | f4dc9a4 | 2005-04-26 15:20:34 +0100 | [diff] [blame] | 152 | stmia sp, {r0 - r12} @ Calling r0 - r12 |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 153 | ARM( add r8, sp, #S_PC ) |
| 154 | ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr |
| 155 | THUMB( mov r8, sp ) |
| 156 | THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 157 | mrs saved_psr, spsr @ called from non-FIQ mode, so ok. |
Russell King | fcea452 | 2017-03-24 16:22:10 +0000 | [diff] [blame] | 158 | TRACE( mov saved_pc, lr ) |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 159 | str saved_pc, [sp, #S_PC] @ Save calling PC |
| 160 | str saved_psr, [sp, #S_PSR] @ Save CPSR |
Russell King | f4dc9a4 | 2005-04-26 15:20:34 +0100 | [diff] [blame] | 161 | str r0, [sp, #S_OLD_R0] @ Save OLD_R0 |
Uwe Kleine-König | 19c4d59 | 2010-05-21 18:06:42 +0100 | [diff] [blame] | 162 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | zero_fp |
Russell King | 195b58a | 2014-08-28 13:08:14 +0100 | [diff] [blame] | 164 | alignment_trap r10, ip, __cr_alignment |
Russell King | dca778c | 2017-03-24 16:23:25 +0000 | [diff] [blame] | 165 | asm_trace_hardirqs_on save=0 |
| 166 | enable_irq_notrace |
| 167 | ct_user_exit save=0 |
Will Deacon | 1aa2b3b | 2013-06-05 11:25:13 +0100 | [diff] [blame] | 168 | |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 169 | /* |
| 170 | * Get the system call number. |
| 171 | */ |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 172 | |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 173 | #if defined(CONFIG_OABI_COMPAT) |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 174 | |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 175 | /* |
| 176 | * If we have CONFIG_OABI_COMPAT then we need to look at the swi |
| 177 | * value to determine if it is an EABI or an old ABI call. |
| 178 | */ |
| 179 | #ifdef CONFIG_ARM_THUMB |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 180 | tst saved_psr, #PSR_T_BIT |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 181 | movne r10, #0 @ no thumb OABI emulation |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 182 | USER( ldreq r10, [saved_pc, #-4] ) @ get SWI instruction |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 183 | #else |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 184 | USER( ldr r10, [saved_pc, #-4] ) @ get SWI instruction |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 185 | #endif |
Ben Dooks | 457c240 | 2013-02-12 18:59:57 +0000 | [diff] [blame] | 186 | ARM_BE8(rev r10, r10) @ little endian instruction |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 187 | |
| 188 | #elif defined(CONFIG_AEABI) |
| 189 | |
| 190 | /* |
| 191 | * Pure EABI user space always put syscall number into scno (r7). |
| 192 | */ |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 193 | #elif defined(CONFIG_ARM_THUMB) |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 194 | /* Legacy ABI only, possibly thumb mode. */ |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 195 | tst saved_psr, #PSR_T_BIT @ this is SPSR from save_user_regs |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 196 | addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 197 | USER( ldreq scno, [saved_pc, #-4] ) |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 198 | |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 199 | #else |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 200 | /* Legacy ABI only. */ |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 201 | USER( ldr scno, [saved_pc, #-4] ) @ get SWI instruction |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 204 | /* saved_psr and saved_pc are now dead */ |
| 205 | |
Russell King | 2190fed | 2015-08-20 10:32:02 +0100 | [diff] [blame] | 206 | uaccess_disable tbl |
| 207 | |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 208 | adr tbl, sys_call_table @ load syscall table pointer |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 209 | |
| 210 | #if defined(CONFIG_OABI_COMPAT) |
| 211 | /* |
| 212 | * If the swi argument is zero, this is an EABI call and we do nothing. |
| 213 | * |
| 214 | * If this is an old ABI call, get the syscall number into scno and |
| 215 | * get the old ABI syscall table address. |
| 216 | */ |
| 217 | bics r10, r10, #0xff000000 |
| 218 | eorne scno, r10, #__NR_OABI_SYSCALL_BASE |
| 219 | ldrne tbl, =sys_oabi_call_table |
| 220 | #elif !defined(CONFIG_AEABI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | bic scno, scno, #0xff000000 @ mask off SWI op-code |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 222 | eor scno, scno, #__NR_SYSCALL_BASE @ check OS number |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 223 | #endif |
Russell King | da594e3 | 2017-03-24 16:19:12 +0000 | [diff] [blame] | 224 | get_thread_info tsk |
Russell King | dca778c | 2017-03-24 16:23:25 +0000 | [diff] [blame] | 225 | /* |
| 226 | * Reload the registers that may have been corrupted on entry to |
| 227 | * the syscall assembly (by tracing or context tracking.) |
| 228 | */ |
| 229 | TRACE( ldmia sp, {r0 - r3} ) |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 230 | |
Al Viro | 8178378 | 2012-07-19 17:48:21 +0100 | [diff] [blame] | 231 | local_restart: |
Nicolas Pitre | 70c70d9 | 2010-08-26 15:08:35 -0700 | [diff] [blame] | 232 | ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing |
Nicolas Pitre | 3f2829a | 2006-01-14 16:31:29 +0000 | [diff] [blame] | 233 | stmdb sp!, {r4, r5} @ push fifth and sixth args |
Nicolas Pitre | 70c70d9 | 2010-08-26 15:08:35 -0700 | [diff] [blame] | 234 | |
Nathaniel Husted | 29ef73b | 2012-01-03 14:23:09 -0500 | [diff] [blame] | 235 | tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | bne __sys_trace |
| 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | cmp scno, #NR_syscalls @ check upper syscall limit |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 239 | badr lr, ret_fast_syscall @ return address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine |
| 241 | |
| 242 | add r1, sp, #S_OFF |
Will Deacon | d95bc25 | 2013-09-19 10:32:20 +0100 | [diff] [blame] | 243 | 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE) |
Russell King | e0f9f4a | 2005-04-26 15:19:24 +0100 | [diff] [blame] | 244 | eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back |
Will Deacon | 377747c | 2013-05-13 19:16:34 +0100 | [diff] [blame] | 245 | bcs arm_syscall |
Will Deacon | d95bc25 | 2013-09-19 10:32:20 +0100 | [diff] [blame] | 246 | mov why, #0 @ no longer a real syscall |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | b sys_ni_syscall @ not private func |
Will Deacon | 1aa2b3b | 2013-06-05 11:25:13 +0100 | [diff] [blame] | 248 | |
| 249 | #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI) |
| 250 | /* |
| 251 | * We failed to handle a fault trying to access the page |
| 252 | * containing the swi instruction, but we're not really in a |
| 253 | * position to return -EFAULT. Instead, return back to the |
| 254 | * instruction and re-enter the user fault handling path trying |
| 255 | * to page it in. This will likely result in sending SEGV to the |
| 256 | * current task. |
| 257 | */ |
| 258 | 9001: |
Russell King | 309ee04 | 2017-03-24 16:15:45 +0000 | [diff] [blame] | 259 | sub lr, saved_pc, #4 |
Will Deacon | 1aa2b3b | 2013-06-05 11:25:13 +0100 | [diff] [blame] | 260 | str lr, [sp, #S_PC] |
Russell King | da594e3 | 2017-03-24 16:19:12 +0000 | [diff] [blame] | 261 | get_thread_info tsk |
Will Deacon | 1aa2b3b | 2013-06-05 11:25:13 +0100 | [diff] [blame] | 262 | b ret_fast_syscall |
| 263 | #endif |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 264 | ENDPROC(vector_swi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * This is the really slow path. We're going to be doing |
| 268 | * context switches, and waiting for our parent to respond. |
| 269 | */ |
| 270 | __sys_trace: |
Will Deacon | ad72254 | 2012-07-06 15:50:14 +0100 | [diff] [blame] | 271 | mov r1, scno |
| 272 | add r0, sp, #S_OFF |
| 273 | bl syscall_trace_enter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Russell King | 14327c6 | 2015-04-21 14:17:25 +0100 | [diff] [blame] | 275 | badr lr, __sys_trace_return @ return address |
Nicolas Pitre | 3f47112 | 2006-01-14 19:30:04 +0000 | [diff] [blame] | 276 | mov scno, r0 @ syscall number (possibly new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | add r1, sp, #S_R0 + S_OFF @ pointer to regs |
| 278 | cmp scno, #NR_syscalls @ check upper syscall limit |
Will Deacon | c7aa00d | 2012-07-19 17:49:22 +0100 | [diff] [blame] | 279 | ldmccia r1, {r0 - r6} @ have to reload r0 - r6 |
| 280 | stmccia sp, {r4, r5} @ and update the stack args |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine |
Kees Cook | ad75b51 | 2012-11-15 22:12:17 +0100 | [diff] [blame] | 282 | cmp scno, #-1 @ skip the syscall? |
| 283 | bne 2b |
| 284 | add sp, sp, #S_OFF @ restore stack |
| 285 | b ret_slow_syscall |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | __sys_trace_return: |
| 288 | str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 |
Will Deacon | ad72254 | 2012-07-06 15:50:14 +0100 | [diff] [blame] | 289 | mov r0, sp |
| 290 | bl syscall_trace_exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | b ret_slow_syscall |
| 292 | |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 293 | __sys_trace_return_nosave: |
Russell King | e0aa3a6 | 2015-08-20 17:39:32 +0100 | [diff] [blame] | 294 | enable_irq_notrace |
Russell King | 3302cad | 2015-08-20 16:13:37 +0100 | [diff] [blame] | 295 | mov r0, sp |
| 296 | bl syscall_trace_exit |
| 297 | b ret_slow_syscall |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | .align 5 |
| 300 | #ifdef CONFIG_ALIGNMENT_TRAP |
| 301 | .type __cr_alignment, #object |
| 302 | __cr_alignment: |
| 303 | .word cr_alignment |
| 304 | #endif |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 305 | .ltorg |
| 306 | |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 307 | .macro syscall_table_start, sym |
| 308 | .equ __sys_nr, 0 |
| 309 | .type \sym, #object |
| 310 | ENTRY(\sym) |
| 311 | .endm |
| 312 | |
| 313 | .macro syscall, nr, func |
| 314 | .ifgt __sys_nr - \nr |
| 315 | .error "Duplicated/unorded system call entry" |
| 316 | .endif |
| 317 | .rept \nr - __sys_nr |
| 318 | .long sys_ni_syscall |
| 319 | .endr |
| 320 | .long \func |
| 321 | .equ __sys_nr, \nr + 1 |
| 322 | .endm |
| 323 | |
| 324 | .macro syscall_table_end, sym |
| 325 | .ifgt __sys_nr - __NR_syscalls |
| 326 | .error "System call table too big" |
| 327 | .endif |
| 328 | .rept __NR_syscalls - __sys_nr |
| 329 | .long sys_ni_syscall |
| 330 | .endr |
| 331 | .size \sym, . - \sym |
| 332 | .endm |
| 333 | |
| 334 | #define NATIVE(nr, func) syscall nr, func |
| 335 | |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 336 | /* |
| 337 | * This is the syscall table declaration for native ABI syscalls. |
| 338 | * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall. |
| 339 | */ |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 340 | syscall_table_start sys_call_table |
| 341 | #define COMPAT(nr, native, compat) syscall nr, native |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 342 | #ifdef CONFIG_AEABI |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 343 | #include <calls-eabi.S> |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 344 | #else |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 345 | #include <calls-oabi.S> |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 346 | #endif |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 347 | #undef COMPAT |
| 348 | syscall_table_end sys_call_table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | /*============================================================================ |
| 351 | * Special system call wrappers |
| 352 | */ |
| 353 | @ r0 = syscall number |
Russell King | 567bd98 | 2005-12-17 15:25:42 +0000 | [diff] [blame] | 354 | @ r8 = syscall table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | sys_syscall: |
Paul Brook | 5247593 | 2006-05-16 14:25:55 +0100 | [diff] [blame] | 356 | bic scno, r0, #__NR_OABI_SYSCALL_BASE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | cmp scno, #__NR_syscall - __NR_SYSCALL_BASE |
| 358 | cmpne scno, #NR_syscalls @ check range |
| 359 | stmloia sp, {r5, r6} @ shuffle args |
| 360 | movlo r0, r1 |
| 361 | movlo r1, r2 |
| 362 | movlo r2, r3 |
| 363 | movlo r3, r4 |
| 364 | ldrlo pc, [tbl, scno, lsl #2] |
| 365 | b sys_ni_syscall |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 366 | ENDPROC(sys_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | sys_sigreturn_wrapper: |
| 369 | add r0, sp, #S_OFF |
Al Viro | 653d48b | 2010-09-17 14:34:39 +0100 | [diff] [blame] | 370 | mov why, #0 @ prevent syscall restart handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | b sys_sigreturn |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 372 | ENDPROC(sys_sigreturn_wrapper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | sys_rt_sigreturn_wrapper: |
| 375 | add r0, sp, #S_OFF |
Al Viro | 653d48b | 2010-09-17 14:34:39 +0100 | [diff] [blame] | 376 | mov why, #0 @ prevent syscall restart handling |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | b sys_rt_sigreturn |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 378 | ENDPROC(sys_rt_sigreturn_wrapper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Nicolas Pitre | 713c481 | 2006-01-14 16:35:03 +0000 | [diff] [blame] | 380 | sys_statfs64_wrapper: |
| 381 | teq r1, #88 |
| 382 | moveq r1, #84 |
| 383 | b sys_statfs64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 384 | ENDPROC(sys_statfs64_wrapper) |
Nicolas Pitre | 713c481 | 2006-01-14 16:35:03 +0000 | [diff] [blame] | 385 | |
| 386 | sys_fstatfs64_wrapper: |
| 387 | teq r1, #88 |
| 388 | moveq r1, #84 |
| 389 | b sys_fstatfs64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 390 | ENDPROC(sys_fstatfs64_wrapper) |
Nicolas Pitre | 713c481 | 2006-01-14 16:35:03 +0000 | [diff] [blame] | 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* |
| 393 | * Note: off_4k (r5) is always units of 4K. If we can't do the requested |
| 394 | * offset, we return EINVAL. |
| 395 | */ |
| 396 | sys_mmap2: |
| 397 | #if PAGE_SHIFT > 12 |
| 398 | tst r5, #PGOFF_MASK |
| 399 | moveq r5, r5, lsr #PAGE_SHIFT - 12 |
| 400 | streq r5, [sp, #4] |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 401 | beq sys_mmap_pgoff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | mov r0, #-EINVAL |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 403 | ret lr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #else |
| 405 | str r5, [sp, #4] |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 406 | b sys_mmap_pgoff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | #endif |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 408 | ENDPROC(sys_mmap2) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 409 | |
| 410 | #ifdef CONFIG_OABI_COMPAT |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 411 | |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 412 | /* |
| 413 | * These are syscalls with argument register differences |
| 414 | */ |
| 415 | |
| 416 | sys_oabi_pread64: |
| 417 | stmia sp, {r3, r4} |
| 418 | b sys_pread64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 419 | ENDPROC(sys_oabi_pread64) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 420 | |
| 421 | sys_oabi_pwrite64: |
| 422 | stmia sp, {r3, r4} |
| 423 | b sys_pwrite64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 424 | ENDPROC(sys_oabi_pwrite64) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 425 | |
| 426 | sys_oabi_truncate64: |
| 427 | mov r3, r2 |
| 428 | mov r2, r1 |
| 429 | b sys_truncate64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 430 | ENDPROC(sys_oabi_truncate64) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 431 | |
| 432 | sys_oabi_ftruncate64: |
| 433 | mov r3, r2 |
| 434 | mov r2, r1 |
| 435 | b sys_ftruncate64 |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 436 | ENDPROC(sys_oabi_ftruncate64) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 437 | |
| 438 | sys_oabi_readahead: |
| 439 | str r3, [sp] |
| 440 | mov r3, r2 |
| 441 | mov r2, r1 |
| 442 | b sys_readahead |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 443 | ENDPROC(sys_oabi_readahead) |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 444 | |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 445 | /* |
| 446 | * Let's declare a second syscall table for old ABI binaries |
| 447 | * using the compatibility syscall entries. |
| 448 | */ |
Russell King | 96a8fae | 2016-10-18 19:57:01 +0100 | [diff] [blame] | 449 | syscall_table_start sys_oabi_call_table |
| 450 | #define COMPAT(nr, native, compat) syscall nr, compat |
| 451 | #include <calls-oabi.S> |
| 452 | syscall_table_end sys_oabi_call_table |
Nicolas Pitre | dd35afc | 2006-01-14 16:36:12 +0000 | [diff] [blame] | 453 | |
Nicolas Pitre | 687ad01 | 2006-01-14 16:35:31 +0000 | [diff] [blame] | 454 | #endif |
| 455 | |