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/capability.h>
12 #include <linux/errno.h>
13 #include <linux/linkage.h>
16 #include <linux/smp.h>
17 #include <linux/mman.h>
18 #include <linux/ptrace.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
21 #include <linux/syscalls.h>
22 #include <linux/file.h>
23 #include <linux/slab.h>
24 #include <linux/utsname.h>
25 #include <linux/unistd.h>
26 #include <linux/sem.h>
27 #include <linux/msg.h>
28 #include <linux/shm.h>
29 #include <linux/compiler.h>
30 #include <linux/module.h>
31 #include <linux/ipc.h>
33 #include <asm/branch.h>
34 #include <asm/cachectl.h>
35 #include <asm/cacheflush.h>
36 #include <asm/asm-offsets.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 EXPORT_SYMBOL(shm_align_mask);
63 #define COLOUR_ALIGN(addr,pgoff) \
64 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
65 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
67 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
68 unsigned long len, unsigned long pgoff, unsigned long flags)
70 struct vm_area_struct * vmm;
72 unsigned long task_size;
74 task_size = STACK_TOP;
79 if (flags & MAP_FIXED) {
80 /* Even MAP_FIXED mappings must reside within task_size. */
81 if (task_size - len < addr)
85 * We do not accept a shared mapping if it would violate
86 * cache aliasing constraints.
88 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
94 if (filp || (flags & MAP_SHARED))
98 addr = COLOUR_ALIGN(addr, pgoff);
100 addr = PAGE_ALIGN(addr);
101 vmm = find_vma(current->mm, addr);
102 if (task_size - len >= addr &&
103 (!vmm || addr + len <= vmm->vm_start))
106 addr = TASK_UNMAPPED_BASE;
108 addr = COLOUR_ALIGN(addr, pgoff);
110 addr = PAGE_ALIGN(addr);
112 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
113 /* At this point: (!vmm || addr < vmm->vm_end). */
114 if (task_size - len < addr)
116 if (!vmm || addr + len <= vmm->vm_start)
120 addr = COLOUR_ALIGN(addr, pgoff);
124 /* common code for old and new mmaps */
125 static inline unsigned long
126 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
127 unsigned long flags, unsigned long fd, unsigned long pgoff)
129 unsigned long error = -EBADF;
130 struct file * file = NULL;
132 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
133 if (!(flags & MAP_ANONYMOUS)) {
139 down_write(¤t->mm->mmap_sem);
140 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
141 up_write(¤t->mm->mmap_sem);
149 asmlinkage unsigned long
150 old_mmap(unsigned long addr, unsigned long len, int prot,
151 int flags, int fd, off_t offset)
153 unsigned long result;
156 if (offset & ~PAGE_MASK)
159 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
165 asmlinkage unsigned long
166 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
167 unsigned long flags, unsigned long fd, unsigned long pgoff)
169 if (pgoff & (~PAGE_MASK >> 12))
172 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
175 save_static_function(sys_fork);
176 static int __used noinline
177 _sys_fork(nabi_no_regargs struct pt_regs regs)
179 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
182 save_static_function(sys_clone);
183 static int __used noinline
184 _sys_clone(nabi_no_regargs struct pt_regs regs)
186 unsigned long clone_flags;
188 int __user *parent_tidptr, *child_tidptr;
190 clone_flags = regs.regs[4];
191 newsp = regs.regs[5];
193 newsp = regs.regs[29];
194 parent_tidptr = (int __user *) regs.regs[6];
196 /* We need to fetch the fifth argument off the stack. */
198 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
199 int __user *__user *usp = (int __user *__user *) regs.regs[29];
200 if (regs.regs[2] == __NR_syscall) {
201 if (get_user (child_tidptr, &usp[5]))
204 else if (get_user (child_tidptr, &usp[4]))
208 child_tidptr = (int __user *) regs.regs[8];
210 return do_fork(clone_flags, newsp, ®s, 0,
211 parent_tidptr, child_tidptr);
215 * sys_execve() executes a new program.
217 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
222 filename = getname((char __user *) (long)regs.regs[4]);
223 error = PTR_ERR(filename);
224 if (IS_ERR(filename))
226 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
227 (char __user *__user *) (long)regs.regs[6], ®s);
235 * Compacrapability ...
237 asmlinkage int sys_uname(struct old_utsname __user * name)
239 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
245 * Compacrapability ...
247 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
253 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
256 error = __copy_to_user(&name->sysname, &utsname()->sysname,
258 error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
259 error -= __copy_to_user(&name->nodename, &utsname()->nodename,
261 error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
262 error -= __copy_to_user(&name->release, &utsname()->release,
264 error -= __put_user(0, name->release + __OLD_UTS_LEN);
265 error -= __copy_to_user(&name->version, &utsname()->version,
267 error -= __put_user(0, name->version + __OLD_UTS_LEN);
268 error -= __copy_to_user(&name->machine, &utsname()->machine,
270 error = __put_user(0, name->machine + __OLD_UTS_LEN);
271 error = error ? -EFAULT : 0;
276 asmlinkage int sys_set_thread_area(unsigned long addr)
278 struct thread_info *ti = task_thread_info(current);
281 if (cpu_has_userlocal)
282 write_c0_userlocal(addr);
287 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
290 case MIPS_ATOMIC_SET:
291 printk(KERN_CRIT "How did I get here?\n");
299 set_thread_flag(TIF_FIXADE);
301 clear_thread_flag(TIF_FIXADE);
303 set_thread_flag(TIF_LOGADE);
305 clear_thread_flag(TIF_FIXADE);
318 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
320 * This is really horribly ugly.
322 asmlinkage int sys_ipc(unsigned int call, int first, int second,
323 unsigned long third, void __user *ptr, long fifth)
327 version = call >> 16; /* hack for backward compatibility */
332 return sys_semtimedop(first, (struct sembuf __user *)ptr,
335 return sys_semtimedop(first, (struct sembuf __user *)ptr,
337 (const struct timespec __user *)fifth);
339 return sys_semget(first, second, third);
344 if (get_user(fourth.__pad, (void __user *__user *) ptr))
346 return sys_semctl(first, second, third, fourth);
350 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
355 struct ipc_kludge tmp;
359 if (copy_from_user(&tmp,
360 (struct ipc_kludge __user *) ptr,
363 return sys_msgrcv(first, tmp.msgp, second,
367 return sys_msgrcv(first,
368 (struct msgbuf __user *) ptr,
369 second, fifth, third);
372 return sys_msgget((key_t) first, second);
374 return sys_msgctl(first, second,
375 (struct msqid_ds __user *) ptr);
381 ret = do_shmat(first, (char __user *) ptr, second,
385 return put_user(raddr, (unsigned long __user *) third);
387 case 1: /* iBCS2 emulator entry point */
388 if (!segment_eq(get_fs(), get_ds()))
390 return do_shmat(first, (char __user *) ptr, second,
391 (unsigned long *) third);
394 return sys_shmdt((char __user *)ptr);
396 return sys_shmget(first, second, third);
398 return sys_shmctl(first, second,
399 (struct shmid_ds __user *) ptr);
406 * No implemented yet ...
408 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
414 * If we ever come here the user sp is bad. Zap the process right away.
415 * Due to the bad stack signaling wouldn't work.
417 asmlinkage void bad_stack(void)
423 * Do a system call from kernel instead of calling sys_execve so we
424 * end up with proper pt_regs.
426 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
428 register unsigned long __a0 asm("$4") = (unsigned long) filename;
429 register unsigned long __a1 asm("$5") = (unsigned long) argv;
430 register unsigned long __a2 asm("$6") = (unsigned long) envp;
431 register unsigned long __a3 asm("$7");
434 __asm__ volatile (" \n"
436 " li $2, %5 # __NR_execve \n"
440 : "=&r" (__v0), "=r" (__a3)
441 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
442 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",