18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci* Copyright (C) 2020 Loongson Technology Corporation Limited
48c2ecf20Sopenharmony_ci*
58c2ecf20Sopenharmony_ci* Author: Hanlu Li <lihanlu@loongson.cn>
68c2ecf20Sopenharmony_ci*/
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __ASM_LOONGARCH_SYSCALL_H
98c2ecf20Sopenharmony_ci#define __ASM_LOONGARCH_SYSCALL_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/compiler.h>
128c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
138c2ecf20Sopenharmony_ci#include <linux/elf-em.h>
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/sched.h>
168c2ecf20Sopenharmony_ci#include <linux/uaccess.h>
178c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
188c2ecf20Sopenharmony_ci#include <asm/unistd.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciextern void *sys_call_table[];
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic inline long syscall_get_nr(struct task_struct *task,
238c2ecf20Sopenharmony_ci				  struct pt_regs *regs)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	return regs->regs[11];
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task,
298c2ecf20Sopenharmony_ci				    struct pt_regs *regs)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci        regs->regs[4] = regs->orig_a0;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task,
358c2ecf20Sopenharmony_ci				     struct pt_regs *regs)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	unsigned long error = regs->regs[4];
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(error) ? error : 0;
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task,
438c2ecf20Sopenharmony_ci					    struct pt_regs *regs)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	return regs->regs[4];
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task,
498c2ecf20Sopenharmony_ci					    struct pt_regs *regs,
508c2ecf20Sopenharmony_ci					    int error, long val)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	regs->regs[4] = (long) error ? error : val;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task,
568c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
578c2ecf20Sopenharmony_ci					 unsigned long *args)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	args[0] = regs->orig_a0;
608c2ecf20Sopenharmony_ci	memcpy(&args[1], &regs->regs[5], 5 * sizeof(long));
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	return AUDIT_ARCH_LOONGARCH64;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#endif	/* __ASM_LOONGARCH_SYSCALL_H */
69