linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: monstr@monstr.eu
To: linux-kernel@vger.kernel.org
Cc: monstr@seznam.cz, arnd@arndb.de, linux-arch@vger.kernel.org,
	stephen.neuendorffer@xilinx.com, John.Linn@xilinx.com,
	john.williams@petalogix.com, matthew@wil.cx,
	will.newton@gmail.com, drepper@redhat.com,
	microblaze-uclinux@itee.uq.edu.au, grant.likely@secretlab.ca,
	vapier.adi@gmail.com, alan@lxorguk.ukuu.org.uk, hpa@zytor.com,
	lethal@linux-sh.org, florian@openwrt.org,
	Michal Simek <monstr@monstr.eu>
Subject: [PATCH 56/58] microblaze_v5: sys_microblaze.c
Date: Tue,  8 Jul 2008 13:59:56 +0200	[thread overview]
Message-ID: <41cdea2c3255c0bcc7da940a2a1e76d48dc71d02.1215517976.git.monstr@monstr.eu> (raw)
In-Reply-To: <64353f136ffa9f5dba8854168b6ef9d3a71f5a47.1215517976.git.monstr@monstr.eu>
In-Reply-To: <80a2e46f2fb93812ab12bf79c703e8e2d6b0faa0.1215517976.git.monstr@monstr.eu>

From: Michal Simek <monstr@monstr.eu>

Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Signed-off-by: Michal Simek <monstr@monstr.eu>
---
 arch/microblaze/kernel/sys_microblaze.c |  272 +++++++++++++++++++++++++++++++
 1 files changed, 272 insertions(+), 0 deletions(-)
 create mode 100644 arch/microblaze/kernel/sys_microblaze.c

