_setjmp.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* $NetBSD: _setjmp.S,v 1.9 2014/05/23 02:34:19 uebayasi Exp $ */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * William Jolitz.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * from: @(#)_setjmp.s 5.1 (Berkeley) 4/23/90
  34. */
  35. #include "linux-regs.h"
  36. #if defined(LIBC_SCCS)
  37. RCSID("$NetBSD: _setjmp.S,v 1.9 2014/05/23 02:34:19 uebayasi Exp $")
  38. #endif
  39. /*
  40. * C library -- _setjmp, _longjmp
  41. *
  42. * _longjmp(a,v)
  43. * will generate a "return(v)" from the last call to
  44. * _setjmp(a)
  45. * by restoring registers from the stack.
  46. * The previous signal state is NOT restored.
  47. */
  48. #ifdef LINUX32
  49. #define _JB_EDX 0
  50. #define _JB_EBX 1
  51. #define _JB_ESP 2
  52. #define _JB_EBP 3
  53. #define _JB_ESI 4
  54. #define _JB_EDI 5
  55. #define MOV movl
  56. #endif
  57. #ifdef LINUX64
  58. #define _JB_RBX 0
  59. #define _JB_RBP 1
  60. #define _JB_R12 2
  61. #define _JB_R13 3
  62. #define _JB_R14 4
  63. #define _JB_R15 5
  64. #define _JB_RSP 6
  65. #define _JB_PC 7
  66. #define MOV movq
  67. #endif
  68. DECLARE_GLOBAL_FUNC _setjmp
  69. #ifdef LINUX32
  70. movl 4(%esp),%eax
  71. movl 0(%esp),%edx
  72. movl %edx, (_JB_EDX * 4)(%eax) /* rta */
  73. movl %ebx, (_JB_EBX * 4)(%eax)
  74. movl %esp, (_JB_ESP * 4)(%eax)
  75. movl %ebp, (_JB_EBP * 4)(%eax)
  76. movl %esi, (_JB_ESI * 4)(%eax)
  77. movl %edi, (_JB_EDI * 4)(%eax)
  78. #endif
  79. #ifdef LINUX64
  80. movq (%rsp),%r11
  81. movq %rbx,(_JB_RBX * 8)(%rdi)
  82. movq %rbp,(_JB_RBP * 8)(%rdi)
  83. movq %r12,(_JB_R12 * 8)(%rdi)
  84. movq %r13,(_JB_R13 * 8)(%rdi)
  85. movq %r14,(_JB_R14 * 8)(%rdi)
  86. movq %r15,(_JB_R15 * 8)(%rdi)
  87. movq %rsp,(_JB_RSP * 8)(%rdi)
  88. movq %r11,(_JB_PC * 8)(%rdi)
  89. #endif
  90. xorl %eax,%eax
  91. ret
  92. DECLARE_GLOBAL_FUNC _longjmp
  93. #ifdef LINUX32
  94. movl 4(%esp),%edx
  95. movl 8(%esp),%eax
  96. movl (_JB_EDX * 4)(%edx),%ecx
  97. movl (_JB_EBX * 4)(%edx),%ebx
  98. movl (_JB_ESP * 4)(%edx),%esp
  99. movl (_JB_EBP * 4)(%edx),%ebp
  100. movl (_JB_ESI * 4)(%edx),%esi
  101. movl (_JB_EDI * 4)(%edx),%edi
  102. #endif
  103. #ifdef LINUX64
  104. movl %esi,%eax
  105. movq (_JB_RBX * 8)(%rdi),%rbx
  106. movq (_JB_RBP * 8)(%rdi),%rbp
  107. movq (_JB_R12 * 8)(%rdi),%r12
  108. movq (_JB_R13 * 8)(%rdi),%r13
  109. movq (_JB_R14 * 8)(%rdi),%r14
  110. movq (_JB_R15 * 8)(%rdi),%r15
  111. movq (_JB_RSP * 8)(%rdi),%rsp
  112. movq (_JB_PC * 8)(%rdi),%rcx
  113. #endif
  114. testl %eax,%eax
  115. jnz 1f
  116. incl %eax
  117. 1: MOV %xcx,0(%xsp)
  118. ret
  119. DECLARE_GLOBAL_FUNC set_sgx_tlongjmp_version
  120. lea_pic sgx_tsetjmp_version, %xax
  121. ret