setjump.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2016 by the Free Pascal development team.
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {**********************************************************************
  11. Set_Jmp/Long_jmp
  12. **********************************************************************}
  13. {$warning Fix register handling in case of nostackframe }
  14. Function fpc_SetJmp (Var S : Jmp_buf) : longint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP'];compilerproc;
  15. asm
  16. {$ifndef REGCALL}
  17. // load S to a0
  18. // with register convention S is in a0 already
  19. move.l 4(sp),a0
  20. {$endif}
  21. // Save nonvolatile registers
  22. {$ifdef ver3_0}
  23. {$if defined(amiga)}
  24. movem.l d2/d3/d4/d5/d6/d7/a2/a3/a4/a6,12(a0) { amiga uses a5 as fp }
  25. {$else}
  26. movem.l d2/d3/d4/d5/d6/d7/a2/a3/a4/a5,12(a0)
  27. {$endif}
  28. {$else}
  29. {$if defined(amiga)}
  30. movem.l d2-d7/a2-a4/a6,12(a0) { amiga uses a5 as fp }
  31. {$else}
  32. movem.l d2-d7/a2-a5,12(a0)
  33. {$endif}
  34. {$endif}
  35. {$if defined(fpu68881) or defined(fpucoldfire)}
  36. fmove.l fpcr,d0
  37. move.l d0,52(a0)
  38. {$endif}
  39. {$if defined(fpu68881)}
  40. fmovem.x fp2-fp7,56(a0)
  41. {$elseif defined(fpucoldfire)}
  42. fmovem.d fp2-fp7,56(a0)
  43. {$endif}
  44. // save FP
  45. move.l fp,(a0)
  46. {$ifndef REGCALL}
  47. // save return address (PC) and pop S off the stack
  48. move.l (sp)+,d0
  49. move.l d0,(sp)
  50. {$else}
  51. move.l (sp),d0
  52. {$endif}
  53. move.l d0,8(a0)
  54. // save SP
  55. move.l sp,d0
  56. // 4 bytes already popped, 4 to go.
  57. addq.l #4,d0
  58. move.l d0,4(a0)
  59. // return 0
  60. clr.l d0
  61. end;
  62. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  63. asm
  64. {$ifndef REGCALL}
  65. // load S to a0
  66. move.l 4(sp),a0
  67. // load 'value' to d0
  68. move.l 8(sp),d0
  69. {$else}
  70. // with register calling convention
  71. // S is in a0 and value is in d0 already
  72. tst.l d0
  73. {$endif}
  74. // don't return zero
  75. bne @valueok
  76. moveq.l #1,d0
  77. @valueok:
  78. // restore FP
  79. move.l (a0),fp
  80. // restore SP
  81. move.l 4(a0),sp
  82. // jump to PC
  83. move.l 8(a0),-(sp)
  84. // Restore registers
  85. {$ifdef ver3_0}
  86. {$if defined(amiga)}
  87. movem.l 12(a0),d2/d3/d4/d5/d6/d7/a2/a3/a4/a6 { amiga uses a5 as fp }
  88. {$else}
  89. movem.l 12(a0),d2/d3/d4/d5/d6/d7/a2/a3/a4/a5
  90. {$endif}
  91. {$else}
  92. {$if defined(amiga)}
  93. movem.l 12(a0),d2-d7/a2-a4/a6 { amiga uses a5 as fp }
  94. {$else}
  95. movem.l 12(a0),d2-d7/a2-a5
  96. {$endif}
  97. {$endif}
  98. {$if defined(fpu68881) or defined(fpucoldfire)}
  99. move.l 52(a0),d1
  100. fmove.l d1,fpcr
  101. {$endif}
  102. {$if defined(fpu68881)}
  103. fmovem.x 56(a0),fp2-fp7
  104. {$elseif defined(fpucoldfire)}
  105. fmovem.d 56(a0),fp2-fp7
  106. {$endif}
  107. // new return pc is at (sp)
  108. end;