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