Blame sysdeps/mips/__longjmp.c

Packit 6c4009
/* Copyright (C) 1992-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Brendan Kehoe (brendan@zen.org).
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 <setjmp.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
#ifndef	__GNUC__
Packit 6c4009
  #error This file uses GNU C extensions; you must compile with GCC.
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
static void __attribute__ ((nomips16))
Packit 6c4009
____longjmp (__jmp_buf env_arg, int val_arg)
Packit 6c4009
{
Packit 6c4009
  /* gcc 1.39.19 miscompiled the longjmp routine (as it did setjmp before
Packit 6c4009
     the hack around it); force it to use $a1 for the longjmp value.
Packit 6c4009
     Without this it saves $a1 in a register which gets clobbered
Packit 6c4009
     along the way.  */
Packit 6c4009
  register struct __jmp_buf_internal_tag *env asm ("a0");
Packit 6c4009
  register int val asm ("a1");
Packit 6c4009
#ifdef CHECK_SP
Packit 6c4009
  register long sp asm ("$29");
Packit 6c4009
  CHECK_SP (env[0].__sp, sp, long);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __mips_hard_float
Packit 6c4009
  /* Pull back the floating point callee-saved registers.  */
Packit 6c4009
  asm volatile ("l.d $f20, %0" : : "m" (env[0].__fpregs[0]));
Packit 6c4009
  asm volatile ("l.d $f22, %0" : : "m" (env[0].__fpregs[1]));
Packit 6c4009
  asm volatile ("l.d $f24, %0" : : "m" (env[0].__fpregs[2]));
Packit 6c4009
  asm volatile ("l.d $f26, %0" : : "m" (env[0].__fpregs[3]));
Packit 6c4009
  asm volatile ("l.d $f28, %0" : : "m" (env[0].__fpregs[4]));
Packit 6c4009
  asm volatile ("l.d $f30, %0" : : "m" (env[0].__fpregs[5]));
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  /* Get the GP. */
Packit 6c4009
  asm volatile ("lw $gp, %0" : : "m" (env[0].__gp));
Packit 6c4009
Packit 6c4009
  /* Get the callee-saved registers.  */
Packit 6c4009
  asm volatile ("lw $16, %0" : : "m" (env[0].__regs[0]));
Packit 6c4009
  asm volatile ("lw $17, %0" : : "m" (env[0].__regs[1]));
Packit 6c4009
  asm volatile ("lw $18, %0" : : "m" (env[0].__regs[2]));
Packit 6c4009
  asm volatile ("lw $19, %0" : : "m" (env[0].__regs[3]));
Packit 6c4009
  asm volatile ("lw $20, %0" : : "m" (env[0].__regs[4]));
Packit 6c4009
  asm volatile ("lw $21, %0" : : "m" (env[0].__regs[5]));
Packit 6c4009
  asm volatile ("lw $22, %0" : : "m" (env[0].__regs[6]));
Packit 6c4009
  asm volatile ("lw $23, %0" : : "m" (env[0].__regs[7]));
Packit 6c4009
Packit 6c4009
  /* Get the PC.  */
Packit 6c4009
  asm volatile ("lw $25, %0" : : "m" (env[0].__pc));
Packit 6c4009
Packit 6c4009
  /* Restore the stack pointer and the FP.  They have to be restored
Packit 6c4009
     last and in a single asm as gcc, depending on options used, may
Packit 6c4009
     use either of them to access env.  */
Packit 6c4009
  asm volatile ("lw $29, %0\n\t"
Packit 6c4009
		"lw $30, %1\n\t" : : "m" (env[0].__sp), "m" (env[0].__fp));
Packit 6c4009
Packit 6c4009
/* Give setjmp 1 if given a 0, or what they gave us if non-zero.  */
Packit 6c4009
  if (val == 0)
Packit 6c4009
    asm volatile ("li $2, 1");
Packit 6c4009
  else
Packit 6c4009
    asm volatile ("move $2, %0" : : "r" (val));
Packit 6c4009
Packit 6c4009
  asm volatile ("jr $25");
Packit 6c4009
Packit 6c4009
  /* Avoid `volatile function does return' warnings.  */
Packit 6c4009
  for (;;);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
strong_alias (____longjmp, __longjmp);