xref: /openbmc/linux/arch/nios2/include/asm/syscall.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1*9952f691SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
21000197dSLey Foon Tan /*
31000197dSLey Foon Tan  * Copyright Altera Corporation (C) <2014>. All rights reserved
41000197dSLey Foon Tan  */
51000197dSLey Foon Tan 
61000197dSLey Foon Tan #ifndef __ASM_NIOS2_SYSCALL_H__
71000197dSLey Foon Tan #define __ASM_NIOS2_SYSCALL_H__
81000197dSLey Foon Tan 
91660aac4SDmitry V. Levin #include <uapi/linux/audit.h>
101000197dSLey Foon Tan #include <linux/err.h>
111000197dSLey Foon Tan #include <linux/sched.h>
121000197dSLey Foon Tan 
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)131000197dSLey Foon Tan static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
141000197dSLey Foon Tan {
151000197dSLey Foon Tan 	return regs->r2;
161000197dSLey Foon Tan }
171000197dSLey Foon Tan 
syscall_rollback(struct task_struct * task,struct pt_regs * regs)181000197dSLey Foon Tan static inline void syscall_rollback(struct task_struct *task,
191000197dSLey Foon Tan 				struct pt_regs *regs)
201000197dSLey Foon Tan {
211000197dSLey Foon Tan 	regs->r2 = regs->orig_r2;
221000197dSLey Foon Tan 	regs->r7 = regs->orig_r7;
231000197dSLey Foon Tan }
241000197dSLey Foon Tan 
syscall_get_error(struct task_struct * task,struct pt_regs * regs)251000197dSLey Foon Tan static inline long syscall_get_error(struct task_struct *task,
261000197dSLey Foon Tan 				struct pt_regs *regs)
271000197dSLey Foon Tan {
281000197dSLey Foon Tan 	return regs->r7 ? regs->r2 : 0;
291000197dSLey Foon Tan }
301000197dSLey Foon Tan 
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)311000197dSLey Foon Tan static inline long syscall_get_return_value(struct task_struct *task,
321000197dSLey Foon Tan 	struct pt_regs *regs)
331000197dSLey Foon Tan {
341000197dSLey Foon Tan 	return regs->r2;
351000197dSLey Foon Tan }
361000197dSLey Foon Tan 
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)371000197dSLey Foon Tan static inline void syscall_set_return_value(struct task_struct *task,
381000197dSLey Foon Tan 	struct pt_regs *regs, int error, long val)
391000197dSLey Foon Tan {
401000197dSLey Foon Tan 	if (error) {
411000197dSLey Foon Tan 		/* error < 0, but nios2 uses > 0 return value */
421000197dSLey Foon Tan 		regs->r2 = -error;
431000197dSLey Foon Tan 		regs->r7 = 1;
441000197dSLey Foon Tan 	} else {
451000197dSLey Foon Tan 		regs->r2 = val;
461000197dSLey Foon Tan 		regs->r7 = 0;
471000197dSLey Foon Tan 	}
481000197dSLey Foon Tan }
491000197dSLey Foon Tan 
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned long * args)501000197dSLey Foon Tan static inline void syscall_get_arguments(struct task_struct *task,
51b35f549dSSteven Rostedt (Red Hat) 	struct pt_regs *regs, unsigned long *args)
521000197dSLey Foon Tan {
531000197dSLey Foon Tan 	*args++ = regs->r4;
541000197dSLey Foon Tan 	*args++ = regs->r5;
551000197dSLey Foon Tan 	*args++ = regs->r6;
561000197dSLey Foon Tan 	*args++ = regs->r7;
571000197dSLey Foon Tan 	*args++ = regs->r8;
58b35f549dSSteven Rostedt (Red Hat) 	*args   = regs->r9;
591000197dSLey Foon Tan }
601000197dSLey Foon Tan 
syscall_get_arch(struct task_struct * task)6116add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
621660aac4SDmitry V. Levin {
631660aac4SDmitry V. Levin 	return AUDIT_ARCH_NIOS2;
641660aac4SDmitry V. Levin }
651660aac4SDmitry V. Levin 
661000197dSLey Foon Tan #endif
67