sys_h8300.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /*
  55. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  56. *
  57. * This is really horribly ugly.
  58. */
  59. asmlinkage int sys_ipc (uint call, int first, int second,
  60. int third, void *ptr, long fifth)
  61. {
  62. int version, ret;
  63. version = call >> 16; /* hack for backward compatibility */
  64. call &= 0xffff;
  65. if (call <= SEMCTL)
  66. switch (call) {
  67. case SEMOP:
  68. return sys_semop (first, (struct sembuf *)ptr, second);
  69. case SEMGET:
  70. return sys_semget (first, second, third);
  71. case SEMCTL: {
  72. union semun fourth;
  73. if (!ptr)
  74. return -EINVAL;
  75. if (get_user(fourth.__pad, (void **) ptr))
  76. return -EFAULT;
  77. return sys_semctl (first, second, third, fourth);
  78. }
  79. default:
  80. return -EINVAL;
  81. }
  82. if (call <= MSGCTL)
  83. switch (call) {
  84. case MSGSND:
  85. return sys_msgsnd (first, (struct msgbuf *) ptr,
  86. second, third);
  87. case MSGRCV:
  88. switch (version) {
  89. case 0: {
  90. struct ipc_kludge tmp;
  91. if (!ptr)
  92. return -EINVAL;
  93. if (copy_from_user (&tmp,
  94. (struct ipc_kludge *)ptr,
  95. sizeof (tmp)))
  96. return -EFAULT;
  97. return sys_msgrcv (first, tmp.msgp, second,
  98. tmp.msgtyp, third);
  99. }
  100. default:
  101. return sys_msgrcv (first,
  102. (struct msgbuf *) ptr,
  103. second, fifth, third);
  104. }
  105. case MSGGET:
  106. return sys_msgget ((key_t) first, second);
  107. case MSGCTL:
  108. return sys_msgctl (first, second,
  109. (struct msqid_ds *) ptr);
  110. default:
  111. return -EINVAL;
  112. }
  113. if (call <= SHMCTL)
  114. switch (call) {
  115. case SHMAT:
  116. switch (version) {
  117. default: {
  118. ulong raddr;
  119. ret = do_shmat (first, (char *) ptr,
  120. second, &raddr);
  121. if (ret)
  122. return ret;
  123. return put_user (raddr, (ulong *) third);
  124. }
  125. }
  126. case SHMDT:
  127. return sys_shmdt ((char *)ptr);
  128. case SHMGET:
  129. return sys_shmget (first, second, third);
  130. case SHMCTL:
  131. return sys_shmctl (first, second,
  132. (struct shmid_ds *) ptr);
  133. default:
  134. return -EINVAL;
  135. }
  136. return -EINVAL;
  137. }
  138. /* sys_cacheflush -- no support. */
  139. asmlinkage int
  140. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  141. {
  142. return -EINVAL;
  143. }
  144. asmlinkage int sys_getpagesize(void)
  145. {
  146. return PAGE_SIZE;
  147. }
  148. #if defined(CONFIG_SYSCALL_PRINT)
  149. asmlinkage void syscall_print(void *dummy,...)
  150. {
  151. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  152. printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
  153. ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
  154. }
  155. #endif
  156. /*
  157. * Do a system call from kernel instead of calling sys_execve so we
  158. * end up with proper pt_regs.
  159. */
  160. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  161. {
  162. register long res __asm__("er0");
  163. register char *const *_c __asm__("er3") = envp;
  164. register char *const *_b __asm__("er2") = argv;
  165. register const char * _a __asm__("er1") = filename;
  166. __asm__ __volatile__ ("mov.l %1,er0\n\t"
  167. "trapa #0\n\t"
  168. : "=r" (res)
  169. : "g" (__NR_execve),
  170. "g" (_a),
  171. "g" (_b),
  172. "g" (_c)
  173. : "cc", "memory");
  174. return res;
  175. }