1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright Altera Corporation (C) <2014>. All rights reserved 4 */ 5 6 #ifndef __ASM_NIOS2_SYSCALL_H__ 7 #define __ASM_NIOS2_SYSCALL_H__ 8 9 #include <uapi/linux/audit.h> 10 #include <linux/err.h> 11 #include <linux/sched.h> 12 13 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) 14 { 15 return regs->r2; 16 } 17 18 static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr) 19 { 20 regs->r2 = nr; 21 } 22 23 static inline void syscall_rollback(struct task_struct *task, 24 struct pt_regs *regs) 25 { 26 regs->r2 = regs->orig_r2; 27 regs->r7 = regs->orig_r7; 28 } 29 30 static inline long syscall_get_error(struct task_struct *task, 31 struct pt_regs *regs) 32 { 33 return regs->r7 ? regs->r2 : 0; 34 } 35 36 static inline long syscall_get_return_value(struct task_struct *task, 37 struct pt_regs *regs) 38 { 39 return regs->r2; 40 } 41 42 static inline void syscall_set_return_value(struct task_struct *task, 43 struct pt_regs *regs, int error, long val) 44 { 45 if (error) { 46 /* error < 0, but nios2 uses > 0 return value */ 47 regs->r2 = -error; 48 regs->r7 = 1; 49 } else { 50 regs->r2 = val; 51 regs->r7 = 0; 52 } 53 } 54 55 static inline void syscall_get_arguments(struct task_struct *task, 56 struct pt_regs *regs, unsigned long *args) 57 { 58 *args++ = regs->r4; 59 *args++ = regs->r5; 60 *args++ = regs->r6; 61 *args++ = regs->r7; 62 *args++ = regs->r8; 63 *args = regs->r9; 64 } 65 66 static inline void syscall_set_arguments(struct task_struct *task, 67 struct pt_regs *regs, const unsigned long *args) 68 { 69 regs->r4 = *args++; 70 regs->r5 = *args++; 71 regs->r6 = *args++; 72 regs->r7 = *args++; 73 regs->r8 = *args++; 74 regs->r9 = *args; 75 } 76 77 static inline int syscall_get_arch(struct task_struct *task) 78 { 79 return AUDIT_ARCH_NIOS2; 80 } 81 82 #endif 83