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/capability.h>
11 #include <linux/errno.h>
12 #include <linux/linkage.h>
15 #include <linux/smp.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/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/compiler.h>
28 #include <linux/module.h>
29 #include <linux/ipc.h>
30 #include <linux/uaccess.h>
31 #include <linux/slab.h>
34 #include <asm/branch.h>
35 #include <asm/cachectl.h>
36 #include <asm/cacheflush.h>
37 #include <asm/asm-offsets.h>
38 #include <asm/signal.h>
40 #include <asm/shmparam.h>
41 #include <asm/sysmips.h>
42 #include <asm/uaccess.h>
45 * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
46 * convention. It returns results in registers $v0 / $v1 which means there
47 * is no need for it to do verify the validity of a userspace pointer
48 * argument. Historically that used to be expensive in Linux. These days
49 * the performance advantage is negligible.
51 asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs)
56 error = do_pipe_flags(fd, 0);
67 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
69 EXPORT_SYMBOL(shm_align_mask);
71 #define COLOUR_ALIGN(addr,pgoff) \
72 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
73 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
75 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
76 unsigned long len, unsigned long pgoff, unsigned long flags)
78 struct vm_area_struct * vmm;
80 unsigned long task_size;
82 task_size = STACK_TOP;
87 if (flags & MAP_FIXED) {
88 /* Even MAP_FIXED mappings must reside within task_size. */
89 if (task_size - len < addr)
93 * We do not accept a shared mapping if it would violate
94 * cache aliasing constraints.
96 if ((flags & MAP_SHARED) &&
97 ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
103 if (filp || (flags & MAP_SHARED))
107 addr = COLOUR_ALIGN(addr, pgoff);
109 addr = PAGE_ALIGN(addr);
110 vmm = find_vma(current->mm, addr);
111 if (task_size - len >= addr &&
112 (!vmm || addr + len <= vmm->vm_start))
115 addr = TASK_UNMAPPED_BASE;
117 addr = COLOUR_ALIGN(addr, pgoff);
119 addr = PAGE_ALIGN(addr);
121 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
122 /* At this point: (!vmm || addr < vmm->vm_end). */
123 if (task_size - len < addr)
125 if (!vmm || addr + len <= vmm->vm_start)
129 addr = COLOUR_ALIGN(addr, pgoff);
133 SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
134 unsigned long, prot, unsigned long, flags, unsigned long,
137 unsigned long result;
140 if (offset & ~PAGE_MASK)
143 result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
149 SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
150 unsigned long, prot, unsigned long, flags, unsigned long, fd,
151 unsigned long, pgoff)
153 if (pgoff & (~PAGE_MASK >> 12))
156 return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
159 save_static_function(sys_fork);
160 static int __used noinline
161 _sys_fork(nabi_no_regargs struct pt_regs regs)
163 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
166 save_static_function(sys_clone);
167 static int __used noinline
168 _sys_clone(nabi_no_regargs struct pt_regs regs)
170 unsigned long clone_flags;
172 int __user *parent_tidptr, *child_tidptr;
174 clone_flags = regs.regs[4];
175 newsp = regs.regs[5];
177 newsp = regs.regs[29];
178 parent_tidptr = (int __user *) regs.regs[6];
180 /* We need to fetch the fifth argument off the stack. */
182 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
183 int __user *__user *usp = (int __user *__user *) regs.regs[29];
184 if (regs.regs[2] == __NR_syscall) {
185 if (get_user (child_tidptr, &usp[5]))
188 else if (get_user (child_tidptr, &usp[4]))
192 child_tidptr = (int __user *) regs.regs[8];
194 return do_fork(clone_flags, newsp, ®s, 0,
195 parent_tidptr, child_tidptr);
199 * sys_execve() executes a new program.
201 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
206 filename = getname((char __user *) (long)regs.regs[4]);
207 error = PTR_ERR(filename);
208 if (IS_ERR(filename))
210 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
211 (char __user *__user *) (long)regs.regs[6], ®s);
218 SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
220 struct thread_info *ti = task_thread_info(current);
223 if (cpu_has_userlocal)
224 write_c0_userlocal(addr);
229 static inline int mips_atomic_set(struct pt_regs *regs,
230 unsigned long addr, unsigned long new)
232 unsigned long old, tmp;
235 if (unlikely(addr & 3))
238 if (unlikely(!access_ok(VERIFY_WRITE, addr, 4)))
241 if (cpu_has_llsc && R10000_LLSC_WAR) {
242 __asm__ __volatile__ (
245 "1: ll %[old], (%[addr]) \n"
246 " move %[tmp], %[new] \n"
247 "2: sc %[tmp], (%[addr]) \n"
248 " beqzl %[tmp], 1b \n"
250 " .section .fixup,\"ax\" \n"
251 "4: li %[err], %[efault] \n"
254 " .section __ex_table,\"a\" \n"
255 " "STR(PTR)" 1b, 4b \n"
256 " "STR(PTR)" 2b, 4b \n"
264 [efault] "i" (-EFAULT)
266 } else if (cpu_has_llsc) {
267 __asm__ __volatile__ (
270 "1: ll %[old], (%[addr]) \n"
271 " move %[tmp], %[new] \n"
272 "2: sc %[tmp], (%[addr]) \n"
273 " bnez %[tmp], 4f \n"
279 " .section .fixup,\"ax\" \n"
280 "5: li %[err], %[efault] \n"
283 " .section __ex_table,\"a\" \n"
284 " "STR(PTR)" 1b, 5b \n"
285 " "STR(PTR)" 2b, 5b \n"
293 [efault] "i" (-EFAULT)
302 err = __get_user(old, (unsigned int *) addr);
303 err |= __put_user(new, (unsigned int *) addr);
314 regs->regs[7] = 0; /* No error */
317 * Don't let your children do this ...
319 __asm__ __volatile__(
325 /* unreached. Honestly. */
329 save_static_function(sys_sysmips);
330 static int __used noinline
331 _sys_sysmips(nabi_no_regargs struct pt_regs regs)
333 long cmd, arg1, arg2, arg3;
341 case MIPS_ATOMIC_SET:
342 return mips_atomic_set(®s, arg1, arg2);
349 set_thread_flag(TIF_FIXADE);
351 clear_thread_flag(TIF_FIXADE);
353 set_thread_flag(TIF_LOGADE);
355 clear_thread_flag(TIF_FIXADE);
368 * No implemented yet ...
370 SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
376 * If we ever come here the user sp is bad. Zap the process right away.
377 * Due to the bad stack signaling wouldn't work.
379 asmlinkage void bad_stack(void)
385 * Do a system call from kernel instead of calling sys_execve so we
386 * end up with proper pt_regs.
388 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
390 register unsigned long __a0 asm("$4") = (unsigned long) filename;
391 register unsigned long __a1 asm("$5") = (unsigned long) argv;
392 register unsigned long __a2 asm("$6") = (unsigned long) envp;
393 register unsigned long __a3 asm("$7");
396 __asm__ volatile (" \n"
398 " li $2, %5 # __NR_execve \n"
402 : "=&r" (__v0), "=r" (__a3)
403 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
404 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",