sys_m32r.c 5.6 KB

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