119e2e172SRalf Baechle /* 2c0ff3c53SRalf Baechle * Access to user system call parameters and results 3c0ff3c53SRalf Baechle * 419e2e172SRalf Baechle * This file is subject to the terms and conditions of the GNU General Public 519e2e172SRalf Baechle * License. See the file "COPYING" in the main directory of this archive 619e2e172SRalf Baechle * for more details. 719e2e172SRalf Baechle * 8c0ff3c53SRalf Baechle * See asm-generic/syscall.h for descriptions of what we must do here. 9c0ff3c53SRalf Baechle * 1019e2e172SRalf Baechle * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org> 1119e2e172SRalf Baechle */ 1219e2e172SRalf Baechle 1319e2e172SRalf Baechle #ifndef __ASM_MIPS_SYSCALL_H 1419e2e172SRalf Baechle #define __ASM_MIPS_SYSCALL_H 1519e2e172SRalf Baechle 16f5179287SRalf Baechle #include <linux/compiler.h> 17579ec9e1SEric Paris #include <uapi/linux/audit.h> 18bec9b2b2SRalf Baechle #include <linux/elf-em.h> 19c0ff3c53SRalf Baechle #include <linux/kernel.h> 20c0ff3c53SRalf Baechle #include <linux/sched.h> 21c0ff3c53SRalf Baechle #include <linux/uaccess.h> 22c0ff3c53SRalf Baechle #include <asm/ptrace.h> 234c21b8fdSMarkos Chandras #include <asm/unistd.h> 244c21b8fdSMarkos Chandras 254c21b8fdSMarkos Chandras #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */ 264c21b8fdSMarkos Chandras #define __NR_syscall 4000 274c21b8fdSMarkos Chandras #endif 28c0ff3c53SRalf Baechle 29c0ff3c53SRalf Baechle static inline long syscall_get_nr(struct task_struct *task, 30c0ff3c53SRalf Baechle struct pt_regs *regs) 31c0ff3c53SRalf Baechle { 324c21b8fdSMarkos Chandras /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ 334c21b8fdSMarkos Chandras if ((config_enabled(CONFIG_32BIT) || 344c21b8fdSMarkos Chandras test_tsk_thread_flag(task, TIF_32BIT_REGS)) && 354c21b8fdSMarkos Chandras (regs->regs[2] == __NR_syscall)) 364c21b8fdSMarkos Chandras return regs->regs[4]; 374c21b8fdSMarkos Chandras else 38c0ff3c53SRalf Baechle return regs->regs[2]; 39c0ff3c53SRalf Baechle } 40c0ff3c53SRalf Baechle 41c0ff3c53SRalf Baechle static inline unsigned long mips_get_syscall_arg(unsigned long *arg, 42c0ff3c53SRalf Baechle struct task_struct *task, struct pt_regs *regs, unsigned int n) 43c0ff3c53SRalf Baechle { 4463238f2cSGuenter Roeck unsigned long usp __maybe_unused = regs->regs[29]; 45c0ff3c53SRalf Baechle 46c0ff3c53SRalf Baechle switch (n) { 47c0ff3c53SRalf Baechle case 0: case 1: case 2: case 3: 48c0ff3c53SRalf Baechle *arg = regs->regs[4 + n]; 49c0ff3c53SRalf Baechle 50c0ff3c53SRalf Baechle return 0; 51c0ff3c53SRalf Baechle 52c0ff3c53SRalf Baechle #ifdef CONFIG_32BIT 53c0ff3c53SRalf Baechle case 4: case 5: case 6: case 7: 5486ca57b5SLars Persson return get_user(*arg, (int *)usp + n); 55c0ff3c53SRalf Baechle #endif 56c0ff3c53SRalf Baechle 57c0ff3c53SRalf Baechle #ifdef CONFIG_64BIT 58c0ff3c53SRalf Baechle case 4: case 5: case 6: case 7: 59c0ff3c53SRalf Baechle #ifdef CONFIG_MIPS32_O32 60c0ff3c53SRalf Baechle if (test_thread_flag(TIF_32BIT_REGS)) 6186ca57b5SLars Persson return get_user(*arg, (int *)usp + n); 62c0ff3c53SRalf Baechle else 63c0ff3c53SRalf Baechle #endif 64c0ff3c53SRalf Baechle *arg = regs->regs[4 + n]; 65c0ff3c53SRalf Baechle 66c0ff3c53SRalf Baechle return 0; 67c0ff3c53SRalf Baechle #endif 68c0ff3c53SRalf Baechle 69c0ff3c53SRalf Baechle default: 70c0ff3c53SRalf Baechle BUG(); 71c0ff3c53SRalf Baechle } 72f5179287SRalf Baechle 73f5179287SRalf Baechle unreachable(); 74c0ff3c53SRalf Baechle } 75c0ff3c53SRalf Baechle 761d7bf993SRalf Baechle static inline long syscall_get_return_value(struct task_struct *task, 771d7bf993SRalf Baechle struct pt_regs *regs) 781d7bf993SRalf Baechle { 791d7bf993SRalf Baechle return regs->regs[2]; 801d7bf993SRalf Baechle } 811d7bf993SRalf Baechle 8222feadbeSMarkos Chandras static inline void syscall_rollback(struct task_struct *task, 8322feadbeSMarkos Chandras struct pt_regs *regs) 8422feadbeSMarkos Chandras { 8522feadbeSMarkos Chandras /* Do nothing */ 8622feadbeSMarkos Chandras } 8722feadbeSMarkos Chandras 881d7bf993SRalf Baechle static inline void syscall_set_return_value(struct task_struct *task, 891d7bf993SRalf Baechle struct pt_regs *regs, 901d7bf993SRalf Baechle int error, long val) 911d7bf993SRalf Baechle { 921d7bf993SRalf Baechle if (error) { 931d7bf993SRalf Baechle regs->regs[2] = -error; 941d7bf993SRalf Baechle regs->regs[7] = -1; 951d7bf993SRalf Baechle } else { 961d7bf993SRalf Baechle regs->regs[2] = val; 971d7bf993SRalf Baechle regs->regs[7] = 0; 981d7bf993SRalf Baechle } 991d7bf993SRalf Baechle } 1001d7bf993SRalf Baechle 101c0ff3c53SRalf Baechle static inline void syscall_get_arguments(struct task_struct *task, 102c0ff3c53SRalf Baechle struct pt_regs *regs, 103c0ff3c53SRalf Baechle unsigned int i, unsigned int n, 104c0ff3c53SRalf Baechle unsigned long *args) 105c0ff3c53SRalf Baechle { 106c0ff3c53SRalf Baechle int ret; 1074c21b8fdSMarkos Chandras /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ 1084c21b8fdSMarkos Chandras if ((config_enabled(CONFIG_32BIT) || 1094c21b8fdSMarkos Chandras test_tsk_thread_flag(task, TIF_32BIT_REGS)) && 1104c21b8fdSMarkos Chandras (regs->regs[2] == __NR_syscall)) { 1114c21b8fdSMarkos Chandras i++; 1124c21b8fdSMarkos Chandras n++; 1134c21b8fdSMarkos Chandras } 114c0ff3c53SRalf Baechle 115c0ff3c53SRalf Baechle while (n--) 116a8031d2cSMarkos Chandras ret |= mips_get_syscall_arg(args++, task, regs, i++); 117c0ff3c53SRalf Baechle 118c0ff3c53SRalf Baechle /* 119c0ff3c53SRalf Baechle * No way to communicate an error because this is a void function. 120c0ff3c53SRalf Baechle */ 121c0ff3c53SRalf Baechle #if 0 122c0ff3c53SRalf Baechle return ret; 123c0ff3c53SRalf Baechle #endif 124c0ff3c53SRalf Baechle } 125c0ff3c53SRalf Baechle 12619e2e172SRalf Baechle extern const unsigned long sys_call_table[]; 12719e2e172SRalf Baechle extern const unsigned long sys32_call_table[]; 12819e2e172SRalf Baechle extern const unsigned long sysn32_call_table[]; 12919e2e172SRalf Baechle 1305e937a9aSEric Paris static inline int syscall_get_arch(void) 131bec9b2b2SRalf Baechle { 132bec9b2b2SRalf Baechle int arch = EM_MIPS; 133bec9b2b2SRalf Baechle #ifdef CONFIG_64BIT 1340b747172SLinus Torvalds if (!test_thread_flag(TIF_32BIT_REGS)) 135bec9b2b2SRalf Baechle arch |= __AUDIT_ARCH_64BIT; 136*f2d0801fSMarkos Chandras if (test_thread_flag(TIF_32BIT_ADDR)) 137*f2d0801fSMarkos Chandras arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; 138bec9b2b2SRalf Baechle #endif 139bec9b2b2SRalf Baechle #if defined(__LITTLE_ENDIAN) 140bec9b2b2SRalf Baechle arch |= __AUDIT_ARCH_LE; 141bec9b2b2SRalf Baechle #endif 142bec9b2b2SRalf Baechle return arch; 143bec9b2b2SRalf Baechle } 144bec9b2b2SRalf Baechle 14519e2e172SRalf Baechle #endif /* __ASM_MIPS_SYSCALL_H */ 146