setjump.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by xxxx
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {**********************************************************************
  12. Set_Jmp/Long_jmp
  13. **********************************************************************}
  14. {$warning Fix register handling in case of nostackframe }
  15. Function fpc_SetJmp (Var S : Jmp_buf) : longint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP'];compilerproc;
  16. asm
  17. // Temporarily store a0 into d0
  18. move.l a0,d0
  19. // load S to a0
  20. move.l 4(sp), a0
  21. // save a0 (now in d0) to offset 40
  22. move.l d0, 40(a0)
  23. // save return address (PC)
  24. move.l (sp), d0
  25. move.l d0, 8(a0)
  26. // save FP
  27. {$if defined(amiga)}
  28. move.l a5, (a0)
  29. {$else}
  30. move.l a6, (a0)
  31. {$endif}
  32. // save SP
  33. move.l sp, d0
  34. addq.l #8, d0
  35. move.l d0, 4(a0)
  36. // save a1
  37. move.l a1,d0
  38. move.l d0,44(a0)
  39. // save a2
  40. move.l a2,d0
  41. move.l d0,48(a0)
  42. // save a3
  43. move.l a3,d0
  44. move.l d0,52(a0)
  45. // save a4
  46. move.l a4,d0
  47. move.l d0,56(a0)
  48. // save a5
  49. move.l a5,d0
  50. move.l d0,60(a0)
  51. // save d1..d7
  52. move d1, 12(a0)
  53. move d2, 16(a0)
  54. move d3, 20(a0)
  55. move d4, 24(a0)
  56. move d5, 28(a0)
  57. move d6, 32(a0)
  58. move d7, 36(a0)
  59. // restore a0
  60. move.l 40(a0), a0
  61. // return 0
  62. clr.l d0
  63. end;
  64. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  65. asm
  66. // load S to a0
  67. move.l 4(sp),a0
  68. // Restore address registers
  69. // restore a1
  70. move.l 44(a0),d0
  71. move.l d0,a1
  72. // restore a2
  73. move.l 48(a0),d0
  74. move.l d0,a2
  75. // restore a3
  76. move.l 52(a0),d0
  77. move.l d0,a3
  78. // restore a4
  79. move.l 56(a0),d0
  80. move.l d0,a4
  81. // restore a5
  82. move.l 60(a0),d0
  83. move.l d0,a5
  84. // restore d1..d7
  85. move 12(a0),d1
  86. move 16(a0),d2
  87. move 20(a0),d3
  88. move 24(a0),d4
  89. move 28(a0),d5
  90. move 32(a0),d6
  91. move 36(a0),d7
  92. // load value to d0
  93. move.l 8(sp),d0
  94. // Save temporarily into d1 slot
  95. move.l d0,12(a0)
  96. // restore FP
  97. {$if defined(amiga)}
  98. move.l (a0), a5
  99. {$else}
  100. move.l (a0), a6
  101. {$endif}
  102. // restore SP
  103. move.l 4(a0), sp
  104. // jump to PC
  105. move.l 8(a0),d0
  106. move.l d0,-(sp)
  107. // restore a0
  108. move.l 40(a0),d0
  109. move.l d0,-(sp)
  110. // restore return value, now at 12(a0)
  111. move.l 12(a0),d0
  112. // restore a0 from stack
  113. move.l (sp)+,a0
  114. // new return pc is at (sp), so we can call rts
  115. rts
  116. end;