setjmp.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 1993 Intel Corporation
  4. *
  5. * Intel hereby grants you permission to copy, modify, and distribute this
  6. * software and its documentation. Intel grants this permission provided
  7. * that the above copyright notice appears in all copies and that both the
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation. In addition, Intel grants this permission provided that
  10. * you prominently mark as "not part of the original" any modifications
  11. * made to this software or documentation, and that the name of Intel
  12. * Corporation not be used in advertising or publicity pertaining to
  13. * distribution of the software or the documentation without specific,
  14. * written prior permission.
  15. *
  16. * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
  17. * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
  18. * OR FITNESS FOR A PARTICULAR PURPOSE. Intel makes no guarantee or
  19. * representations regarding the use of, or the results of the use of,
  20. * the software and documentation in terms of correctness, accuracy,
  21. * reliability, currentness, or otherwise; and you rely on the software,
  22. * documentation and results solely at your own risk.
  23. *
  24. * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
  25. * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
  26. * OF ANY KIND. IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
  27. * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
  28. *
  29. ******************************************************************************/
  30. /***************************************************************************
  31. *
  32. * Modified from the original in order to fit with
  33. * uClibc's setjmp, _setjmp, __sigsetjmp and ___sigjmp_save.
  34. *
  35. *
  36. * int setjmp (jmp_buf __env) is the BSD style setjmp function.
  37. * It simply calls __sigsetjmp(env, 1)
  38. *
  39. * int _setjmp (jmp_buf __env) is the posix style setjmp function.
  40. * It simply calls __sigsetjmp(env, 0)
  41. * This is the one normally used.
  42. *
  43. ***************************************************************************/
  44. .text
  45. .align 4
  46. .globl _setjmp
  47. .globl __setjmp
  48. _setjmp:
  49. mov 1, g1 /* __sigsetjmp(env, 1) */
  50. bx __sigsetjmp
  51. __setjmp:
  52. mov 0, g1 /* __sigsetjmp(env, 0) */
  53. bx __sigsetjmp
  54. /******************************************************************************/
  55. /* */
  56. /* setjmp(), longjmp() */
  57. /* */
  58. /******************************************************************************/
  59. .file "setjmp.S"
  60. .text
  61. /* .link_pix */
  62. .align 4
  63. .globl __sigsetjmp
  64. __sigsetjmp:
  65. flushreg
  66. andnot 0xf,pfp,g2 /* get pfp, mask out return status bits */
  67. st g2, 0x58(g0) /* save fp of caller*/
  68. /* save globals not killed by the calling convention */
  69. stq g8, 0x40(g0) /* save g8-g11*/
  70. st g12, 0x50(g0) /* save g12*/
  71. st g14, 0x54(g0) /* save g14*/
  72. /* save previous frame local registers */
  73. ldq (g2), g4 /* get previous frame pfp, sp, rip, r3 */
  74. stq g4, (g0) /* save pfp, sp, rip, r3 */
  75. ldq 0x10(g2), g4 /* get previous frame r4-r7 */
  76. stq g4, 0x10(g0) /* save r4-r7 */
  77. ldq 0x20(g2), g4 /* get previous frame r8-r11 */
  78. stq g4, 0x20(g0) /* save r8-r11 */
  79. ldq 0x30(g2), g4 /* get previous frame r12-r15 */
  80. stq g4, 0x30(g0) /* save r12-r15 */
  81. bx ___sigjmp_save
  82. /*
  83. * fake a return to the place that called the corresponding __sigsetjmp
  84. */
  85. .align 4
  86. .globl ___longjmp
  87. ___longjmp:
  88. call 0f /* ensure there is at least one stack frame */
  89. 0:
  90. flushreg /* do this before swapping stack */
  91. ld 0x58(g0), pfp /* get fp of caller of setjmp */
  92. /* restore local registers
  93. * the following code modifies the frame of the function which originally
  94. * called setjmp.
  95. */
  96. ldq (g0), g4 /* get pfp, sp, rip, r3 */
  97. stq g4, (pfp) /* restore pfp, sp, rip, r3 */
  98. ldq 0x10(g0), g4 /* get r4-r7 */
  99. stq g4, 0x10(pfp) /* restore r4-r7 */
  100. ldq 0x20(g0), g4 /* get r8-r11 */
  101. stq g4, 0x20(pfp) /* restore r8-r11 */
  102. ldq 0x30(g0), g4 /* get r12-r15 */
  103. stq g4, 0x30(pfp) /* restore r12-r15 */
  104. /* restore global registers */
  105. ldq 0x40(g0), g8 /* get old g8-g11 values */
  106. ld 0x50(g0), g12 /* get old g12 value */
  107. ld 0x54(g0), g14 /* get old g14 value */
  108. mov g1, g0 /* get return value */
  109. cmpo g0, 0 /* make sure it is not zero */
  110. bne 0f
  111. mov 1, g0 /* return 1 by default */
  112. 0:
  113. ret /* return to caller of __sigsetjmp */