__longjmp.S 3.0 KB

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