Merge branch 'topic/azt3328' into for-linus
[pandora-kernel.git] / arch / microblaze / kernel / sys_microblaze.c
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
15 #include <linux/errno.h>
16 #include <linux/mm.h>
17 #include <linux/smp.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
35 #include <asm/syscalls.h>
36
37 asmlinkage long microblaze_vfork(struct pt_regs *regs)
38 {
39         return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
40                                                 regs, 0, NULL, NULL);
41 }
42
43 asmlinkage long microblaze_clone(int flags, unsigned long stack, struct pt_regs *regs)
44 {
45         if (!stack)
46                 stack = regs->r1;
47         return do_fork(flags, stack, regs, 0, NULL, NULL);
48 }
49
50 asmlinkage long microblaze_execve(char __user *filenamei, char __user *__user *argv,
51                         char __user *__user *envp, struct pt_regs *regs)
52 {
53         int error;
54         char *filename;
55
56         filename = getname(filenamei);
57         error = PTR_ERR(filename);
58         if (IS_ERR(filename))
59                 goto out;
60         error = do_execve(filename, argv, envp, regs);
61         putname(filename);
62 out:
63         return error;
64 }
65
66 asmlinkage long
67 sys_mmap2(unsigned long addr, unsigned long len,
68         unsigned long prot, unsigned long flags,
69         unsigned long fd, unsigned long pgoff)
70 {
71         struct file *file = NULL;
72         int ret = -EBADF;
73
74         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
75         if (!(flags & MAP_ANONYMOUS)) {
76                 file = fget(fd);
77                 if (!file) {
78                         printk(KERN_INFO "no fd in mmap\r\n");
79                         goto out;
80                 }
81         }
82
83         down_write(&current->mm->mmap_sem);
84         ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
85         up_write(&current->mm->mmap_sem);
86         if (file)
87                 fput(file);
88 out:
89         return ret;
90 }
91
92 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
93                         unsigned long prot, unsigned long flags,
94                         unsigned long fd, off_t pgoff)
95 {
96         int err = -EINVAL;
97
98         if (pgoff & ~PAGE_MASK) {
99                 printk(KERN_INFO "no pagemask in mmap\r\n");
100                 goto out;
101         }
102
103         err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
104 out:
105         return err;
106 }
107
108 /*
109  * Do a system call from kernel instead of calling sys_execve so we
110  * end up with proper pt_regs.
111  */
112 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
113 {
114         register const char *__a __asm__("r5") = filename;
115         register const void *__b __asm__("r6") = argv;
116         register const void *__c __asm__("r7") = envp;
117         register unsigned long __syscall __asm__("r12") = __NR_execve;
118         register unsigned long __ret __asm__("r3");
119         __asm__ __volatile__ ("brki r14, 0x8"
120                         : "=r" (__ret), "=r" (__syscall)
121                         : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
122                         : "r4", "r8", "r9",
123                         "r10", "r11", "r14", "cc", "memory");
124         return __ret;
125 }