sys_h8300.c 6.6 KB

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