syscall.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. */
  10. #include <linux/capability.h>
  11. #include <linux/errno.h>
  12. #include <linux/linkage.h>
  13. #include <linux/fs.h>
  14. #include <linux/smp.h>
  15. #include <linux/ptrace.h>
  16. #include <linux/string.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/file.h>
  19. #include <linux/utsname.h>
  20. #include <linux/unistd.h>
  21. #include <linux/sem.h>
  22. #include <linux/msg.h>
  23. #include <linux/shm.h>
  24. #include <linux/compiler.h>
  25. #include <linux/ipc.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/slab.h>
  28. #include <linux/elf.h>
  29. #include <asm/asm.h>
  30. #include <asm/branch.h>
  31. #include <asm/cachectl.h>
  32. #include <asm/cacheflush.h>
  33. #include <asm/asm-offsets.h>
  34. #include <asm/signal.h>
  35. #include <asm/sim.h>
  36. #include <asm/shmparam.h>
  37. #include <asm/sysmips.h>
  38. #include <asm/uaccess.h>
  39. #include <asm/switch_to.h>
  40. /*
  41. * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
  42. * convention. It returns results in registers $v0 / $v1 which means there
  43. * is no need for it to do verify the validity of a userspace pointer
  44. * argument. Historically that used to be expensive in Linux. These days
  45. * the performance advantage is negligible.
  46. */
  47. asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs)
  48. {
  49. int fd[2];
  50. int error, res;
  51. error = do_pipe_flags(fd, 0);
  52. if (error) {
  53. res = error;
  54. goto out;
  55. }
  56. regs.regs[3] = fd[1];
  57. res = fd[0];
  58. out:
  59. return res;
  60. }
  61. SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
  62. unsigned long, prot, unsigned long, flags, unsigned long,
  63. fd, off_t, offset)
  64. {
  65. unsigned long result;
  66. result = -EINVAL;
  67. if (offset & ~PAGE_MASK)
  68. goto out;
  69. result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  70. out:
  71. return result;
  72. }
  73. SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
  74. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  75. unsigned long, pgoff)
  76. {
  77. if (pgoff & (~PAGE_MASK >> 12))
  78. return -EINVAL;
  79. return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
  80. }
  81. save_static_function(sys_fork);
  82. static int __used noinline
  83. _sys_fork(nabi_no_regargs struct pt_regs regs)
  84. {
  85. return do_fork(SIGCHLD, regs.regs[29], 0, NULL, NULL);
  86. }
  87. save_static_function(sys_clone);
  88. static int __used noinline
  89. _sys_clone(nabi_no_regargs struct pt_regs regs)
  90. {
  91. unsigned long clone_flags;
  92. unsigned long newsp;
  93. int __user *parent_tidptr, *child_tidptr;
  94. clone_flags = regs.regs[4];
  95. newsp = regs.regs[5];
  96. if (!newsp)
  97. newsp = regs.regs[29];
  98. parent_tidptr = (int __user *) regs.regs[6];
  99. #ifdef CONFIG_32BIT
  100. /* We need to fetch the fifth argument off the stack. */
  101. child_tidptr = NULL;
  102. if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
  103. int __user *__user *usp = (int __user *__user *) regs.regs[29];
  104. if (regs.regs[2] == __NR_syscall) {
  105. if (get_user (child_tidptr, &usp[5]))
  106. return -EFAULT;
  107. }
  108. else if (get_user (child_tidptr, &usp[4]))
  109. return -EFAULT;
  110. }
  111. #else
  112. child_tidptr = (int __user *) regs.regs[8];
  113. #endif
  114. return do_fork(clone_flags, newsp, 0,
  115. parent_tidptr, child_tidptr);
  116. }
  117. SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
  118. {
  119. struct thread_info *ti = task_thread_info(current);
  120. ti->tp_value = addr;
  121. if (cpu_has_userlocal)
  122. write_c0_userlocal(addr);
  123. return 0;
  124. }
  125. static inline int mips_atomic_set(struct pt_regs *regs,
  126. unsigned long addr, unsigned long new)
  127. {
  128. unsigned long old, tmp;
  129. unsigned int err;
  130. if (unlikely(addr & 3))
  131. return -EINVAL;
  132. if (unlikely(!access_ok(VERIFY_WRITE, addr, 4)))
  133. return -EINVAL;
  134. if (cpu_has_llsc && R10000_LLSC_WAR) {
  135. __asm__ __volatile__ (
  136. " .set mips3 \n"
  137. " li %[err], 0 \n"
  138. "1: ll %[old], (%[addr]) \n"
  139. " move %[tmp], %[new] \n"
  140. "2: sc %[tmp], (%[addr]) \n"
  141. " beqzl %[tmp], 1b \n"
  142. "3: \n"
  143. " .section .fixup,\"ax\" \n"
  144. "4: li %[err], %[efault] \n"
  145. " j 3b \n"
  146. " .previous \n"
  147. " .section __ex_table,\"a\" \n"
  148. " "STR(PTR)" 1b, 4b \n"
  149. " "STR(PTR)" 2b, 4b \n"
  150. " .previous \n"
  151. " .set mips0 \n"
  152. : [old] "=&r" (old),
  153. [err] "=&r" (err),
  154. [tmp] "=&r" (tmp)
  155. : [addr] "r" (addr),
  156. [new] "r" (new),
  157. [efault] "i" (-EFAULT)
  158. : "memory");
  159. } else if (cpu_has_llsc) {
  160. __asm__ __volatile__ (
  161. " .set mips3 \n"
  162. " li %[err], 0 \n"
  163. "1: ll %[old], (%[addr]) \n"
  164. " move %[tmp], %[new] \n"
  165. "2: sc %[tmp], (%[addr]) \n"
  166. " bnez %[tmp], 4f \n"
  167. "3: \n"
  168. " .subsection 2 \n"
  169. "4: b 1b \n"
  170. " .previous \n"
  171. " \n"
  172. " .section .fixup,\"ax\" \n"
  173. "5: li %[err], %[efault] \n"
  174. " j 3b \n"
  175. " .previous \n"
  176. " .section __ex_table,\"a\" \n"
  177. " "STR(PTR)" 1b, 5b \n"
  178. " "STR(PTR)" 2b, 5b \n"
  179. " .previous \n"
  180. " .set mips0 \n"
  181. : [old] "=&r" (old),
  182. [err] "=&r" (err),
  183. [tmp] "=&r" (tmp)
  184. : [addr] "r" (addr),
  185. [new] "r" (new),
  186. [efault] "i" (-EFAULT)
  187. : "memory");
  188. } else {
  189. do {
  190. preempt_disable();
  191. ll_bit = 1;
  192. ll_task = current;
  193. preempt_enable();
  194. err = __get_user(old, (unsigned int *) addr);
  195. err |= __put_user(new, (unsigned int *) addr);
  196. if (err)
  197. break;
  198. rmb();
  199. } while (!ll_bit);
  200. }
  201. if (unlikely(err))
  202. return err;
  203. regs->regs[2] = old;
  204. regs->regs[7] = 0; /* No error */
  205. /*
  206. * Don't let your children do this ...
  207. */
  208. __asm__ __volatile__(
  209. " move $29, %0 \n"
  210. " j syscall_exit \n"
  211. : /* no outputs */
  212. : "r" (regs));
  213. /* unreached. Honestly. */
  214. while (1);
  215. }
  216. save_static_function(sys_sysmips);
  217. static int __used noinline
  218. _sys_sysmips(nabi_no_regargs struct pt_regs regs)
  219. {
  220. long cmd, arg1, arg2;
  221. cmd = regs.regs[4];
  222. arg1 = regs.regs[5];
  223. arg2 = regs.regs[6];
  224. switch (cmd) {
  225. case MIPS_ATOMIC_SET:
  226. return mips_atomic_set(&regs, arg1, arg2);
  227. case MIPS_FIXADE:
  228. if (arg1 & ~3)
  229. return -EINVAL;
  230. if (arg1 & 1)
  231. set_thread_flag(TIF_FIXADE);
  232. else
  233. clear_thread_flag(TIF_FIXADE);
  234. if (arg1 & 2)
  235. set_thread_flag(TIF_LOGADE);
  236. else
  237. clear_thread_flag(TIF_LOGADE);
  238. return 0;
  239. case FLUSH_CACHE:
  240. __flush_cache_all();
  241. return 0;
  242. }
  243. return -EINVAL;
  244. }
  245. /*
  246. * No implemented yet ...
  247. */
  248. SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
  249. {
  250. return -ENOSYS;
  251. }
  252. /*
  253. * If we ever come here the user sp is bad. Zap the process right away.
  254. * Due to the bad stack signaling wouldn't work.
  255. */
  256. asmlinkage void bad_stack(void)
  257. {
  258. do_exit(SIGSEGV);
  259. }