1#ifndef __ASM_MICROBLAZE_SYSCALL_H
2#define __ASM_MICROBLAZE_SYSCALL_H
3
4#include <uapi/linux/audit.h>
5#include <linux/kernel.h>
6#include <linux/sched.h>
7#include <asm/ptrace.h>
8
9/* The system call number is given by the user in R12 */
10static inline long syscall_get_nr(struct task_struct *task,
11				  struct pt_regs *regs)
12{
13	return regs->r12;
14}
15
16static inline void syscall_rollback(struct task_struct *task,
17				    struct pt_regs *regs)
18{
19	/* TODO.  */
20}
21
22static inline long syscall_get_error(struct task_struct *task,
23				     struct pt_regs *regs)
24{
25	return IS_ERR_VALUE(regs->r3) ? regs->r3 : 0;
26}
27
28static inline long syscall_get_return_value(struct task_struct *task,
29					    struct pt_regs *regs)
30{
31	return regs->r3;
32}
33
34static inline void syscall_set_return_value(struct task_struct *task,
35					    struct pt_regs *regs,
36					    int error, long val)
37{
38	if (error)
39		regs->r3 = -error;
40	else
41		regs->r3 = val;
42}
43
44static inline microblaze_reg_t microblaze_get_syscall_arg(struct pt_regs *regs,
45							  unsigned int n)
46{
47	switch (n) {
48	case 5: return regs->r10;
49	case 4: return regs->r9;
50	case 3: return regs->r8;
51	case 2: return regs->r7;
52	case 1: return regs->r6;
53	case 0: return regs->r5;
54	default:
55		BUG();
56	}
57	return ~0;
58}
59
60static inline void microblaze_set_syscall_arg(struct pt_regs *regs,
61					      unsigned int n,
62					      unsigned long val)
63{
64	switch (n) {
65	case 5:
66		regs->r10 = val;
67	case 4:
68		regs->r9 = val;
69	case 3:
70		regs->r8 = val;
71	case 2:
72		regs->r7 = val;
73	case 1:
74		regs->r6 = val;
75	case 0:
76		regs->r5 = val;
77	default:
78		BUG();
79	}
80}
81
82static inline void syscall_get_arguments(struct task_struct *task,
83					 struct pt_regs *regs,
84					 unsigned int i, unsigned int n,
85					 unsigned long *args)
86{
87	while (n--)
88		*args++ = microblaze_get_syscall_arg(regs, i++);
89}
90
91static inline void syscall_set_arguments(struct task_struct *task,
92					 struct pt_regs *regs,
93					 unsigned int i, unsigned int n,
94					 const unsigned long *args)
95{
96	while (n--)
97		microblaze_set_syscall_arg(regs, i++, *args++);
98}
99
100asmlinkage unsigned long do_syscall_trace_enter(struct pt_regs *regs);
101asmlinkage void do_syscall_trace_leave(struct pt_regs *regs);
102
103static inline int syscall_get_arch(void)
104{
105	return AUDIT_ARCH_MICROBLAZE;
106}
107#endif /* __ASM_MICROBLAZE_SYSCALL_H */
108