__longjmp.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 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 <jmpbuf-offsets.h>
  15. #define ENV(base,reg) [%base + (reg * 4)]
  16. #define ST_FLUSH_WINDOWS 3
  17. #define RW_FP [%fp + 0x48]
  18. .global __longjmp
  19. .type __longjmp,%function
  20. .align 4
  21. __longjmp:
  22. .register %g2, #scratch
  23. .register %g3, #scratch
  24. /* Store our arguments in global registers so we can still
  25. * use them while unwinding frames and their register windows. */
  26. ld ENV(o0,JB_FP), %g3 /* Cache target FP in register %g3. */
  27. mov %o0, %g1 /* ENV in %g1 */
  28. orcc %o1, %g0, %g2 /* VAL in %g2 */
  29. be,a 0f /* Branch if zero; else skip delay slot. */
  30. mov 1, %g2 /* Delay slot only hit if zero: VAL = 1. */
  31. 0:
  32. xor %fp, %g3, %o0
  33. add %fp, 512, %o1
  34. andncc %o0, 4095, %o0
  35. bne .Lthread
  36. cmp %o1, %g3
  37. bl .Lthread
  38. /* Now we will loop, unwinding the register windows up the stack
  39. * until the restored %fp value matches the target value in %g3. */
  40. .Lloop:
  41. cmp %fp, %g3 /* Have we reached the target frame? */
  42. bl,a .Lloop /* Loop while current fp is below target. */
  43. restore /* Unwind register window in delay slot. */
  44. be,a .Lfound /* Better have hit it exactly. */
  45. ld ENV(g1,JB_SP), %o0 /* Delay slot: extract target SP. */
  46. .Lthread:
  47. /*
  48. * Do a "flush register windows trap". The trap handler in the
  49. * kernel writes all the register windows to their stack slots, and
  50. * marks them all as invalid (needing to be sucked up from the
  51. * stack when used). This ensures that all information needed to
  52. * unwind to these callers is in memory, not in the register
  53. * windows.
  54. */
  55. ta ST_FLUSH_WINDOWS
  56. ld ENV(g1,JB_PC), %o7 /* Set return PC. */
  57. ld ENV(g1,JB_SP), %fp /* Set saved SP on restore below. */
  58. sub %fp, 64, %sp /* Allocate a register frame. */
  59. st %g3, RW_FP /* Set saved FP on restore below. */
  60. retl
  61. restore %g2, 0, %o0 /* Restore values from above register frame. */
  62. .Lfound:
  63. /* We have unwound register windows so %fp matches the target. */
  64. mov %o0, %sp /* OK, install new SP. */
  65. .Lsp_ok:
  66. ld ENV(g1,JB_PC), %o0 /* Extract target return PC. */
  67. jmp %o0 + 8 /* Return there. */
  68. mov %g2, %o0 /* Delay slot: set return value. */
  69. .size __longjmp,.-__longjmp
  70. libc_hidden_def(__longjmp)