2 * arch/xtensa/kernel/syscall.c
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
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Copyright (C) 2000 Silicon Graphics, Inc.
10 * Copyright (C) 1995 - 2000 by Ralf Baechle
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>
21 #include <linux/config.h>
22 #include <linux/linkage.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>
43 #include <asm/shmparam.h>
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[];
53 * sys_pipe() is the normal C calling standard for creating a pipe. It's not
54 * the way unix traditional does this, though.
57 int sys_pipe(int __user *userfds)
64 if (copy_to_user(userfds, fd, 2 * sizeof(int)))
71 * Common code for old and new mmaps.
73 long sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
74 unsigned long flags, unsigned long fd, unsigned long pgoff)
77 struct file * file = NULL;
79 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
80 if (!(flags & MAP_ANONYMOUS)) {
86 down_write(¤t->mm->mmap_sem);
87 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
88 up_write(¤t->mm->mmap_sem);
96 int sys_clone(struct pt_regs *regs)
98 unsigned long clone_flags;
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];
106 newsp = regs->areg[1];
107 return do_fork(clone_flags,newsp,regs,0,parent_tidptr,child_tidptr);
111 * sys_execve() executes a new program.
114 int sys_execve(struct pt_regs *regs)
119 filename = getname((char *) (long)regs->areg[5]);
120 error = PTR_ERR(filename);
121 if (IS_ERR(filename))
123 error = do_execve(filename, (char **) (long)regs->areg[3],
124 (char **) (long)regs->areg[4], regs);
131 int sys_uname(struct old_utsname * name)
133 if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
139 * Build the string table for the builtin "poor man's strace".
143 #define SYSCALL(fun, narg) #fun,
144 static char *sfnames[] = {
145 #include "syscalls.h"
150 void system_call (struct pt_regs *regs)
153 unsigned long parm0, parm1, parm2, parm3, parm4, parm5;
155 unsigned int syscallnr;
160 unsigned long parms[6];
164 regs->syscall = regs->areg[2];
168 /* Have to load after syscall_trace because strace
169 * sometimes changes regs->syscall.
171 syscallnr = regs->syscall;
173 parm0 = parm1 = parm2 = parm3 = parm4 = parm5 = 0;
175 /* Restore interrupt level to syscall invoker's.
176 * If this were in assembly, we wouldn't disable
177 * interrupts in the first place:
179 local_save_flags (ps);
180 local_irq_restore((ps & ~XCHAL_PS_INTLEVEL_MASK) |
181 (regs->ps & XCHAL_PS_INTLEVEL_MASK) );
183 if (syscallnr > __NR_Linux_syscalls) {
184 regs->areg[2] = -ENOSYS;
188 syscall = sys_call_table[syscallnr];
189 nargs = sys_narg_table[syscallnr];
191 if (syscall == NULL) {
192 regs->areg[2] = -ENOSYS;
196 /* There shouldn't be more than six arguments in the table! */
199 panic("Internal error - too many syscall arguments (%d)!\n",
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.
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.
214 * For clarity, the following truth table enumerates all
217 * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
218 * --------- -------------- ----------------------------------
223 * 4 a2 a6, a3, a4, a5
224 * 5 a2 a7, a3, a4, a5, a6
225 * 6 a2 a8, a3, a4, a5, a6, a7
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;
245 sysname = sfnames[syscallnr];
246 if (strncmp(sysname, "sys_", 4) == 0)
247 sysname = sysname + 4;
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]);
256 res = syscall((void *)parm0, parm1, parm2, parm3, parm4, parm5);
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]);
263 printk(") = %d\n", res);
265 printk(") = %#x\n", res);