sys_microblaze.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/syscalls.h>
  18. #include <linux/sem.h>
  19. #include <linux/msg.h>
  20. #include <linux/shm.h>
  21. #include <linux/stat.h>
  22. #include <linux/mman.h>
  23. #include <linux/sys.h>
  24. #include <linux/ipc.h>
  25. #include <linux/file.h>
  26. #include <linux/module.h>
  27. #include <linux/err.h>
  28. #include <linux/fs.h>
  29. #include <linux/semaphore.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/unistd.h>
  32. #include <asm/syscalls.h>
  33. asmlinkage long microblaze_vfork(struct pt_regs *regs)
  34. {
  35. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
  36. regs, 0, NULL, NULL);
  37. }
  38. asmlinkage long microblaze_clone(int flags, unsigned long stack, struct pt_regs *regs)
  39. {
  40. if (!stack)
  41. stack = regs->r1;
  42. return do_fork(flags, stack, regs, 0, NULL, NULL);
  43. }
  44. asmlinkage long microblaze_execve(char __user *filenamei, char __user *__user *argv,
  45. char __user *__user *envp, struct pt_regs *regs)
  46. {
  47. int error;
  48. char *filename;
  49. filename = getname(filenamei);
  50. error = PTR_ERR(filename);
  51. if (IS_ERR(filename))
  52. goto out;
  53. error = do_execve(filename, argv, envp, regs);
  54. putname(filename);
  55. out:
  56. return error;
  57. }
  58. asmlinkage long
  59. sys_mmap2(unsigned long addr, unsigned long len,
  60. unsigned long prot, unsigned long flags,
  61. unsigned long fd, unsigned long pgoff)
  62. {
  63. struct file *file = NULL;
  64. int ret = -EBADF;
  65. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  66. if (!(flags & MAP_ANONYMOUS)) {
  67. file = fget(fd);
  68. if (!file) {
  69. printk(KERN_INFO "no fd in mmap\r\n");
  70. goto out;
  71. }
  72. }
  73. down_write(&current->mm->mmap_sem);
  74. ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  75. up_write(&current->mm->mmap_sem);
  76. if (file)
  77. fput(file);
  78. out:
  79. return ret;
  80. }
  81. asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
  82. unsigned long prot, unsigned long flags,
  83. unsigned long fd, off_t pgoff)
  84. {
  85. int err = -EINVAL;
  86. if (pgoff & ~PAGE_MASK) {
  87. printk(KERN_INFO "no pagemask in mmap\r\n");
  88. goto out;
  89. }
  90. err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
  91. out:
  92. return err;
  93. }
  94. /*
  95. * Do a system call from kernel instead of calling sys_execve so we
  96. * end up with proper pt_regs.
  97. */
  98. int kernel_execve(const char *filename, char *const argv[], char *const envp[])
  99. {
  100. register const char *__a __asm__("r5") = filename;
  101. register const void *__b __asm__("r6") = argv;
  102. register const void *__c __asm__("r7") = envp;
  103. register unsigned long __syscall __asm__("r12") = __NR_execve;
  104. register unsigned long __ret __asm__("r3");
  105. __asm__ __volatile__ ("brki r14, 0x8"
  106. : "=r" (__ret), "=r" (__syscall)
  107. : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
  108. : "r4", "r8", "r9",
  109. "r10", "r11", "r14", "cc", "memory");
  110. return __ret;
  111. }