sys_m32r.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  73. unsigned long prot, unsigned long flags,
  74. unsigned long fd, unsigned long pgoff)
  75. {
  76. int error = -EBADF;
  77. struct file *file = NULL;
  78. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  79. if (!(flags & MAP_ANONYMOUS)) {
  80. file = fget(fd);
  81. if (!file)
  82. goto out;
  83. }
  84. down_write(&current->mm->mmap_sem);
  85. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  86. up_write(&current->mm->mmap_sem);
  87. if (file)
  88. fput(file);
  89. out:
  90. return error;
  91. }
  92. /*
  93. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  94. *
  95. * This is really horribly ugly.
  96. */
  97. asmlinkage int sys_ipc(uint call, int first, int second,
  98. int third, void __user *ptr, long fifth)
  99. {
  100. int version, ret;
  101. version = call >> 16; /* hack for backward compatibility */
  102. call &= 0xffff;
  103. switch (call) {
  104. case SEMOP:
  105. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  106. second, NULL);
  107. case SEMTIMEDOP:
  108. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  109. second, (const struct timespec __user *)fifth);
  110. case SEMGET:
  111. return sys_semget (first, second, third);
  112. case SEMCTL: {
  113. union semun fourth;
  114. if (!ptr)
  115. return -EINVAL;
  116. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  117. return -EFAULT;
  118. return sys_semctl (first, second, third, fourth);
  119. }
  120. case MSGSND:
  121. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  122. second, third);
  123. case MSGRCV:
  124. switch (version) {
  125. case 0: {
  126. struct ipc_kludge tmp;
  127. if (!ptr)
  128. return -EINVAL;
  129. if (copy_from_user(&tmp,
  130. (struct ipc_kludge __user *) ptr,
  131. sizeof (tmp)))
  132. return -EFAULT;
  133. return sys_msgrcv (first, tmp.msgp, second,
  134. tmp.msgtyp, third);
  135. }
  136. default:
  137. return sys_msgrcv (first,
  138. (struct msgbuf __user *) ptr,
  139. second, fifth, third);
  140. }
  141. case MSGGET:
  142. return sys_msgget ((key_t) first, second);
  143. case MSGCTL:
  144. return sys_msgctl (first, second,
  145. (struct msqid_ds __user *) ptr);
  146. case SHMAT: {
  147. ulong raddr;
  148. if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
  149. sizeof(ulong)))
  150. return -EFAULT;
  151. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  152. if (ret)
  153. return ret;
  154. return put_user (raddr, (ulong __user *) third);
  155. }
  156. case SHMDT:
  157. return sys_shmdt ((char __user *)ptr);
  158. case SHMGET:
  159. return sys_shmget (first, second, third);
  160. case SHMCTL:
  161. return sys_shmctl (first, second,
  162. (struct shmid_ds __user *) ptr);
  163. default:
  164. return -ENOSYS;
  165. }
  166. }
  167. asmlinkage int sys_uname(struct old_utsname __user * name)
  168. {
  169. int err;
  170. if (!name)
  171. return -EFAULT;
  172. down_read(&uts_sem);
  173. err = copy_to_user(name, utsname(), sizeof (*name));
  174. up_read(&uts_sem);
  175. return err?-EFAULT:0;
  176. }
  177. asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
  178. {
  179. /* This should flush more selectively ... */
  180. _flush_cache_all();
  181. return 0;
  182. }
  183. asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
  184. {
  185. /* Not implemented yet. */
  186. return -ENOSYS;
  187. }
  188. /*
  189. * Do a system call from kernel instead of calling sys_execve so we
  190. * end up with proper pt_regs.
  191. */
  192. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  193. {
  194. register long __scno __asm__ ("r7") = __NR_execve;
  195. register long __arg3 __asm__ ("r2") = (long)(envp);
  196. register long __arg2 __asm__ ("r1") = (long)(argv);
  197. register long __res __asm__ ("r0") = (long)(filename);
  198. __asm__ __volatile__ (
  199. "trap #" SYSCALL_VECTOR "|| nop"
  200. : "=r" (__res)
  201. : "r" (__scno), "0" (__res), "r" (__arg2),
  202. "r" (__arg3)
  203. : "memory");
  204. return __res;
  205. }