diff --git a/arch/microblaze/kernel/sys_microblaze.c b/arch/microblaze/kernel/sys_microblaze.c
new file mode 100644
index 0000000..def5ff9
--- /dev/null
+++ b/arch/microblaze/kernel/sys_microblaze.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2007 PetaLogix
+ *	John Williams <john.williams@petalogix.com>
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ *	Yasushi SHOJI <yashi@atmark-techno.com>
+ *	Tetsuya OHKAWA <tetsuya@atmark-techno.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/syscalls.h>
+#include <linux/sem.h>
+#include <linux/msg.h>
+#include <linux/shm.h>
+#include <linux/stat.h>
+#include <linux/mman.h>
+#include <linux/sys.h>
+#include <linux/ipc.h>
+#include <linux/utsname.h>
+#include <linux/file.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/ipc.h>
+#include <linux/semaphore.h>
+
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+
+/*
+ * sys_ipc() is the de-multiplexer for the SysV IPC calls..
+ *
+ * This is really horribly ugly. This will be remove with new toolchain.
+ */
+int
+sys_ipc(uint call, int first, int second, int third, void *ptr, long fifth)
+{
+	int version, ret;
+
+	version = call >> 16; /* hack for backward compatibility */
+	call &= 0xffff;
+
+	ret = -EINVAL;
+	switch (call) {
+	case SEMOP:
+		ret = sys_semop(first, (struct sembuf *)ptr, second);
+		break;
+	case SEMGET:
+		ret = sys_semget(first, second, third);
+		break;
+	case SEMCTL:
+	{
+		union semun fourth;
+
+		if (!ptr)
+			break;
+		if ((ret = access_ok(VERIFY_READ, ptr,
+					sizeof(long)) ? 0 : -EFAULT)
+			|| (ret = get_user(fourth.__pad, (void **)ptr)))
+			break;
+		ret = sys_semctl(first, second, third, fourth);
+		break;
+	}
+	case MSGSND:
+		ret = sys_msgsnd(first, (struct msgbuf *) ptr, second, third);
+		break;
+	case MSGRCV:
+		switch (version) {
+		case 0: {
+			struct ipc_kludge tmp;
+
+			if (!ptr)
+				break;
+			if ((ret = access_ok(VERIFY_READ, ptr,
+					sizeof(tmp)) ? 0 : -EFAULT)
+				|| (ret = copy_from_user(&tmp,
+						(struct ipc_kludge *) ptr,
+						sizeof(tmp))))
+				break;
+			ret = sys_msgrcv(first, tmp.msgp, second, tmp.msgtyp,
+					third);
+			break;
+			}
+		default:
+			ret = sys_msgrcv(first, (struct msgbuf *) ptr,
+					second, fifth, third);
+			break;
+		}
+		break;
+	case MSGGET:
+		ret = sys_msgget((key_t) first, second);
+		break;
+	case MSGCTL:
+		ret = sys_msgctl(first, second, (struct msqid_ds *) ptr);
+		break;
+	case SHMAT:
+		switch (version) {
+		default: {
+			ulong raddr;
+
+			if ((ret = access_ok(VERIFY_WRITE, (ulong *) third,
+					sizeof(ulong)) ? 0 : -EFAULT))
+				break;
+			ret = do_shmat(first, (char *) ptr, second, &raddr);
+			if (ret)
+				break;
+			ret = put_user(raddr, (ulong *) third);
+			break;
+			}
+		case 1:	/* iBCS2 emulator entry point */
+			if (!segment_eq(get_fs(), get_ds()))
+				break;
+			ret = do_shmat(first, (char *) ptr, second,
+					(ulong *) third);
+			break;
+		}
+		break;
+	case SHMDT:
+		ret = sys_shmdt((char *)ptr);
+		break;
+	case SHMGET:
+		ret = sys_shmget(first, second, third);
+		break;
+	case SHMCTL:
+		ret = sys_shmctl(first, second, (struct shmid_ds *) ptr);
+		break;
+	}
+
+	return ret;
+}
+
+long execve(const char *filename, char **argv, char **envp)
+{
+	struct pt_regs regs;
+	int ret;
+
+	memset(&regs, 0, sizeof(struct pt_regs));
+	local_save_flags(regs.msr);
+	ret = do_execve((char *)filename, (char __user * __user *)argv,
+			(char __user * __user *)envp, &regs);
+
+	if (ret < 0)
+		goto out;
+
+	/*
+	 * Save argc to the register structure for userspace.
+	 */
+	regs.r5 = ret; /* FIXME */
+
+	/*
+	 * We were successful. We won't be returning to our caller, but
+	 * instead to user space by manipulating the kernel stack.
+	 */
+	asm volatile ("addk	r5, r0, %0	\n\t"
+			"addk	r6, r0, %1	\n\t"
+			/* copy regs to top of stack */
+			"brlid	r15, memmove	\n\t"
+			"addik	r7, r0, %2	\n\t"
+			"brid	ret_to_user	\n\t"
+			/* reposition stack pointer */
+			"addk	r1, r0, r3	\n\t"
+			:
+			: "r" (task_pt_regs(current)),
+			"r" (&regs),
+			"i" (sizeof(regs))
+			: "r1", "r3", "r5", "r6", "r7", "r15", "memory");
+
+out:
+	return ret;
+}
+EXPORT_SYMBOL(execve);
+
+asmlinkage int sys_vfork(struct pt_regs *regs)
+{
+	return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
+						regs, 0, NULL, NULL);
+}
+
+asmlinkage int sys_clone(int flags, unsigned long stack, struct pt_regs *regs)
+{
+	if (!stack)
+		stack = regs->r1;
+	return do_fork(flags, stack, regs, 0, NULL, NULL);
+}
+
+asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
+			char __user * __user *envp, struct pt_regs *regs)
+{
+	int error;
+	char *filename;
+
+	filename = getname(filenamei);
+	error = PTR_ERR(filename);
+	if (IS_ERR(filename))
+		goto out;
+	error = do_execve(filename, argv, envp, regs);
+	putname(filename);
+out:
+	return error;
+}
+
+static inline unsigned long
+do_mmap2(unsigned long addr, size_t len,
+	unsigned long prot, unsigned long flags,
+	unsigned long fd, unsigned long pgoff)
+{
+	struct file *file = NULL;
+	int ret = -EBADF;
+
+	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
+	if (!(flags & MAP_ANONYMOUS))
+		if (!(file = fget(fd))) {
+			printk(KERN_INFO "no fd in mmap\r\n");
+			goto out;
+		}
+
+	down_write(&current->mm->mmap_sem);
+	ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	up_write(&current->mm->mmap_sem);
+	if (file)
+		fput(file);
+out:
+	return ret;
+}
+
+unsigned long sys_mmap2(unsigned long addr, size_t len,
+			unsigned long prot, unsigned long flags,
+			unsigned long fd, unsigned long pgoff)
+{
+	return do_mmap2(addr, len, prot, flags, fd, pgoff);
+}
+
+unsigned long sys_mmap(unsigned long addr, size_t len,
+			unsigned long prot, unsigned long flags,
+			unsigned long fd, off_t offset)
+{
+	int err = -EINVAL;
+
+	if (offset & ~PAGE_MASK) {
+		printk(KERN_INFO "no pagemask in mmap\r\n");
+		goto out;
+	}
+
+	err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+out:
+	return err;
+}
+
+/*
+ * Do a system call from kernel instead of calling sys_execve so we
+ * end up with proper pt_regs.
+ */
+int kernel_execve(const char *filename, char *const argv[], char *const envp[])
+{
+	register const char *__a __asm__("r5") = filename;
+	register const void *__b __asm__("r6") = argv;
+	register const void *__c __asm__("r7") = envp;
+	register unsigned long __syscall __asm__("r12") = __NR_execve;
+	register unsigned long __ret __asm__("r3");
+	__asm__ __volatile__ ("brki r14, 0x8"
+			: "=r" (__ret), "=r" (__syscall)
+			: "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
+			: "r4", "r8", "r9",
+			"r10", "r11", "r14", "cc", "memory");
+	return __ret;
+}
-- 
1.5.4.GIT

  reply	other threads:[~2008-07-08 12:07 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08 11:59 microblaze_v5: Status message monstr
2008-07-08 11:59 ` [PATCH 01/58] microblaze_v5: Kconfig patches monstr
2008-07-08 11:59   ` [PATCH 02/58] microblaze_v5: Makefiles for Microblaze cpu monstr
2008-07-08 11:59     ` [PATCH 03/58] microblaze_v5: Cpuinfo handling monstr
2008-07-08 11:59       ` [PATCH 04/58] microblaze_v5: Open firmware files1 monstr
2008-07-08 11:59         ` [PATCH 05/58] microblaze_v5: Open firmware files2 monstr
2008-07-08 11:59           ` [PATCH 06/58] microblaze_v5: Open firmware common files monstr
2008-07-08 11:59             ` [PATCH 07/58] microblaze_v5: exception handling monstr
2008-07-08 11:59               ` [PATCH 08/58] microblaze_v5: Signal support monstr
2008-07-08 11:59                 ` [PATCH 09/58] microblaze_v5: Interrupt handling, timer support, supported function monstr
2008-07-08 11:59                   ` [PATCH 10/58] microblaze_v5: cache support monstr
2008-07-08 11:59                     ` monstr
2008-07-08 11:59                     ` [PATCH 11/58] microblaze_v5: Generic dts file for platforms monstr
2008-07-08 11:59                       ` [PATCH 12/58] microblaze_v5: kernel modules support monstr
2008-07-08 11:59                         ` [PATCH 13/58] microblaze_v5: lmb support monstr
2008-07-08 11:59                           ` [PATCH 14/58] microblaze_v5: PVR support, cpuinfo support monstr
2008-07-08 11:59                             ` [PATCH 15/58] microblaze_v5: defconfig file monstr
2008-07-08 11:59                               ` [PATCH 16/58] microblaze_v5: head.S + linker script monstr
2008-07-08 11:59                                 ` [PATCH 17/58] microblaze_v5: supported function for memory - kernel/lib monstr
2008-07-08 11:59                                   ` [PATCH 18/58] microblaze_v5: checksum support monstr
2008-07-08 11:59                                     ` [PATCH 19/58] microblaze_v5: early_printk support monstr
2008-07-08 11:59                                       ` [PATCH 20/58] microblaze_v5: uaccess files monstr
2008-07-08 11:59                                         ` [PATCH 21/58] microblaze_v5: heartbeat file monstr
2008-07-08 11:59                                           ` [PATCH 22/58] microblaze_v5: setup.c - system setting monstr
2008-07-08 11:59                                             ` [PATCH 23/58] microblaze_v5: asm-offsets monstr
2008-07-08 11:59                                               ` [PATCH 24/58] microblaze_v5: process and init task function monstr
2008-07-08 11:59                                                 ` [PATCH 25/58] microblaze_v5: time support monstr
2008-07-08 11:59                                                   ` [PATCH 26/58] microblaze_v5: virtualization monstr
2008-07-08 11:59                                                     ` [PATCH 27/58] microblaze_v5: ptrace support monstr
2008-07-08 11:59                                                       ` [PATCH 28/58] microblaze_v5: traps support monstr
2008-07-08 11:59                                                         ` [PATCH 29/58] microblaze_v5: memory inicialization, MMU, TLB monstr
2008-07-08 11:59                                                           ` [PATCH 30/58] microblaze_v5: page.h, segment.h, unaligned.h monstr
2008-07-08 11:59                                                             ` [PATCH 31/58] microblaze_v5: includes SHM*, msgbuf monstr
2008-07-08 11:59                                                               ` [PATCH 32/58] microblaze_v5: bug headers files monstr
2008-07-08 11:59                                                                 ` [PATCH 33/58] microblaze_v5: definitions of types monstr
2008-07-08 11:59                                                                   ` [PATCH 34/58] microblaze_v5: ioctl support monstr
2008-07-08 11:59                                                                     ` [PATCH 35/58] microblaze_v5: io.h IO operations monstr
2008-07-08 11:59                                                                       ` [PATCH 36/58] microblaze_v5: headers for executables format FLAT, ELF monstr
2008-07-08 11:59                                                                         ` [PATCH 37/58] microblaze_v5: dma support monstr
2008-07-08 11:59                                                                           ` [PATCH 38/58] microblaze_v5: headers for irq monstr
2008-07-08 11:59                                                                             ` [PATCH 39/58] microblaze_v5: atomic.h bitops.h byteorder.h monstr
2008-07-08 11:59                                                                               ` [PATCH 40/58] microblaze_v5: headers pgalloc.h pgtable.h monstr
2008-07-08 11:59                                                                                 ` [PATCH 41/58] microblaze_v5: system.h pvr.h processor.h monstr
2008-07-08 11:59                                                                                   ` [PATCH 42/58] microblaze_v5: clinkage.h linkage.h sections.h kmap_types.h monstr
2008-07-08 11:59                                                                                     ` [PATCH 43/58] microblaze_v5: stats headers monstr
2008-07-08 11:59                                                                                       ` [PATCH 44/58] microblaze_v5: termbits.h termios.h monstr
2008-07-08 11:59                                                                                         ` [PATCH 45/58] microblaze_v5: sigcontext.h siginfo.h monstr
2008-07-08 11:59                                                                                           ` [PATCH 46/58] microblaze_v5: headers simple files - empty or redirect to asm-generic monstr
2008-07-08 11:59                                                                                             ` [PATCH 47/58] microblaze_v5: headers files entry.h current.h mman.h registers.h sembuf.h monstr
2008-07-08 11:59                                                                                               ` [PATCH 48/58] microblaze_v5: device.h param.h topology.h monstr
2008-07-08 11:59                                                                                                 ` [PATCH 49/58] microblaze_v5: pool.h socket.h monstr
2008-07-08 11:59                                                                                                   ` [PATCH 50/58] microblaze_v5: generic files sockios.h ucontext.h monstr
2008-07-08 11:59                                                                                                     ` [PATCH 51/58] microblaze_v5: setup.h string.h thread_info.h monstr
2008-07-08 11:59                                                                                                       ` [PATCH 52/58] microblaze_v5: Kbuild file monstr
2008-07-08 11:59                                                                                                         ` [PATCH 53/58] microblaze_v5: pci headers monstr
2008-07-08 11:59                                                                                                           ` [PATCH 54/58] microblaze_v5: IPC headers monstr
2008-07-08 11:59                                                                                                             ` [PATCH 55/58] microblaze_v5: entry.S monstr
2008-07-08 11:59                                                                                                               ` monstr [this message]
2008-07-08 11:59                                                                                                                 ` [PATCH 57/58] microblaze_v5: syscall_table.S and unistd.h monstr
2008-07-08 11:59                                                                                                                   ` [PATCH 58/58] microblaze_v5: Enable drivers for Microblaze monstr
2008-07-08 23:47                                       ` [PATCH 19/58] microblaze_v5: early_printk support John Williams
2008-07-08 19:43 ` microblaze_v5: Status message Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41cdea2c3255c0bcc7da940a2a1e76d48dc71d02.1215517976.git.monstr@monstr.eu \
    --to=monstr@monstr.eu \
    --cc=John.Linn@xilinx.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arnd@arndb.de \
    --cc=drepper@redhat.com \
    --cc=florian@openwrt.org \
    --cc=grant.likely@secretlab.ca \
    --cc=hpa@zytor.com \
    --cc=john.williams@petalogix.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=microblaze-uclinux@itee.uq.edu.au \
    --cc=monstr@seznam.cz \
    --cc=stephen.neuendorffer@xilinx.com \
    --cc=vapier.adi@gmail.com \
    --cc=will.newton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).