2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #include <linux/errno.h>
11 #include <linux/linkage.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/mman.h>
16 #include <linux/ptrace.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
19 #include <linux/syscalls.h>
20 #include <linux/file.h>
21 #include <linux/slab.h>
22 #include <linux/utsname.h>
23 #include <linux/unistd.h>
24 #include <linux/sem.h>
25 #include <linux/msg.h>
26 #include <linux/shm.h>
27 #include <linux/vs_cvirt.h>
28 #include <linux/compiler.h>
29 #include <linux/vs_cvirt.h>
31 #include <asm/branch.h>
32 #include <asm/cachectl.h>
33 #include <asm/cacheflush.h>
35 #include <asm/offset.h>
36 #include <asm/signal.h>
38 #include <asm/shmparam.h>
39 #include <asm/sysmips.h>
40 #include <asm/uaccess.h>
42 asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs)
58 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
60 #define COLOUR_ALIGN(addr,pgoff) \
61 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
62 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
64 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
65 unsigned long len, unsigned long pgoff, unsigned long flags)
67 struct vm_area_struct * vmm;
69 unsigned long task_size;
72 task_size = TASK_SIZE;
74 task_size = (current->thread.mflags & MF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE;
77 if (flags & MAP_FIXED) {
79 * We do not accept a shared mapping if it would violate
80 * cache aliasing constraints.
82 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
90 if (filp || (flags & MAP_SHARED))
94 addr = COLOUR_ALIGN(addr, pgoff);
96 addr = PAGE_ALIGN(addr);
97 vmm = find_vma(current->mm, addr);
98 if (task_size - len >= addr &&
99 (!vmm || addr + len <= vmm->vm_start))
102 addr = TASK_UNMAPPED_BASE;
104 addr = COLOUR_ALIGN(addr, pgoff);
106 addr = PAGE_ALIGN(addr);
108 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
109 /* At this point: (!vmm || addr < vmm->vm_end). */
110 if (task_size - len < addr)
112 if (!vmm || addr + len <= vmm->vm_start)
116 addr = COLOUR_ALIGN(addr, pgoff);
120 /* common code for old and new mmaps */
122 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
123 unsigned long flags, unsigned long fd, unsigned long pgoff)
125 unsigned long error = -EBADF;
126 struct file * file = NULL;
128 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
129 if (!(flags & MAP_ANONYMOUS)) {
135 down_write(¤t->mm->mmap_sem);
136 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
137 up_write(¤t->mm->mmap_sem);
145 asmlinkage unsigned long old_mmap(unsigned long addr, size_t len, int prot,
146 int flags, int fd, off_t offset)
148 unsigned long result;
151 if (offset & ~PAGE_MASK)
154 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
161 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
162 unsigned long flags, unsigned long fd, unsigned long pgoff)
164 return do_mmap2(addr, len, prot, flags, fd, pgoff);
167 save_static_function(sys_fork);
168 __attribute_used__ noinline static int
169 _sys_fork(nabi_no_regargs struct pt_regs regs)
171 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
174 save_static_function(sys_clone);
175 __attribute_used__ noinline static int
176 _sys_clone(nabi_no_regargs struct pt_regs regs)
178 unsigned long clone_flags;
180 int *parent_tidptr, *child_tidptr;
182 clone_flags = regs.regs[4];
183 newsp = regs.regs[5];
185 newsp = regs.regs[29];
186 parent_tidptr = (int *) regs.regs[6];
187 child_tidptr = (int *) regs.regs[7];
188 return do_fork(clone_flags, newsp, ®s, 0,
189 parent_tidptr, child_tidptr);
193 * sys_execve() executes a new program.
195 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
200 filename = getname((char *) (long)regs.regs[4]);
201 error = PTR_ERR(filename);
202 if (IS_ERR(filename))
204 error = do_execve(filename, (char **) (long)regs.regs[5],
205 (char **) (long)regs.regs[6], ®s);
213 * Compacrapability ...
215 asmlinkage int sys_uname(struct old_utsname * name)
217 if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
223 * Compacrapability ...
225 asmlinkage int sys_olduname(struct oldold_utsname * name)
228 struct new_utsname *ptr;
232 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
235 ptr = vx_new_utsname();
236 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
237 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
238 error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
239 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
240 error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
241 error -= __put_user(0,name->release+__OLD_UTS_LEN);
242 error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
243 error -= __put_user(0,name->version+__OLD_UTS_LEN);
244 error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
245 error = __put_user(0,name->machine+__OLD_UTS_LEN);
246 error = error ? -EFAULT : 0;
251 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
258 char nodename[__NEW_UTS_LEN + 1];
260 if (!capable(CAP_SYS_ADMIN))
263 name = (char *) arg1;
265 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
269 down_write(&uts_sem);
270 strncpy(vx_new_uts(nodename), nodename, len);
271 nodename[__NEW_UTS_LEN] = '\0';
272 strlcpy(vx_new_uts(nodename), nodename,
273 sizeof(vx_new_uts(nodename)));
278 case MIPS_ATOMIC_SET:
279 printk(KERN_CRIT "How did I get here?\n");
283 tmp = current->thread.mflags & ~3;
284 current->thread.mflags = tmp | (arg1 & 3);
299 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
301 * This is really horribly ugly.
303 asmlinkage int sys_ipc (uint call, int first, int second,
304 unsigned long third, void *ptr, long fifth)
308 version = call >> 16; /* hack for backward compatibility */
313 return sys_semtimedop (first, (struct sembuf *)ptr, second,
316 return sys_semtimedop (first, (struct sembuf *)ptr, second,
317 (const struct timespec __user *)fifth);
319 return sys_semget (first, second, third);
324 if (get_user(fourth.__pad, (void **) ptr))
326 return sys_semctl (first, second, third, fourth);
330 return sys_msgsnd (first, (struct msgbuf *) ptr,
335 struct ipc_kludge tmp;
339 if (copy_from_user(&tmp,
340 (struct ipc_kludge *) ptr,
343 return sys_msgrcv (first, tmp.msgp, second,
347 return sys_msgrcv (first,
348 (struct msgbuf *) ptr,
349 second, fifth, third);
352 return sys_msgget ((key_t) first, second);
354 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
360 ret = do_shmat (first, (char *) ptr, second, &raddr);
363 return put_user (raddr, (ulong *) third);
365 case 1: /* iBCS2 emulator entry point */
366 if (!segment_eq(get_fs(), get_ds()))
368 return do_shmat (first, (char *) ptr, second, (ulong *) third);
371 return sys_shmdt ((char *)ptr);
373 return sys_shmget (first, second, third);
375 return sys_shmctl (first, second,
376 (struct shmid_ds *) ptr);
383 * Native ABI that is O32 or N64 version
385 asmlinkage long sys_shmat(int shmid, char __user *shmaddr,
386 int shmflg, unsigned long *addr)
391 err = do_shmat(shmid, shmaddr, shmflg, &raddr);
395 return put_user(raddr, addr);
399 * No implemented yet ...
401 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
407 * If we ever come here the user sp is bad. Zap the process right away.
408 * Due to the bad stack signaling wouldn't work.
410 asmlinkage void bad_stack(void)