1*0a6a1f1dSLionel Sambuc/* $NetBSD: swapcontext.S,v 1.12 2015/04/06 01:50:46 uwe Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras/*- 42fe8fb19SBen Gras * Copyright (c) 2001 The NetBSD Foundation, Inc. 52fe8fb19SBen Gras * All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * This code is derived from software contributed to The NetBSD Foundation 82fe8fb19SBen Gras * by Klaus Klein. 92fe8fb19SBen Gras * 102fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 112fe8fb19SBen Gras * modification, are permitted provided that the following conditions 122fe8fb19SBen Gras * are met: 132fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 142fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 152fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 162fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 172fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 182fe8fb19SBen Gras * 192fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 202fe8fb19SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 212fe8fb19SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 222fe8fb19SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 232fe8fb19SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 242fe8fb19SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 252fe8fb19SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 262fe8fb19SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 272fe8fb19SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 282fe8fb19SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 292fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE. 302fe8fb19SBen Gras */ 312fe8fb19SBen Gras 322fe8fb19SBen Gras#include <machine/asm.h> 332fe8fb19SBen Gras#if defined(SYSLIBC_SCCS) && !defined(lint) 34*0a6a1f1dSLionel Sambuc RCSID("$NetBSD: swapcontext.S,v 1.12 2015/04/06 01:50:46 uwe Exp $") 352fe8fb19SBen Gras#endif /* SYSLIBC_SCCS and not lint */ 362fe8fb19SBen Gras 372fe8fb19SBen Gras/* 382fe8fb19SBen Gras * int 392fe8fb19SBen Gras * swapcontext(ucontext_t * restrict oucp, ucontext_t * restrict ucp); 402fe8fb19SBen Gras */ 412fe8fb19SBen GrasENTRY(swapcontext) 422fe8fb19SBen Gras PIC_PROLOGUE(.L_got) 432fe8fb19SBen Gras sts.l pr, @-sp 442fe8fb19SBen Gras 452fe8fb19SBen Gras mov.l .L__getcontext, r0 46*0a6a1f1dSLionel Sambuc mov.l r5, @-sp 47*0a6a1f1dSLionel Sambuc1: CALL r0 ! _getcontext(oucp) 482fe8fb19SBen Gras mov.l r4, @-sp 49*0a6a1f1dSLionel Sambuc !! getcontext captures oucp resuming here with r12 (when PIC), 50*0a6a1f1dSLionel Sambuc !! pr, r5 and r4 pushed onto the stack 512fe8fb19SBen Gras 52*0a6a1f1dSLionel Sambuc tst r0, r0 53*0a6a1f1dSLionel Sambuc bf.s 3f ! return error from getcontext 54*0a6a1f1dSLionel Sambuc mov.l @sp, r1 ! saved oucp 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc !! adjust oucp to resume after setcontext below 57*0a6a1f1dSLionel Sambuc mova 3f, r0 58*0a6a1f1dSLionel Sambuc mov.l r0, @(36 + 1 * 4, r1) ! _UC_MACHINE_SET_PC(oucp, pr) 59*0a6a1f1dSLionel Sambuc 602fe8fb19SBen Gras mov.l .L_setcontext, r2 61*0a6a1f1dSLionel Sambuc2: CALL r2 ! setcontext(ucp) 62*0a6a1f1dSLionel Sambuc mov.l @(4, sp), r4 ! saved ucp 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc .align 2 65*0a6a1f1dSLionel Sambuc3: !! we get here on errors and when resuming oucp 66*0a6a1f1dSLionel Sambuc add #8, sp ! skip r4 and r5 672fe8fb19SBen Gras lds.l @sp+, pr 682fe8fb19SBen Gras rts 69*0a6a1f1dSLionel Sambuc PIC_EPILOGUE_SLOT 702fe8fb19SBen Gras 712fe8fb19SBen Gras .align 2 722fe8fb19SBen Gras.L_got: PIC_GOT_DATUM 732fe8fb19SBen Gras.L__getcontext: CALL_DATUM(_C_LABEL(_getcontext), 1b) 742fe8fb19SBen Gras.L_setcontext: CALL_DATUM(_C_LABEL(setcontext), 2b) 752fe8fb19SBen Gras SET_ENTRY_SIZE(swapcontext) 76