18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _ASM_ARC_SYSCALL_H
78c2ecf20Sopenharmony_ci#define _ASM_ARC_SYSCALL_H  1
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
108c2ecf20Sopenharmony_ci#include <linux/err.h>
118c2ecf20Sopenharmony_ci#include <linux/sched.h>
128c2ecf20Sopenharmony_ci#include <asm/unistd.h>
138c2ecf20Sopenharmony_ci#include <asm/ptrace.h>		/* in_syscall() */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistatic inline long
168c2ecf20Sopenharmony_cisyscall_get_nr(struct task_struct *task, struct pt_regs *regs)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	if (user_mode(regs) && in_syscall(regs))
198c2ecf20Sopenharmony_ci		return regs->r8;
208c2ecf20Sopenharmony_ci	else
218c2ecf20Sopenharmony_ci		return -1;
228c2ecf20Sopenharmony_ci}
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic inline void
258c2ecf20Sopenharmony_cisyscall_rollback(struct task_struct *task, struct pt_regs *regs)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	regs->r0 = regs->orig_r0;
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic inline long
318c2ecf20Sopenharmony_cisyscall_get_error(struct task_struct *task, struct pt_regs *regs)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	/* 0 if syscall succeeded, otherwise -Errorcode */
348c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline long
388c2ecf20Sopenharmony_cisyscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	return regs->r0;
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic inline void
448c2ecf20Sopenharmony_cisyscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
458c2ecf20Sopenharmony_ci			 int error, long val)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	regs->r0 = (long) error ?: val;
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci * @i:      argument index [0,5]
528c2ecf20Sopenharmony_ci * @n:      number of arguments; n+i must be [1,6].
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_cistatic inline void
558c2ecf20Sopenharmony_cisyscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
568c2ecf20Sopenharmony_ci		      unsigned long *args)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	unsigned long *inside_ptregs = &(regs->r0);
598c2ecf20Sopenharmony_ci	unsigned int n = 6;
608c2ecf20Sopenharmony_ci	unsigned int i = 0;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	while (n--) {
638c2ecf20Sopenharmony_ci		args[i++] = (*inside_ptregs);
648c2ecf20Sopenharmony_ci		inside_ptregs--;
658c2ecf20Sopenharmony_ci	}
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline int
698c2ecf20Sopenharmony_cisyscall_get_arch(struct task_struct *task)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return IS_ENABLED(CONFIG_ISA_ARCOMPACT)
728c2ecf20Sopenharmony_ci		? (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
738c2ecf20Sopenharmony_ci			? AUDIT_ARCH_ARCOMPACTBE : AUDIT_ARCH_ARCOMPACT)
748c2ecf20Sopenharmony_ci		: (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
758c2ecf20Sopenharmony_ci			? AUDIT_ARCH_ARCV2BE : AUDIT_ARCH_ARCV2);
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif
79