MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / kernel / sys_nios2.c
blob7b08c6c4930f08db934ade27b751248045bfc507
1 /*
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
8 * platform.
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
21 * details.
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>
31 #include <linux/mm.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>
47 #include <asm/ipc.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)
57 int fd[2];
58 int error;
60 error = do_pipe(fd);
61 if (!error) {
62 if (copy_to_user(fildes, fd, 2*sizeof(int)))
63 error = -EFAULT;
65 return error;
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)
74 int error = -EBADF;
75 struct file * file = NULL;
77 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
78 if (!(flags & MAP_ANONYMOUS)) {
79 file = fget(fd);
80 if (!file)
81 goto out;
84 down_write(&current->mm->mmap_sem);
85 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
86 up_write(&current->mm->mmap_sem);
88 if (file)
89 fput(file);
90 out:
91 return error;
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 {
109 unsigned long addr;
110 unsigned long len;
111 unsigned long prot;
112 unsigned long flags;
113 unsigned long fd;
114 unsigned long offset;
117 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
119 struct mmap_arg_struct a;
120 int error = -EFAULT;
122 if (copy_from_user(&a, arg, sizeof(a)))
123 goto out;
125 error = -EINVAL;
126 if (a.offset & ~PAGE_MASK)
127 goto out;
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);
132 out:
133 return error;
136 struct sel_arg_struct {
137 unsigned long n;
138 fd_set *inp, *outp, *exp;
139 struct timeval *tvp;
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)))
147 return -EFAULT;
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)
160 int version;
162 version = call >> 16; /* hack for backward compatibility */
163 call &= 0xffff;
165 if (call <= SEMCTL)
166 switch (call) {
167 case SEMOP:
168 return sys_semop (first, (struct sembuf *)ptr, second);
169 case SEMGET:
170 return sys_semget (first, second, third);
171 case SEMCTL: {
172 union semun fourth;
173 if (!ptr)
174 return -EINVAL;
175 if (get_user(fourth.__pad, (void **) ptr))
176 return -EFAULT;
177 return sys_semctl (first, second, third, fourth);
179 default:
180 return -EINVAL;
182 if (call <= MSGCTL)
183 switch (call) {
184 case MSGSND:
185 return sys_msgsnd (first, (struct msgbuf *) ptr,
186 second, third);
187 case MSGRCV:
188 switch (version) {
189 case 0: {
190 struct ipc_kludge tmp;
191 if (!ptr)
192 return -EINVAL;
193 if (copy_from_user (&tmp,
194 (struct ipc_kludge *)ptr,
195 sizeof (tmp)))
196 return -EFAULT;
197 return sys_msgrcv (first, tmp.msgp, second,
198 tmp.msgtyp, third);
200 default:
201 return sys_msgrcv (first,
202 (struct msgbuf *) ptr,
203 second, fifth, third);
205 case MSGGET:
206 return sys_msgget ((key_t) first, second);
207 case MSGCTL:
208 return sys_msgctl (first, second,
209 (struct msqid_ds *) ptr);
210 default:
211 return -EINVAL;
214 return -EINVAL;
217 /* sys_cacheflush -- flush the processor cache. */
218 asmlinkage int
219 sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
221 flush_cache_all();
222 return(0);
225 asmlinkage int sys_getpagesize(void)
227 return PAGE_SIZE;
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)
243 : "memory");
245 return __res;