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