1*c9951c23Suwe/* $NetBSD: swapcontext.S,v 1.12 2015/04/06 01:50:46 uwe Exp $ */ 2c7e237f2Sthorpej 3c7e237f2Sthorpej/*- 4c7e237f2Sthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc. 5c7e237f2Sthorpej * All rights reserved. 6c7e237f2Sthorpej * 7c7e237f2Sthorpej * This code is derived from software contributed to The NetBSD Foundation 8c7e237f2Sthorpej * by Klaus Klein. 9c7e237f2Sthorpej * 10c7e237f2Sthorpej * Redistribution and use in source and binary forms, with or without 11c7e237f2Sthorpej * modification, are permitted provided that the following conditions 12c7e237f2Sthorpej * are met: 13c7e237f2Sthorpej * 1. Redistributions of source code must retain the above copyright 14c7e237f2Sthorpej * notice, this list of conditions and the following disclaimer. 15c7e237f2Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 16c7e237f2Sthorpej * notice, this list of conditions and the following disclaimer in the 17c7e237f2Sthorpej * documentation and/or other materials provided with the distribution. 18c7e237f2Sthorpej * 19c7e237f2Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20c7e237f2Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21c7e237f2Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22c7e237f2Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23c7e237f2Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24c7e237f2Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25c7e237f2Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26c7e237f2Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27c7e237f2Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28c7e237f2Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29c7e237f2Sthorpej * POSSIBILITY OF SUCH DAMAGE. 30c7e237f2Sthorpej */ 31c7e237f2Sthorpej 32c7e237f2Sthorpej#include <machine/asm.h> 33c7e237f2Sthorpej#if defined(SYSLIBC_SCCS) && !defined(lint) 34*c9951c23Suwe RCSID("$NetBSD: swapcontext.S,v 1.12 2015/04/06 01:50:46 uwe Exp $") 35c7e237f2Sthorpej#endif /* SYSLIBC_SCCS and not lint */ 36c7e237f2Sthorpej 378238ccbbSuwe/* 388238ccbbSuwe * int 398238ccbbSuwe * swapcontext(ucontext_t * restrict oucp, ucontext_t * restrict ucp); 408238ccbbSuwe */ 41c7e237f2SthorpejENTRY(swapcontext) 4289723f20Suwe PIC_PROLOGUE(.L_got) 438238ccbbSuwe sts.l pr, @-sp 44fa0fe9c8Suwe 458238ccbbSuwe mov.l .L__getcontext, r0 46*c9951c23Suwe mov.l r5, @-sp 47*c9951c23Suwe1: CALL r0 ! _getcontext(oucp) 488238ccbbSuwe mov.l r4, @-sp 49*c9951c23Suwe !! getcontext captures oucp resuming here with r12 (when PIC), 50*c9951c23Suwe !! pr, r5 and r4 pushed onto the stack 51*c9951c23Suwe 52c7e237f2Sthorpej tst r0, r0 53*c9951c23Suwe bf.s 3f ! return error from getcontext 54*c9951c23Suwe mov.l @sp, r1 ! saved oucp 558238ccbbSuwe 56*c9951c23Suwe !! adjust oucp to resume after setcontext below 57*c9951c23Suwe mova 3f, r0 58*c9951c23Suwe mov.l r0, @(36 + 1 * 4, r1) ! _UC_MACHINE_SET_PC(oucp, pr) 591a997bcdSuwe 608238ccbbSuwe mov.l .L_setcontext, r2 61*c9951c23Suwe2: CALL r2 ! setcontext(ucp) 62*c9951c23Suwe mov.l @(4, sp), r4 ! saved ucp 63*c9951c23Suwe 64*c9951c23Suwe .align 2 65*c9951c23Suwe3: !! we get here on errors and when resuming oucp 66*c9951c23Suwe add #8, sp ! skip r4 and r5 678238ccbbSuwe lds.l @sp+, pr 68fa0fe9c8Suwe rts 69*c9951c23Suwe PIC_EPILOGUE_SLOT 70c7e237f2Sthorpej 71c7e237f2Sthorpej .align 2 72fa0fe9c8Suwe.L_got: PIC_GOT_DATUM 73fa0fe9c8Suwe.L__getcontext: CALL_DATUM(_C_LABEL(_getcontext), 1b) 74fa0fe9c8Suwe.L_setcontext: CALL_DATUM(_C_LABEL(setcontext), 2b) 757581f118Suwe SET_ENTRY_SIZE(swapcontext) 76