yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /* Adapted from glibc */ |
| 2 | /* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */ |
| 3 | |
| 4 | /* clone is even more special than fork as it mucks with stacks |
| 5 | and invokes a function in the right context after its all over. */ |
| 6 | |
| 7 | #define _ERRNO_H |
| 8 | #include <features.h> |
| 9 | #include <bits/errno.h> |
| 10 | #include <sys/syscall.h> |
| 11 | #include "m68k_pic.S" |
| 12 | |
| 13 | /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */ |
| 14 | |
| 15 | .text |
| 16 | .align 4 |
| 17 | .type clone,@function |
| 18 | .globl clone; |
| 19 | clone: |
| 20 | /* Sanity check arguments. */ |
| 21 | movel #-EINVAL, %d0 |
| 22 | movel 4(%sp), %d1 /* no NULL function pointers */ |
| 23 | movel %d1, %a0 |
| 24 | tstl %d1 |
| 25 | beq.w __syscall_error_trampoline |
| 26 | movel 8(%sp), %d1 /* no NULL stack pointers */ |
| 27 | movel %d1, %a1 |
| 28 | tstl %d1 |
| 29 | beq.w __syscall_error_trampoline |
| 30 | |
| 31 | /* Allocate space and copy the argument onto the new stack. */ |
| 32 | movel 16(%sp), -(%a1) |
| 33 | |
| 34 | /* Do the system call */ |
| 35 | #if 1 /* defined (CONFIG_COLDFIRE) */ |
| 36 | movel %d2, %d1 /* save %d2 and get stack pointer */ |
| 37 | movel %a1, %d2 |
| 38 | movel %d1, %a1 |
| 39 | #else |
| 40 | exg %d2, %a1 /* save %d2 and get stack pointer */ |
| 41 | #endif |
| 42 | movel 12(%sp), %d1 /* get flags */ |
| 43 | movel #__NR_clone, %d0 |
| 44 | trap #0 |
| 45 | #if 1 /* defined (CONFIG_COLDFIRE) */ |
| 46 | movel %d2, %d1 /* restore %d2 */ |
| 47 | movel %a1, %d2 |
| 48 | movel %d1, %a1 |
| 49 | #else |
| 50 | exg %d2, %a1 /* restore %d2 */ |
| 51 | #endif |
| 52 | |
| 53 | tstl %d0 |
| 54 | bmi.w __syscall_error_trampoline |
| 55 | beq.w thread_start |
| 56 | |
| 57 | rts |
| 58 | |
| 59 | thread_start: |
| 60 | /*subl %fp, %fp*/ /* terminate the stack frame */ |
| 61 | jsr (%a0) |
| 62 | movel %d0, -(%sp) |
| 63 | movel #__NR_exit, %d0 |
| 64 | trap #0 |
| 65 | /*jsr exit*/ |
| 66 | |
| 67 | __syscall_error_trampoline: |
| 68 | JUMP __syscall_error,%a0 |
| 69 | |