18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright Altera Corporation (C) <2014>. All rights reserved 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __ASM_NIOS2_SYSCALL_H__ 78c2ecf20Sopenharmony_ci#define __ASM_NIOS2_SYSCALL_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h> 108c2ecf20Sopenharmony_ci#include <linux/err.h> 118c2ecf20Sopenharmony_ci#include <linux/sched.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci return regs->r2; 168c2ecf20Sopenharmony_ci} 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task, 198c2ecf20Sopenharmony_ci struct pt_regs *regs) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci regs->r2 = regs->orig_r2; 228c2ecf20Sopenharmony_ci regs->r7 = regs->orig_r7; 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task, 268c2ecf20Sopenharmony_ci struct pt_regs *regs) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci return regs->r7 ? regs->r2 : 0; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task, 328c2ecf20Sopenharmony_ci struct pt_regs *regs) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci return regs->r2; 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task, 388c2ecf20Sopenharmony_ci struct pt_regs *regs, int error, long val) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci if (error) { 418c2ecf20Sopenharmony_ci /* error < 0, but nios2 uses > 0 return value */ 428c2ecf20Sopenharmony_ci regs->r2 = -error; 438c2ecf20Sopenharmony_ci regs->r7 = 1; 448c2ecf20Sopenharmony_ci } else { 458c2ecf20Sopenharmony_ci regs->r2 = val; 468c2ecf20Sopenharmony_ci regs->r7 = 0; 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task, 518c2ecf20Sopenharmony_ci struct pt_regs *regs, unsigned long *args) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci *args++ = regs->r4; 548c2ecf20Sopenharmony_ci *args++ = regs->r5; 558c2ecf20Sopenharmony_ci *args++ = regs->r6; 568c2ecf20Sopenharmony_ci *args++ = regs->r7; 578c2ecf20Sopenharmony_ci *args++ = regs->r8; 588c2ecf20Sopenharmony_ci *args = regs->r9; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic inline void syscall_set_arguments(struct task_struct *task, 628c2ecf20Sopenharmony_ci struct pt_regs *regs, const unsigned long *args) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci regs->r4 = *args++; 658c2ecf20Sopenharmony_ci regs->r5 = *args++; 668c2ecf20Sopenharmony_ci regs->r6 = *args++; 678c2ecf20Sopenharmony_ci regs->r7 = *args++; 688c2ecf20Sopenharmony_ci regs->r8 = *args++; 698c2ecf20Sopenharmony_ci regs->r9 = *args; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci return AUDIT_ARCH_NIOS2; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#endif 78