sys_h8300.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/utsname.h>
  20. #include <linux/fs.h>
  21. #include <linux/ipc.h>
  22. #include <asm/setup.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/cachectl.h>
  25. #include <asm/traps.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. #if 0 /* DAVIDM - do we want this */
  84. struct mmap_arg_struct64 {
  85. __u32 addr;
  86. __u32 len;
  87. __u32 prot;
  88. __u32 flags;
  89. __u64 offset; /* 64 bits */
  90. __u32 fd;
  91. };
  92. asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
  93. {
  94. int error = -EFAULT;
  95. struct file * file = NULL;
  96. struct mmap_arg_struct64 a;
  97. unsigned long pgoff;
  98. if (copy_from_user(&a, arg, sizeof(a)))
  99. return -EFAULT;
  100. if ((long)a.offset & ~PAGE_MASK)
  101. return -EINVAL;
  102. pgoff = a.offset >> PAGE_SHIFT;
  103. if ((a.offset >> PAGE_SHIFT) != pgoff)
  104. return -EINVAL;
  105. if (!(a.flags & MAP_ANONYMOUS)) {
  106. error = -EBADF;
  107. file = fget(a.fd);
  108. if (!file)
  109. goto out;
  110. }
  111. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  112. down_write(&current->mm->mmap_sem);
  113. error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
  114. up_write(&current->mm->mmap_sem);
  115. if (file)
  116. fput(file);
  117. out:
  118. return error;
  119. }
  120. #endif
  121. struct sel_arg_struct {
  122. unsigned long n;
  123. fd_set *inp, *outp, *exp;
  124. struct timeval *tvp;
  125. };
  126. asmlinkage int old_select(struct sel_arg_struct *arg)
  127. {
  128. struct sel_arg_struct a;
  129. if (copy_from_user(&a, arg, sizeof(a)))
  130. return -EFAULT;
  131. /* sys_select() does the appropriate kernel locking */
  132. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  133. }
  134. /*
  135. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  136. *
  137. * This is really horribly ugly.
  138. */
  139. asmlinkage int sys_ipc (uint call, int first, int second,
  140. int third, void *ptr, long fifth)
  141. {
  142. int version, ret;
  143. version = call >> 16; /* hack for backward compatibility */
  144. call &= 0xffff;
  145. if (call <= SEMCTL)
  146. switch (call) {
  147. case SEMOP:
  148. return sys_semop (first, (struct sembuf *)ptr, second);
  149. case SEMGET:
  150. return sys_semget (first, second, third);
  151. case SEMCTL: {
  152. union semun fourth;
  153. if (!ptr)
  154. return -EINVAL;
  155. if (get_user(fourth.__pad, (void **) ptr))
  156. return -EFAULT;
  157. return sys_semctl (first, second, third, fourth);
  158. }
  159. default:
  160. return -EINVAL;
  161. }
  162. if (call <= MSGCTL)
  163. switch (call) {
  164. case MSGSND:
  165. return sys_msgsnd (first, (struct msgbuf *) ptr,
  166. second, third);
  167. case MSGRCV:
  168. switch (version) {
  169. case 0: {
  170. struct ipc_kludge tmp;
  171. if (!ptr)
  172. return -EINVAL;
  173. if (copy_from_user (&tmp,
  174. (struct ipc_kludge *)ptr,
  175. sizeof (tmp)))
  176. return -EFAULT;
  177. return sys_msgrcv (first, tmp.msgp, second,
  178. tmp.msgtyp, third);
  179. }
  180. default:
  181. return sys_msgrcv (first,
  182. (struct msgbuf *) ptr,
  183. second, fifth, third);
  184. }
  185. case MSGGET:
  186. return sys_msgget ((key_t) first, second);
  187. case MSGCTL:
  188. return sys_msgctl (first, second,
  189. (struct msqid_ds *) ptr);
  190. default:
  191. return -EINVAL;
  192. }
  193. if (call <= SHMCTL)
  194. switch (call) {
  195. case SHMAT:
  196. switch (version) {
  197. default: {
  198. ulong raddr;
  199. ret = do_shmat (first, (char *) ptr,
  200. second, &raddr);
  201. if (ret)
  202. return ret;
  203. return put_user (raddr, (ulong *) third);
  204. }
  205. }
  206. case SHMDT:
  207. return sys_shmdt ((char *)ptr);
  208. case SHMGET:
  209. return sys_shmget (first, second, third);
  210. case SHMCTL:
  211. return sys_shmctl (first, second,
  212. (struct shmid_ds *) ptr);
  213. default:
  214. return -EINVAL;
  215. }
  216. return -EINVAL;
  217. }
  218. /* sys_cacheflush -- no support. */
  219. asmlinkage int
  220. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  221. {
  222. return -EINVAL;
  223. }
  224. asmlinkage int sys_getpagesize(void)
  225. {
  226. return PAGE_SIZE;
  227. }
  228. #if defined(CONFIG_SYSCALL_PRINT)
  229. asmlinkage void syscall_print(void *dummy,...)
  230. {
  231. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  232. printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
  233. ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
  234. }
  235. #endif
  236. /*
  237. * Do a system call from kernel instead of calling sys_execve so we
  238. * end up with proper pt_regs.
  239. */
  240. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  241. {
  242. register long res __asm__("er0");
  243. register char *const *_c __asm__("er3") = envp;
  244. register char *const *_b __asm__("er2") = argv;
  245. register const char * _a __asm__("er1") = filename;
  246. __asm__ __volatile__ ("mov.l %1,er0\n\t"
  247. "trapa #0\n\t"
  248. : "=r" (res)
  249. : "g" (__NR_execve),
  250. "g" (_a),
  251. "g" (_b),
  252. "g" (_c)
  253. : "cc", "memory");
  254. return res;
  255. }