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 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> |
| 17 | #include <asm/thread_info.h> |
| 18 | #include <asm/unistd.h> |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #ifndef CONFIG_MIPS32_O32 |
| 21 | /* No O32, so define handle_sys here */ |
| 22 | #define handle_sysn32 handle_sys |
| 23 | #endif |
| 24 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 25 | .align 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | NESTED(handle_sysn32, PT_SIZE, sp) |
| 27 | #ifndef CONFIG_MIPS32_O32 |
| 28 | .set noat |
| 29 | SAVE_SOME |
Atsushi Nemoto | eae6c0d | 2006-09-26 23:43:40 +0900 | [diff] [blame] | 30 | TRACE_IRQS_ON_RELOAD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | STI |
| 32 | .set at |
| 33 | #endif |
| 34 | |
| 35 | dsubu t0, v0, __NR_N32_Linux # check syscall number |
Firoz Khan | be85643 | 2018-12-13 14:37:36 +0530 | [diff] [blame] | 36 | sltiu t0, t0, __NR_N32_Linux_syscalls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #ifndef CONFIG_MIPS32_O32 |
| 39 | ld t1, PT_EPC(sp) # skip syscall on return |
| 40 | daddiu t1, 4 # skip to next instruction |
| 41 | sd t1, PT_EPC(sp) |
| 42 | #endif |
| 43 | beqz t0, not_n32_scall |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | sd a3, PT_R26(sp) # save a3 for syscall restarting |
| 46 | |
Ralf Baechle | e7f3b48 | 2013-05-29 01:02:18 +0200 | [diff] [blame] | 47 | li t1, _TIF_WORK_SYSCALL_ENTRY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | LONG_L t0, TI_FLAGS($28) # syscall tracing enabled? |
| 49 | and t0, t1, t0 |
| 50 | bnez t0, n32_syscall_trace_entry |
| 51 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 52 | syscall_common: |
Matt Redfearn | a400bed | 2016-03-29 09:35:31 +0100 | [diff] [blame] | 53 | dsll t0, v0, 3 # offset into table |
| 54 | ld t2, (sysn32_call_table - (__NR_N32_Linux * 8))(t0) |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | jalr t2 # Do The Real Thing (TM) |
| 57 | |
| 58 | li t0, -EMAXERRNO - 1 # error? |
| 59 | sltu t0, t0, v0 |
| 60 | sd t0, PT_R7(sp) # set error flag |
| 61 | beqz t0, 1f |
| 62 | |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 63 | ld t1, PT_R2(sp) # syscall number |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | dnegu v0 # error |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 65 | sd t1, PT_R0(sp) # save it for syscall restarting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | 1: sd v0, PT_R2(sp) # result |
| 67 | |
Al Viro | 02f884e | 2012-05-05 16:11:35 -0400 | [diff] [blame] | 68 | j syscall_exit_partial |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | /* ------------------------------------------------------------------------ */ |
| 71 | |
| 72 | n32_syscall_trace_entry: |
| 73 | SAVE_STATIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | move a0, sp |
Markos Chandras | 9f16143 | 2015-08-13 08:47:59 +0100 | [diff] [blame] | 75 | move a1, v0 |
Ralf Baechle | 8b659a3 | 2011-05-19 09:21:29 +0100 | [diff] [blame] | 76 | jal syscall_trace_enter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 78 | bltz v0, 1f # seccomp failed? Skip syscall |
Markos Chandras | 9d37c40 | 2014-01-22 14:40:02 +0000 | [diff] [blame] | 79 | |
Ralf Baechle | 04a7052 | 2005-11-30 16:24:57 +0000 | [diff] [blame] | 80 | RESTORE_STATIC |
Matt Redfearn | a400bed | 2016-03-29 09:35:31 +0100 | [diff] [blame] | 81 | ld v0, PT_R2(sp) # Restore syscall (maybe modified) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | ld a0, PT_R4(sp) # Restore argument registers |
| 83 | ld a1, PT_R5(sp) |
| 84 | ld a2, PT_R6(sp) |
| 85 | ld a3, PT_R7(sp) |
| 86 | ld a4, PT_R8(sp) |
| 87 | ld a5, PT_R9(sp) |
Matt Redfearn | a400bed | 2016-03-29 09:35:31 +0100 | [diff] [blame] | 88 | |
| 89 | dsubu t2, v0, __NR_N32_Linux # check (new) syscall number |
Firoz Khan | be85643 | 2018-12-13 14:37:36 +0530 | [diff] [blame] | 90 | sltiu t0, t2, __NR_N32_Linux_syscalls |
Matt Redfearn | a400bed | 2016-03-29 09:35:31 +0100 | [diff] [blame] | 91 | beqz t0, not_n32_scall |
| 92 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 93 | j syscall_common |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Markos Chandras | d218af7 | 2015-09-25 08:17:42 +0100 | [diff] [blame] | 95 | 1: j syscall_exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | not_n32_scall: |
| 98 | /* This is not an n32 compatibility syscall, pass it on to |
| 99 | the n64 syscall handlers. */ |
| 100 | j handle_sys64 |
| 101 | |
| 102 | END(handle_sysn32) |
| 103 | |
Firoz Khan | dc7077f | 2019-01-02 20:26:17 +0530 | [diff] [blame] | 104 | #define __SYSCALL(nr, entry) PTR entry |
Ralf Baechle | 43dec43 | 2012-07-12 14:02:41 +0200 | [diff] [blame] | 105 | .type sysn32_call_table, @object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | EXPORT(sysn32_call_table) |
Masahiro Yamada | ecbba30 | 2021-03-01 23:48:24 +0900 | [diff] [blame] | 107 | #include <asm/syscall_table_n32.h> |