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>
46 extern void do_syscall_trace(void);
47 typedef int (*syscall_t
)(void *a0
,...);
48 extern syscall_t sys_call_table
[];
49 extern unsigned char sys_narg_table
[];
52 * sys_pipe() is the normal C calling standard for creating a pipe. It's not
53 * the way unix traditional does this, though.
56 int sys_pipe(int __user
*userfds
)
63 if (copy_to_user(userfds
, fd
, 2 * sizeof(int)))
70 * Common code for old and new mmaps.
72 long sys_mmap(unsigned long addr
, unsigned long len
, unsigned long prot
,
73 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
76 struct file
* file
= NULL
;
78 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
79 if (!(flags
& MAP_ANONYMOUS
)) {
85 down_write(¤t
->mm
->mmap_sem
);
86 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
87 up_write(¤t
->mm
->mmap_sem
);
95 int sys_clone(struct pt_regs
*regs
)
97 unsigned long clone_flags
;
99 int __user
*parent_tidptr
, *child_tidptr
;
100 clone_flags
= regs
->areg
[4];
101 newsp
= regs
->areg
[3];
102 parent_tidptr
= (int __user
*)regs
->areg
[5];
103 child_tidptr
= (int __user
*)regs
->areg
[6];
105 newsp
= regs
->areg
[1];
106 return do_fork(clone_flags
,newsp
,regs
,0,parent_tidptr
,child_tidptr
);
110 * sys_execve() executes a new program.
113 int sys_execve(struct pt_regs
*regs
)
118 filename
= getname((char *) (long)regs
->areg
[5]);
119 error
= PTR_ERR(filename
);
120 if (IS_ERR(filename
))
122 error
= do_execve(filename
, (char **) (long)regs
->areg
[3],
123 (char **) (long)regs
->areg
[4], regs
);
130 int sys_uname(struct old_utsname
* name
)
132 if (name
&& !copy_to_user(name
, &system_utsname
, sizeof (*name
)))
138 * Build the string table for the builtin "poor man's strace".
142 #define SYSCALL(fun, narg) #fun,
143 static char *sfnames
[] = {
144 #include "syscalls.h"
149 void system_call (struct pt_regs
*regs
)
152 unsigned long parm0
, parm1
, parm2
, parm3
, parm4
, parm5
;
154 unsigned int syscallnr
;
159 unsigned long parms
[6];
163 regs
->syscall
= regs
->areg
[2];
167 /* Have to load after syscall_trace because strace
168 * sometimes changes regs->syscall.
170 syscallnr
= regs
->syscall
;
172 parm0
= parm1
= parm2
= parm3
= parm4
= parm5
= 0;
174 /* Restore interrupt level to syscall invoker's.
175 * If this were in assembly, we wouldn't disable
176 * interrupts in the first place:
178 local_save_flags (ps
);
179 local_irq_restore((ps
& ~XCHAL_PS_INTLEVEL_MASK
) |
180 (regs
->ps
& XCHAL_PS_INTLEVEL_MASK
) );
182 if (syscallnr
> __NR_Linux_syscalls
) {
183 regs
->areg
[2] = -ENOSYS
;
187 syscall
= sys_call_table
[syscallnr
];
188 nargs
= sys_narg_table
[syscallnr
];
190 if (syscall
== NULL
) {
191 regs
->areg
[2] = -ENOSYS
;
195 /* There shouldn't be more than six arguments in the table! */
198 panic("Internal error - too many syscall arguments (%d)!\n",
201 /* Linux takes system-call arguments in registers. The ABI
202 * and Xtensa software conventions require the system-call
203 * number in a2. If an argument exists in a2, we move it to
204 * the next available register. Note that for improved
205 * efficiency, we do NOT shift all parameters down one
206 * register to maintain the original order.
208 * At best case (zero arguments), we just write the syscall
209 * number to a2. At worst case (1 to 6 arguments), we move
210 * the argument in a2 to the next available register, then
211 * write the syscall number to a2.
213 * For clarity, the following truth table enumerates all
216 * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
217 * --------- -------------- ----------------------------------
222 * 4 a2 a6, a3, a4, a5
223 * 5 a2 a7, a3, a4, a5, a6
224 * 6 a2 a8, a3, a4, a5, a6, a7
227 parm0
= regs
->areg
[nargs
+2];
228 parm1
= regs
->areg
[3];
229 parm2
= regs
->areg
[4];
230 parm3
= regs
->areg
[5];
231 parm4
= regs
->areg
[6];
232 parm5
= regs
->areg
[7];
233 } else /* nargs == 0 */
234 parm0
= (unsigned long) regs
;
244 sysname
= sfnames
[syscallnr
];
245 if (strncmp(sysname
, "sys_", 4) == 0)
246 sysname
= sysname
+ 4;
248 printk("\017SYSCALL:I:%x:%d:%s %s(", regs
->pc
, current
->pid
,
249 current
->comm
, sysname
);
250 for (i
= 0; i
< nargs
; i
++)
251 printk((i
>0) ? ", %#lx" : "%#lx", parms
[i
]);
255 res
= syscall((void *)parm0
, parm1
, parm2
, parm3
, parm4
, parm5
);
258 printk("\017SYSCALL:O:%d:%s %s(",current
->pid
, current
->comm
, sysname
);
259 for (i
= 0; i
< nargs
; i
++)
260 printk((i
>0) ? ", %#lx" : "%#lx", parms
[i
]);
262 printk(") = %d\n", res
);
264 printk(") = %#x\n", res
);