setjump.inc 2.5 KB

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