1*0a6a1f1dSLionel Sambuc/* $NetBSD: swapcontext.S,v 1.6 2014/05/22 15:01:56 uebayasi Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras/* 42fe8fb19SBen Gras * Copyright (c) 2003 Wasabi Systems, Inc. 52fe8fb19SBen Gras * All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * Written by Frank van der Linden for Wasabi Systems, Inc. 82fe8fb19SBen Gras * 92fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 102fe8fb19SBen Gras * modification, are permitted provided that the following conditions 112fe8fb19SBen Gras * are met: 122fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 132fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 142fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 152fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 162fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 172fe8fb19SBen Gras * 3. All advertising materials mentioning features or use of this software 182fe8fb19SBen Gras * must display the following acknowledgement: 192fe8fb19SBen Gras * This product includes software developed for the NetBSD Project by 202fe8fb19SBen Gras * Wasabi Systems, Inc. 212fe8fb19SBen Gras * 4. The name of Wasabi Systems, Inc. may not be used to endorse 222fe8fb19SBen Gras * or promote products derived from this software without specific prior 232fe8fb19SBen Gras * written permission. 242fe8fb19SBen Gras * 252fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 262fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 272fe8fb19SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 282fe8fb19SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 292fe8fb19SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 302fe8fb19SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 312fe8fb19SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 322fe8fb19SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 332fe8fb19SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 342fe8fb19SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 352fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE. 362fe8fb19SBen Gras */ 372fe8fb19SBen Gras 382fe8fb19SBen Gras#include <machine/asm.h> 392fe8fb19SBen Gras 402fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 41*0a6a1f1dSLionel Sambuc RCSID("$NetBSD: swapcontext.S,v 1.6 2014/05/22 15:01:56 uebayasi Exp $") 422fe8fb19SBen Gras#endif /* LIBC_SCCS && !lint */ 432fe8fb19SBen Gras 442fe8fb19SBen Gras/* 452fe8fb19SBen Gras * 56 == offsetof(ucontext_t, uc_mcontext) 462fe8fb19SBen Gras * 21 == _REG_RIP 472fe8fb19SBen Gras * 24 == _REG_URSP 482fe8fb19SBen Gras */ 492fe8fb19SBen Gras 502fe8fb19SBen GrasENTRY(swapcontext) 512fe8fb19SBen Gras pushq %rdi /* preserve oucp */ 522fe8fb19SBen Gras pushq %rsi /* preserve ucp */ 5384d9c625SLionel Sambuc#ifdef __PIC__ 542fe8fb19SBen Gras call PIC_PLT(_C_LABEL(_getcontext)) 552fe8fb19SBen Gras#else 562fe8fb19SBen Gras call _C_LABEL(_getcontext) 572fe8fb19SBen Gras#endif 582fe8fb19SBen Gras popq %rsi 592fe8fb19SBen Gras popq %rdi 602fe8fb19SBen Gras testl %eax,%eax 612fe8fb19SBen Gras jnz 2f 622fe8fb19SBen Gras movq 0(%rsp),%r11 632fe8fb19SBen Gras movq %r11,(56 + 21 * 8)(%rdi) 642fe8fb19SBen Gras leaq 8(%rsp),%r11 652fe8fb19SBen Gras movq %r11,(56 + 24 * 8)(%rdi) 662fe8fb19SBen Gras movq %rsi,%rdi 6784d9c625SLionel Sambuc#ifdef __PIC__ 682fe8fb19SBen Gras call PIC_PLT(_C_LABEL(setcontext)) 692fe8fb19SBen Gras#else 702fe8fb19SBen Gras call _C_LABEL(setcontext) 712fe8fb19SBen Gras#endif 722fe8fb19SBen Gras2: 732fe8fb19SBen Gras ret 74*0a6a1f1dSLionel SambucEND(swapcontext) 75