Blame sysdeps/sparc/sparc32/__longjmp.S

Packit 6c4009
/* Copyright (C) 1991-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
Packit 6c4009
#include <jmpbuf-offsets.h>
Packit 6c4009
#define ENV(base,reg) [%base + (reg * 4)]
Packit 6c4009
#define ST_FLUSH_WINDOWS 3
Packit 6c4009
Packit 6c4009
ENTRY(__longjmp)
Packit 6c4009
	/* Store our arguments in global registers so we can still
Packit 6c4009
	   use them while unwinding frames and their register windows.  */
Packit 6c4009
Packit 6c4009
	ld ENV(o0,JB_FP), %g3	/* Cache target FP in register %g3.  */
Packit 6c4009
#ifdef PTR_DEMANGLE
Packit 6c4009
	PTR_DEMANGLE (%g3, %g3, %g4)
Packit 6c4009
#endif
Packit 6c4009
	mov %o0, %g1		/* ENV in %g1 */
Packit 6c4009
	orcc %o1, %g0, %g2	/* VAL in %g2 */
Packit 6c4009
	be,a 0f			/* Branch if zero; else skip delay slot.  */
Packit 6c4009
	 mov 1, %g2		/* Delay slot only hit if zero: VAL = 1.  */
Packit 6c4009
0:
Packit 6c4009
	xor %fp, %g3, %o0
Packit 6c4009
	add %fp, 512, %o1
Packit 6c4009
	andncc %o0, 4095, %o0
Packit 6c4009
	bne LOC(thread)
Packit 6c4009
	 cmp %o1, %g3
Packit 6c4009
	bl LOC(thread)
Packit 6c4009
Packit 6c4009
	/* Now we will loop, unwinding the register windows up the stack
Packit 6c4009
	   until the restored %fp value matches the target value in %g3.  */
Packit 6c4009
Packit 6c4009
LOC(loop):
Packit 6c4009
	cmp %fp, %g3		/* Have we reached the target frame? */
Packit 6c4009
	bl,a LOC(loop)		/* Loop while current fp is below target.  */
Packit 6c4009
	 restore		/* Unwind register window in delay slot.  */
Packit 6c4009
	be,a LOC(found)		/* Better have hit it exactly.  */
Packit 6c4009
	 ld ENV(g1,JB_SP), %o0	/* Delay slot: extract target SP.  */
Packit 6c4009
Packit 6c4009
LOC(thread):
Packit 6c4009
	save	%sp, -96, %sp
Packit 6c4009
	/*
Packit 6c4009
	 * Do a "flush register windows trap".  The trap handler in the
Packit 6c4009
	 * kernel writes all the register windows to their stack slots, and
Packit 6c4009
	 * marks them all as invalid (needing to be sucked up from the
Packit 6c4009
	 * stack when used).  This ensures that all information needed to
Packit 6c4009
	 * unwind to these callers is in memory, not in the register
Packit 6c4009
	 * windows.
Packit 6c4009
	 */
Packit 6c4009
	ta	ST_FLUSH_WINDOWS
Packit 6c4009
#ifdef PTR_DEMANGLE
Packit 6c4009
	ld	ENV(g1,JB_PC), %g5 /* Set return PC. */
Packit 6c4009
	ld	ENV(g1,JB_SP), %g1 /* Set saved SP on restore below. */
Packit 6c4009
	PTR_DEMANGLE2 (%i7, %g5, %g4)
Packit 6c4009
	PTR_DEMANGLE2 (%fp, %g1, %g4)
Packit 6c4009
#else
Packit 6c4009
	ld	ENV(g1,JB_PC), %i7 /* Set return PC. */
Packit 6c4009
	ld	ENV(g1,JB_SP), %fp /* Set saved SP on restore below. */
Packit 6c4009
#endif
Packit 6c4009
	jmp	%i7 + 8
Packit 6c4009
	 restore %g2, 0, %o0	/* Restore values from above register frame. */
Packit 6c4009
Packit 6c4009
LOC(found):
Packit 6c4009
	/* We have unwound register windows so %fp matches the target.  */
Packit 6c4009
#ifdef PTR_DEMANGLE
Packit 6c4009
	PTR_DEMANGLE2 (%sp, %o0, %g4)
Packit 6c4009
#else
Packit 6c4009
	mov %o0, %sp		/* OK, install new SP.  */
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
LOC(sp_ok):
Packit 6c4009
	ld ENV(g1,JB_PC), %o0	/* Extract target return PC.  */
Packit 6c4009
#ifdef PTR_DEMANGLE
Packit 6c4009
	PTR_DEMANGLE2 (%o0, %o0, %g4)
Packit 6c4009
#endif
Packit 6c4009
	jmp %o0 + 8		/* Return there.  */
Packit 6c4009
	 mov %g2, %o0		/* Delay slot: set return value.  */
Packit 6c4009
Packit 6c4009
END(__longjmp)