150476Speter/*-
215903Swosch * Copyright (c) 2003 Peter Wemm <peter@FreeBSD.org>
3139761Skrion * All rights reserved.
431074Swosch *
515903Swosch * Redistribution and use in source and binary forms, with or without
615903Swosch * modification, are permitted provided that the following conditions
715903Swosch * are met:
815903Swosch * 1. Redistributions of source code must retain the above copyright
915903Swosch *    notice, this list of conditions and the following disclaimer.
1015903Swosch * 2. Redistributions in binary form must reproduce the above copyright
1115903Swosch *    notice, this list of conditions and the following disclaimer in the
1215903Swosch *    documentation and/or other materials provided with the distribution.
1315903Swosch *
1415903Swosch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1515903Swosch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1615903Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1715903Swosch * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1815903Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1915903Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2015903Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2115903Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2274806Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2315903Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2415903Swosch * SUCH DAMAGE.
2523546Swosch */
2623546Swosch
2715903Swosch#include <machine/asm.h>
2815903Swosch__FBSDID("$FreeBSD: releng/10.2/lib/libc/amd64/sys/getcontext.S 240178 2012-09-06 20:59:49Z jilles $");
29139761Skrion
30139761Skrion#include <SYS.h>
3115903Swosch
3215903Swosch/*
33139761Skrion * This has to be magic to handle the multiple returns.
3415903Swosch * Otherwise, the setcontext() syscall will return here and we'll
3515903Swosch * pop off the return address and go to the *setcontext* call.
36139109Sru */
3720935Swosch	.weak	_getcontext
3860749Shoek	.set	_getcontext,__sys_getcontext
3917511Speter	.weak	getcontext
4015903Swosch	.set	getcontext,__sys_getcontext
4127659SpstENTRY(__sys_getcontext)
4227659Spst	movq	(%rsp),%rsi	/* save getcontext return address */
4327659Spst	mov	$SYS_getcontext,%rax
4427659Spst	KERNCALL
4527659Spst	jb	HIDENAME(cerror)
4615903Swosch	addq	$8,%rsp		/* remove stale (setcontext) return address */
4715903Swosch	jmp	*%rsi		/* restore return address */
4815903SwoschEND(__sys_getcontext)
4915903Swosch
5015903Swosch	.section .note.GNU-stack,"",%progbits
511638Srgrimes