setjump.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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)}
  36. fmovem.x fp2-fp7,52(a0)
  37. {$elseif defined(fpucoldfire)}
  38. fmovem.d fp2-fp7,52(a0)
  39. {$endif}
  40. // save FP
  41. move.l fp,(a0)
  42. {$ifndef REGCALL}
  43. // save return address (PC) and pop S off the stack
  44. move.l (sp)+,d0
  45. move.l d0,(sp)
  46. {$else}
  47. move.l (sp),d0
  48. {$endif}
  49. move.l d0,8(a0)
  50. // save SP
  51. move.l sp,d0
  52. // 4 bytes already popped, 4 to go.
  53. addq.l #4,d0
  54. move.l d0,4(a0)
  55. // return 0
  56. clr.l d0
  57. end;
  58. Procedure fpc_longJmp (Var S : Jmp_buf; value : longint); assembler;nostackframe;[Public, alias : 'FPC_LONGJMP'];compilerproc;
  59. asm
  60. {$ifndef REGCALL}
  61. // load S to a0
  62. move.l 4(sp),a0
  63. // load 'value' to d0
  64. move.l 8(sp),d0
  65. {$else}
  66. // with register calling convention
  67. // S is in a0 and value is in d0 already
  68. tst.l d0
  69. {$endif}
  70. // don't return zero
  71. bne @valueok
  72. moveq.l #1,d0
  73. @valueok:
  74. // restore FP
  75. move.l (a0),fp
  76. // restore SP
  77. move.l 4(a0),sp
  78. // jump to PC
  79. move.l 8(a0),-(sp)
  80. // Restore registers
  81. {$ifdef ver3_0}
  82. {$if defined(amiga)}
  83. movem.l 12(a0),d2/d3/d4/d5/d6/d7/a2/a3/a4/a6 { amiga uses a5 as fp }
  84. {$else}
  85. movem.l 12(a0),d2/d3/d4/d5/d6/d7/a2/a3/a4/a5
  86. {$endif}
  87. {$else}
  88. {$if defined(amiga)}
  89. movem.l 12(a0),d2-d7/a2-a4/a6 { amiga uses a5 as fp }
  90. {$else}
  91. movem.l 12(a0),d2-d7/a2-a5
  92. {$endif}
  93. {$endif}
  94. {$if defined(fpu68881)}
  95. fmovem.x 52(a0),fp2-fp7
  96. {$elseif defined(fpucoldfire)}
  97. fmovem.d 52(a0),fp2-fp7
  98. {$endif}
  99. // new return pc is at (sp)
  100. end;