sys_microblaze.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
  5. *
  6. * Copyright (C) 2006 Atmark Techno, Inc.
  7. * Yasushi SHOJI <yashi@atmark-techno.com>
  8. * Tetsuya OHKAWA <tetsuya@atmark-techno.com>
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/mm.h>
  16. #include <linux/smp.h>
  17. #include <linux/smp_lock.h>
  18. #include <linux/syscalls.h>
  19. #include <linux/sem.h>
  20. #include <linux/msg.h>
  21. #include <linux/shm.h>
  22. #include <linux/stat.h>
  23. #include <linux/mman.h>
  24. #include <linux/sys.h>
  25. #include <linux/ipc.h>
  26. #include <linux/utsname.h>
  27. #include <linux/file.h>
  28. #include <linux/module.h>
  29. #include <linux/err.h>
  30. #include <linux/fs.h>
  31. #include <linux/semaphore.h>
  32. #include <linux/uaccess.h>
  33. #include <linux/unistd.h>
  34. #include <asm/syscalls.h>
  35. /*
  36. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  37. *
  38. * This is really horribly ugly. This will be remove with new toolchain.
  39. */
  40. asmlinkage int
  41. sys_ipc(uint call, int first, int second, int third, void *ptr, long fifth)
  42. {
  43. int version, ret;
  44. version = call >> 16; /* hack for backward compatibility */
  45. call &= 0xffff;
  46. ret = -EINVAL;
  47. switch (call) {
  48. case SEMOP:
  49. ret = sys_semop(first, (struct sembuf *)ptr, second);
  50. break;
  51. case SEMGET:
  52. ret = sys_semget(first, second, third);
  53. break;
  54. case SEMCTL:
  55. {
  56. union semun fourth;
  57. if (!ptr)
  58. break;
  59. ret = (access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
  60. || (get_user(fourth.__pad, (void **)ptr)) ;
  61. if (ret)
  62. break;
  63. ret = sys_semctl(first, second, third, fourth);
  64. break;
  65. }
  66. case MSGSND:
  67. ret = sys_msgsnd(first, (struct msgbuf *) ptr, second, third);
  68. break;
  69. case MSGRCV:
  70. switch (version) {
  71. case 0: {
  72. struct ipc_kludge tmp;
  73. if (!ptr)
  74. break;
  75. ret = (access_ok(VERIFY_READ, ptr, sizeof(tmp))
  76. ? 0 : -EFAULT) || copy_from_user(&tmp,
  77. (struct ipc_kludge *) ptr, sizeof(tmp));
  78. if (ret)
  79. break;
  80. ret = sys_msgrcv(first, tmp.msgp, second, tmp.msgtyp,
  81. third);
  82. break;
  83. }
  84. default:
  85. ret = sys_msgrcv(first, (struct msgbuf *) ptr,
  86. second, fifth, third);
  87. break;
  88. }
  89. break;
  90. case MSGGET:
  91. ret = sys_msgget((key_t) first, second);
  92. break;
  93. case MSGCTL:
  94. ret = sys_msgctl(first, second, (struct msqid_ds *) ptr);
  95. break;
  96. case SHMAT:
  97. switch (version) {
  98. default: {
  99. ulong raddr;
  100. ret = access_ok(VERIFY_WRITE, (ulong *) third,
  101. sizeof(ulong)) ? 0 : -EFAULT;
  102. if (ret)
  103. break;
  104. ret = do_shmat(first, (char *) ptr, second, &raddr);
  105. if (ret)
  106. break;
  107. ret = put_user(raddr, (ulong *) third);
  108. break;
  109. }
  110. case 1: /* iBCS2 emulator entry point */
  111. if (!segment_eq(get_fs(), get_ds()))
  112. break;
  113. ret = do_shmat(first, (char *) ptr, second,
  114. (ulong *) third);
  115. break;
  116. }
  117. break;
  118. case SHMDT:
  119. ret = sys_shmdt((char *)ptr);
  120. break;
  121. case SHMGET:
  122. ret = sys_shmget(first, second, third);
  123. break;
  124. case SHMCTL:
  125. ret = sys_shmctl(first, second, (struct shmid_ds *) ptr);
  126. break;
  127. }
  128. return ret;
  129. }
  130. asmlinkage int sys_vfork(struct pt_regs *regs)
  131. {
  132. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
  133. regs, 0, NULL, NULL);
  134. }
  135. asmlinkage int sys_clone(int flags, unsigned long stack, struct pt_regs *regs)
  136. {
  137. if (!stack)
  138. stack = regs->r1;
  139. return do_fork(flags, stack, regs, 0, NULL, NULL);
  140. }
  141. asmlinkage int sys_execve(char __user *filenamei, char __user *__user *argv,
  142. char __user *__user *envp, struct pt_regs *regs)
  143. {
  144. int error;
  145. char *filename;
  146. filename = getname(filenamei);
  147. error = PTR_ERR(filename);
  148. if (IS_ERR(filename))
  149. goto out;
  150. error = do_execve(filename, argv, envp, regs);
  151. putname(filename);
  152. out:
  153. return error;
  154. }
  155. asmlinkage unsigned long
  156. sys_mmap2(unsigned long addr, size_t len,
  157. unsigned long prot, unsigned long flags,
  158. unsigned long fd, unsigned long pgoff)
  159. {
  160. struct file *file = NULL;
  161. int ret = -EBADF;
  162. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  163. if (!(flags & MAP_ANONYMOUS)) {
  164. file = fget(fd);
  165. if (!file) {
  166. printk(KERN_INFO "no fd in mmap\r\n");
  167. goto out;
  168. }
  169. }
  170. down_write(&current->mm->mmap_sem);
  171. ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  172. up_write(&current->mm->mmap_sem);
  173. if (file)
  174. fput(file);
  175. out:
  176. return ret;
  177. }
  178. asmlinkage unsigned long sys_mmap(unsigned long addr, size_t len,
  179. unsigned long prot, unsigned long flags,
  180. unsigned long fd, off_t offset)
  181. {
  182. int err = -EINVAL;
  183. if (offset & ~PAGE_MASK) {
  184. printk(KERN_INFO "no pagemask in mmap\r\n");
  185. goto out;
  186. }
  187. err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  188. out:
  189. return err;
  190. }
  191. /*
  192. * Do a system call from kernel instead of calling sys_execve so we
  193. * end up with proper pt_regs.
  194. */
  195. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  196. {
  197. register const char *__a __asm__("r5") = filename;
  198. register const void *__b __asm__("r6") = argv;
  199. register const void *__c __asm__("r7") = envp;
  200. register unsigned long __syscall __asm__("r12") = __NR_execve;
  201. register unsigned long __ret __asm__("r3");
  202. __asm__ __volatile__ ("brki r14, 0x8"
  203. : "=r" (__ret), "=r" (__syscall)
  204. : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
  205. : "r4", "r8", "r9",
  206. "r10", "r11", "r14", "cc", "memory");
  207. return __ret;
  208. }