xref: /netbsd-src/lib/libc/arch/vax/sys/getcontext.S (revision 452fee2663636ff13be8d7236edf5a46060414de)
1*452fee26Schs/*	$NetBSD: getcontext.S,v 1.6 2011/11/21 16:17:48 chs Exp $	*/
295b5cce5Smatt
395b5cce5Smatt/*-
495b5cce5Smatt * Copyright (c) 2003 The NetBSD Foundation, Inc.
595b5cce5Smatt * All rights reserved.
695b5cce5Smatt *
795b5cce5Smatt * This code is derived from software contributed to The NetBSD Foundation
895b5cce5Smatt * by Matt Thomas.
995b5cce5Smatt *
1095b5cce5Smatt * Redistribution and use in source and binary forms, with or without
1195b5cce5Smatt * modification, are permitted provided that the following conditions
1295b5cce5Smatt * are met:
1395b5cce5Smatt * 1. Redistributions of source code must retain the above copyright
1495b5cce5Smatt *    notice, this list of conditions and the following disclaimer.
1595b5cce5Smatt * 2. Redistributions in binary form must reproduce the above copyright
1695b5cce5Smatt *    notice, this list of conditions and the following disclaimer in the
1795b5cce5Smatt *    documentation and/or other materials provided with the distribution.
1895b5cce5Smatt *
1995b5cce5Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2095b5cce5Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2195b5cce5Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2295b5cce5Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2395b5cce5Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2495b5cce5Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2595b5cce5Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2695b5cce5Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2795b5cce5Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2895b5cce5Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2995b5cce5Smatt * POSSIBILITY OF SUCH DAMAGE.
3095b5cce5Smatt */
3195b5cce5Smatt
3295b5cce5Smatt#include "SYS.h"
3395b5cce5Smatt
34787e823fSmatt#ifdef SYSLIBC_SCCS
35*452fee26SchsRCSID("$NetBSD: getcontext.S,v 1.6 2011/11/21 16:17:48 chs Exp $")
36787e823fSmatt#endif
37787e823fSmatt
3861687fc2Smatt#ifdef WEAK_ALIAS
3961687fc2SmattWEAK_ALIAS(getcontext, _getcontext)
4061687fc2Smatt#endif
4161687fc2Smatt
4294face2fSmatt/*
4394face2fSmatt * Can't use R4 or R5 since those needed by the phread_switch code.
4494face2fSmatt */
4561687fc2SmattENTRY(_getcontext, 0)
4694face2fSmatt	clrl	%r0			/* assume success */
4795b5cce5Smatt	chmk	$SYS_getcontext		/* getcontext(oucp) */
4895b5cce5Smatt	jcc	1f
4995b5cce5Smatt	jmp	CERROR+2		/* badness happened */
5095b5cce5Smatt
51*452fee26Schs1:	movl	4(%ap),%r0		/* ptr to ucontext */
52*452fee26Schs	movl	16(%fp),%r1		/* PC to return to */
5395b5cce5Smatt	movab	2f,16(%fp)		/* let's return early */
5495b5cce5Smatt	ret
5595b5cce5Smatt	/*
5695b5cce5Smatt	 * Now we have the blown away the callframe and argument
5795b5cce5Smatt	 * list so it's as if we've return from the function except
5895b5cce5Smatt	 * we aren't executing the caller's code (yet).  So it's
5995b5cce5Smatt	 * the callers state but we still have control.
6095b5cce5Smatt	 */
6194face2fSmatt	_ALIGN_TEXT
62*452fee26Schs2:	movq	%ap,(36+12*4)(%r0)	/* adjust AP + SP */
63*452fee26Schs	movl	%fp,(36+14*4)(%r0)	/* adjust FP */
64*452fee26Schs	movl	%r3,(36+15*4)(%r0)	/* adjust PC */
65*452fee26Schs	clrl	%r0
66*452fee26Schs	jmp	(%r1)			/* and return */
67787e823fSmattEND(_getcontext)
68