sys_h8300.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. /* common code for old and new mmaps */
  27. static inline long do_mmap2(
  28. unsigned long addr, unsigned long len,
  29. unsigned long prot, unsigned long flags,
  30. unsigned long fd, unsigned long pgoff)
  31. {
  32. int error = -EBADF;
  33. struct file * file = NULL;
  34. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  35. if (!(flags & MAP_ANONYMOUS)) {
  36. file = fget(fd);
  37. if (!file)
  38. goto out;
  39. }
  40. down_write(&current->mm->mmap_sem);
  41. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  42. up_write(&current->mm->mmap_sem);
  43. if (file)
  44. fput(file);
  45. out:
  46. return error;
  47. }
  48. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  49. unsigned long prot, unsigned long flags,
  50. unsigned long fd, unsigned long pgoff)
  51. {
  52. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  53. }
  54. /*
  55. * Perform the select(nd, in, out, ex, tv) and mmap() system
  56. * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
  57. * handle more than 4 system call parameters, so these system calls
  58. * used a memory block for parameter passing..
  59. */
  60. struct mmap_arg_struct {
  61. unsigned long addr;
  62. unsigned long len;
  63. unsigned long prot;
  64. unsigned long flags;
  65. unsigned long fd;
  66. unsigned long offset;
  67. };
  68. asmlinkage int old_mmap(struct mmap_arg_struct *arg)
  69. {
  70. struct mmap_arg_struct a;
  71. int error = -EFAULT;
  72. if (copy_from_user(&a, arg, sizeof(a)))
  73. goto out;
  74. error = -EINVAL;
  75. if (a.offset & ~PAGE_MASK)
  76. goto out;
  77. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  78. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  79. out:
  80. return error;
  81. }
  82. #if 0 /* DAVIDM - do we want this */
  83. struct mmap_arg_struct64 {
  84. __u32 addr;
  85. __u32 len;
  86. __u32 prot;
  87. __u32 flags;
  88. __u64 offset; /* 64 bits */
  89. __u32 fd;
  90. };
  91. asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
  92. {
  93. int error = -EFAULT;
  94. struct file * file = NULL;
  95. struct mmap_arg_struct64 a;
  96. unsigned long pgoff;
  97. if (copy_from_user(&a, arg, sizeof(a)))
  98. return -EFAULT;
  99. if ((long)a.offset & ~PAGE_MASK)
  100. return -EINVAL;
  101. pgoff = a.offset >> PAGE_SHIFT;
  102. if ((a.offset >> PAGE_SHIFT) != pgoff)
  103. return -EINVAL;
  104. if (!(a.flags & MAP_ANONYMOUS)) {
  105. error = -EBADF;
  106. file = fget(a.fd);
  107. if (!file)
  108. goto out;
  109. }
  110. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  111. down_write(&current->mm->mmap_sem);
  112. error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
  113. up_write(&current->mm->mmap_sem);
  114. if (file)
  115. fput(file);
  116. out:
  117. return error;
  118. }
  119. #endif
  120. struct sel_arg_struct {
  121. unsigned long n;
  122. fd_set *inp, *outp, *exp;
  123. struct timeval *tvp;
  124. };
  125. asmlinkage int old_select(struct sel_arg_struct *arg)
  126. {
  127. struct sel_arg_struct a;
  128. if (copy_from_user(&a, arg, sizeof(a)))
  129. return -EFAULT;
  130. /* sys_select() does the appropriate kernel locking */
  131. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  132. }
  133. /*
  134. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  135. *
  136. * This is really horribly ugly.
  137. */
  138. asmlinkage int sys_ipc (uint call, int first, int second,
  139. int third, void *ptr, long fifth)
  140. {
  141. int version, ret;
  142. version = call >> 16; /* hack for backward compatibility */
  143. call &= 0xffff;
  144. if (call <= SEMCTL)
  145. switch (call) {
  146. case SEMOP:
  147. return sys_semop (first, (struct sembuf *)ptr, second);
  148. case SEMGET:
  149. return sys_semget (first, second, third);
  150. case SEMCTL: {
  151. union semun fourth;
  152. if (!ptr)
  153. return -EINVAL;
  154. if (get_user(fourth.__pad, (void **) ptr))
  155. return -EFAULT;
  156. return sys_semctl (first, second, third, fourth);
  157. }
  158. default:
  159. return -EINVAL;
  160. }
  161. if (call <= MSGCTL)
  162. switch (call) {
  163. case MSGSND:
  164. return sys_msgsnd (first, (struct msgbuf *) ptr,
  165. second, third);
  166. case MSGRCV:
  167. switch (version) {
  168. case 0: {
  169. struct ipc_kludge tmp;
  170. if (!ptr)
  171. return -EINVAL;
  172. if (copy_from_user (&tmp,
  173. (struct ipc_kludge *)ptr,
  174. sizeof (tmp)))
  175. return -EFAULT;
  176. return sys_msgrcv (first, tmp.msgp, second,
  177. tmp.msgtyp, third);
  178. }
  179. default:
  180. return sys_msgrcv (first,
  181. (struct msgbuf *) ptr,
  182. second, fifth, third);
  183. }
  184. case MSGGET:
  185. return sys_msgget ((key_t) first, second);
  186. case MSGCTL:
  187. return sys_msgctl (first, second,
  188. (struct msqid_ds *) ptr);
  189. default:
  190. return -EINVAL;
  191. }
  192. if (call <= SHMCTL)
  193. switch (call) {
  194. case SHMAT:
  195. switch (version) {
  196. default: {
  197. ulong raddr;
  198. ret = do_shmat (first, (char *) ptr,
  199. second, &raddr);
  200. if (ret)
  201. return ret;
  202. return put_user (raddr, (ulong *) third);
  203. }
  204. }
  205. case SHMDT:
  206. return sys_shmdt ((char *)ptr);
  207. case SHMGET:
  208. return sys_shmget (first, second, third);
  209. case SHMCTL:
  210. return sys_shmctl (first, second,
  211. (struct shmid_ds *) ptr);
  212. default:
  213. return -EINVAL;
  214. }
  215. return -EINVAL;
  216. }
  217. /* sys_cacheflush -- no support. */
  218. asmlinkage int
  219. sys_cacheflush (unsigned long addr, int scope, int cache, unsigned long len)
  220. {
  221. return -EINVAL;
  222. }
  223. asmlinkage int sys_getpagesize(void)
  224. {
  225. return PAGE_SIZE;
  226. }
  227. #if defined(CONFIG_SYSCALL_PRINT)
  228. asmlinkage void syscall_print(void *dummy,...)
  229. {
  230. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  231. printk("call %06lx:%ld 1:%08lx,2:%08lx,3:%08lx,ret:%08lx\n",
  232. ((regs->pc)&0xffffff)-2,regs->orig_er0,regs->er1,regs->er2,regs->er3,regs->er0);
  233. }
  234. #endif
  235. /*
  236. * Do a system call from kernel instead of calling sys_execve so we
  237. * end up with proper pt_regs.
  238. */
  239. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  240. {
  241. register long res __asm__("er0");
  242. register char *const *_c __asm__("er3") = envp;
  243. register char *const *_b __asm__("er2") = argv;
  244. register const char * _a __asm__("er1") = filename;
  245. __asm__ __volatile__ ("mov.l %1,er0\n\t"
  246. "trapa #0\n\t"
  247. : "=r" (res)
  248. : "g" (__NR_execve),
  249. "g" (_a),
  250. "g" (_b),
  251. "g" (_c)
  252. : "cc", "memory");
  253. return res;
  254. }