xref: /netbsd-src/lib/libc/arch/powerpc64/gen/swapcontext.S (revision d213e5903af55bc2aa72e9f1e64b7f41ce7a28f4)
1*d213e590Sjoerg/*	$NetBSD: swapcontext.S,v 1.5 2014/08/13 15:41:21 joerg Exp $	*/
2d48f1466Sross
3d48f1466Sross/*-
4d48f1466Sross * Copyright (c) 2001 The NetBSD Foundation, Inc.
5d48f1466Sross * All rights reserved.
6d48f1466Sross *
7d48f1466Sross * This code is derived from software contributed to The NetBSD Foundation
8d48f1466Sross * by Klaus Klein.
9d48f1466Sross *
10d48f1466Sross * Redistribution and use in source and binary forms, with or without
11d48f1466Sross * modification, are permitted provided that the following conditions
12d48f1466Sross * are met:
13d48f1466Sross * 1. Redistributions of source code must retain the above copyright
14d48f1466Sross *    notice, this list of conditions and the following disclaimer.
15d48f1466Sross * 2. Redistributions in binary form must reproduce the above copyright
16d48f1466Sross *    notice, this list of conditions and the following disclaimer in the
17d48f1466Sross *    documentation and/or other materials provided with the distribution.
18d48f1466Sross *
19d48f1466Sross * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d48f1466Sross * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d48f1466Sross * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d48f1466Sross * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d48f1466Sross * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d48f1466Sross * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d48f1466Sross * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d48f1466Sross * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d48f1466Sross * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d48f1466Sross * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d48f1466Sross * POSSIBILITY OF SUCH DAMAGE.
30d48f1466Sross */
31d48f1466Sross
32d48f1466Sross#include "SYS.h"
33d48f1466Sross
34d48f1466Sross#if defined(LIBC_SCCS) && !defined(lint)
35d48f1466Sross	.text
36*d213e590Sjoerg	.asciz "$NetBSD: swapcontext.S,v 1.5 2014/08/13 15:41:21 joerg Exp $"
37d48f1466Sross#endif /* LIBC_SCCS && !lint */
38d48f1466Sross
39d48f1466SrossENTRY(swapcontext)
4050500ff1Sross	mc_off	= 56				# offset of uc_mcontext
41d48f1466Sross	stdu	%r1,-SF_SZ(%r1)			# set up new stack frame
42d48f1466Sross	mflr	%r0
43*d213e590Sjoerg	std	%r0,(SF_SZ+SF_LR)(%r1)		# save link register
4450500ff1Sross	std	%r3,SF_PARAM(%r1)		# must save oucp (was 8)
4550500ff1Sross	std	%r4,SF_PARAM+8(%r1)		# must save ucp (was 12)
4650500ff1Sross	bl	._getcontext			# getcontext(oucp)
47d48f1466Sross	nop
48d48f1466Sross	cmpdi	%r3,0
49d48f1466Sross	bne	1f
50d48f1466Sross	ld	%r11,SF_PARAM(%r1)		# load oucp for adjustment
5150500ff1Sross	ld	%r0,SF_SZ+SF_LR(%r1)		# get LR back
5250500ff1Sross	std	%r0,mc_off+34*8(%r11)	# 	pc <- lr
53d48f1466Sross	la	%r0,16(%r1)
5450500ff1Sross	std	%r0,mc_off+1*8(%r11)		# adjust sp
5550500ff1Sross	ld	%r3,SF_PARAM+8(%r1)		# load ucp
56bba80928Smanu	bl	PIC_PLT(_C_LABEL(setcontext))	# setcontext(ucp)
5750500ff1Sross	nop
58d48f1466Sross1:
59d48f1466Sross	ld	%r0,SF_SZ+SF_LR(%r1)
60d48f1466Sross	mtlr	%r0
61d48f1466Sross	la	%r1,SF_SZ(%r1)
62d48f1466Sross	blr
63