swapcontext.S revision 1.9.8.2 1 1.9.8.2 martin /* $NetBSD: swapcontext.S,v 1.9.8.2 2008/04/28 20:22:58 martin Exp $ */
2 1.9.8.2 martin
3 1.9.8.2 martin /*-
4 1.9.8.2 martin * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.9.8.2 martin * All rights reserved.
6 1.9.8.2 martin *
7 1.9.8.2 martin * This code is derived from software contributed to The NetBSD Foundation
8 1.9.8.2 martin * by Klaus Klein.
9 1.9.8.2 martin *
10 1.9.8.2 martin * Redistribution and use in source and binary forms, with or without
11 1.9.8.2 martin * modification, are permitted provided that the following conditions
12 1.9.8.2 martin * are met:
13 1.9.8.2 martin * 1. Redistributions of source code must retain the above copyright
14 1.9.8.2 martin * notice, this list of conditions and the following disclaimer.
15 1.9.8.2 martin * 2. Redistributions in binary form must reproduce the above copyright
16 1.9.8.2 martin * notice, this list of conditions and the following disclaimer in the
17 1.9.8.2 martin * documentation and/or other materials provided with the distribution.
18 1.9.8.2 martin *
19 1.9.8.2 martin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.9.8.2 martin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.9.8.2 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.9.8.2 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.9.8.2 martin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.9.8.2 martin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.9.8.2 martin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.9.8.2 martin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.9.8.2 martin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.9.8.2 martin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.9.8.2 martin * POSSIBILITY OF SUCH DAMAGE.
30 1.9.8.2 martin */
31 1.9.8.2 martin
32 1.9.8.2 martin #include <machine/asm.h>
33 1.9.8.2 martin #if defined(SYSLIBC_SCCS) && !defined(lint)
34 1.9.8.2 martin RCSID("$NetBSD: swapcontext.S,v 1.9.8.2 2008/04/28 20:22:58 martin Exp $")
35 1.9.8.2 martin #endif /* SYSLIBC_SCCS and not lint */
36 1.9.8.2 martin
37 1.9.8.2 martin /*
38 1.9.8.2 martin * int
39 1.9.8.2 martin * swapcontext(ucontext_t * restrict oucp, ucontext_t * restrict ucp);
40 1.9.8.2 martin */
41 1.9.8.2 martin ENTRY(swapcontext)
42 1.9.8.2 martin PIC_PROLOGUE(.L_got)
43 1.9.8.2 martin mov.l r5, @-sp
44 1.9.8.2 martin sts.l pr, @-sp
45 1.9.8.2 martin
46 1.9.8.2 martin mov.l .L__getcontext, r0
47 1.9.8.2 martin 1: CALL r0 /* _getcontext(oucp) */
48 1.9.8.2 martin mov.l r4, @-sp
49 1.9.8.2 martin mov.l @sp+, r1
50 1.9.8.2 martin tst r0, r0
51 1.9.8.2 martin bf 3f /* return error from getcontext */
52 1.9.8.2 martin
53 1.9.8.2 martin /* Note: getcontext does _UC_MACHINE_INTRV(oucp) = 0 for us */
54 1.9.8.2 martin mov.l @sp, r0
55 1.9.8.2 martin mov.l r0, @(36 + 1 * 4, r1) /* _UC_MACHINE_SET_PC(oucp, pr) */
56 1.9.8.2 martin mov.l .L_setcontext, r2
57 1.9.8.2 martin 2: CALL r2 /* setcontext(ucp) */
58 1.9.8.2 martin mov.l @(4, sp), r4
59 1.9.8.2 martin /* if we get here, return error from setcontext */
60 1.9.8.2 martin 3:
61 1.9.8.2 martin lds.l @sp+, pr
62 1.9.8.2 martin #ifdef PIC
63 1.9.8.2 martin add #4, sp
64 1.9.8.2 martin rts
65 1.9.8.2 martin PIC_EPILOGUE
66 1.9.8.2 martin #else
67 1.9.8.2 martin rts
68 1.9.8.2 martin add #4, sp
69 1.9.8.2 martin #endif
70 1.9.8.2 martin
71 1.9.8.2 martin .align 2
72 1.9.8.2 martin .L_got: PIC_GOT_DATUM
73 1.9.8.2 martin .L__getcontext: CALL_DATUM(_C_LABEL(_getcontext), 1b)
74 1.9.8.2 martin .L_setcontext: CALL_DATUM(_C_LABEL(setcontext), 2b)
75 1.9.8.2 martin SET_ENTRY_SIZE(swapcontext)
76