sys_m68k.c 5.1 KB

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