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