setjmp.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Copyright (C) 1991-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <setjmp.h>
  15. /* Save the current program position in ENV and return 0. */
  16. int
  17. #if defined BSD_SETJMP
  18. # undef setjmp
  19. # define savemask 1
  20. setjmp (jmp_buf env)
  21. #elif defined BSD__SETJMP
  22. # undef _setjmp
  23. # define savemask 0
  24. _setjmp (jmp_buf env)
  25. #else
  26. __sigsetjmp (jmp_buf env, int savemask)
  27. #endif
  28. {
  29. /* Save data registers D1 through D7. */
  30. asm volatile ("movem%.l %/d1-%/d7, %0"
  31. : : "m" (env[0].__jmpbuf[0].__dregs[0]));
  32. /* Save return address in place of register A0. */
  33. env[0].__jmpbuf[0].__aregs[0] = __builtin_return_address (0);
  34. /* Save address registers A1 through A5. */
  35. asm volatile ("movem%.l %/a1-%/a5, %0"
  36. : : "m" (env[0].__jmpbuf[0].__aregs[1]));
  37. /* Save caller's FP, not our own. */
  38. env[0].__jmpbuf[0].__fp = *(int **) __builtin_frame_address (0);
  39. /* Save caller's SP, not our own. */
  40. env[0].__jmpbuf[0].__sp = (int *) __builtin_frame_address (0) + 2;
  41. #if defined __HAVE_68881__ || defined __HAVE_FPU__
  42. /* Save floating-point (68881) registers FP0 through FP7. */
  43. asm volatile ("fmovem%.x %/fp0-%/fp7, %0"
  44. : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
  45. #elif defined (__mcffpu__)
  46. asm volatile ("fmovem %/fp0-%/fp7, %0"
  47. : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
  48. #endif
  49. #if IS_IN (rtld)
  50. /* In ld.so we never save the signal mask. */
  51. return 0;
  52. #else
  53. /* Save the signal mask if requested. */
  54. return __sigjmp_save (env, savemask);
  55. #endif
  56. }
  57. #if !defined BSD_SETJMP && !defined BSD__SETJMP
  58. libc_hidden_def (__sigsetjmp)
  59. #endif