sys_m32r.c 4.7 KB

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