sys_m32r.c 5.0 KB

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