1 fe8c925e 2005-07-21 devnull #include "FreeBSD-386-asm.s"
4 fe8c925e 2005-07-21 devnull * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
5 fe8c925e 2005-07-21 devnull * All rights reserved.
7 fe8c925e 2005-07-21 devnull * Redistribution and use in source and binary forms, with or without
8 fe8c925e 2005-07-21 devnull * modification, are permitted provided that the following conditions
9 fe8c925e 2005-07-21 devnull * are met:
10 fe8c925e 2005-07-21 devnull * 1. Redistributions of source code must retain the above copyright
11 fe8c925e 2005-07-21 devnull * notice, this list of conditions and the following disclaimer.
12 fe8c925e 2005-07-21 devnull * 2. Redistributions in binary form must reproduce the above copyright
13 fe8c925e 2005-07-21 devnull * notice, this list of conditions and the following disclaimer in the
14 fe8c925e 2005-07-21 devnull * documentation and/or other materials provided with the distribution.
16 fe8c925e 2005-07-21 devnull * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 fe8c925e 2005-07-21 devnull * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 fe8c925e 2005-07-21 devnull * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 fe8c925e 2005-07-21 devnull * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 fe8c925e 2005-07-21 devnull * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 fe8c925e 2005-07-21 devnull * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 fe8c925e 2005-07-21 devnull * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 fe8c925e 2005-07-21 devnull * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 fe8c925e 2005-07-21 devnull * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 fe8c925e 2005-07-21 devnull * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 fe8c925e 2005-07-21 devnull * SUCH DAMAGE.
29 fe8c925e 2005-07-21 devnull #include <sys/syscall.h>
30 fe8c925e 2005-07-21 devnull #include <machine/asm.h>
32 fe8c925e 2005-07-21 devnull ENTRY(rfork_thread)
33 fe8c925e 2005-07-21 devnull pushl %ebp
34 fe8c925e 2005-07-21 devnull movl %esp, %ebp
35 fe8c925e 2005-07-21 devnull pushl %esi
38 fe8c925e 2005-07-21 devnull * Push thread info onto the new thread's stack
40 fe8c925e 2005-07-21 devnull movl 12(%ebp), %esi # get stack addr
42 fe8c925e 2005-07-21 devnull subl $4, %esi
43 fe8c925e 2005-07-21 devnull movl 20(%ebp), %eax # get start argument
44 fe8c925e 2005-07-21 devnull movl %eax, (%esi)
46 fe8c925e 2005-07-21 devnull subl $4, %esi
47 fe8c925e 2005-07-21 devnull movl 16(%ebp), %eax # get start thread address
48 fe8c925e 2005-07-21 devnull movl %eax, (%esi)
51 fe8c925e 2005-07-21 devnull * Prepare and execute the thread creation syscall
53 fe8c925e 2005-07-21 devnull pushl 8(%ebp)
55 fe8c925e 2005-07-21 devnull movl $SYS_rfork, %eax
56 fe8c925e 2005-07-21 devnull int $0x80
60 fe8c925e 2005-07-21 devnull * Check to see if we are in the parent or child
62 fe8c925e 2005-07-21 devnull cmpl $0, %edx
64 fe8c925e 2005-07-21 devnull addl $8, %esp
65 fe8c925e 2005-07-21 devnull popl %esi
66 fe8c925e 2005-07-21 devnull movl %ebp, %esp
67 fe8c925e 2005-07-21 devnull popl %ebp
69 fe8c925e 2005-07-21 devnull .p2align 2
72 fe8c925e 2005-07-21 devnull * If we are in the child (new thread), then
73 fe8c925e 2005-07-21 devnull * set-up the call to the internal subroutine. If it
74 fe8c925e 2005-07-21 devnull * returns, then call __exit.
77 fe8c925e 2005-07-21 devnull movl %esi,%esp
78 fe8c925e 2005-07-21 devnull popl %eax
79 fe8c925e 2005-07-21 devnull call *%eax
80 fe8c925e 2005-07-21 devnull addl $4, %esp
83 fe8c925e 2005-07-21 devnull * Exit system call
85 fe8c925e 2005-07-21 devnull pushl %eax
87 fe8c925e 2005-07-21 devnull movl $SYS_exit, %eax
88 fe8c925e 2005-07-21 devnull int $0x80
91 fe8c925e 2005-07-21 devnull * Branch here if the thread creation fails:
94 fe8c925e 2005-07-21 devnull addl $8, %esp
95 fe8c925e 2005-07-21 devnull popl %esi
96 fe8c925e 2005-07-21 devnull movl %ebp, %esp
97 fe8c925e 2005-07-21 devnull popl %ebp
98 fe8c925e 2005-07-21 devnull PIC_PROLOGUE
99 c54b8b69 2006-01-27 devnull jmp PIC_PLT(_C_LABEL(__cerror))