1/* $OpenBSD: tfork_thread.S,v 1.7 2016/05/15 00:15:10 guenther Exp $ */ 2 3/* 4 * Copyright (c) 2005 Tim Wiess <tim@nop.cx> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#include "SYS.h" 20 21ENTRY(__tfork_thread) 22 /* call __tfork */ 23 li %r0, SYS___tfork 24 sc 25 cmpwi %r0, 0 26 bne 1f 27 28 /* check if we are parent or child */ 29 cmpwi %r3, 0 30 bnelr 31 32 /* child */ 33 mtlr %r5 /* fp */ 34 mr %r3, %r6 /* arg */ 35 subi %r1, %r1, 16 /* fixup sp to get headroom */ 36 blrl 37 38 /* child returned, call __threxit */ 39 li %r0, SYS___threxit 40 sc 411: 42 stw 0, R2_OFFSET_ERRNO(%r2) 43 li %r3, -1 44 blr 45END(__tfork_thread) 46