blob: 2250fe9d269b7e150333186b1948d059c4a1c85a [file] [log] [blame]
Michal Simek7dcbbb22009-03-27 14:25:28 +01001/*
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>
Michal Simek7dcbbb22009-03-27 14:25:28 +010018#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>
Michal Simek7dcbbb22009-03-27 14:25:28 +010026#include <linux/file.h>
27#include <linux/module.h>
28#include <linux/err.h>
29#include <linux/fs.h>
Michal Simek7dcbbb22009-03-27 14:25:28 +010030#include <linux/semaphore.h>
Michal Simek7dcbbb22009-03-27 14:25:28 +010031#include <linux/uaccess.h>
32#include <linux/unistd.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Michal Simek7dcbbb22009-03-27 14:25:28 +010034
35#include <asm/syscalls.h>
Michal Simek7dcbbb22009-03-27 14:25:28 +010036
Arnd Bergmanne5135882009-06-18 19:55:30 +020037asmlinkage long microblaze_vfork(struct pt_regs *regs)
Michal Simek7dcbbb22009-03-27 14:25:28 +010038{
39 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
40 regs, 0, NULL, NULL);
41}
42
Arnd Bergmanne5135882009-06-18 19:55:30 +020043asmlinkage long microblaze_clone(int flags, unsigned long stack, struct pt_regs *regs)
Michal Simek7dcbbb22009-03-27 14:25:28 +010044{
45 if (!stack)
46 stack = regs->r1;
47 return do_fork(flags, stack, regs, 0, NULL, NULL);
48}
49
David Howellsd7627462010-08-17 23:52:56 +010050asmlinkage long microblaze_execve(const char __user *filenamei,
51 const char __user *const __user *argv,
52 const char __user *const __user *envp,
53 struct pt_regs *regs)
Michal Simek7dcbbb22009-03-27 14:25:28 +010054{
55 int error;
56 char *filename;
57
58 filename = getname(filenamei);
59 error = PTR_ERR(filename);
60 if (IS_ERR(filename))
61 goto out;
62 error = do_execve(filename, argv, envp, regs);
63 putname(filename);
64out:
65 return error;
66}
67
Arnd Bergmanne5135882009-06-18 19:55:30 +020068asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
Michal Simek7dcbbb22009-03-27 14:25:28 +010069 unsigned long prot, unsigned long flags,
Arnd Bergmanne5135882009-06-18 19:55:30 +020070 unsigned long fd, off_t pgoff)
Michal Simek7dcbbb22009-03-27 14:25:28 +010071{
Al Virof8b72562009-11-30 17:37:04 -050072 if (pgoff & ~PAGE_MASK)
73 return -EINVAL;
Michal Simek7dcbbb22009-03-27 14:25:28 +010074
Al Virof8b72562009-11-30 17:37:04 -050075 return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
Michal Simek7dcbbb22009-03-27 14:25:28 +010076}
77
78/*
79 * Do a system call from kernel instead of calling sys_execve so we
80 * end up with proper pt_regs.
81 */
David Howellsd7627462010-08-17 23:52:56 +010082int kernel_execve(const char *filename,
83 const char *const argv[],
84 const char *const envp[])
Michal Simek7dcbbb22009-03-27 14:25:28 +010085{
86 register const char *__a __asm__("r5") = filename;
87 register const void *__b __asm__("r6") = argv;
88 register const void *__c __asm__("r7") = envp;
89 register unsigned long __syscall __asm__("r12") = __NR_execve;
90 register unsigned long __ret __asm__("r3");
91 __asm__ __volatile__ ("brki r14, 0x8"
92 : "=r" (__ret), "=r" (__syscall)
93 : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
94 : "r4", "r8", "r9",
95 "r10", "r11", "r14", "cc", "memory");
96 return __ret;
97}