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.

147 lines
4.6 KiB

4 years ago
  1. // TITLE("Set Jump Extended")
  2. //++
  3. //
  4. // Copyright (c) 1993 Microsoft Corporation
  5. // Copyright (c) 1993 Digital Equipment Corporation
  6. //
  7. // Module Name:
  8. //
  9. // setjmpex.s
  10. //
  11. // Abstract:
  12. //
  13. // This module implements the Alpha acc compiler specific routine to
  14. // provide SAFE handling of setjmp/longjmp with respect to structured
  15. // exception handling.
  16. //
  17. // Author:
  18. //
  19. // David N. Cutler (davec) 2-Apr-1993
  20. //
  21. // Environment:
  22. //
  23. // Any mode.
  24. //
  25. // Revision History:
  26. //
  27. // Thomas Van Baak (tvb) 22-Apr-1993
  28. //
  29. // Adapted for Alpha AXP.
  30. //
  31. //--
  32. #include "ksalpha.h"
  33. //
  34. // Define variable that will cause setjmp/longjmp to be safe with respect
  35. // to structured exception handling.
  36. //
  37. .globl _setjmpexused
  38. .data
  39. _setjmpexused:
  40. .long _setjmpex // set address of safe setjmp routine
  41. SBTTL("Set Jump Extended")
  42. //++
  43. //
  44. // int
  45. // _setjmpex (
  46. // IN jmp_buf JumpBuffer
  47. // )
  48. //
  49. // Routine Description:
  50. //
  51. // This function implements a safe setjmp.
  52. //
  53. // Arguments:
  54. //
  55. // JumpBuffer (a0) - Supplies the address of a jump buffer to store the
  56. // jump information.
  57. //
  58. // Return Value:
  59. //
  60. // A value of zero is returned.
  61. //
  62. //--
  63. .struct 0
  64. SjRa: .space 8 // saved return address
  65. SjS0: .space 8 // saved integer register s0
  66. SjFl: .space 8 // InFunction flag variable
  67. SjEf: .space 8 // EstablisherFrame(s) structure
  68. SjCx: .space ContextFrameLength // context frame
  69. SetjmpFrameLength:
  70. NESTED_ENTRY(_setjmpex, SetjmpFrameLength, zero)
  71. lda sp, -SetjmpFrameLength(sp) // allocate stack frame
  72. stq ra, SjRa(sp) // save return address
  73. stq s0, SjS0(sp) // save integer register s0
  74. PROLOGUE_END
  75. //
  76. // Save the nonvolatile machine state.
  77. //
  78. lda t0, SjCx(sp) // address of context record
  79. stt f2, CxFltF2(t0) // save floating registers f2 - f9
  80. stt f3, CxFltF3(t0) //
  81. stt f4, CxFltF4(t0) //
  82. stt f5, CxFltF5(t0) //
  83. stt f6, CxFltF6(t0) //
  84. stt f7, CxFltF7(t0) //
  85. stt f8, CxFltF8(t0) //
  86. stt f9, CxFltF9(t0) //
  87. stq s0, CxIntS0(t0) // save integer registers s0 - fp/s6
  88. stq s1, CxIntS1(t0) //
  89. stq s2, CxIntS2(t0) //
  90. stq s3, CxIntS3(t0) //
  91. stq s4, CxIntS4(t0) //
  92. stq s5, CxIntS5(t0) //
  93. stq fp, CxIntFp(t0) //
  94. stq gp, CxIntGp(t0) // save integer register gp
  95. lda v0, SetjmpFrameLength(sp) // compute stack pointer address
  96. stq v0, CxIntSp(t0) // save stack pointer
  97. stq ra, CxIntRa(t0) // save return address
  98. stq ra, CxFir(t0) // save continuation address
  99. ldil t1, 2 // get acc safe setjmp flag
  100. stl t1, JbType(a0) // set jump buffer context type
  101. stl ra, JbPc(a0) // save target instruction address
  102. mov a0, s0 // preserve jump buffer address
  103. //
  104. // Perform unwind to determine the virtual frame pointer of the caller.
  105. //
  106. subl ra, 4, a0 // compute control PC address
  107. bsr RtlLookupFunctionEntry // lookup function table address
  108. ldq a0, SjRa(sp) // get return address
  109. subl a0, 4, a0 // compute control PC address
  110. mov v0, a1 // set address of function entry
  111. lda a2, SjCx(sp) // address of context record
  112. lda a3, SjFl(sp) // set address of in function variable
  113. lda a4, SjEf(sp) // set frame pointers address
  114. mov zero, a5 // set context pointer array address
  115. bsr RtlVirtualUnwind // compute virtual frame pointer value
  116. //
  117. // Set return value, restore registers, deallocate stack frame, and return.
  118. //
  119. ldl t0, SjEf(sp) // get virtual frame pointer
  120. stl t0, JbFp(s0) // save virtual frame pointer address
  121. mov zero, v0 // set return value
  122. ldq s0, SjS0(sp) // restore integer register s0
  123. ldq ra, SjRa(sp) // restore return address
  124. lda sp, SetjmpFrameLength(sp) // deallocate stack frame
  125. ret zero, (ra) // return
  126. .end _setjmpex