diff options
Diffstat (limited to 'libc/sysdeps/linux/h8300/clone.S')
-rw-r--r-- | libc/sysdeps/linux/h8300/clone.S | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/libc/sysdeps/linux/h8300/clone.S b/libc/sysdeps/linux/h8300/clone.S index 554a29703..a00eba4cb 100644 --- a/libc/sysdeps/linux/h8300/clone.S +++ b/libc/sysdeps/linux/h8300/clone.S @@ -1,5 +1,4 @@ -/* Adapted from glibc */ -/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */ +/* Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp> */ /* clone is even more special than fork as it mucks with stacks and invokes a function in the right context after its all over. */ @@ -8,7 +7,8 @@ #include <bits/errno.h> #include <sys/syscall.h> -/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */ +/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg + void *parent_tidptr, void *tls, void *child_tidptr) */ #ifdef __H8300H__ .h8300h @@ -18,8 +18,8 @@ #endif .text -.globl _clone -_clone: +.globl clone +clone: /* Sanity check arguments. */ mov.l #-EINVAL,er3 mov.l er0,er0 /* no NULL function pointers */ @@ -31,13 +31,25 @@ _clone: mov.l @(4:16,sp),er3 mov.l er3,@-er1 - /* Do the system call */ + /* setup argument */ mov.l er0,er3 /* er3 = child entry */ - mov.l er1,er0 - mov.l er2,er1 /* er1 = flags */ - mov.l er0,er2 /* er2 = child sp */ - mov.l #__NR_clone,r0 + sub.l #20,sp + mov.l er2,@sp /* flags */ + mov.l er1,@(4,sp) /* new sp */ + mov.l sp,er1 + mov.l @(20+8,sp),er0 + mov.l er0,@er1 /* parent tid */ + adds #4,er1 + mov.l @(20+16,sp),er0 + mov.l er0,@er1 /* child tid */ + adds #4,er1 + mov.l @(20+12,sp),er0 + mov.l er0,@er1 /* tls */ + /* do the system call */ + mov.l sp,er1 + mov.l #__NR_clone,er0 trapa #0 + add.l #20,sp mov.l er0,er0 bmi __syscall_error beq thread_start @@ -62,7 +74,9 @@ __syscall_error: thread_start: mov.l @sp+,er0 /* restore args */ - jsr @er3 + jsr @er3 mov.l er0,er1 mov.l #__NR_exit,er0 trapa #0 + + .end |