_setjmp.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* $OpenBSD: _setjmp.S,v 1.4 2007/11/25 18:25:36 deraadt Exp $ */
  2. /* $NetBSD: _setjmp.S,v 1.1.1.1 1998/06/20 05:18:14 eeh Exp $ */
  3. /*
  4. * Copyright (c) 1992, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This software was developed by the Computer Systems Engineering group
  8. * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
  9. * contributed to Berkeley.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp
  36. */
  37. /*
  38. * C library -- _setjmp, _longjmp
  39. *
  40. * _longjmp(a,v)
  41. * will generate a "return(v?v:1)" from
  42. * the last call to
  43. * _setjmp(a)
  44. * by unwinding the call stack.
  45. * The previous signal state is NOT restored.
  46. */
  47. #include "DEFS.h"
  48. ENTRY(_setjmp)
  49. btst 1, %sp
  50. bne,a,pt %xcc, 1f ! 32 or 64-bit stack?
  51. std %sp, [%o0+0] ! 32-bit stack pointer & return pc
  52. stx %sp, [%o0+0] ! 64-bit stack pointer
  53. stx %o7, [%o0+8] ! 64-bit return pc
  54. stx %fp, [%o0+16] ! 64-bit frame pointer
  55. retl
  56. clr %o0
  57. 1:
  58. st %fp, [%o0+8] ! 32-bit frame pointer
  59. retl
  60. clr %o0
  61. ENTRY(_longjmp)
  62. set 1, %g6
  63. btst 1, %fp ! 32 or 64-bit stack?
  64. movrz %o1, %o1, %g6 ! compute v ? v : 1 in a global register
  65. bne,pt %xcc, 2f ! 64-bit
  66. mov %o0, %g1 ! save a in another global register
  67. ld [%g1+8], %g7 /* get caller's frame */
  68. 1:
  69. cmp %fp, %g7 ! compare against desired frame
  70. bl,a 1b ! if below,
  71. restore ! pop frame and loop
  72. bne,pn %icc, Llongjmpbotch ! if there,
  73. ldd [%g1+0], %o2 ! fetch return %sp and pc, and get out
  74. ba,a,pt %icc, 4f
  75. 2:
  76. ldx [%g1+16], %g7 /* get caller's frame */
  77. 3:
  78. cmp %fp, %g7 ! compare against desired frame
  79. bl,a,pt %xcc, 3b ! if below,
  80. restore ! pop frame and loop
  81. bne,pn %xcc, Llongjmpbotch ! if there,
  82. ldx [%g1+0], %o2 ! fetch return %sp and pc, and get out
  83. ldx [%g1+8], %o3
  84. 4:
  85. cmp %o2, %sp ! %sp must not decrease
  86. blt,pn %icc, Llongjmpbotch
  87. movge %icc, %o2, %sp ! it is OK, put it in place
  88. jmp %o3 + 8 ! success, return %g6
  89. mov %g6, %o0
  90. Lbotch:
  91. call _longjmperror ! otherwise, went too far; bomb out
  92. nop
  93. unimp 0
  94. ! otherwise, went too far; bomb out