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>
6 * Copyright (C) 2006 Atmark Techno, Inc.
7 * Yasushi SHOJI <yashi@atmark-techno.com>
8 * Tetsuya OHKAWA <tetsuya@atmark-techno.com>
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
15 #include <linux/errno.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>
31 #include <linux/semaphore.h>
32 #include <linux/uaccess.h>
33 #include <linux/unistd.h>
35 #include <asm/syscalls.h>
37 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
39 * This is really horribly ugly. This will be remove with new toolchain.
42 sys_ipc(uint call, int first, int second, int third, void *ptr, long fifth)
46 version = call >> 16; /* hack for backward compatibility */
52 ret = sys_semop(first, (struct sembuf *)ptr, second);
55 ret = sys_semget(first, second, third);
63 ret = (access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
64 || (get_user(fourth.__pad, (void **)ptr)) ;
67 ret = sys_semctl(first, second, third, fourth);
71 ret = sys_msgsnd(first, (struct msgbuf *) ptr, second, third);
76 struct ipc_kludge tmp;
80 ret = (access_ok(VERIFY_READ, ptr, sizeof(tmp))
81 ? 0 : -EFAULT) || copy_from_user(&tmp,
82 (struct ipc_kludge *) ptr, sizeof(tmp));
85 ret = sys_msgrcv(first, tmp.msgp, second, tmp.msgtyp,
90 ret = sys_msgrcv(first, (struct msgbuf *) ptr,
91 second, fifth, third);
96 ret = sys_msgget((key_t) first, second);
99 ret = sys_msgctl(first, second, (struct msqid_ds *) ptr);
105 ret = access_ok(VERIFY_WRITE, (ulong *) third,
106 sizeof(ulong)) ? 0 : -EFAULT;
109 ret = do_shmat(first, (char *) ptr, second, &raddr);
112 ret = put_user(raddr, (ulong *) third);
115 case 1: /* iBCS2 emulator entry point */
116 if (!segment_eq(get_fs(), get_ds()))
118 ret = do_shmat(first, (char *) ptr, second,
124 ret = sys_shmdt((char *)ptr);
127 ret = sys_shmget(first, second, third);
130 ret = sys_shmctl(first, second, (struct shmid_ds *) ptr);
136 asmlinkage long microblaze_vfork(struct pt_regs *regs)
138 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
139 regs, 0, NULL, NULL);
142 asmlinkage long microblaze_clone(int flags, unsigned long stack, struct pt_regs *regs)
146 return do_fork(flags, stack, regs, 0, NULL, NULL);
149 asmlinkage long microblaze_execve(char __user *filenamei, char __user *__user *argv,
150 char __user *__user *envp, struct pt_regs *regs)
155 filename = getname(filenamei);
156 error = PTR_ERR(filename);
157 if (IS_ERR(filename))
159 error = do_execve(filename, argv, envp, regs);
166 sys_mmap2(unsigned long addr, unsigned long len,
167 unsigned long prot, unsigned long flags,
168 unsigned long fd, unsigned long pgoff)
170 struct file *file = NULL;
173 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
174 if (!(flags & MAP_ANONYMOUS)) {
177 printk(KERN_INFO "no fd in mmap\r\n");
182 down_write(¤t->mm->mmap_sem);
183 ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
184 up_write(¤t->mm->mmap_sem);
191 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
192 unsigned long prot, unsigned long flags,
193 unsigned long fd, off_t pgoff)
197 if (pgoff & ~PAGE_MASK) {
198 printk(KERN_INFO "no pagemask in mmap\r\n");
202 err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
208 * Do a system call from kernel instead of calling sys_execve so we
209 * end up with proper pt_regs.
211 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
213 register const char *__a __asm__("r5") = filename;
214 register const void *__b __asm__("r6") = argv;
215 register const void *__c __asm__("r7") = envp;
216 register unsigned long __syscall __asm__("r12") = __NR_execve;
217 register unsigned long __ret __asm__("r3");
218 __asm__ __volatile__ ("brki r14, 0x8"
219 : "=r" (__ret), "=r" (__syscall)
220 : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
222 "r10", "r11", "r14", "cc", "memory");