1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Author: Hanlu Li <lihanlu@loongson.cn> 4 * Huacai Chen <chenhuacai@loongson.cn> 5 * 6 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 7 */ 8 9 #ifndef __ASM_LOONGARCH_SYSCALL_H 10 #define __ASM_LOONGARCH_SYSCALL_H 11 12 #include <linux/compiler.h> 13 #include <uapi/linux/audit.h> 14 #include <linux/elf-em.h> 15 #include <linux/kernel.h> 16 #include <linux/sched.h> 17 #include <linux/uaccess.h> 18 #include <asm/ptrace.h> 19 #include <asm/unistd.h> 20 21 extern void *sys_call_table[]; 22 23 static inline long syscall_get_nr(struct task_struct *task, 24 struct pt_regs *regs) 25 { 26 return regs->regs[11]; 27 } 28 29 static inline void syscall_set_nr(struct task_struct *task, 30 struct pt_regs *regs, 31 int nr) 32 { 33 regs->regs[11] = nr; 34 } 35 36 static inline void syscall_rollback(struct task_struct *task, 37 struct pt_regs *regs) 38 { 39 regs->regs[4] = regs->orig_a0; 40 } 41 42 static inline long syscall_get_error(struct task_struct *task, 43 struct pt_regs *regs) 44 { 45 unsigned long error = regs->regs[4]; 46 47 return IS_ERR_VALUE(error) ? error : 0; 48 } 49 50 static inline long syscall_get_return_value(struct task_struct *task, 51 struct pt_regs *regs) 52 { 53 return regs->regs[4]; 54 } 55 56 static inline void syscall_set_return_value(struct task_struct *task, 57 struct pt_regs *regs, 58 int error, long val) 59 { 60 regs->regs[4] = (long) error ? error : val; 61 } 62 63 static inline void syscall_get_arguments(struct task_struct *task, 64 struct pt_regs *regs, 65 unsigned long *args) 66 { 67 args[0] = regs->orig_a0; 68 memcpy(&args[1], ®s->regs[5], 5 * sizeof(long)); 69 } 70 71 static inline void syscall_set_arguments(struct task_struct *task, 72 struct pt_regs *regs, 73 unsigned long *args) 74 { 75 regs->orig_a0 = args[0]; 76 memcpy(®s->regs[5], &args[1], 5 * sizeof(long)); 77 } 78 79 static inline int syscall_get_arch(struct task_struct *task) 80 { 81 return AUDIT_ARCH_LOONGARCH64; 82 } 83 84 static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) 85 { 86 return false; 87 } 88 89 #endif /* __ASM_LOONGARCH_SYSCALL_H */ 90