__longjmp.S 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright (C) 1991, 93, 96, 97, 98, 99, 2000 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. /* Code taken from glibc/sysdeps/sparc/sparc32/ (glibc 2.2.2) */
  16. //#include "sysdep.h"
  17. #include <sysdep.h>
  18. #define _ASM 1
  19. #define _SETJMP_H
  20. #include <bits/setjmp.h>
  21. #define ENV(base,reg) [%base + (reg * 4)]
  22. #define ST_FLUSH_WINDOWS 3
  23. #define RW_FP [%fp + 0x48]
  24. ENTRY(__longjmp)
  25. /* Store our arguments in global registers so we can still
  26. use them while unwinding frames and their register windows. */
  27. ld ENV(o0,JB_FP), %g3 /* Cache target FP in register %g3. */
  28. mov %o0, %g1 /* ENV in %g1 */
  29. orcc %o1, %g0, %g2 /* VAL in %g2 */
  30. be,a 0f /* Branch if zero; else skip delay slot. */
  31. mov 1, %g2 /* Delay slot only hit if zero: VAL = 1. */
  32. 0:
  33. xor %fp, %g3, %o0
  34. add %fp, 512, %o1
  35. andncc %o0, 4095, %o0
  36. bne thread
  37. //bne LOC(thread)
  38. cmp %o1, %g3
  39. bl thread
  40. //bl LOC(thread)
  41. /* Now we will loop, unwinding the register windows up the stack
  42. until the restored %fp value matches the target value in %g3. */
  43. //LOC(loop):
  44. loop:
  45. cmp %fp, %g3 /* Have we reached the target frame? */
  46. bl,a loop /* Loop while current fp is below target. */
  47. //bl,a LOC(loop) /* Loop while current fp is below target. */
  48. restore /* Unwind register window in delay slot. */
  49. be,a found /* Better have hit it exactly. */
  50. //be,a LOC(found) /* Better have hit it exactly. */
  51. ld ENV(g1,JB_SP), %o0 /* Delay slot: extract target SP. */
  52. thread:
  53. //LOC(thread):
  54. /*
  55. * Do a "flush register windows trap". The trap handler in the
  56. * kernel writes all the register windows to their stack slots, and
  57. * marks them all as invalid (needing to be sucked up from the
  58. * stack when used). This ensures that all information needed to
  59. * unwind to these callers is in memory, not in the register
  60. * windows.
  61. */
  62. ta ST_FLUSH_WINDOWS
  63. ld ENV(g1,JB_PC), %o7 /* Set return PC. */
  64. ld ENV(g1,JB_SP), %fp /* Set saved SP on restore below. */
  65. sub %fp, 64, %sp /* Allocate a register frame. */
  66. st %g3, RW_FP /* Set saved FP on restore below. */
  67. retl
  68. restore %g2, 0, %o0 /* Restore values from above register frame. */
  69. found:
  70. //LOC(found):
  71. /* We have unwound register windows so %fp matches the target. */
  72. mov %o0, %sp /* OK, install new SP. */
  73. //LOC(sp_ok):
  74. sp_ok:
  75. ld ENV(g1,JB_PC), %o0 /* Extract target return PC. */
  76. jmp %o0 + 8 /* Return there. */
  77. mov %g2, %o0 /* Delay slot: set return value. */
  78. END(__longjmp)