xref: /minix3/lib/libc/arch/x86_64/sys/getcontext.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: getcontext.S,v 1.4 2014/05/22 15:01:57 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
392fe8fb19SBen Gras#include "SYS.h"
402fe8fb19SBen Gras
412fe8fb19SBen Gras#if defined(SYSLIBC_SCCS) && !defined(lint)
42*0a6a1f1dSLionel Sambuc	RCSID("$NetBSD: getcontext.S,v 1.4 2014/05/22 15:01:57 uebayasi Exp $")
432fe8fb19SBen Gras#endif
442fe8fb19SBen Gras
452fe8fb19SBen Gras#ifdef WEAK_ALIAS
462fe8fb19SBen GrasWEAK_ALIAS(getcontext, _getcontext)
472fe8fb19SBen Gras#endif
482fe8fb19SBen Gras
492fe8fb19SBen Gras/*
502fe8fb19SBen Gras * 56 == offsetof(ucontext_t, uc_mcontext)
512fe8fb19SBen Gras * 14 == _REG_RAX
522fe8fb19SBen Gras * 21 == _REG_RIP
532fe8fb19SBen Gras * 24 == _REG_URSP
542fe8fb19SBen Gras */
552fe8fb19SBen Gras
562fe8fb19SBen Gras_SYSCALL(_getcontext,getcontext)
572fe8fb19SBen Gras	movq	(%rsp),%r11
582fe8fb19SBen Gras	movq	%r11,(56 + 21 * 8)(%rdi)
592fe8fb19SBen Gras	leaq	8(%rsp),%r11
602fe8fb19SBen Gras	movq	%r11,(56 + 24 * 8)(%rdi)
612fe8fb19SBen Gras	movq	$0,(56 + 14 * 8)(%rdi)
622fe8fb19SBen Gras	xorl	%eax,%eax
632fe8fb19SBen Gras	ret
64*0a6a1f1dSLionel SambucEND(_getcontext)
65