Blame sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S

Packit 6c4009
/* Set up a context to call a function.
Packit 6c4009
   Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
#define __ASSEMBLY__
Packit 6c4009
#include <asm/ptrace.h>
Packit 6c4009
#include "ucontext_i.h"
Packit 6c4009
Packit 6c4009
ENTRY(__makecontext)
Packit 6c4009
	/* Set up the first 7 args to the function in its registers */
Packit 6c4009
	lwz	r11,_UC_REGS_PTR(r3)
Packit 6c4009
	stw	r6,_UC_GREGS+(PT_R3*4)(r11)
Packit 6c4009
	stw	r7,_UC_GREGS+(PT_R4*4)(r11)
Packit 6c4009
	stw	r8,_UC_GREGS+(PT_R5*4)(r11)
Packit 6c4009
	stw	r9,_UC_GREGS+(PT_R6*4)(r11)
Packit 6c4009
	stw	r10,_UC_GREGS+(PT_R7*4)(r11)
Packit 6c4009
	lwz	r8,8(r1)
Packit 6c4009
	lwz	r9,12(r1)
Packit 6c4009
	stw	r8,_UC_GREGS+(PT_R8*4)(r11)
Packit 6c4009
	stw	r9,_UC_GREGS+(PT_R9*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the NIP to the start of the function */
Packit 6c4009
	stw	r4,_UC_GREGS+(PT_NIP*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the function's r31 to ucp->uc_link for the exitcode below. */
Packit 6c4009
	lwz	r7,_UC_LINK(r3)
Packit 6c4009
	stw	r7,_UC_GREGS+(PT_R31*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the function's LR to point to the exitcode below. */
Packit 6c4009
#ifdef PIC
Packit 6c4009
	mflr	r0
Packit 6c4009
	cfi_register(lr,r0)
Packit 6c4009
	/* Use this conditional form of branch and link to avoid destroying
Packit 6c4009
	   the cpu link stack used to predict blr return addresses.  */
Packit 6c4009
	bcl	20,31,1f
Packit 6c4009
1:	mflr	r6
Packit 6c4009
	addi	r6,r6,L(exitcode)-1b
Packit 6c4009
	mtlr	r0
Packit 6c4009
	cfi_same_value (lr)
Packit 6c4009
#else
Packit 6c4009
	lis	r6,L(exitcode)@ha
Packit 6c4009
	addi	r6,r6,L(exitcode)@l
Packit 6c4009
#endif
Packit 6c4009
	stw	r6,_UC_GREGS+(PT_LNK*4)(r11)
Packit 6c4009
Packit 6c4009
	/*
Packit 6c4009
	 * Set up the stack frame for the function.
Packit 6c4009
	 * If we have more than 5 args to the function (8 args to makecontext),
Packit 6c4009
	 * there will be some arguments on the stack which have to end up
Packit 6c4009
	 * in registers.  If there are more than 8 args to the function,
Packit 6c4009
	 * we have to copy (argc - 8) args from our stack to the functions'
Packit 6c4009
	 * stack (and allow space for them in the frame).
Packit 6c4009
	 */
Packit 6c4009
	lwz	r4,_UC_STACK_SP(r3)
Packit 6c4009
	lwz	r8,_UC_STACK_SIZE(r3)
Packit 6c4009
	add	r4,r4,r8
Packit 6c4009
	rlwinm	r4,r4,0,0,27	/* round down to 16-byte boundary */
Packit 6c4009
	addi	r7,r4,-16	/* stack frame for fn's caller */
Packit 6c4009
	cmpwi	r5,8
Packit 6c4009
	blt	2f		/* less than 8 args is easy */
Packit 6c4009
	lwz	r10,16(r1)
Packit 6c4009
	stw	r10,_UC_GREGS+(PT_R10*4)(r11)
Packit 6c4009
	beq	2f		/* if exactly 8 args */
Packit 6c4009
	subi	r9,r5,3
Packit 6c4009
	subi	r5,r5,8
Packit 6c4009
	rlwinm	r9,r9,2,0,27
Packit 6c4009
	subf	r7,r9,r4
Packit 6c4009
	mtctr	r5		/* copy the 9th and following args */
Packit 6c4009
	addi	r6,r1,16
Packit 6c4009
	addi	r8,r7,4
Packit 6c4009
3:	lwzu	r10,4(r6)
Packit 6c4009
	stwu	r10,4(r8)
Packit 6c4009
	bdnz	3b
Packit 6c4009
2:	stw	r7,_UC_GREGS+(PT_R1*4)(r11)
Packit 6c4009
	li	r6,0
Packit 6c4009
	stw	r6,0(r7)
Packit 6c4009
Packit 6c4009
	blr
Packit 6c4009
Packit 6c4009
	cfi_endproc
Packit 6c4009
	nop
Packit 6c4009
/*
Packit 6c4009
 * If the function returns, it comes here.  We put ucp->uc_link in
Packit 6c4009
 * r31, which is a callee-saved register.  We have to continue with
Packit 6c4009
 * the context that r31 points to, or exit if it is 0.
Packit 6c4009
 */
Packit 6c4009
L(exitcode):
Packit 6c4009
	mr.	r3,r31
Packit 6c4009
	beq	4f
Packit 6c4009
	bl	__setcontext@local
Packit 6c4009
4:	bl	HIDDEN_JUMPTARGET(exit)
Packit 6c4009
	b	4b
Packit 6c4009
Packit 6c4009
	cfi_startproc
Packit 6c4009
END(__makecontext)
Packit 6c4009
Packit 6c4009
versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_4)
Packit 6c4009
Packit 6c4009
#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)
Packit 6c4009
Packit 6c4009
	compat_text_section
Packit 6c4009
ENTRY(__novec_makecontext)
Packit 6c4009
	/* Set up the first 7 args to the function in its registers */
Packit 6c4009
	addi	r11,r3,_UC_REG_SPACE
Packit 6c4009
	stw	r11,_UC_REGS_PTR(r3)
Packit 6c4009
	stw	r6,_UC_GREGS+(PT_R3*4)(r11)
Packit 6c4009
	stw	r7,_UC_GREGS+(PT_R4*4)(r11)
Packit 6c4009
	stw	r8,_UC_GREGS+(PT_R5*4)(r11)
Packit 6c4009
	stw	r9,_UC_GREGS+(PT_R6*4)(r11)
Packit 6c4009
	stw	r10,_UC_GREGS+(PT_R7*4)(r11)
Packit 6c4009
	lwz	r8,8(r1)
Packit 6c4009
	lwz	r9,12(r1)
Packit 6c4009
	stw	r8,_UC_GREGS+(PT_R8*4)(r11)
Packit 6c4009
	stw	r9,_UC_GREGS+(PT_R9*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the NIP to the start of the function */
Packit 6c4009
	stw	r4,_UC_GREGS+(PT_NIP*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the function's r31 to ucp->uc_link for the exitcode below. */
Packit 6c4009
	lwz	r7,_UC_LINK(r3)
Packit 6c4009
	stw	r7,_UC_GREGS+(PT_R31*4)(r11)
Packit 6c4009
Packit 6c4009
	/* Set the function's LR to point to the exitcode below. */
Packit 6c4009
#ifdef PIC
Packit 6c4009
	mflr	r0
Packit 6c4009
	cfi_register(lr,r0)
Packit 6c4009
	/* Use this conditional form of branch and link to avoid destroying
Packit 6c4009
	   the cpu link stack used to predict blr return addresses.  */
Packit 6c4009
	bcl	20,31,1f
Packit 6c4009
1:	mflr	r6
Packit 6c4009
	addi	r6,r6,L(novec_exitcode)-1b
Packit 6c4009
	mtlr	r0
Packit 6c4009
	cfi_same_value (lr)
Packit 6c4009
#else
Packit 6c4009
	lis	r6,L(novec_exitcode)@ha
Packit 6c4009
	addi	r6,r6,L(novec_exitcode)@l
Packit 6c4009
#endif
Packit 6c4009
	stw	r6,_UC_GREGS+(PT_LNK*4)(r11)
Packit 6c4009
Packit 6c4009
	/*
Packit 6c4009
	 * Set up the stack frame for the function.
Packit 6c4009
	 * If we have more than 5 args to the function (8 args to makecontext),
Packit 6c4009
	 * there will be some arguments on the stack which have to end up
Packit 6c4009
	 * in registers.  If there are more than 8 args to the function,
Packit 6c4009
	 * we have to copy (argc - 8) args from our stack to the functions'
Packit 6c4009
	 * stack (and allow space for them in the frame).
Packit 6c4009
	 */
Packit 6c4009
	lwz	r4,_UC_STACK_SP(r3)
Packit 6c4009
	lwz	r8,_UC_STACK_SIZE(r3)
Packit 6c4009
	add	r4,r4,r8
Packit 6c4009
	rlwinm	r4,r4,0,0,27	/* round down to 16-byte boundary */
Packit 6c4009
	addi	r7,r4,-16	/* stack frame for fn's caller */
Packit 6c4009
	cmpwi	r5,8
Packit 6c4009
	blt	2f		/* less than 8 args is easy */
Packit 6c4009
	lwz	r10,16(r1)
Packit 6c4009
	stw	r10,_UC_GREGS+(PT_R10*4)(r11)
Packit 6c4009
	beq	2f		/* if exactly 8 args */
Packit 6c4009
	subi	r9,r5,3
Packit 6c4009
	subi	r5,r5,8
Packit 6c4009
	rlwinm	r9,r9,2,0,27
Packit 6c4009
	subf	r7,r9,r4
Packit 6c4009
	mtctr	r5		/* copy the 9th and following args */
Packit 6c4009
	addi	r6,r1,16
Packit 6c4009
	addi	r8,r7,4
Packit 6c4009
3:	lwzu	r10,4(r6)
Packit 6c4009
	stwu	r10,4(r8)
Packit 6c4009
	bdnz	3b
Packit 6c4009
2:	stw	r7,_UC_GREGS+(PT_R1*4)(r11)
Packit 6c4009
	li	r6,0
Packit 6c4009
	stw	r6,0(r7)
Packit 6c4009
Packit 6c4009
	blr
Packit 6c4009
Packit 6c4009
	cfi_endproc
Packit 6c4009
	nop
Packit 6c4009
/*
Packit 6c4009
 * If the function returns, it comes here.  We put ucp->uc_link in
Packit 6c4009
 * r31, which is a callee-saved register.  We have to continue with
Packit 6c4009
 * the context that r31 points to, or exit if it is 0.
Packit 6c4009
 */
Packit 6c4009
L(novec_exitcode):
Packit 6c4009
	mr.	r3,r31
Packit 6c4009
	beq	4f
Packit 6c4009
	bl	__novec_setcontext@local
Packit 6c4009
4:	bl	HIDDEN_JUMPTARGET(exit)
Packit 6c4009
	b	4b
Packit 6c4009
Packit 6c4009
	cfi_startproc
Packit 6c4009
END(__novec_makecontext)
Packit 6c4009
	.previous
Packit 6c4009
Packit 6c4009
compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3)
Packit 6c4009
Packit 6c4009
#define _ERRNO_H	1
Packit 6c4009
#include <bits/errno.h>
Packit 6c4009
Packit 6c4009
	compat_text_section
Packit 6c4009
ENTRY (__makecontext_stub)
Packit 6c4009
	li	r3,ENOSYS
Packit 6c4009
	b	__syscall_error@local
Packit 6c4009
END (__makecontext_stub)
Packit 6c4009
	.previous
Packit 6c4009
Packit 6c4009
compat_symbol (libc, __makecontext_stub, makecontext, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
#endif