18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2001 - 2007 Tensilica Inc.
78c2ecf20Sopenharmony_ci * Copyright (C) 2018 Cadence Design Systems Inc.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _ASM_SYSCALL_H
118c2ecf20Sopenharmony_ci#define _ASM_SYSCALL_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/err.h>
148c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
158c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	return AUDIT_ARCH_XTENSA;
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_citypedef void (*syscall_t)(void);
238c2ecf20Sopenharmony_ciextern syscall_t sys_call_table[];
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic inline long syscall_get_nr(struct task_struct *task,
268c2ecf20Sopenharmony_ci				  struct pt_regs *regs)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	return regs->syscall;
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task,
328c2ecf20Sopenharmony_ci				    struct pt_regs *regs)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	/* Do nothing. */
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task,
388c2ecf20Sopenharmony_ci				     struct pt_regs *regs)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	/* 0 if syscall succeeded, otherwise -Errorcode */
418c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(regs->areg[2]) ? regs->areg[2] : 0;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task,
458c2ecf20Sopenharmony_ci					    struct pt_regs *regs)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	return regs->areg[2];
488c2ecf20Sopenharmony_ci}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task,
518c2ecf20Sopenharmony_ci					    struct pt_regs *regs,
528c2ecf20Sopenharmony_ci					    int error, long val)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	regs->areg[2] = (long) error ? error : val;
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define SYSCALL_MAX_ARGS 6
588c2ecf20Sopenharmony_ci#define XTENSA_SYSCALL_ARGUMENT_REGS {6, 3, 4, 5, 8, 9}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task,
618c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
628c2ecf20Sopenharmony_ci					 unsigned long *args)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	static const unsigned int reg[] = XTENSA_SYSCALL_ARGUMENT_REGS;
658c2ecf20Sopenharmony_ci	unsigned int i;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	for (i = 0; i < 6; ++i)
688c2ecf20Sopenharmony_ci		args[i] = regs->areg[reg[i]];
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic inline void syscall_set_arguments(struct task_struct *task,
728c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
738c2ecf20Sopenharmony_ci					 const unsigned long *args)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	static const unsigned int reg[] = XTENSA_SYSCALL_ARGUMENT_REGS;
768c2ecf20Sopenharmony_ci	unsigned int i;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	for (i = 0; i < 6; ++i)
798c2ecf20Sopenharmony_ci		regs->areg[reg[i]] = args[i];
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciasmlinkage long xtensa_rt_sigreturn(void);
838c2ecf20Sopenharmony_ciasmlinkage long xtensa_shmat(int, char __user *, int);
848c2ecf20Sopenharmony_ciasmlinkage long xtensa_fadvise64_64(int, int,
858c2ecf20Sopenharmony_ci				    unsigned long long, unsigned long long);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#endif
88