xref: /netbsd-src/lib/libc/arch/vax/gen/swapcontext.S (revision 787e823fd1325737172861d30c613c7e6e7d2f3d)
1*787e823fSmatt/*	$NetBSD: swapcontext.S,v 1.4 2011/01/25 02:38:15 matt Exp $	*/
28c295614Smatt
38c295614Smatt/*-
48c295614Smatt * Copyright (c) 2003 The NetBSD Foundation, Inc.
58c295614Smatt * All rights reserved.
68c295614Smatt *
78c295614Smatt * This code is derived from software contributed to The NetBSD Foundation
88c295614Smatt * by Matt Thomas.
98c295614Smatt *
108c295614Smatt * Redistribution and use in source and binary forms, with or without
118c295614Smatt * modification, are permitted provided that the following conditions
128c295614Smatt * are met:
138c295614Smatt * 1. Redistributions of source code must retain the above copyright
148c295614Smatt *    notice, this list of conditions and the following disclaimer.
158c295614Smatt * 2. Redistributions in binary form must reproduce the above copyright
168c295614Smatt *    notice, this list of conditions and the following disclaimer in the
178c295614Smatt *    documentation and/or other materials provided with the distribution.
188c295614Smatt *
198c295614Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
208c295614Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
218c295614Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
228c295614Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
238c295614Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
248c295614Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
258c295614Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
268c295614Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
278c295614Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
288c295614Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
298c295614Smatt * POSSIBILITY OF SUCH DAMAGE.
308c295614Smatt */
318c295614Smatt
328c295614Smatt#include "SYS.h"
338c295614Smatt
34*787e823fSmatt#ifdef LIBC_SCCS
35*787e823fSmattRCSID("$NetBSD: swapcontext.S,v 1.4 2011/01/25 02:38:15 matt Exp $")
36*787e823fSmatt#endif
37*787e823fSmatt
388c295614SmattENTRY(swapcontext, 0)
3921375ddfSmatt	clrl	%r0			/* assume getcontext succeeds */
408c295614Smatt	chmk	$SYS_getcontext		/* getcontext(oucp) */
418c295614Smatt	jcc	1f
4221375ddfSmatt	jmp	CERROR+2		/* something bad happened */
438c295614Smatt
4421375ddfSmatt1:	movl	4(%ap),%r0		/* get oucp */
458c295614Smatt	addl3	(%ap),$(5+1),%r1	/* size of callframe + arglist (LW) */
4621375ddfSmatt	bbs	$13,6(%fp),2f		/* was this a CALLG? */
4721375ddfSmatt	movl	$5,%r1			/* size of callframe (in LW) */
4821375ddfSmatt2:	movl	8(%fp),(36+12*4)(%r0)		/* restore AP */
4921375ddfSmatt	moval	(%sp)[%r1],(36+13*4)(%r0)	/* restore SP */
5021375ddfSmatt	movq	12(%fp),(36+14*4)(%r0)		/* restore FP + PC */
518c295614Smatt
528c295614Smatt	pushl	8(%ap)
538c295614Smatt	calls	$1,_C_LABEL(setcontext) /* setcontext(ucp) */
548c295614Smatt	ret
55*787e823fSmattEND(swapcontext)
56