2 * linux/arch/nios2nommu/kernel/sys_nios2.c
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 * This file contains various random system calls that
7 * have a non-standard calling sequence on the Linux/nios2nommu
10 * All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
20 * NON INFRINGEMENT. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/errno.h>
30 #include <linux/sched.h>
32 #include <linux/smp.h>
33 #include <linux/smp_lock.h>
34 #include <linux/sem.h>
35 #include <linux/msg.h>
36 #include <linux/shm.h>
37 #include <linux/stat.h>
38 #include <linux/syscalls.h>
39 #include <linux/mman.h>
40 #include <linux/file.h>
41 #include <linux/utsname.h>
43 #include <asm/setup.h>
44 #include <asm/uaccess.h>
45 #include <asm/cachectl.h>
46 #include <asm/traps.h>
48 #include <asm/cacheflush.h>
49 #include <asm/unistd.h>
52 * sys_pipe() is the normal C calling standard for creating
53 * a pipe. It's not the way unix traditionally does this, though.
55 asmlinkage
int sys_pipe(unsigned long * fildes
)
62 if (copy_to_user(fildes
, fd
, 2*sizeof(int)))
68 /* common code for old and new mmaps */
69 static inline long do_mmap2(
70 unsigned long addr
, unsigned long len
,
71 unsigned long prot
, unsigned long flags
,
72 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 asmlinkage
long sys_mmap2(unsigned long addr
, unsigned long len
,
95 unsigned long prot
, unsigned long flags
,
96 unsigned long fd
, unsigned long pgoff
)
98 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
);
102 * Perform the select(nd, in, out, ex, tv) and mmap() system
103 * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
104 * handle more than 4 system call parameters, so these system calls
105 * used a memory block for parameter passing..
108 struct mmap_arg_struct
{
114 unsigned long offset
;
117 asmlinkage
int old_mmap(struct mmap_arg_struct
*arg
)
119 struct mmap_arg_struct a
;
122 if (copy_from_user(&a
, arg
, sizeof(a
)))
126 if (a
.offset
& ~PAGE_MASK
)
129 a
.flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
131 error
= do_mmap2(a
.addr
, a
.len
, a
.prot
, a
.flags
, a
.fd
, a
.offset
>> PAGE_SHIFT
);
136 struct sel_arg_struct
{
138 fd_set
*inp
, *outp
, *exp
;
142 asmlinkage
int old_select(struct sel_arg_struct
*arg
)
144 struct sel_arg_struct a
;
146 if (copy_from_user(&a
, arg
, sizeof(a
)))
148 /* sys_select() does the appropriate kernel locking */
149 return sys_select(a
.n
, a
.inp
, a
.outp
, a
.exp
, a
.tvp
);
153 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
155 * This is really horribly ugly.
157 asmlinkage
int sys_ipc (uint call
, int first
, int second
,
158 int third
, void *ptr
, long fifth
)
162 version
= call
>> 16; /* hack for backward compatibility */
168 return sys_semop (first
, (struct sembuf
*)ptr
, second
);
170 return sys_semget (first
, second
, third
);
175 if (get_user(fourth
.__pad
, (void **) ptr
))
177 return sys_semctl (first
, second
, third
, fourth
);
185 return sys_msgsnd (first
, (struct msgbuf
*) ptr
,
190 struct ipc_kludge tmp
;
193 if (copy_from_user (&tmp
,
194 (struct ipc_kludge
*)ptr
,
197 return sys_msgrcv (first
, tmp
.msgp
, second
,
201 return sys_msgrcv (first
,
202 (struct msgbuf
*) ptr
,
203 second
, fifth
, third
);
206 return sys_msgget ((key_t
) first
, second
);
208 return sys_msgctl (first
, second
,
209 (struct msqid_ds
*) ptr
);
217 /* sys_cacheflush -- flush the processor cache. */
219 sys_cacheflush (unsigned long addr
, int scope
, int cache
, unsigned long len
)
225 asmlinkage
int sys_getpagesize(void)
231 * Do a system call from kernel instead of calling sys_execve so we
232 * end up with proper pt_regs.
234 int kernel_execve(const char *filename
, char *const argv
[], char *const envp
[])
236 register long __res
__asm__ ("r2") = TRAP_ID_SYSCALL
;
237 register long __sc
__asm__ ("r3") = __NR_execve
;
238 register long __a
__asm__ ("r4") = (long) filename
;
239 register long __b
__asm__ ("r5") = (long) argv
;
240 register long __c
__asm__ ("r6") = (long) envp
;
241 __asm__
__volatile__ ("trap" : "=r" (__res
)
242 : "0" (__res
), "r" (__sc
), "r" (__a
), "r" (__b
), "r" (__c
)