• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Access to user system call parameters and results
3  *
4  * Copyright (C) 2008 Imagination Technologies Ltd.
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU General Public License v.2.
9  *
10  * See asm-generic/syscall.h for descriptions of what we must do here.
11  */
12 
13 #ifndef _ASM_METAG_SYSCALL_H
14 #define _ASM_METAG_SYSCALL_H
15 
16 #include <linux/sched.h>
17 #include <linux/err.h>
18 #include <linux/uaccess.h>
19 
20 #include <asm/switch.h>
21 
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)22 static inline long syscall_get_nr(struct task_struct *task,
23 				  struct pt_regs *regs)
24 {
25 	unsigned long insn;
26 
27 	/*
28 	 * FIXME there's no way to find out how we got here other than to
29 	 * examine the memory at the PC to see if it is a syscall
30 	 * SWITCH instruction.
31 	 */
32 	if (get_user(insn, (unsigned long *)(regs->ctx.CurrPC - 4)))
33 		return -1;
34 
35 	if (insn == __METAG_SW_ENCODING(SYS))
36 		return regs->ctx.DX[0].U1;
37 	else
38 		return -1L;
39 }
40 
syscall_rollback(struct task_struct * task,struct pt_regs * regs)41 static inline void syscall_rollback(struct task_struct *task,
42 				    struct pt_regs *regs)
43 {
44 	/* do nothing */
45 }
46 
syscall_get_error(struct task_struct * task,struct pt_regs * regs)47 static inline long syscall_get_error(struct task_struct *task,
48 				     struct pt_regs *regs)
49 {
50 	unsigned long error = regs->ctx.DX[0].U0;
51 	return IS_ERR_VALUE(error) ? error : 0;
52 }
53 
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)54 static inline long syscall_get_return_value(struct task_struct *task,
55 					    struct pt_regs *regs)
56 {
57 	return regs->ctx.DX[0].U0;
58 }
59 
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)60 static inline void syscall_set_return_value(struct task_struct *task,
61 					    struct pt_regs *regs,
62 					    int error, long val)
63 {
64 	regs->ctx.DX[0].U0 = (long) error ?: val;
65 }
66 
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned int i,unsigned int n,unsigned long * args)67 static inline void syscall_get_arguments(struct task_struct *task,
68 					 struct pt_regs *regs,
69 					 unsigned int i, unsigned int n,
70 					 unsigned long *args)
71 {
72 	unsigned int reg, j;
73 	BUG_ON(i + n > 6);
74 
75 	for (j = i, reg = 6 - i; j < (i + n); j++, reg--) {
76 		if (reg % 2)
77 			args[j] = regs->ctx.DX[(reg + 1) / 2].U0;
78 		else
79 			args[j] = regs->ctx.DX[reg / 2].U1;
80 	}
81 }
82 
syscall_set_arguments(struct task_struct * task,struct pt_regs * regs,unsigned int i,unsigned int n,const unsigned long * args)83 static inline void syscall_set_arguments(struct task_struct *task,
84 					 struct pt_regs *regs,
85 					 unsigned int i, unsigned int n,
86 					 const unsigned long *args)
87 {
88 	unsigned int reg;
89 	BUG_ON(i + n > 6);
90 
91 	for (reg = 6 - i; i < (i + n); i++, reg--) {
92 		if (reg % 2)
93 			regs->ctx.DX[(reg + 1) / 2].U0 = args[i];
94 		else
95 			regs->ctx.DX[reg / 2].U1 = args[i];
96 	}
97 }
98 
99 #define NR_syscalls __NR_syscalls
100 
101 /* generic syscall table */
102 extern const void *sys_call_table[];
103 
104 #endif	/* _ASM_METAG_SYSCALL_H */
105