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