sys_h8300.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * linux/arch/h8300/kernel/sys_h8300.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the H8/300
  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/fs.h>
  20. #include <linux/ipc.h>
  21. #include <asm/setup.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/cachectl.h>
  24. #include <asm/traps.h>
  25. #include <asm/unistd.h>
  26. /*
  27. * Perform the select(nd, in, out, ex, tv) and mmap() system
  28. * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
  29. * handle more than 4 system call parameters, so these system calls
  30. * used a memory block for parameter passing..
  31. */
  32. struct mmap_arg_struct {
  33. unsigned long addr;
  34. unsigned long len;
  35. unsigned long prot;
  36. unsigned long flags;
  37. unsigned long fd;
  38. unsigned long offset;
  39. };
  40. asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  41. {
  42. struct mmap_arg_struct a;
  43. int error = -EFAULT;
  44. if (copy_from_user(&a, arg, sizeof(a)))
  45. goto out;
  46. error = -EINVAL;
  47. if (a.offset & ~PAGE_MASK)
  48. goto out;
  49. error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
  50. a.offset >> PAGE_SHIFT);
  51. out:
  52. return error;
  53. }
  54. struct sel_arg_struct {
  55. unsigned long n;
  56. fd_set *inp, *outp, *exp;
  57. struct timeval *tvp;
  58. };
  59. asmlinkage int old_select(struct sel_arg_struct *arg)
  60. {
  61. struct sel_arg_struct a;
  62. if (copy_from_user(&a, arg, sizeof(a)))
  63. return -EFAULT;
  64. /* sys_select() does the appropriate kernel locking */
  65. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  66. }
  67. /*
  68. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  69. *
  70. * This is really horribly ugly.
  71. */
  72. asmlinkage int sys_ipc (uint call, int first, int second,
  73. int third, void *ptr, long fifth)
  74. {
  75. int version, ret;
  76. version = call >> 16; /* hack for backward compatibility */
  77. call &= 0xffff;
  78. if (call <= SEMCTL)
  79. switch (call) {
  80. case SEMOP:
  81. return sys_semop (first, (struct sembuf *)ptr, second);
  82. case SEMGET:
  83. return sys_semget (first, second, third);
  84. case SEMCTL: {
  85. union semun fourth;
  86. if (!ptr)
  87. return -EINVAL;
  88. if (get_user(fourth.__pad, (void **) ptr))
  89. return -EFAULT;
  90. return sys_semctl (first, second, third, fourth);
  91. }
  92. default:
  93. return -EINVAL;
  94. }
  95. if (call <= MSGCTL)
  96. switch (call) {
  97. case MSGSND:
  98. return sys_msgsnd (first, (struct msgbuf *) ptr,
  99. second, third);
  100. case MSGRCV:
  101. switch (version) {
  102. case 0: {
  103. struct ipc_kludge tmp;
  104. if (!ptr)
  105. return -EINVAL;
  106. if (copy_from_user (&tmp,
  107. (struct ipc_kludge *)ptr,
  108. sizeof (tmp)))
  109. return -EFAULT;
  110. return sys_msgrcv (first, tmp.msgp, second,
  111. tmp.msgtyp, third);
  112. }
  113. default:
  114. return sys_msgrcv (first,
  115. (struct msgbuf *) ptr,
  116. second, fifth, third);
  117. }
  118. case MSGGET:
  119. return sys_msgget ((key_t) first, second);
  120. case MSGCTL:
  121. return sys_msgctl (first, second,
  122. (struct msqid_ds *) ptr);
  123. default:
  124. return -EINVAL;
  125. }
  126. if (call <= SHMCTL)
  127. switch (call) {
  128. case SHMAT:
  129. switch (version) {
  130. default: {
  131. ulong raddr;
  132. ret = do_shmat (first, (char *) ptr,
  133. second, &raddr);
  134. if (ret)
  135. return ret;
  136. return put_user (raddr, (ulong *) third);
  137. }
  138. }
  139. case SHMDT:
  140. return sys_shmdt ((char *)ptr);
  141. case SHMGET:
  142. return sys_shmget (first, second, third);
  143. case SHMCTL:
  144. return sys_shmctl (first, second,
  145. (struct shmid_ds *) ptr);
  146. default:
  147. return -EINVAL;
  148. }
  149. return -EINVAL;
  150. }
  151. /* sys_cacheflush -- no support. */
  152. asmlinkage int
  153. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  154. {
  155. return -EINVAL;
  156. }
  157. asmlinkage int sys_getpagesize(void)
  158. {
  159. return PAGE_SIZE;
  160. }
  161. #if defined(CONFIG_SYSCALL_PRINT)
  162. asmlinkage void syscall_print(void *dummy,...)
  163. {
  164. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  165. printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
  166. ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
  167. }
  168. #endif
  169. /*
  170. * Do a system call from kernel instead of calling sys_execve so we
  171. * end up with proper pt_regs.
  172. */
  173. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  174. {
  175. register long res __asm__("er0");
  176. register char *const *_c __asm__("er3") = envp;
  177. register char *const *_b __asm__("er2") = argv;
  178. register const char * _a __asm__("er1") = filename;
  179. __asm__ __volatile__ ("mov.l %1,er0\n\t"
  180. "trapa #0\n\t"
  181. : "=r" (res)
  182. : "g" (__NR_execve),
  183. "g" (_a),
  184. "g" (_b),
  185. "g" (_c)
  186. : "cc", "memory");
  187. return res;
  188. }