2 * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 * File: libc/ppc/sys/vfork.s
30 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
35 /* We use mode-independent "g" opcodes such as "srgi", and/or
36 * mode-independent macros such as MI_GET_ADDRESS. These expand
37 * into word operations when targeting __ppc__, and into doubleword
38 * operations when targeting __ppc64__.
40 #include <architecture/ppc/mode_independent_asm.h>
42 /* In vfork(), the child runs in parent's address space. */
46 MI_ENTRY_POINT(_vfork)
47 MI_GET_ADDRESS(r5,__current_pid) // get address of __current_pid in r5
49 lwarx r6,0,r5 // don't cache pid across vfork
51 ble-- 3f // is another vfork in progress
52 li r6,0 // if not, erase the stored pid
54 addi r6,r6,-1 // count the parallel vforks in
55 stwcx. r6,0,r5 // negative cached pid values
60 b Lbotch // error return
63 beq Lparent // parent, since a1 == 0 in parent,
68 Lparent: // r3 == child's pid
69 lwarx r6,0,r5 // we're back, decrement vfork count
76 lwarx r6,0,r5 // never went, decrement vfork count
81 MI_BRANCH_EXTERNAL(cerror)