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, 05 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #include <linux/a.out.h>
11 #include <linux/errno.h>
12 #include <linux/linkage.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/mman.h>
17 #include <linux/ptrace.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/syscalls.h>
21 #include <linux/file.h>
22 #include <linux/slab.h>
23 #include <linux/utsname.h>
24 #include <linux/unistd.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/vs_cvirt.h>
29 #include <linux/compiler.h>
30 #include <linux/vs_cvirt.h>
32 #include <asm/branch.h>
33 #include <asm/cachectl.h>
34 #include <asm/cacheflush.h>
36 #include <asm/offset.h>
37 #include <asm/signal.h>
39 #include <asm/shmparam.h>
40 #include <asm/sysmips.h>
41 #include <asm/uaccess.h>
43 asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs)
59 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
61 #define COLOUR_ALIGN(addr,pgoff) \
62 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
63 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
65 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
66 unsigned long len, unsigned long pgoff, unsigned long flags)
68 struct vm_area_struct * vmm;
70 unsigned long task_size;
72 task_size = STACK_TOP;
74 if (flags & MAP_FIXED) {
76 * We do not accept a shared mapping if it would violate
77 * cache aliasing constraints.
79 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
87 if (filp || (flags & MAP_SHARED))
91 addr = COLOUR_ALIGN(addr, pgoff);
93 addr = PAGE_ALIGN(addr);
94 vmm = find_vma(current->mm, addr);
95 if (task_size - len >= addr &&
96 (!vmm || addr + len <= vmm->vm_start))
99 addr = TASK_UNMAPPED_BASE;
101 addr = COLOUR_ALIGN(addr, pgoff);
103 addr = PAGE_ALIGN(addr);
105 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
106 /* At this point: (!vmm || addr < vmm->vm_end). */
107 if (task_size - len < addr)
109 if (!vmm || addr + len <= vmm->vm_start)
113 addr = COLOUR_ALIGN(addr, pgoff);
117 /* common code for old and new mmaps */
118 static inline unsigned long
119 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
120 unsigned long flags, unsigned long fd, unsigned long pgoff)
122 unsigned long error = -EBADF;
123 struct file * file = NULL;
125 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
126 if (!(flags & MAP_ANONYMOUS)) {
132 down_write(¤t->mm->mmap_sem);
133 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
134 up_write(¤t->mm->mmap_sem);
142 asmlinkage unsigned long
143 old_mmap(unsigned long addr, unsigned long len, int prot,
144 int flags, int fd, off_t offset)
146 unsigned long result;
149 if (offset & ~PAGE_MASK)
152 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
158 asmlinkage unsigned long
159 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
160 unsigned long flags, unsigned long fd, unsigned long pgoff)
162 return do_mmap2(addr, len, prot, flags, fd, pgoff);
165 save_static_function(sys_fork);
166 __attribute_used__ noinline static int
167 _sys_fork(nabi_no_regargs struct pt_regs regs)
169 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
172 save_static_function(sys_clone);
173 __attribute_used__ noinline static int
174 _sys_clone(nabi_no_regargs struct pt_regs regs)
176 unsigned long clone_flags;
178 int *parent_tidptr, *child_tidptr;
180 clone_flags = regs.regs[4];
181 newsp = regs.regs[5];
183 newsp = regs.regs[29];
184 parent_tidptr = (int *) regs.regs[6];
185 child_tidptr = (int *) regs.regs[7];
186 return do_fork(clone_flags, newsp, ®s, 0,
187 parent_tidptr, child_tidptr);
191 * sys_execve() executes a new program.
193 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
198 filename = getname((char *) (long)regs.regs[4]);
199 error = PTR_ERR(filename);
200 if (IS_ERR(filename))
202 error = do_execve(filename, (char **) (long)regs.regs[5],
203 (char **) (long)regs.regs[6], ®s);
211 * Compacrapability ...
213 asmlinkage int sys_uname(struct old_utsname * name)
215 if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
221 * Compacrapability ...
223 asmlinkage int sys_olduname(struct oldold_utsname * name)
226 struct new_utsname *ptr;
230 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
233 ptr = vx_new_utsname();
234 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
235 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
236 error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
237 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
238 error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
239 error -= __put_user(0,name->release+__OLD_UTS_LEN);
240 error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
241 error -= __put_user(0,name->version+__OLD_UTS_LEN);
242 error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
243 error = __put_user(0,name->machine+__OLD_UTS_LEN);
244 error = error ? -EFAULT : 0;
249 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
256 char nodename[__NEW_UTS_LEN + 1];
258 if (!capable(CAP_SYS_ADMIN))
261 name = (char *) arg1;
263 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
267 down_write(&uts_sem);
268 strncpy(vx_new_uts(nodename), nodename, len);
269 nodename[__NEW_UTS_LEN] = '\0';
270 strlcpy(vx_new_uts(nodename), nodename,
271 sizeof(vx_new_uts(nodename)));
276 case MIPS_ATOMIC_SET:
277 printk(KERN_CRIT "How did I get here?\n");
281 tmp = current->thread.mflags & ~3;
282 current->thread.mflags = tmp | (arg1 & 3);
297 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
299 * This is really horribly ugly.
301 asmlinkage int sys_ipc (uint call, int first, int second,
302 unsigned long third, void *ptr, long fifth)
306 version = call >> 16; /* hack for backward compatibility */
311 return sys_semtimedop (first, (struct sembuf *)ptr, second,
314 return sys_semtimedop (first, (struct sembuf *)ptr, second,
315 (const struct timespec __user *)fifth);
317 return sys_semget (first, second, third);
322 if (get_user(fourth.__pad, (void **) ptr))
324 return sys_semctl (first, second, third, fourth);
328 return sys_msgsnd (first, (struct msgbuf *) ptr,
333 struct ipc_kludge tmp;
337 if (copy_from_user(&tmp,
338 (struct ipc_kludge *) ptr,
341 return sys_msgrcv (first, tmp.msgp, second,
345 return sys_msgrcv (first,
346 (struct msgbuf *) ptr,
347 second, fifth, third);
350 return sys_msgget ((key_t) first, second);
352 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
358 ret = do_shmat (first, (char *) ptr, second, &raddr);
361 return put_user (raddr, (ulong *) third);
363 case 1: /* iBCS2 emulator entry point */
364 if (!segment_eq(get_fs(), get_ds()))
366 return do_shmat (first, (char *) ptr, second, (ulong *) third);
369 return sys_shmdt ((char *)ptr);
371 return sys_shmget (first, second, third);
373 return sys_shmctl (first, second,
374 (struct shmid_ds *) ptr);
381 * No implemented yet ...
383 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
389 * If we ever come here the user sp is bad. Zap the process right away.
390 * Due to the bad stack signaling wouldn't work.
392 asmlinkage void bad_stack(void)