]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/xtensa/kernel/syscalls.c
[PATCH] xtensa: remove old syscalls
[linux-2.6.git] / arch / xtensa / kernel / syscalls.c
1 /*
2  * arch/xtensa/kernel/syscall.c
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2001 - 2005 Tensilica Inc.
9  * Copyright (C) 2000 Silicon Graphics, Inc.
10  * Copyright (C) 1995 - 2000 by Ralf Baechle
11  *
12  * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
13  * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14  * Chris Zankel <chris@zankel.net>
15  * Kevin Chea
16  *
17  */
18
19 #define DEBUG   0
20
21 #include <linux/config.h>
22 #include <linux/linkage.h>
23 #include <linux/mm.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/mman.h>
27 #include <linux/sched.h>
28 #include <linux/file.h>
29 #include <linux/slab.h>
30 #include <linux/utsname.h>
31 #include <linux/unistd.h>
32 #include <linux/stringify.h>
33 #include <linux/syscalls.h>
34 #include <linux/sem.h>
35 #include <linux/msg.h>
36 #include <linux/shm.h>
37 #include <linux/errno.h>
38 #include <asm/ptrace.h>
39 #include <asm/signal.h>
40 #include <asm/uaccess.h>
41 #include <asm/hardirq.h>
42 #include <asm/mman.h>
43 #include <asm/shmparam.h>
44 #include <asm/page.h>
45 #include <asm/ipc.h>
46
47 extern void do_syscall_trace(void);
48 typedef int (*syscall_t)(void *a0,...);
49 extern syscall_t sys_call_table[];
50 extern unsigned char sys_narg_table[];
51
52 /*
53  * sys_pipe() is the normal C calling standard for creating a pipe. It's not
54  * the way unix traditional does this, though.
55  */
56
57 int sys_pipe(int __user *userfds)
58 {
59         int fd[2];
60         int error;
61
62         error = do_pipe(fd);
63         if (!error) {
64                 if (copy_to_user(userfds, fd, 2 * sizeof(int)))
65                         error = -EFAULT;
66         }
67         return error;
68 }
69
70 /*
71  * Common code for old and new mmaps.
72  */
73 long sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
74                unsigned long flags, unsigned long fd, unsigned long pgoff)
75 {
76         int error = -EBADF;
77         struct file * file = NULL;
78
79         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
80         if (!(flags & MAP_ANONYMOUS)) {
81                 file = fget(fd);
82                 if (!file)
83                         goto out;
84         }
85
86         down_write(&current->mm->mmap_sem);
87         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
88         up_write(&current->mm->mmap_sem);
89
90         if (file)
91                 fput(file);
92 out:
93         return error;
94 }
95
96 int sys_clone(struct pt_regs *regs)
97 {
98         unsigned long clone_flags;
99         unsigned long newsp;
100         int __user *parent_tidptr, *child_tidptr;
101         clone_flags = regs->areg[4];
102         newsp = regs->areg[3];
103         parent_tidptr = (int __user *)regs->areg[5];
104         child_tidptr = (int __user *)regs->areg[6];
105         if (!newsp)
106                 newsp = regs->areg[1];
107         return do_fork(clone_flags,newsp,regs,0,parent_tidptr,child_tidptr);
108 }
109
110 /*
111  * sys_execve() executes a new program.
112  */
113
114 int sys_execve(struct pt_regs *regs)
115 {
116         int error;
117         char * filename;
118
119         filename = getname((char *) (long)regs->areg[5]);
120         error = PTR_ERR(filename);
121         if (IS_ERR(filename))
122                 goto out;
123         error = do_execve(filename, (char **) (long)regs->areg[3],
124                           (char **) (long)regs->areg[4], regs);
125         putname(filename);
126
127 out:
128         return error;
129 }
130
131 int sys_uname(struct old_utsname * name)
132 {
133         if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
134                 return 0;
135         return -EFAULT;
136 }
137
138 /*
139  * Build the string table for the builtin "poor man's strace".
140  */
141
142 #if DEBUG
143 #define SYSCALL(fun, narg) #fun,
144 static char *sfnames[] = {
145 #include "syscalls.h"
146 };
147 #undef SYS
148 #endif
149
150 void system_call (struct pt_regs *regs)
151 {
152         syscall_t syscall;
153         unsigned long parm0, parm1, parm2, parm3, parm4, parm5;
154         int nargs, res;
155         unsigned int syscallnr;
156         int ps;
157
158 #if DEBUG
159         int i;
160         unsigned long parms[6];
161         char *sysname;
162 #endif
163
164         regs->syscall = regs->areg[2];
165
166         do_syscall_trace();
167
168         /* Have to load after syscall_trace because strace
169          * sometimes changes regs->syscall.
170          */
171         syscallnr = regs->syscall;
172
173         parm0 = parm1 = parm2 = parm3 = parm4 = parm5 = 0;
174
175         /* Restore interrupt level to syscall invoker's.
176          * If this were in assembly, we wouldn't disable
177          * interrupts in the first place:
178          */
179         local_save_flags (ps);
180         local_irq_restore((ps & ~XCHAL_PS_INTLEVEL_MASK) |
181                           (regs->ps & XCHAL_PS_INTLEVEL_MASK) );
182
183         if (syscallnr > __NR_Linux_syscalls) {
184                 regs->areg[2] = -ENOSYS;
185                 return;
186         }
187
188         syscall = sys_call_table[syscallnr];
189         nargs = sys_narg_table[syscallnr];
190
191         if (syscall == NULL) {
192                 regs->areg[2] = -ENOSYS;
193                 return;
194         }
195
196         /* There shouldn't be more than six arguments in the table! */
197
198         if (nargs > 6)
199                 panic("Internal error - too many syscall arguments (%d)!\n",
200                       nargs);
201
202         /* Linux takes system-call arguments in registers.  The ABI
203          * and Xtensa software conventions require the system-call
204          * number in a2.  If an argument exists in a2, we move it to
205          * the next available register.  Note that for improved
206          * efficiency, we do NOT shift all parameters down one
207          * register to maintain the original order.
208          *
209          * At best case (zero arguments), we just write the syscall
210          * number to a2.  At worst case (1 to 6 arguments), we move
211          * the argument in a2 to the next available register, then
212          * write the syscall number to a2.
213          *
214          * For clarity, the following truth table enumerates all
215          * possibilities.
216          *
217          * arguments    syscall number  arg0, arg1, arg2, arg3, arg4, arg5
218          * ---------    --------------  ----------------------------------
219          *      0             a2
220          *      1             a2        a3
221          *      2             a2        a4,   a3
222          *      3             a2        a5,   a3,   a4
223          *      4             a2        a6,   a3,   a4,   a5
224          *      5             a2        a7,   a3,   a4,   a5,   a6
225          *      6             a2        a8,   a3,   a4,   a5,   a6,   a7
226          */
227         if (nargs) {
228                 parm0 = regs->areg[nargs+2];
229                 parm1 = regs->areg[3];
230                 parm2 = regs->areg[4];
231                 parm3 = regs->areg[5];
232                 parm4 = regs->areg[6];
233                 parm5 = regs->areg[7];
234         } else /* nargs == 0 */
235                 parm0 = (unsigned long) regs;
236
237 #if DEBUG
238         parms[0] = parm0;
239         parms[1] = parm1;
240         parms[2] = parm2;
241         parms[3] = parm3;
242         parms[4] = parm4;
243         parms[5] = parm5;
244
245         sysname = sfnames[syscallnr];
246         if (strncmp(sysname, "sys_", 4) == 0)
247                 sysname = sysname + 4;
248
249         printk("\017SYSCALL:I:%x:%d:%s  %s(", regs->pc, current->pid,
250                current->comm, sysname);
251         for (i = 0; i < nargs; i++)
252                 printk((i>0) ? ", %#lx" : "%#lx", parms[i]);
253         printk(")\n");
254 #endif
255
256         res = syscall((void *)parm0, parm1, parm2, parm3, parm4, parm5);
257
258 #if DEBUG
259         printk("\017SYSCALL:O:%d:%s  %s(",current->pid, current->comm, sysname);
260         for (i = 0; i < nargs; i++)
261                 printk((i>0) ? ", %#lx" : "%#lx", parms[i]);
262         if (res < 4096)
263                 printk(") = %d\n", res);
264         else
265                 printk(") = %#x\n", res);
266 #endif /* DEBUG */
267
268         regs->areg[2] = res;
269         do_syscall_trace();
270 }