sys_m68k.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * linux/arch/m68knommu/kernel/sys_m68k.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/m68k
  6. * platform.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <linux/smp.h>
  12. #include <linux/sem.h>
  13. #include <linux/msg.h>
  14. #include <linux/shm.h>
  15. #include <linux/stat.h>
  16. #include <linux/syscalls.h>
  17. #include <linux/mman.h>
  18. #include <linux/file.h>
  19. #include <linux/ipc.h>
  20. #include <linux/fs.h>
  21. #include <asm/setup.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/cachectl.h>
  24. #include <asm/traps.h>
  25. #include <asm/cacheflush.h>
  26. #include <asm/unistd.h>
  27. /*
  28. * Perform the select(nd, in, out, ex, tv) and mmap() system
  29. * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
  30. * handle more than 4 system call parameters, so these system calls
  31. * used a memory block for parameter passing..
  32. */
  33. struct mmap_arg_struct {
  34. unsigned long addr;
  35. unsigned long len;
  36. unsigned long prot;
  37. unsigned long flags;
  38. unsigned long fd;
  39. unsigned long offset;
  40. };
  41. asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  42. {
  43. struct mmap_arg_struct a;
  44. int error = -EFAULT;
  45. if (copy_from_user(&a, arg, sizeof(a)))
  46. goto out;
  47. error = -EINVAL;
  48. if (a.offset & ~PAGE_MASK)
  49. goto out;
  50. error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
  51. a.offset >> PAGE_SHIFT);
  52. out:
  53. return error;
  54. }
  55. /*
  56. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  57. *
  58. * This is really horribly ugly.
  59. */
  60. asmlinkage int sys_ipc (uint call, int first, int second,
  61. int third, void *ptr, long fifth)
  62. {
  63. int version, ret;
  64. version = call >> 16; /* hack for backward compatibility */
  65. call &= 0xffff;
  66. if (call <= SEMCTL)
  67. switch (call) {
  68. case SEMOP:
  69. return sys_semop (first, (struct sembuf *)ptr, second);
  70. case SEMGET:
  71. return sys_semget (first, second, third);
  72. case SEMCTL: {
  73. union semun fourth;
  74. if (!ptr)
  75. return -EINVAL;
  76. if (get_user(fourth.__pad, (void **) ptr))
  77. return -EFAULT;
  78. return sys_semctl (first, second, third, fourth);
  79. }
  80. default:
  81. return -EINVAL;
  82. }
  83. if (call <= MSGCTL)
  84. switch (call) {
  85. case MSGSND:
  86. return sys_msgsnd (first, (struct msgbuf *) ptr,
  87. second, third);
  88. case MSGRCV:
  89. switch (version) {
  90. case 0: {
  91. struct ipc_kludge tmp;
  92. if (!ptr)
  93. return -EINVAL;
  94. if (copy_from_user (&tmp,
  95. (struct ipc_kludge *)ptr,
  96. sizeof (tmp)))
  97. return -EFAULT;
  98. return sys_msgrcv (first, tmp.msgp, second,
  99. tmp.msgtyp, third);
  100. }
  101. default:
  102. return sys_msgrcv (first,
  103. (struct msgbuf *) ptr,
  104. second, fifth, third);
  105. }
  106. case MSGGET:
  107. return sys_msgget ((key_t) first, second);
  108. case MSGCTL:
  109. return sys_msgctl (first, second,
  110. (struct msqid_ds *) ptr);
  111. default:
  112. return -EINVAL;
  113. }
  114. if (call <= SHMCTL)
  115. switch (call) {
  116. case SHMAT:
  117. switch (version) {
  118. default: {
  119. ulong raddr;
  120. ret = do_shmat (first, ptr, second, &raddr);
  121. if (ret)
  122. return ret;
  123. return put_user (raddr, (ulong __user *) third);
  124. }
  125. }
  126. case SHMDT:
  127. return sys_shmdt (ptr);
  128. case SHMGET:
  129. return sys_shmget (first, second, third);
  130. case SHMCTL:
  131. return sys_shmctl (first, second, ptr);
  132. default:
  133. return -ENOSYS;
  134. }
  135. return -EINVAL;
  136. }
  137. /* sys_cacheflush -- flush (part of) the processor cache. */
  138. asmlinkage int
  139. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  140. {
  141. flush_cache_all();
  142. return(0);
  143. }
  144. asmlinkage int sys_getpagesize(void)
  145. {
  146. return PAGE_SIZE;
  147. }
  148. /*
  149. * Do a system call from kernel instead of calling sys_execve so we
  150. * end up with proper pt_regs.
  151. */
  152. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  153. {
  154. register long __res asm ("%d0") = __NR_execve;
  155. register long __a asm ("%d1") = (long)(filename);
  156. register long __b asm ("%d2") = (long)(argv);
  157. register long __c asm ("%d3") = (long)(envp);
  158. asm volatile ("trap #0" : "+d" (__res)
  159. : "d" (__a), "d" (__b), "d" (__c));
  160. return __res;
  161. }
  162. asmlinkage unsigned long sys_get_thread_area(void)
  163. {
  164. return current_thread_info()->tp_value;
  165. }
  166. asmlinkage int sys_set_thread_area(unsigned long tp)
  167. {
  168. current_thread_info()->tp_value = tp;
  169. return 0;
  170. }
  171. /* This syscall gets its arguments in A0 (mem), D2 (oldval) and
  172. D1 (newval). */
  173. asmlinkage int
  174. sys_atomic_cmpxchg_32(unsigned long newval, int oldval, int d3, int d4, int d5,
  175. unsigned long __user * mem)
  176. {
  177. struct mm_struct *mm = current->mm;
  178. unsigned long mem_value;
  179. down_read(&mm->mmap_sem);
  180. mem_value = *mem;
  181. if (mem_value == oldval)
  182. *mem = newval;
  183. up_read(&mm->mmap_sem);
  184. return mem_value;
  185. }
  186. asmlinkage int sys_atomic_barrier(void)
  187. {
  188. /* no code needed for uniprocs */
  189. return 0;
  190. }