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>
30 #include <asm/branch.h>
31 #include <asm/cachectl.h>
32 #include <asm/cacheflush.h>
34 #include <asm/offset.h>
35 #include <asm/signal.h>
37 #include <asm/shmparam.h>
38 #include <asm/sysmips.h>
39 #include <asm/uaccess.h>
41 asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs)
57 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
59 #define COLOUR_ALIGN(addr,pgoff) \
60 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
61 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
63 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
64 unsigned long len, unsigned long pgoff, unsigned long flags)
66 struct vm_area_struct * vmm;
68 unsigned long task_size;
71 task_size = TASK_SIZE;
73 task_size = (current->thread.mflags & MF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE;
76 if (flags & MAP_FIXED) {
78 * We do not accept a shared mapping if it would violate
79 * cache aliasing constraints.
81 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
89 if (filp || (flags & MAP_SHARED))
93 addr = COLOUR_ALIGN(addr, pgoff);
95 addr = PAGE_ALIGN(addr);
96 vmm = find_vma(current->mm, addr);
97 if (task_size - len >= addr &&
98 (!vmm || addr + len <= vmm->vm_start))
101 addr = TASK_UNMAPPED_BASE;
103 addr = COLOUR_ALIGN(addr, pgoff);
105 addr = PAGE_ALIGN(addr);
107 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
108 /* At this point: (!vmm || addr < vmm->vm_end). */
109 if (task_size - len < addr)
111 if (!vmm || addr + len <= vmm->vm_start)
115 addr = COLOUR_ALIGN(addr, pgoff);
119 /* common code for old and new mmaps */
121 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
122 unsigned long flags, unsigned long fd, unsigned long pgoff)
124 unsigned long error = -EBADF;
125 struct file * file = NULL;
127 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
128 if (!(flags & MAP_ANONYMOUS)) {
134 down_write(¤t->mm->mmap_sem);
135 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
136 up_write(¤t->mm->mmap_sem);
144 asmlinkage unsigned long old_mmap(unsigned long addr, size_t len, int prot,
145 int flags, int fd, off_t offset)
147 unsigned long result;
150 if (offset & ~PAGE_MASK)
153 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
160 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
161 unsigned long flags, unsigned long fd, unsigned long pgoff)
163 return do_mmap2(addr, len, prot, flags, fd, pgoff);
166 save_static_function(sys_fork);
167 __attribute_used__ noinline static int
168 _sys_fork(nabi_no_regargs struct pt_regs regs)
170 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
173 save_static_function(sys_clone);
174 __attribute_used__ noinline static int
175 _sys_clone(nabi_no_regargs struct pt_regs regs)
177 unsigned long clone_flags;
179 int *parent_tidptr, *child_tidptr;
181 clone_flags = regs.regs[4];
182 newsp = regs.regs[5];
184 newsp = regs.regs[29];
185 parent_tidptr = (int *) regs.regs[6];
186 child_tidptr = (int *) regs.regs[7];
187 return do_fork(clone_flags, newsp, ®s, 0,
188 parent_tidptr, child_tidptr);
192 * sys_execve() executes a new program.
194 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
199 filename = getname((char *) (long)regs.regs[4]);
200 error = PTR_ERR(filename);
201 if (IS_ERR(filename))
203 error = do_execve(filename, (char **) (long)regs.regs[5],
204 (char **) (long)regs.regs[6], ®s);
212 * Compacrapability ...
214 asmlinkage int sys_uname(struct old_utsname * name)
216 if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
222 * Compacrapability ...
224 asmlinkage int sys_olduname(struct oldold_utsname * name)
227 struct new_utsname *ptr;
231 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
234 ptr = vx_new_utsname();
235 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
236 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
237 error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
238 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
239 error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
240 error -= __put_user(0,name->release+__OLD_UTS_LEN);
241 error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
242 error -= __put_user(0,name->version+__OLD_UTS_LEN);
243 error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
244 error = __put_user(0,name->machine+__OLD_UTS_LEN);
245 error = error ? -EFAULT : 0;
250 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
257 char nodename[__NEW_UTS_LEN + 1];
259 if (!capable(CAP_SYS_ADMIN))
262 name = (char *) arg1;
264 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
268 down_write(&uts_sem);
269 strncpy(vx_new_uts(nodename), nodename, len);
270 nodename[__NEW_UTS_LEN] = '\0';
271 strlcpy(vx_new_uts(nodename), nodename,
272 sizeof(vx_new_uts(nodename)));
277 case MIPS_ATOMIC_SET:
278 printk(KERN_CRIT "How did I get here?\n");
282 tmp = current->thread.mflags & ~3;
283 current->thread.mflags = tmp | (arg1 & 3);
298 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
300 * This is really horribly ugly.
302 asmlinkage int sys_ipc (uint call, int first, int second,
303 unsigned long third, void *ptr, long fifth)
307 version = call >> 16; /* hack for backward compatibility */
312 return sys_semtimedop (first, (struct sembuf *)ptr, second,
315 return sys_semtimedop (first, (struct sembuf *)ptr, second,
316 (const struct timespec __user *)fifth);
318 return sys_semget (first, second, third);
323 if (get_user(fourth.__pad, (void **) ptr))
325 return sys_semctl (first, second, third, fourth);
329 return sys_msgsnd (first, (struct msgbuf *) ptr,
334 struct ipc_kludge tmp;
338 if (copy_from_user(&tmp,
339 (struct ipc_kludge *) ptr,
342 return sys_msgrcv (first, tmp.msgp, second,
346 return sys_msgrcv (first,
347 (struct msgbuf *) ptr,
348 second, fifth, third);
351 return sys_msgget ((key_t) first, second);
353 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
359 ret = do_shmat (first, (char *) ptr, second, &raddr);
362 return put_user (raddr, (ulong *) third);
364 case 1: /* iBCS2 emulator entry point */
365 if (!segment_eq(get_fs(), get_ds()))
367 return do_shmat (first, (char *) ptr, second, (ulong *) third);
370 return sys_shmdt ((char *)ptr);
372 return sys_shmget (first, second, third);
374 return sys_shmctl (first, second,
375 (struct shmid_ds *) ptr);
382 * Native ABI that is O32 or N64 version
384 asmlinkage long sys_shmat(int shmid, char __user *shmaddr,
385 int shmflg, unsigned long *addr)
390 err = do_shmat(shmid, shmaddr, shmflg, &raddr);
394 return put_user(raddr, addr);
398 * No implemented yet ...
400 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
406 * If we ever come here the user sp is bad. Zap the process right away.
407 * Due to the bad stack signaling wouldn't work.
409 asmlinkage void bad_stack(void)