sys_m32r.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * linux/arch/m32r/kernel/sys_m32r.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/M32R platform.
  6. *
  7. * Taken from i386 version.
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/sched.h>
  11. #include <linux/mm.h>
  12. #include <linux/fs.h>
  13. #include <linux/smp.h>
  14. #include <linux/sem.h>
  15. #include <linux/msg.h>
  16. #include <linux/shm.h>
  17. #include <linux/stat.h>
  18. #include <linux/syscalls.h>
  19. #include <linux/mman.h>
  20. #include <linux/file.h>
  21. #include <linux/utsname.h>
  22. #include <linux/ipc.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/cachectl.h>
  25. #include <asm/cacheflush.h>
  26. #include <asm/syscall.h>
  27. #include <asm/unistd.h>
  28. /*
  29. * sys_tas() - test-and-set
  30. */
  31. asmlinkage int sys_tas(int __user *addr)
  32. {
  33. int oldval;
  34. if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
  35. return -EFAULT;
  36. /* atomic operation:
  37. * oldval = *addr; *addr = 1;
  38. */
  39. __asm__ __volatile__ (
  40. DCACHE_CLEAR("%0", "r4", "%1")
  41. " .fillinsn\n"
  42. "1:\n"
  43. " lock %0, @%1 -> unlock %2, @%1\n"
  44. "2:\n"
  45. /* NOTE:
  46. * The m32r processor can accept interrupts only
  47. * at the 32-bit instruction boundary.
  48. * So, in the above code, the "unlock" instruction
  49. * can be executed continuously after the "lock"
  50. * instruction execution without any interruptions.
  51. */
  52. ".section .fixup,\"ax\"\n"
  53. " .balign 4\n"
  54. "3: ldi %0, #%3\n"
  55. " seth r14, #high(2b)\n"
  56. " or3 r14, r14, #low(2b)\n"
  57. " jmp r14\n"
  58. ".previous\n"
  59. ".section __ex_table,\"a\"\n"
  60. " .balign 4\n"
  61. " .long 1b,3b\n"
  62. ".previous\n"
  63. : "=&r" (oldval)
  64. : "r" (addr), "r" (1), "i"(-EFAULT)
  65. : "r14", "memory"
  66. #ifdef CONFIG_CHIP_M32700_TS1
  67. , "r4"
  68. #endif /* CONFIG_CHIP_M32700_TS1 */
  69. );
  70. return oldval;
  71. }
  72. /*
  73. * sys_pipe() is the normal C calling standard for creating
  74. * a pipe. It's not the way Unix traditionally does this, though.
  75. */
  76. asmlinkage int
  77. sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,
  78. unsigned long r3, unsigned long r4, unsigned long r5,
  79. unsigned long r6, struct pt_regs regs)
  80. {
  81. int fd[2];
  82. int error;
  83. error = do_pipe(fd);
  84. if (!error) {
  85. if (copy_to_user((void __user *)r0, fd, 2*sizeof(int))) {
  86. sys_close(fd[0]);
  87. sys_close(fd[1]);
  88. error = -EFAULT;
  89. }
  90. }
  91. return error;
  92. }
  93. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  94. unsigned long prot, unsigned long flags,
  95. unsigned long fd, unsigned long pgoff)
  96. {
  97. int error = -EBADF;
  98. struct file *file = NULL;
  99. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  100. if (!(flags & MAP_ANONYMOUS)) {
  101. file = fget(fd);
  102. if (!file)
  103. goto out;
  104. }
  105. down_write(&current->mm->mmap_sem);
  106. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  107. up_write(&current->mm->mmap_sem);
  108. if (file)
  109. fput(file);
  110. out:
  111. return error;
  112. }
  113. /*
  114. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  115. *
  116. * This is really horribly ugly.
  117. */
  118. asmlinkage int sys_ipc(uint call, int first, int second,
  119. int third, void __user *ptr, long fifth)
  120. {
  121. int version, ret;
  122. version = call >> 16; /* hack for backward compatibility */
  123. call &= 0xffff;
  124. switch (call) {
  125. case SEMOP:
  126. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  127. second, NULL);
  128. case SEMTIMEDOP:
  129. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  130. second, (const struct timespec __user *)fifth);
  131. case SEMGET:
  132. return sys_semget (first, second, third);
  133. case SEMCTL: {
  134. union semun fourth;
  135. if (!ptr)
  136. return -EINVAL;
  137. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  138. return -EFAULT;
  139. return sys_semctl (first, second, third, fourth);
  140. }
  141. case MSGSND:
  142. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  143. second, third);
  144. case MSGRCV:
  145. switch (version) {
  146. case 0: {
  147. struct ipc_kludge tmp;
  148. if (!ptr)
  149. return -EINVAL;
  150. if (copy_from_user(&tmp,
  151. (struct ipc_kludge __user *) ptr,
  152. sizeof (tmp)))
  153. return -EFAULT;
  154. return sys_msgrcv (first, tmp.msgp, second,
  155. tmp.msgtyp, third);
  156. }
  157. default:
  158. return sys_msgrcv (first,
  159. (struct msgbuf __user *) ptr,
  160. second, fifth, third);
  161. }
  162. case MSGGET:
  163. return sys_msgget ((key_t) first, second);
  164. case MSGCTL:
  165. return sys_msgctl (first, second,
  166. (struct msqid_ds __user *) ptr);
  167. case SHMAT: {
  168. ulong raddr;
  169. if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
  170. sizeof(ulong)))
  171. return -EFAULT;
  172. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  173. if (ret)
  174. return ret;
  175. return put_user (raddr, (ulong __user *) third);
  176. }
  177. case SHMDT:
  178. return sys_shmdt ((char __user *)ptr);
  179. case SHMGET:
  180. return sys_shmget (first, second, third);
  181. case SHMCTL:
  182. return sys_shmctl (first, second,
  183. (struct shmid_ds __user *) ptr);
  184. default:
  185. return -ENOSYS;
  186. }
  187. }
  188. asmlinkage int sys_uname(struct old_utsname __user * name)
  189. {
  190. int err;
  191. if (!name)
  192. return -EFAULT;
  193. down_read(&uts_sem);
  194. err = copy_to_user(name, utsname(), sizeof (*name));
  195. up_read(&uts_sem);
  196. return err?-EFAULT:0;
  197. }
  198. asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
  199. {
  200. /* This should flush more selectively ... */
  201. _flush_cache_all();
  202. return 0;
  203. }
  204. asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
  205. {
  206. /* Not implemented yet. */
  207. return -ENOSYS;
  208. }
  209. /*
  210. * Do a system call from kernel instead of calling sys_execve so we
  211. * end up with proper pt_regs.
  212. */
  213. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  214. {
  215. register long __scno __asm__ ("r7") = __NR_execve;
  216. register long __arg3 __asm__ ("r2") = (long)(envp);
  217. register long __arg2 __asm__ ("r1") = (long)(argv);
  218. register long __res __asm__ ("r0") = (long)(filename);
  219. __asm__ __volatile__ (
  220. "trap #" SYSCALL_VECTOR "|| nop"
  221. : "=r" (__res)
  222. : "r" (__scno), "0" (__res), "r" (__arg2),
  223. "r" (__arg3)
  224. : "memory");
  225. return __res;
  226. }