2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
24 * File: libc/ppc/sys/fork.s
27 * 18-Nov-92 Ben Fathi (benf@next.com)
28 * Created from M88K sources
30 * 11-Jan-92 Peter King (king@next.com)
31 * Created from M68K sources
34 #import <sys/syscall.h>
35 #import <architecture/ppc/asm_help.h>
36 #import <architecture/ppc/pseudo_inst.h>
37 #import <mach/ppc/syscall_sw.h>
39 /* We use 8 bytes for LOCAL_VAR(1) and LOCAL_VAR(2) */
40 NESTED(_fork, 8, 0, 0, 0)
41 CALL_EXTERN(__cthread_fork_prepare)
42 #if defined(__DYNAMIC__)
45 .ascii "__dyld_fork_prepare\0"
52 addis r3,r3,ha16(LC1-1b)
53 addi r3,r3,lo16(LC1-1b)
54 addi r4,r1,LOCAL_VAR(1)
56 lwz r3,LOCAL_VAR(1)(r1)
62 b Lbotch // error return
65 beq Lparent // parent, since a1 == 0 in parent,
67 #if defined(__DYNAMIC__)
70 .ascii "__dyld_fork_child\0"
77 addis r3,r3,ha16(LC3-1b)
78 addi r3,r3,lo16(LC3-1b)
79 addi r4,r1,LOCAL_VAR(1)
81 lwz r3,LOCAL_VAR(1)(r1)
85 CALL_EXTERN(_fork_mach_init)
86 CALL_EXTERN(__cthread_fork_child)
87 #if defined(__DYNAMIC__)
90 .ascii "__dyld_fork_child_final\0"
97 addis r3,r3,ha16(LC4-1b)
98 addi r3,r3,lo16(LC4-1b)
99 addi r4,r1,LOCAL_VAR(1)
100 bl __dyld_func_lookup
101 lwz r3,LOCAL_VAR(1)(r1)
110 #if defined(__DYNAMIC__)
111 stw r3,LOCAL_VAR(2)(r1) // save child pid
116 addis r3,r3,ha16(LC2-1b)
117 addi r3,r3,lo16(LC2-1b)
118 addi r4,r1,LOCAL_VAR(1)
119 bl __dyld_func_lookup
120 lwz r3,LOCAL_VAR(1)(r1)
124 CALL_EXTERN(__cthread_fork_parent)
125 #if defined(__DYNAMIC__)
126 lwz r3,LOCAL_VAR(2)(r1)
131 #if defined(__DYNAMIC__)
134 .ascii "__dyld_fork_parent\0"
137 stw r3,LOCAL_VAR(2)(r1) // save error value
142 addis r3,r3,ha16(LC2-1b)
143 addi r3,r3,lo16(LC2-1b)
144 addi r4,r1,LOCAL_VAR(1)
145 bl __dyld_func_lookup
146 lwz r3,LOCAL_VAR(1)(r1)
149 lwz r3,LOCAL_VAR(2)(r1) // restore error value for cerror
154 * We use cthread_fork_parent() to clean up after a fork error
155 * (unlock cthreads and mailloc packages) so the parent
156 * process can Malloc() after fork() errors without
159 CALL_EXTERN_AGAIN(__cthread_fork_parent)
160 li32 r3,-1 // error return