Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1995, 96, 97, 98, 99, 2000, 01, 02 by Ralf Baechle |
| 7 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
| 8 | * Copyright (C) 2001 MIPS Technologies, Inc. |
| 9 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/errno.h> |
| 11 | #include <asm/asm.h> |
| 12 | #include <asm/asmmacro.h> |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 13 | #include <asm/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/mipsregs.h> |
| 15 | #include <asm/regdef.h> |
| 16 | #include <asm/stackframe.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 17 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/sysmips.h> |
| 19 | #include <asm/thread_info.h> |
| 20 | #include <asm/unistd.h> |
| 21 | #include <asm/war.h> |
| 22 | |
| 23 | #ifndef CONFIG_BINFMT_ELF32 |
| 24 | /* Neither O32 nor N32, so define handle_sys here */ |
| 25 | #define handle_sys64 handle_sys |
| 26 | #endif |
| 27 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 28 | .align 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | NESTED(handle_sys64, PT_SIZE, sp) |
| 30 | #if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32) |
| 31 | /* |
| 32 | * When 32-bit compatibility is configured scall_o32.S |
| 33 | * already did this. |
| 34 | */ |
| 35 | .set noat |
| 36 | SAVE_SOME |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 37 | TRACE_IRQS_ON_RELOAD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | STI |
| 39 | .set at |
| 40 | #endif |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #if !defined(CONFIG_MIPS32_O32) && !defined(CONFIG_MIPS32_N32) |
| 43 | ld t1, PT_EPC(sp) # skip syscall on return |
| 44 | daddiu t1, 4 # skip to next instruction |
| 45 | sd t1, PT_EPC(sp) |
| 46 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | sd a3, PT_R26(sp) # save a3 for syscall restarting |
| 49 | |
Ralf Baechle | e7f3b48 | 2013-05-29 01:02:18 +0200 | [diff] [blame] | 50 | li t1, _TIF_WORK_SYSCALL_ENTRY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | LONG_L t0, TI_FLAGS($28) # syscall tracing enabled? |
| 52 | and t0, t1, t0 |
| 53 | bnez t0, syscall_trace_entry |
| 54 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 55 | syscall_common: |
| 56 | dsubu t2, v0, __NR_64_Linux |
Firoz Khan | be85643 | 2018-12-13 14:37:36 +0530 | [diff] [blame] | 57 | sltiu t0, t2, __NR_64_Linux_syscalls |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 58 | beqz t0, illegal_syscall |
| 59 | |
| 60 | dsll t0, t2, 3 # offset into table |
| 61 | dla t2, sys_call_table |
| 62 | daddu t0, t2, t0 |
| 63 | ld t2, (t0) # syscall routine |
| 64 | beqz t2, illegal_syscall |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | jalr t2 # Do The Real Thing (TM) |
| 67 | |
| 68 | li t0, -EMAXERRNO - 1 # error? |
| 69 | sltu t0, t0, v0 |
| 70 | sd t0, PT_R7(sp) # set error flag |
| 71 | beqz t0, 1f |
| 72 | |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 73 | ld t1, PT_R2(sp) # syscall number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | dnegu v0 # error |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 75 | sd t1, PT_R0(sp) # save it for syscall restarting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | 1: sd v0, PT_R2(sp) # result |
| 77 | |
| 78 | n64_syscall_exit: |
Al Viro | 02f884e | 2012-05-05 16:11:35 -0400 | [diff] [blame] | 79 | j syscall_exit_partial |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* ------------------------------------------------------------------------ */ |
| 82 | |
| 83 | syscall_trace_entry: |
| 84 | SAVE_STATIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | move a0, sp |
Markos Chandras | 9f16143 | 2015-08-13 08:47:59 +0100 | [diff] [blame] | 86 | move a1, v0 |
Ralf Baechle | 8b659a3 | 2011-05-19 09:21:29 +0100 | [diff] [blame] | 87 | jal syscall_trace_enter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 89 | bltz v0, 1f # seccomp failed? Skip syscall |
Markos Chandras | 9d37c40 | 2014-01-22 14:40:02 +0000 | [diff] [blame] | 90 | |
Ralf Baechle | 04a7052 | 2005-11-30 16:24:57 +0000 | [diff] [blame] | 91 | RESTORE_STATIC |
Matt Redfearn | a400bed | 2016-03-29 09:35:31 +0100 | [diff] [blame] | 92 | ld v0, PT_R2(sp) # Restore syscall (maybe modified) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | ld a0, PT_R4(sp) # Restore argument registers |
| 94 | ld a1, PT_R5(sp) |
| 95 | ld a2, PT_R6(sp) |
| 96 | ld a3, PT_R7(sp) |
| 97 | ld a4, PT_R8(sp) |
| 98 | ld a5, PT_R9(sp) |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 99 | j syscall_common |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 101 | 1: j syscall_exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | illegal_syscall: |
| 104 | /* This also isn't a 64-bit syscall, throw an error. */ |
Atsushi Nemoto | bda8229 | 2008-10-25 01:17:22 +0900 | [diff] [blame] | 105 | li v0, ENOSYS # error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | sd v0, PT_R2(sp) |
| 107 | li t0, 1 # set error flag |
| 108 | sd t0, PT_R7(sp) |
| 109 | j n64_syscall_exit |
| 110 | END(handle_sys64) |
| 111 | |
Firoz Khan | 99bf73e | 2018-12-13 14:37:39 +0530 | [diff] [blame] | 112 | #define __SYSCALL(nr, entry, nargs) PTR entry |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | .align 3 |
Ralf Baechle | 03b94e2 | 2012-07-12 14:06:46 +0200 | [diff] [blame] | 114 | .type sys_call_table, @object |
| 115 | EXPORT(sys_call_table) |
Firoz Khan | 99bf73e | 2018-12-13 14:37:39 +0530 | [diff] [blame] | 116 | #include <asm/syscall_table_64_n64.h> |
| 117 | #undef __SYSCALL |