Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 |
| 4 | * for more details. |
| 5 | * |
| 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. |
| 9 | */ |
Randy Dunlap | a941564 | 2006-01-11 12:17:48 -0800 | [diff] [blame] | 10 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/errno.h> |
| 12 | #include <linux/linkage.h> |
| 13 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 14 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Ralf Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 28 | #include <linux/module.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 29 | #include <linux/ipc.h> |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 32 | #include <linux/random.h> |
David Daney | 652b14a | 2010-07-19 13:14:57 -0700 | [diff] [blame] | 33 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 35 | #include <asm/asm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/branch.h> |
| 37 | #include <asm/cachectl.h> |
| 38 | #include <asm/cacheflush.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 39 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/signal.h> |
| 41 | #include <asm/sim.h> |
| 42 | #include <asm/shmparam.h> |
| 43 | #include <asm/sysmips.h> |
| 44 | #include <asm/uaccess.h> |
| 45 | |
Ralf Baechle | 8213bbf | 2008-07-20 13:16:46 +0100 | [diff] [blame] | 46 | /* |
| 47 | * For historic reasons the pipe(2) syscall on MIPS has an unusual calling |
| 48 | * convention. It returns results in registers $v0 / $v1 which means there |
| 49 | * is no need for it to do verify the validity of a userspace pointer |
| 50 | * argument. Historically that used to be expensive in Linux. These days |
| 51 | * the performance advantage is negligible. |
| 52 | */ |
| 53 | asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | int fd[2]; |
| 56 | int error, res; |
| 57 | |
Ulrich Drepper | ed8cae8 | 2008-07-23 21:29:30 -0700 | [diff] [blame] | 58 | error = do_pipe_flags(fd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (error) { |
| 60 | res = error; |
| 61 | goto out; |
| 62 | } |
| 63 | regs.regs[3] = fd[1]; |
| 64 | res = fd[0]; |
| 65 | out: |
| 66 | return res; |
| 67 | } |
| 68 | |
| 69 | unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ |
| 70 | |
Ralf Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 71 | EXPORT_SYMBOL(shm_align_mask); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define COLOUR_ALIGN(addr,pgoff) \ |
| 74 | ((((addr) + shm_align_mask) & ~shm_align_mask) + \ |
| 75 | (((pgoff) << PAGE_SHIFT) & shm_align_mask)) |
| 76 | |
| 77 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, |
| 78 | unsigned long len, unsigned long pgoff, unsigned long flags) |
| 79 | { |
| 80 | struct vm_area_struct * vmm; |
| 81 | int do_color_align; |
| 82 | unsigned long task_size; |
| 83 | |
David Daney | c52d0d3 | 2010-02-18 16:13:04 -0800 | [diff] [blame] | 84 | #ifdef CONFIG_32BIT |
| 85 | task_size = TASK_SIZE; |
| 86 | #else /* Must be CONFIG_64BIT*/ |
| 87 | task_size = test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE; |
| 88 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
David Daney | 098362e | 2007-10-27 23:10:20 -0700 | [diff] [blame] | 90 | if (len > task_size) |
| 91 | return -ENOMEM; |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | if (flags & MAP_FIXED) { |
David Daney | 098362e | 2007-10-27 23:10:20 -0700 | [diff] [blame] | 94 | /* Even MAP_FIXED mappings must reside within task_size. */ |
| 95 | if (task_size - len < addr) |
| 96 | return -EINVAL; |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* |
| 99 | * We do not accept a shared mapping if it would violate |
| 100 | * cache aliasing constraints. |
| 101 | */ |
Al Viro | e77414e | 2009-12-05 15:10:44 -0500 | [diff] [blame] | 102 | if ((flags & MAP_SHARED) && |
| 103 | ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return -EINVAL; |
| 105 | return addr; |
| 106 | } |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | do_color_align = 0; |
| 109 | if (filp || (flags & MAP_SHARED)) |
| 110 | do_color_align = 1; |
| 111 | if (addr) { |
| 112 | if (do_color_align) |
| 113 | addr = COLOUR_ALIGN(addr, pgoff); |
| 114 | else |
| 115 | addr = PAGE_ALIGN(addr); |
| 116 | vmm = find_vma(current->mm, addr); |
| 117 | if (task_size - len >= addr && |
| 118 | (!vmm || addr + len <= vmm->vm_start)) |
| 119 | return addr; |
| 120 | } |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 121 | addr = current->mm->mmap_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (do_color_align) |
| 123 | addr = COLOUR_ALIGN(addr, pgoff); |
| 124 | else |
| 125 | addr = PAGE_ALIGN(addr); |
| 126 | |
| 127 | for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) { |
| 128 | /* At this point: (!vmm || addr < vmm->vm_end). */ |
| 129 | if (task_size - len < addr) |
| 130 | return -ENOMEM; |
| 131 | if (!vmm || addr + len <= vmm->vm_start) |
| 132 | return addr; |
| 133 | addr = vmm->vm_end; |
| 134 | if (do_color_align) |
| 135 | addr = COLOUR_ALIGN(addr, pgoff); |
| 136 | } |
| 137 | } |
| 138 | |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 139 | void arch_pick_mmap_layout(struct mm_struct *mm) |
| 140 | { |
| 141 | unsigned long random_factor = 0UL; |
| 142 | |
| 143 | if (current->flags & PF_RANDOMIZE) { |
| 144 | random_factor = get_random_int(); |
| 145 | random_factor = random_factor << PAGE_SHIFT; |
| 146 | if (TASK_IS_32BIT_ADDR) |
| 147 | random_factor &= 0xfffffful; |
| 148 | else |
| 149 | random_factor &= 0xffffffful; |
| 150 | } |
| 151 | |
| 152 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; |
| 153 | mm->get_unmapped_area = arch_get_unmapped_area; |
| 154 | mm->unmap_area = arch_unmap_area; |
| 155 | } |
| 156 | |
David Daney | 652b14a | 2010-07-19 13:14:57 -0700 | [diff] [blame] | 157 | static inline unsigned long brk_rnd(void) |
| 158 | { |
| 159 | unsigned long rnd = get_random_int(); |
| 160 | |
| 161 | rnd = rnd << PAGE_SHIFT; |
| 162 | /* 8MB for 32bit, 256MB for 64bit */ |
| 163 | if (TASK_IS_32BIT_ADDR) |
| 164 | rnd = rnd & 0x7ffffful; |
| 165 | else |
| 166 | rnd = rnd & 0xffffffful; |
| 167 | |
| 168 | return rnd; |
| 169 | } |
| 170 | |
| 171 | unsigned long arch_randomize_brk(struct mm_struct *mm) |
| 172 | { |
| 173 | unsigned long base = mm->brk; |
| 174 | unsigned long ret; |
| 175 | |
| 176 | ret = PAGE_ALIGN(base + brk_rnd()); |
| 177 | |
| 178 | if (ret < mm->brk) |
| 179 | return mm->brk; |
| 180 | |
| 181 | return ret; |
| 182 | } |
| 183 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 184 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, |
| 185 | unsigned long, prot, unsigned long, flags, unsigned long, |
| 186 | fd, off_t, offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | unsigned long result; |
| 189 | |
| 190 | result = -EINVAL; |
| 191 | if (offset & ~PAGE_MASK) |
| 192 | goto out; |
| 193 | |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 194 | result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | out: |
| 197 | return result; |
| 198 | } |
| 199 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 200 | SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len, |
| 201 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
| 202 | unsigned long, pgoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
H. Peter Anvin | 947df17 | 2006-02-24 21:20:29 -0800 | [diff] [blame] | 204 | if (pgoff & (~PAGE_MASK >> 12)) |
| 205 | return -EINVAL; |
| 206 | |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 207 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | save_static_function(sys_fork); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame] | 211 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | _sys_fork(nabi_no_regargs struct pt_regs regs) |
| 213 | { |
| 214 | return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL); |
| 215 | } |
| 216 | |
| 217 | save_static_function(sys_clone); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame] | 218 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | _sys_clone(nabi_no_regargs struct pt_regs regs) |
| 220 | { |
| 221 | unsigned long clone_flags; |
| 222 | unsigned long newsp; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 223 | int __user *parent_tidptr, *child_tidptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | clone_flags = regs.regs[4]; |
| 226 | newsp = regs.regs[5]; |
| 227 | if (!newsp) |
| 228 | newsp = regs.regs[29]; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 229 | parent_tidptr = (int __user *) regs.regs[6]; |
| 230 | #ifdef CONFIG_32BIT |
| 231 | /* We need to fetch the fifth argument off the stack. */ |
| 232 | child_tidptr = NULL; |
| 233 | if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { |
| 234 | int __user *__user *usp = (int __user *__user *) regs.regs[29]; |
| 235 | if (regs.regs[2] == __NR_syscall) { |
| 236 | if (get_user (child_tidptr, &usp[5])) |
| 237 | return -EFAULT; |
| 238 | } |
| 239 | else if (get_user (child_tidptr, &usp[4])) |
| 240 | return -EFAULT; |
| 241 | } |
| 242 | #else |
| 243 | child_tidptr = (int __user *) regs.regs[8]; |
| 244 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return do_fork(clone_flags, newsp, ®s, 0, |
| 246 | parent_tidptr, child_tidptr); |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * sys_execve() executes a new program. |
| 251 | */ |
| 252 | asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs) |
| 253 | { |
| 254 | int error; |
| 255 | char * filename; |
| 256 | |
David Howells | c788732 | 2010-08-11 11:26:22 +0100 | [diff] [blame] | 257 | filename = getname((const char __user *) (long)regs.regs[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | error = PTR_ERR(filename); |
| 259 | if (IS_ERR(filename)) |
| 260 | goto out; |
David Howells | d762746 | 2010-08-17 23:52:56 +0100 | [diff] [blame] | 261 | error = do_execve(filename, |
| 262 | (const char __user *const __user *) (long)regs.regs[5], |
| 263 | (const char __user *const __user *) (long)regs.regs[6], |
| 264 | ®s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | putname(filename); |
| 266 | |
| 267 | out: |
| 268 | return error; |
| 269 | } |
| 270 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 271 | SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 272 | { |
Al Viro | dc8f602 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 273 | struct thread_info *ti = task_thread_info(current); |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 274 | |
| 275 | ti->tp_value = addr; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 276 | if (cpu_has_userlocal) |
| 277 | write_c0_userlocal(addr); |
Ralf Baechle | 06be375 | 2006-09-19 17:18:53 +0100 | [diff] [blame] | 278 | |
| 279 | return 0; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 282 | static inline int mips_atomic_set(struct pt_regs *regs, |
| 283 | unsigned long addr, unsigned long new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 285 | unsigned long old, tmp; |
| 286 | unsigned int err; |
| 287 | |
| 288 | if (unlikely(addr & 3)) |
| 289 | return -EINVAL; |
| 290 | |
| 291 | if (unlikely(!access_ok(VERIFY_WRITE, addr, 4))) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 295 | __asm__ __volatile__ ( |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 296 | " .set mips3 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 297 | " li %[err], 0 \n" |
| 298 | "1: ll %[old], (%[addr]) \n" |
| 299 | " move %[tmp], %[new] \n" |
| 300 | "2: sc %[tmp], (%[addr]) \n" |
| 301 | " beqzl %[tmp], 1b \n" |
| 302 | "3: \n" |
| 303 | " .section .fixup,\"ax\" \n" |
| 304 | "4: li %[err], %[efault] \n" |
| 305 | " j 3b \n" |
| 306 | " .previous \n" |
| 307 | " .section __ex_table,\"a\" \n" |
| 308 | " "STR(PTR)" 1b, 4b \n" |
| 309 | " "STR(PTR)" 2b, 4b \n" |
| 310 | " .previous \n" |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 311 | " .set mips0 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 312 | : [old] "=&r" (old), |
| 313 | [err] "=&r" (err), |
| 314 | [tmp] "=&r" (tmp) |
| 315 | : [addr] "r" (addr), |
| 316 | [new] "r" (new), |
| 317 | [efault] "i" (-EFAULT) |
| 318 | : "memory"); |
| 319 | } else if (cpu_has_llsc) { |
| 320 | __asm__ __volatile__ ( |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 321 | " .set mips3 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 322 | " li %[err], 0 \n" |
| 323 | "1: ll %[old], (%[addr]) \n" |
| 324 | " move %[tmp], %[new] \n" |
| 325 | "2: sc %[tmp], (%[addr]) \n" |
| 326 | " bnez %[tmp], 4f \n" |
| 327 | "3: \n" |
| 328 | " .subsection 2 \n" |
| 329 | "4: b 1b \n" |
| 330 | " .previous \n" |
| 331 | " \n" |
| 332 | " .section .fixup,\"ax\" \n" |
| 333 | "5: li %[err], %[efault] \n" |
| 334 | " j 3b \n" |
| 335 | " .previous \n" |
| 336 | " .section __ex_table,\"a\" \n" |
| 337 | " "STR(PTR)" 1b, 5b \n" |
| 338 | " "STR(PTR)" 2b, 5b \n" |
| 339 | " .previous \n" |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 340 | " .set mips0 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 341 | : [old] "=&r" (old), |
| 342 | [err] "=&r" (err), |
| 343 | [tmp] "=&r" (tmp) |
| 344 | : [addr] "r" (addr), |
| 345 | [new] "r" (new), |
| 346 | [efault] "i" (-EFAULT) |
| 347 | : "memory"); |
| 348 | } else { |
| 349 | do { |
| 350 | preempt_disable(); |
| 351 | ll_bit = 1; |
| 352 | ll_task = current; |
| 353 | preempt_enable(); |
| 354 | |
| 355 | err = __get_user(old, (unsigned int *) addr); |
| 356 | err |= __put_user(new, (unsigned int *) addr); |
| 357 | if (err) |
| 358 | break; |
| 359 | rmb(); |
| 360 | } while (!ll_bit); |
| 361 | } |
| 362 | |
| 363 | if (unlikely(err)) |
| 364 | return err; |
| 365 | |
| 366 | regs->regs[2] = old; |
| 367 | regs->regs[7] = 0; /* No error */ |
| 368 | |
| 369 | /* |
| 370 | * Don't let your children do this ... |
| 371 | */ |
| 372 | __asm__ __volatile__( |
| 373 | " move $29, %0 \n" |
| 374 | " j syscall_exit \n" |
| 375 | : /* no outputs */ |
| 376 | : "r" (regs)); |
| 377 | |
| 378 | /* unreached. Honestly. */ |
| 379 | while (1); |
| 380 | } |
| 381 | |
| 382 | save_static_function(sys_sysmips); |
| 383 | static int __used noinline |
| 384 | _sys_sysmips(nabi_no_regargs struct pt_regs regs) |
| 385 | { |
David Daney | 7a6e4ca | 2011-01-24 14:51:35 -0800 | [diff] [blame] | 386 | long cmd, arg1, arg2; |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 387 | |
| 388 | cmd = regs.regs[4]; |
| 389 | arg1 = regs.regs[5]; |
| 390 | arg2 = regs.regs[6]; |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 391 | |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 392 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | case MIPS_ATOMIC_SET: |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 394 | return mips_atomic_set(®s, arg1, arg2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | case MIPS_FIXADE: |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 397 | if (arg1 & ~3) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | if (arg1 & 1) |
| 401 | set_thread_flag(TIF_FIXADE); |
| 402 | else |
| 403 | clear_thread_flag(TIF_FIXADE); |
| 404 | if (arg1 & 2) |
| 405 | set_thread_flag(TIF_LOGADE); |
| 406 | else |
Stefan Oberhumer | e56293b | 2011-01-17 09:19:53 +0100 | [diff] [blame] | 407 | clear_thread_flag(TIF_LOGADE); |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | return 0; |
| 410 | |
| 411 | case FLUSH_CACHE: |
| 412 | __flush_cache_all(); |
| 413 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | |
| 419 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | * No implemented yet ... |
| 421 | */ |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 422 | SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
| 424 | return -ENOSYS; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * If we ever come here the user sp is bad. Zap the process right away. |
| 429 | * Due to the bad stack signaling wouldn't work. |
| 430 | */ |
| 431 | asmlinkage void bad_stack(void) |
| 432 | { |
| 433 | do_exit(SIGSEGV); |
| 434 | } |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * Do a system call from kernel instead of calling sys_execve so we |
| 438 | * end up with proper pt_regs. |
| 439 | */ |
David Howells | d762746 | 2010-08-17 23:52:56 +0100 | [diff] [blame] | 440 | int kernel_execve(const char *filename, |
| 441 | const char *const argv[], |
| 442 | const char *const envp[]) |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 443 | { |
| 444 | register unsigned long __a0 asm("$4") = (unsigned long) filename; |
| 445 | register unsigned long __a1 asm("$5") = (unsigned long) argv; |
| 446 | register unsigned long __a2 asm("$6") = (unsigned long) envp; |
| 447 | register unsigned long __a3 asm("$7"); |
| 448 | unsigned long __v0; |
| 449 | |
| 450 | __asm__ volatile (" \n" |
| 451 | " .set noreorder \n" |
| 452 | " li $2, %5 # __NR_execve \n" |
| 453 | " syscall \n" |
| 454 | " move %0, $2 \n" |
| 455 | " .set reorder \n" |
| 456 | : "=&r" (__v0), "=r" (__a3) |
| 457 | : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve) |
| 458 | : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", |
| 459 | "memory"); |
| 460 | |
| 461 | if (__a3 == 0) |
| 462 | return __v0; |
| 463 | |
| 464 | return -__v0; |
| 465 | } |