sys_m68k.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. /* common code for old and new mmaps */
  28. static inline long do_mmap2(
  29. unsigned long addr, unsigned long len,
  30. unsigned long prot, unsigned long flags,
  31. unsigned long fd, unsigned long pgoff)
  32. {
  33. int error = -EBADF;
  34. struct file * file = NULL;
  35. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  36. if (!(flags & MAP_ANONYMOUS)) {
  37. file = fget(fd);
  38. if (!file)
  39. goto out;
  40. }
  41. down_write(&current->mm->mmap_sem);
  42. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  43. up_write(&current->mm->mmap_sem);
  44. if (file)
  45. fput(file);
  46. out:
  47. return error;
  48. }
  49. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  50. unsigned long prot, unsigned long flags,
  51. unsigned long fd, unsigned long pgoff)
  52. {
  53. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  54. }
  55. /*
  56. * Perform the select(nd, in, out, ex, tv) and mmap() system
  57. * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
  58. * handle more than 4 system call parameters, so these system calls
  59. * used a memory block for parameter passing..
  60. */
  61. struct mmap_arg_struct {
  62. unsigned long addr;
  63. unsigned long len;
  64. unsigned long prot;
  65. unsigned long flags;
  66. unsigned long fd;
  67. unsigned long offset;
  68. };
  69. asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  70. {
  71. struct mmap_arg_struct a;
  72. int error = -EFAULT;
  73. if (copy_from_user(&a, arg, sizeof(a)))
  74. goto out;
  75. error = -EINVAL;
  76. if (a.offset & ~PAGE_MASK)
  77. goto out;
  78. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  79. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  80. out:
  81. return error;
  82. }
  83. struct sel_arg_struct {
  84. unsigned long n;
  85. fd_set *inp, *outp, *exp;
  86. struct timeval *tvp;
  87. };
  88. asmlinkage int old_select(struct sel_arg_struct *arg)
  89. {
  90. struct sel_arg_struct a;
  91. if (copy_from_user(&a, arg, sizeof(a)))
  92. return -EFAULT;
  93. /* sys_select() does the appropriate kernel locking */
  94. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  95. }
  96. /*
  97. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  98. *
  99. * This is really horribly ugly.
  100. */
  101. asmlinkage int sys_ipc (uint call, int first, int second,
  102. int third, void *ptr, long fifth)
  103. {
  104. int version, ret;
  105. version = call >> 16; /* hack for backward compatibility */
  106. call &= 0xffff;
  107. if (call <= SEMCTL)
  108. switch (call) {
  109. case SEMOP:
  110. return sys_semop (first, (struct sembuf *)ptr, second);
  111. case SEMGET:
  112. return sys_semget (first, second, third);
  113. case SEMCTL: {
  114. union semun fourth;
  115. if (!ptr)
  116. return -EINVAL;
  117. if (get_user(fourth.__pad, (void **) ptr))
  118. return -EFAULT;
  119. return sys_semctl (first, second, third, fourth);
  120. }
  121. default:
  122. return -EINVAL;
  123. }
  124. if (call <= MSGCTL)
  125. switch (call) {
  126. case MSGSND:
  127. return sys_msgsnd (first, (struct msgbuf *) ptr,
  128. second, third);
  129. case MSGRCV:
  130. switch (version) {
  131. case 0: {
  132. struct ipc_kludge tmp;
  133. if (!ptr)
  134. return -EINVAL;
  135. if (copy_from_user (&tmp,
  136. (struct ipc_kludge *)ptr,
  137. sizeof (tmp)))
  138. return -EFAULT;
  139. return sys_msgrcv (first, tmp.msgp, second,
  140. tmp.msgtyp, third);
  141. }
  142. default:
  143. return sys_msgrcv (first,
  144. (struct msgbuf *) ptr,
  145. second, fifth, third);
  146. }
  147. case MSGGET:
  148. return sys_msgget ((key_t) first, second);
  149. case MSGCTL:
  150. return sys_msgctl (first, second,
  151. (struct msqid_ds *) ptr);
  152. default:
  153. return -EINVAL;
  154. }
  155. if (call <= SHMCTL)
  156. switch (call) {
  157. case SHMAT:
  158. switch (version) {
  159. default: {
  160. ulong raddr;
  161. ret = do_shmat (first, ptr, second, &raddr);
  162. if (ret)
  163. return ret;
  164. return put_user (raddr, (ulong __user *) third);
  165. }
  166. }
  167. case SHMDT:
  168. return sys_shmdt (ptr);
  169. case SHMGET:
  170. return sys_shmget (first, second, third);
  171. case SHMCTL:
  172. return sys_shmctl (first, second, ptr);
  173. default:
  174. return -ENOSYS;
  175. }
  176. return -EINVAL;
  177. }
  178. /* sys_cacheflush -- flush (part of) the processor cache. */
  179. asmlinkage int
  180. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  181. {
  182. flush_cache_all();
  183. return(0);
  184. }
  185. asmlinkage int sys_getpagesize(void)
  186. {
  187. return PAGE_SIZE;
  188. }
  189. /*
  190. * Do a system call from kernel instead of calling sys_execve so we
  191. * end up with proper pt_regs.
  192. */
  193. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  194. {
  195. register long __res asm ("%d0") = __NR_execve;
  196. register long __a asm ("%d1") = (long)(filename);
  197. register long __b asm ("%d2") = (long)(argv);
  198. register long __c asm ("%d3") = (long)(envp);
  199. asm volatile ("trap #0" : "+d" (__res)
  200. : "d" (__a), "d" (__b), "d" (__c));
  201. return __res;
  202. }