setjmpa.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. setjmpa.S
  9. Abstract:
  10. This module implements functionality for non-local goto statements.
  11. Author:
  12. Evan Green 28-Jul-2013
  13. Environment:
  14. User Mode C Library
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <minoca/kernel/arm.inc>
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. #define JUMP_BUFFER_SAVE_MASK 0x00
  24. //
  25. // This offset represents the start offset of the registers in the jump buffer.
  26. //
  27. #define JUMP_BUFFER_REGISTER_OFFSET 0x0C
  28. //
  29. // This offset represents the end of the registers in the jump buffer.
  30. //
  31. #define JUMP_BUFFER_REGISTER_END_OFFSET 0x34
  32. //
  33. // ----------------------------------------------------------------------- Code
  34. //
  35. ASSEMBLY_FILE_HEADER
  36. //
  37. // int
  38. // setjmp (
  39. // jmp_buf Environment
  40. // )
  41. //
  42. /*++
  43. Routine Description:
  44. This routine saves the calling environment into the given buffer for
  45. later use by longjmp.
  46. Arguments:
  47. Environment - Supplies the pointer to the environment to save the
  48. application context in.
  49. Return Value:
  50. 0 if this was the direct call to set jump.
  51. Non-zero if this was a call from long jump.
  52. --*/
  53. EXPORTED_FUNCTION _setjmp
  54. END_FUNCTION _setjmp
  55. EXPORTED_FUNCTION setjmp
  56. //
  57. // Clear out the boolean indicating whether or not the mask was saved.
  58. //
  59. mov %r2, #0
  60. str %r2, [%r0, #JUMP_BUFFER_SAVE_MASK]
  61. //
  62. // Save the registers.
  63. //
  64. ldr %r2, =JUMP_BUFFER_REGISTER_END_OFFSET
  65. add %r2, %r0, %r2
  66. mov %r12, %sp
  67. stmdb %r2, {%r4-%r11, %r12, %lr}
  68. //
  69. // Return 0.
  70. //
  71. mov %r0, #0
  72. bx %lr
  73. END_FUNCTION setjmp
  74. //
  75. // int
  76. // sigsetjmp (
  77. // sigjmp_buf Environment,
  78. // int SaveMask
  79. // )
  80. //
  81. /*++
  82. Routine Description:
  83. This routine saves the calling environment into the given buffer for
  84. later use by longjmp.
  85. Arguments:
  86. Environment - Supplies the pointer to the environment to save the
  87. application context in.
  88. SaveMask - Supplies a value indicating if the caller would like the
  89. current signal mask to be saved in the environment as well.
  90. Return Value:
  91. 0 if this was the direct call to setjmp.
  92. Non-zero if this was a call from longjmp.
  93. --*/
  94. EXPORTED_FUNCTION sigsetjmp
  95. //
  96. // Save the registers.
  97. //
  98. ldr %r2, =JUMP_BUFFER_REGISTER_END_OFFSET
  99. add %r2, %r0, %r2
  100. mov %r12, %sp
  101. stmdb %r2, {%r4-%r11, %r12, %lr}
  102. //
  103. // Call the helper routine to potentially save the mask.
  104. //
  105. stmdb %sp!, {%lr} @ Save the original lr.
  106. bl ClpSetJump @ Call the helper with the same parameters.
  107. ldmia %sp!, {%lr} @ Restore lr.
  108. //
  109. // Return 0.
  110. //
  111. mov %r0, #0
  112. bx %lr
  113. END_FUNCTION sigsetjmp
  114. //
  115. // void
  116. // ClpLongJump (
  117. // jmp_buf Environment,
  118. // int Value
  119. // )
  120. //
  121. /*++
  122. Routine Description:
  123. This routine restores given environment.
  124. Arguments:
  125. Environment - Supplies a pointer to the environment to restore.
  126. Value - Supplies the value to make appear as the return value from the
  127. set jump function.
  128. Return Value:
  129. None, the function does not return.
  130. --*/
  131. FUNCTION ClpLongJump
  132. ldr %r2, =JUMP_BUFFER_REGISTER_OFFSET
  133. add %r2, %r0, %r2
  134. mov %r0, %r1
  135. ldmia %r2, {%r4-%r11, %r12, %lr}
  136. mov %sp, %r12
  137. bx %lr
  138. END_FUNCTION ClpLongJump