sys_h8300.c 6.0 KB

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