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/linkage.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/mman.h>
26 #include <linux/sched.h>
27 #include <linux/file.h>
28 #include <linux/slab.h>
29 #include <linux/utsname.h>
30 #include <linux/unistd.h>
31 #include <linux/stringify.h>
32 #include <linux/syscalls.h>
33 #include <linux/sem.h>
34 #include <linux/msg.h>
35 #include <linux/shm.h>
36 #include <linux/errno.h>
37 #include <asm/ptrace.h>
38 #include <asm/signal.h>
39 #include <asm/uaccess.h>
40 #include <asm/hardirq.h>
42 #include <asm/shmparam.h>
45 extern void do_syscall_trace(void);
46 typedef int (*syscall_t
)(void *a0
,...);
47 extern syscall_t sys_call_table
[];
48 extern unsigned char sys_narg_table
[];
51 * sys_pipe() is the normal C calling standard for creating a pipe. It's not
52 * the way unix traditional does this, though.
55 int sys_pipe(int __user
*userfds
)
62 if (copy_to_user(userfds
, fd
, 2 * sizeof(int)))
69 * Common code for old and new mmaps.
71 long sys_mmap(unsigned long addr
, unsigned long len
, unsigned long prot
,
72 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
75 struct file
* file
= NULL
;
77 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
78 if (!(flags
& MAP_ANONYMOUS
)) {
84 down_write(¤t
->mm
->mmap_sem
);
85 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
86 up_write(¤t
->mm
->mmap_sem
);
94 int sys_clone(struct pt_regs
*regs
)
96 unsigned long clone_flags
;
98 int __user
*parent_tidptr
, *child_tidptr
;
99 clone_flags
= regs
->areg
[4];
100 newsp
= regs
->areg
[3];
101 parent_tidptr
= (int __user
*)regs
->areg
[5];
102 child_tidptr
= (int __user
*)regs
->areg
[6];
104 newsp
= regs
->areg
[1];
105 return do_fork(clone_flags
,newsp
,regs
,0,parent_tidptr
,child_tidptr
);
109 * sys_execve() executes a new program.
112 int sys_execve(struct pt_regs
*regs
)
117 filename
= getname((char *) (long)regs
->areg
[5]);
118 error
= PTR_ERR(filename
);
119 if (IS_ERR(filename
))
121 error
= do_execve(filename
, (char **) (long)regs
->areg
[3],
122 (char **) (long)regs
->areg
[4], regs
);
129 int sys_uname(struct old_utsname
* name
)
131 if (name
&& !copy_to_user(name
, &system_utsname
, sizeof (*name
)))
137 * Build the string table for the builtin "poor man's strace".
141 #define SYSCALL(fun, narg) #fun,
142 static char *sfnames
[] = {
143 #include "syscalls.h"
148 void system_call (struct pt_regs
*regs
)
151 unsigned long parm0
, parm1
, parm2
, parm3
, parm4
, parm5
;
153 unsigned int syscallnr
;
158 unsigned long parms
[6];
162 regs
->syscall
= regs
->areg
[2];
166 /* Have to load after syscall_trace because strace
167 * sometimes changes regs->syscall.
169 syscallnr
= regs
->syscall
;
171 parm0
= parm1
= parm2
= parm3
= parm4
= parm5
= 0;
173 /* Restore interrupt level to syscall invoker's.
174 * If this were in assembly, we wouldn't disable
175 * interrupts in the first place:
177 local_save_flags (ps
);
178 local_irq_restore((ps
& ~XCHAL_PS_INTLEVEL_MASK
) |
179 (regs
->ps
& XCHAL_PS_INTLEVEL_MASK
) );
181 if (syscallnr
> __NR_Linux_syscalls
) {
182 regs
->areg
[2] = -ENOSYS
;
186 syscall
= sys_call_table
[syscallnr
];
187 nargs
= sys_narg_table
[syscallnr
];
189 if (syscall
== NULL
) {
190 regs
->areg
[2] = -ENOSYS
;
194 /* There shouldn't be more than six arguments in the table! */
197 panic("Internal error - too many syscall arguments (%d)!\n",
200 /* Linux takes system-call arguments in registers. The ABI
201 * and Xtensa software conventions require the system-call
202 * number in a2. If an argument exists in a2, we move it to
203 * the next available register. Note that for improved
204 * efficiency, we do NOT shift all parameters down one
205 * register to maintain the original order.
207 * At best case (zero arguments), we just write the syscall
208 * number to a2. At worst case (1 to 6 arguments), we move
209 * the argument in a2 to the next available register, then
210 * write the syscall number to a2.
212 * For clarity, the following truth table enumerates all
215 * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
216 * --------- -------------- ----------------------------------
221 * 4 a2 a6, a3, a4, a5
222 * 5 a2 a7, a3, a4, a5, a6
223 * 6 a2 a8, a3, a4, a5, a6, a7
226 parm0
= regs
->areg
[nargs
+2];
227 parm1
= regs
->areg
[3];
228 parm2
= regs
->areg
[4];
229 parm3
= regs
->areg
[5];
230 parm4
= regs
->areg
[6];
231 parm5
= regs
->areg
[7];
232 } else /* nargs == 0 */
233 parm0
= (unsigned long) regs
;
243 sysname
= sfnames
[syscallnr
];
244 if (strncmp(sysname
, "sys_", 4) == 0)
245 sysname
= sysname
+ 4;
247 printk("\017SYSCALL:I:%x:%d:%s %s(", regs
->pc
, current
->pid
,
248 current
->comm
, sysname
);
249 for (i
= 0; i
< nargs
; i
++)
250 printk((i
>0) ? ", %#lx" : "%#lx", parms
[i
]);
254 res
= syscall((void *)parm0
, parm1
, parm2
, parm3
, parm4
, parm5
);
257 printk("\017SYSCALL:O:%d:%s %s(",current
->pid
, current
->comm
, sysname
);
258 for (i
= 0; i
< nargs
; i
++)
259 printk((i
>0) ? ", %#lx" : "%#lx", parms
[i
]);
261 printk(") = %d\n", res
);
263 printk(") = %#x\n", res
);