18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OpenRISC Linux
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Linux architectural port borrowing liberally from similar works of
68c2ecf20Sopenharmony_ci * others.  All original copyrights apply as per the original source
78c2ecf20Sopenharmony_ci * declaration.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * OpenRISC implementation:
108c2ecf20Sopenharmony_ci * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
118c2ecf20Sopenharmony_ci * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
128c2ecf20Sopenharmony_ci * et al.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef __ASM_OPENRISC_SYSCALL_H__
168c2ecf20Sopenharmony_ci#define __ASM_OPENRISC_SYSCALL_H__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
198c2ecf20Sopenharmony_ci#include <linux/err.h>
208c2ecf20Sopenharmony_ci#include <linux/sched.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic inline int
238c2ecf20Sopenharmony_cisyscall_get_nr(struct task_struct *task, struct pt_regs *regs)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	return regs->orig_gpr11;
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic inline void
298c2ecf20Sopenharmony_cisyscall_rollback(struct task_struct *task, struct pt_regs *regs)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	regs->gpr[11] = regs->orig_gpr11;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline long
358c2ecf20Sopenharmony_cisyscall_get_error(struct task_struct *task, struct pt_regs *regs)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(regs->gpr[11]) ? regs->gpr[11] : 0;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic inline long
418c2ecf20Sopenharmony_cisyscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	return regs->gpr[11];
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline void
478c2ecf20Sopenharmony_cisyscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
488c2ecf20Sopenharmony_ci			 int error, long val)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	regs->gpr[11] = (long) error ?: val;
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline void
548c2ecf20Sopenharmony_cisyscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
558c2ecf20Sopenharmony_ci		      unsigned long *args)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	memcpy(args, &regs->gpr[3], 6 * sizeof(args[0]));
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline void
618c2ecf20Sopenharmony_cisyscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
628c2ecf20Sopenharmony_ci		      const unsigned long *args)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	memcpy(&regs->gpr[3], args, 6 * sizeof(args[0]));
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	return AUDIT_ARCH_OPENRISC;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci#endif
72