Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
6.2 KiB

4 years ago
  1. // TITLE("Long Jump")
  2. //++
  3. //
  4. // Copyright (c) 1993 Microsoft Corporation
  5. // Copyright (c) 1993 Digital Equipment Corporation
  6. //
  7. // Module Name:
  8. //
  9. // longjmp.s
  10. //
  11. // Abstract:
  12. //
  13. // This module implements the Alpha specific routine to perform a long
  14. // jump operation. Three jump buffer types are supported: unsafe, safe
  15. // acc-style (virtual frame pointer, PC mapped SEH scope), and safe
  16. // GEM-style (real frame pointer, SEB-based SEH context).
  17. //
  18. // N.B. This routine conditionally provides UNSAFE handling of longjmp
  19. // which is NOT integrated with structured exception handling. The
  20. // determination is made based on whether an unitialized variable
  21. // has been set to a nonzero value.
  22. //
  23. // Author:
  24. //
  25. // David N. Cutler (davec) 2-Apr-1993
  26. //
  27. // Environment:
  28. //
  29. // Any mode.
  30. //
  31. // Revision History:
  32. //
  33. // Thomas Van Baak (tvb) 22-Apr-1993
  34. //
  35. // Adapted for Alpha AXP.
  36. //
  37. //--
  38. #include "ksalpha.h"
  39. //
  40. // Define jump buffer types.
  41. //
  42. // _JMPBUF_TYPE_ZERO was used for Beta2 which functions the same as
  43. // _JMPBUF_TYPE_ACC.
  44. //
  45. // _JMPBUF_TYPE_FAST is for jump buffers containing the set of
  46. // non-volatile integer and floating registers. This form
  47. // of setjmp/longjmp is not compatible with SEH.
  48. //
  49. // _JMPBUF_TYPE_ACC is for setjmp/longjmp compatible with SEH.
  50. // The Alpha acc compiler uses a virtual frame pointer.
  51. //
  52. // _JMPBUF_TYPE_GEM is for setjmp/longjmp compatible with SEH.
  53. // The Alpha GEM C compiler uses a real frame pointer, and
  54. // SEH scope is maintained with a SEB pointer.
  55. //
  56. #define _JMPBUF_TYPE_ZERO 0
  57. #define _JMPBUF_TYPE_FAST 1
  58. #define _JMPBUF_TYPE_ACC 2
  59. #define _JMPBUF_TYPE_GEM 3
  60. SBTTL("Long Jump")
  61. //++
  62. //
  63. // int
  64. // longjmp (
  65. // IN jmp_buf JumpBuffer,
  66. // IN int ReturnValue
  67. // )
  68. //
  69. // Routine Description:
  70. //
  71. // This function performs a long jump to the context specified by the
  72. // jump buffer.
  73. //
  74. // Arguments:
  75. //
  76. // JumpBuffer (a0) - Supplies the address of a jump buffer that contains
  77. // jump information.
  78. //
  79. // ReturnValue (a1) - Supplies the value that is to be returned to the
  80. // caller of set jump.
  81. //
  82. // Return Value:
  83. //
  84. // None.
  85. //
  86. //--
  87. LEAF_ENTRY(longjmp)
  88. ldil t0, 1 // force nonzero value, if
  89. cmoveq a1, t0, a1 // given return value is zero
  90. ldl t1, JbType(a0) // get setjmp context type flag
  91. subq t1, 1, t2 // if eq 1, fast, unsafe longjmp
  92. bne t2, 10f // otherwise, provide safe longjmp
  93. //
  94. // Type 0x1: Provide unsafe handling of longjmp.
  95. //
  96. mov a1, v0 // set return value
  97. ldt f2, JbFltF2(a0) // restore floating registers f2 - f9
  98. ldt f3, JbFltF3(a0) //
  99. ldt f4, JbFltF4(a0) //
  100. ldt f5, JbFltF5(a0) //
  101. ldt f6, JbFltF6(a0) //
  102. ldt f7, JbFltF7(a0) //
  103. ldt f8, JbFltF8(a0) //
  104. ldt f9, JbFltF9(a0) //
  105. ldq s0, JbIntS0(a0) // restore integer registers s0 - s6/fp
  106. ldq s1, JbIntS1(a0) //
  107. ldq s2, JbIntS2(a0) //
  108. ldq s3, JbIntS3(a0) //
  109. ldq s4, JbIntS4(a0) //
  110. ldq s5, JbIntS5(a0) //
  111. ldq fp, JbIntS6(a0) //
  112. ldq a1, JbFir(a0) // get setjmp return address
  113. ldq sp, JbIntSp(a0) // restore stack pointer
  114. jmp zero, (a1) // jump back to setjmp site
  115. //
  116. // Type 0x0: Provide safe handling of longjmp (idw 404 style).
  117. // Type 0x2: Provide safe handling of longjmp (acc style).
  118. //
  119. 10: bic t1, 0x2, t2 // if 0 or 2, safe acc longjmp
  120. bne t2, longjmpRfp // if not, safe GEM longjmp
  121. mov a1, a3 // set return value
  122. mov zero, a2 // set exception record addres
  123. ldl a1, JbPc(a0) // set target instruction address
  124. ldl a0, JbFp(a0) // set target virtual frame pointer
  125. br zero, RtlUnwind // finish in common code
  126. .end longjmp
  127. SBTTL("Long Jump - GEM")
  128. .struct 0
  129. LjRa: .space 8 // saved return address
  130. .space 8 // padding for 16-byte stack alignment
  131. LjEr: .space ExceptionRecordLength // local exception record
  132. LongjmpFrameLength:
  133. //
  134. // Type 0x3: Provide safe handling of longjmp (GEM style).
  135. //
  136. NESTED_ENTRY(longjmpRfp, LongjmpFrameLength, ra)
  137. lda sp, -LongjmpFrameLength(sp) // allocate stack frame
  138. stq ra, LjRa(sp) // save return address
  139. PROLOGUE_END
  140. //
  141. // Set up the following local exception record:
  142. //
  143. // ExceptionRecord.ExceptionCode = STATUS_UNWIND;
  144. // ExceptionRecord.ExceptionFlags = EXCEPTION_UNWINDING;
  145. // ExceptionRecord.ExceptionRecord = NULL;
  146. // ExceptionRecord.ExceptionAddress = 0;
  147. // ExceptionRecord.NumberParameters = 1;
  148. // ExceptionRecord.ExceptionInformation[0] = Seb;
  149. //
  150. 10: mov a1, a3 // set return value
  151. lda a2, LjEr(sp) // set exception record address
  152. ldil t0, STATUS_UNWIND // get status code
  153. stl t0, ErExceptionCode(a2) // store in exception record
  154. ldil t1, EXCEPTION_UNWINDING // get exception flags
  155. stl t1, ErExceptionFlags(a2) // store in exception record
  156. stl zero, ErExceptionRecord(a2) // store in exception record
  157. stl zero, ErExceptionAddress(a2) // store in exception record
  158. ldil t2, 1 // get number of parameters
  159. stl t2, ErNumberParameters(a2) // store in exception record
  160. ldl t3, JbSeb(a0) // get SEB pointer
  161. stl t3, ErExceptionInformation(a2) // store in exception record
  162. ldl a1, JbPc(a0) // set target instruction address
  163. ldl a0, JbFp(a0) // set target real frame pointer
  164. bsr ra, RtlUnwindRfp // finish in common code
  165. .end longjmpRfp