From: Nathan Lynch <ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
To: Oren Laadan <orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
Cc: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 3/4] mktree: initial powerpc support hacks
Date: Wed, 16 Sep 2009 04:27:50 -0500 [thread overview]
Message-ID: <1253093271-16357-4-git-send-email-ntl@pobox.com> (raw)
In-Reply-To: <1253093271-16357-1-git-send-email-ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
---
clone_ppc32.S | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
powerpc_asm.h | 46 +++++++++++++++++++++++++++++++++
restart.c | 24 +++++++++++++++++
3 files changed, 149 insertions(+), 0 deletions(-)
create mode 100644 clone_ppc32.S
create mode 100644 powerpc_asm.h
diff --git a/clone_ppc32.S b/clone_ppc32.S
new file mode 100644
index 0000000..e159b19
--- /dev/null
+++ b/clone_ppc32.S
@@ -0,0 +1,79 @@
+#include <asm/unistd.h>
+#include "powerpc_asm.h"
+
+/* int [r3] clone_with_pids(int (*fn)(void *arg) [r3],
+ * void *child_stack [r4],
+ * int flags [r5],
+ * void *arg [r6],
+ * void *parent_tid [r7],
+ * void *tls [r8],
+ * void *child_tid [r9],
+ * struct target_pid_set *setp [r10]);
+ * Creates a child task with the pids specified by setp.
+ * Returns to parent only, child execution and exit is handled here.
+ * On error, returns negated errno. On success, returns the pid of the child
+ * created.
+ */
+
+ .text
+ .globl __clone_with_pids
+__clone_with_pids:
+
+ /* No argument validation. */
+
+ /* Set up parent's stack frame. */
+ stwu r1,-32(r1)
+
+ /* Save non-volatiles (r28-r31) which we plan to use. */
+ stmw r28,16(r1)
+
+ /* Set up child's stack frame. */
+ clrrwi r4,r4,4
+ li r0,0
+ stw r0,-16(r4)
+
+ /* Save fn, stack pointer, flags, and arg across system call. */
+ mr r28,r3
+ mr r29,r4
+ mr r30,r5
+ mr r31,r6
+
+ /* Set up arguments for system call. Stack pointer is already in r4. */
+ mr r3,r5 /* flags */
+ mr r5,r7 /* parent_tid */
+ mr r6,r8 /* tls */
+ mr r7,r9 /* child_tid */
+ mr r8,r10 /* setp */
+
+ /* Do the system call */
+ li r0,__NR_clone_with_pids
+ sc
+
+ /* Parent or child? */
+ cmpwi cr1,r3,0
+ crandc 4*cr1+eq,4*cr1+eq,4*cr0+so
+ bne cr1,parent
+
+ /* Child. Call fn. */
+ mtctr r28
+ mr r3,r31
+ bctrl
+
+ /* Assume result of fn in r3 and exit. */
+ li r0,__NR_exit
+ sc
+
+parent:
+ /* Restore non-volatiles. */
+ lmw r28,16(r1)
+
+ addi r1,r1,32
+
+ /* Return to caller on success. */
+ bnslr
+
+ /* Handle error. Negate the return value to signal an error
+ * to the caller, which must set errno.
+ */
+ neg r3,r3
+ blr
diff --git a/powerpc_asm.h b/powerpc_asm.h
new file mode 100644
index 0000000..58f459f
--- /dev/null
+++ b/powerpc_asm.h
@@ -0,0 +1,46 @@
+#ifndef __POWERPC_ASM_H
+#define _POWERPC_ASM_H
+
+#define r0 0
+#define r1 1
+#define r2 2
+#define r3 3
+#define r4 4
+#define r5 5
+#define r6 6
+#define r7 7
+#define r8 8
+#define r9 9
+#define r10 10
+#define r11 11
+#define r12 12
+#define r13 13
+#define r14 14
+#define r15 15
+#define r16 16
+#define r17 17
+#define r18 18
+#define r19 19
+#define r20 20
+#define r21 21
+#define r22 22
+#define r23 23
+#define r24 24
+#define r25 25
+#define r26 26
+#define r27 27
+#define r28 28
+#define r29 29
+#define r30 30
+#define r31 31
+
+#define cr0 0
+#define cr1 1
+#define cr2 2
+#define cr3 3
+#define cr4 4
+#define cr5 5
+#define cr6 6
+#define cr7 7
+
+#endif /* _POWERPC_ASM_H */
diff --git a/restart.c b/restart.c
index b93a2e1..499614e 100644
--- a/restart.c
+++ b/restart.c
@@ -1951,6 +1951,30 @@ int clone_with_pids(int (*fn)(void *), void *child_stack, int flags,
return retval;
}
+#elif defined(__powerpc__) && defined(__NR_clone_with_pids)
+
+extern int __clone_with_pids(int (*fn)(void *arg), void *child_stack, int flags,
+ void *arg, void *parent_tid, void *tls,
+ void *child_tid, struct target_pid_set *setp);
+
+static int clone_with_pids(int (*fn)(void *), void *child_stack, int flags,
+ struct target_pid_set *target_pids, void *arg)
+{
+ void *parent_tid = NULL;
+ void *tls = NULL;
+ void *child_tid = NULL;
+ pid_t newpid;
+
+ newpid = __clone_with_pids(fn, child_stack, flags, arg, parent_tid,
+ tls, child_tid, target_pids);
+
+ if (newpid < 0) {
+ errno = -newpid;
+ return -1;
+ }
+
+ return newpid;
+}
#else /* !defined(__NR_clone_with_pids) */
/* on other architectures fallback to regular clone(2) */
--
1.6.0.6
next prev parent reply other threads:[~2009-09-16 9:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 9:27 [PATCH 0/4] user-cr: powerpc support etc Nathan Lynch
[not found] ` <1253093271-16357-1-git-send-email-ntl-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org>
2009-09-16 9:27 ` [PATCH 1/4] fix rename fallout Nathan Lynch
2009-09-16 9:27 ` [PATCH 2/4] restart: (build fix hack) define sa_family_t and struct linger Nathan Lynch
2009-09-16 9:27 ` Nathan Lynch [this message]
2009-09-16 9:27 ` [PATCH 4/4] makefile hack for powerpc Nathan Lynch
2009-09-16 18:05 ` [PATCH 0/4] user-cr: powerpc support etc Oren Laadan
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=1253093271-16357-4-git-send-email-ntl@pobox.com \
--to=ntl-e+axbwqsrlaavxtiumwx3w@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org \
/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